config reload: destroy old seat when removed from config

This adds new sway_seat_destroy and sway_cursor_destroy helpers
and compare new and old config on free
This commit is contained in:
Dominique Martinet 2018-01-16 21:16:04 +01:00
parent 869be4378d
commit 5766f426aa
7 changed files with 45 additions and 1 deletions

View file

@ -25,6 +25,7 @@ struct sway_cursor {
struct wl_listener request_set_cursor;
};
void sway_cursor_destroy(struct sway_cursor *cursor);
struct sway_cursor *sway_cursor_create(struct sway_seat *seat);
#endif

View file

@ -46,4 +46,6 @@ void sway_input_manager_apply_seat_config(struct sway_input_manager *input,
struct sway_seat *sway_input_manager_get_default_seat(
struct sway_input_manager *input);
struct sway_seat *input_manager_get_seat(struct sway_input_manager *input,
const char *seat_name);
#endif

View file

@ -29,6 +29,8 @@ struct sway_seat {
struct sway_seat *sway_seat_create(struct sway_input_manager *input,
const char *seat_name);
void sway_seat_destroy(struct sway_seat *seat);
void sway_seat_add_device(struct sway_seat *seat,
struct sway_input_device *device);

View file

@ -21,6 +21,7 @@
#endif
#include <wlr/types/wlr_output.h>
#include "sway/input/input-manager.h"
#include "sway/input/seat.h"
#include "sway/commands.h"
#include "sway/config.h"
#include "sway/layout.h"
@ -109,6 +110,23 @@ void free_config(struct sway_config *config) {
free(config);
}
static void destroy_removed_seats(struct sway_config *old_config,
struct sway_config *new_config) {
struct seat_config *seat_config;
struct sway_seat *seat;
int i;
for (i = 0; i < old_config->seat_configs->length; i++) {
seat_config = old_config->seat_configs->items[i];
/* Also destroy seats that aren't present in new config */
if (new_config && list_seq_find(new_config->seat_configs,
seat_name_cmp, seat_config->name) < 0) {
seat = input_manager_get_seat(input_manager,
seat_config->name);
sway_seat_destroy(seat);
}
}
}
static void config_defaults(struct sway_config *config) {
if (!(config->symbols = create_list())) goto cleanup;
if (!(config->modes = create_list())) goto cleanup;
@ -382,6 +400,7 @@ bool load_main_config(const char *file, bool is_active) {
}
if (old_config) {
destroy_removed_seats(old_config, config);
free_config(old_config);
}
config->reading = false;

View file

@ -149,6 +149,16 @@ static void handle_request_set_cursor(struct wl_listener *listener,
wlr_log(L_DEBUG, "TODO: handle request set cursor event: %p", event);
}
void sway_cursor_destroy(struct sway_cursor *cursor) {
if (!cursor) {
return;
}
wlr_xcursor_manager_destroy(cursor->xcursor_manager);
wlr_cursor_destroy(cursor->cursor);
free(cursor);
}
struct sway_cursor *sway_cursor_create(struct sway_seat *seat) {
struct sway_cursor *cursor = calloc(1, sizeof(struct sway_cursor));
if (!sway_assert(cursor, "could not allocate sway cursor")) {

View file

@ -23,7 +23,7 @@ struct sway_input_manager *input_manager;
struct input_config *current_input_config = NULL;
struct seat_config *current_seat_config = NULL;
static struct sway_seat *input_manager_get_seat(
struct sway_seat *input_manager_get_seat(
struct sway_input_manager *input, const char *seat_name) {
struct sway_seat *seat = NULL;
wl_list_for_each(seat, &input->seats, link) {

View file

@ -21,6 +21,16 @@ static void seat_device_destroy(struct sway_seat_device *seat_device) {
free(seat_device);
}
void sway_seat_destroy(struct sway_seat *seat) {
struct sway_seat_device *seat_device, *next;
wl_list_for_each_safe(seat_device, next, &seat->devices, link) {
seat_device_destroy(seat_device);
}
sway_cursor_destroy(seat->cursor);
wl_list_remove(&seat->link);
wlr_seat_destroy(seat->wlr_seat);
}
struct sway_seat *sway_seat_create(struct sway_input_manager *input,
const char *seat_name) {
struct sway_seat *seat = calloc(1, sizeof(struct sway_seat));