From 869be4378d44e08c686b550a86a5e4fa60915edb Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Fri, 5 Jan 2018 22:05:48 +0100 Subject: [PATCH 1/3] commands: add 'reload' command --- sway/commands.c | 1 + sway/commands/reload.c | 21 +++++++++++++++++++++ sway/config.c | 4 ++++ sway/meson.build | 1 + 4 files changed, 27 insertions(+) create mode 100644 sway/commands/reload.c diff --git a/sway/commands.c b/sway/commands.c index a77ff791..d4262c08 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -136,6 +136,7 @@ static struct cmd_handler handlers[] = { { "input", cmd_input }, { "kill", cmd_kill }, { "output", cmd_output }, + { "reload", cmd_reload }, { "seat", cmd_seat }, { "set", cmd_set }, }; diff --git a/sway/commands/reload.c b/sway/commands/reload.c new file mode 100644 index 00000000..2b553845 --- /dev/null +++ b/sway/commands/reload.c @@ -0,0 +1,21 @@ +#include "sway/commands.h" +#include "sway/config.h" +#include "sway/layout.h" + +struct cmd_results *cmd_reload(int argc, char **argv) { + struct cmd_results *error = NULL; + if (config->reading) { + return cmd_results_new(CMD_FAILURE, "reload", "Can't be used in config file."); + } + if ((error = checkarg(argc, "reload", EXPECTED_EQUAL_TO, 0))) { + return error; + } + if (!load_main_config(config->current_config, true)) { + return cmd_results_new(CMD_FAILURE, "reload", "Error(s) reloading config."); + } + + load_swaybars(); + + arrange_windows(&root_container, -1, -1); + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} diff --git a/sway/config.c b/sway/config.c index 1fd123b7..cb22f664 100644 --- a/sway/config.c +++ b/sway/config.c @@ -698,3 +698,7 @@ char *do_var_replacement(char *str) { } return str; } + +void load_swaybars() { + /* stub function for reload commnd, to fill when we restore swaybars */ +} diff --git a/sway/meson.build b/sway/meson.build index 80ccc01d..51e9e4db 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -34,6 +34,7 @@ sway_sources = files( 'commands/input/xkb_rules.c', 'commands/input/xkb_variant.c', 'commands/output.c', + 'commands/reload.c', 'config.c', 'config/output.c', 'config/seat.c', From 5766f426aac11bf39234dcca4c479ee865081dad Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Tue, 16 Jan 2018 21:16:04 +0100 Subject: [PATCH 2/3] 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 --- include/sway/input/cursor.h | 1 + include/sway/input/input-manager.h | 2 ++ include/sway/input/seat.h | 2 ++ sway/config.c | 19 +++++++++++++++++++ sway/input/cursor.c | 10 ++++++++++ sway/input/input-manager.c | 2 +- sway/input/seat.c | 10 ++++++++++ 7 files changed, 45 insertions(+), 1 deletion(-) diff --git a/include/sway/input/cursor.h b/include/sway/input/cursor.h index 2f70cf4b..a16b793b 100644 --- a/include/sway/input/cursor.h +++ b/include/sway/input/cursor.h @@ -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 diff --git a/include/sway/input/input-manager.h b/include/sway/input/input-manager.h index 2bf297ce..63806b8e 100644 --- a/include/sway/input/input-manager.h +++ b/include/sway/input/input-manager.h @@ -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 diff --git a/include/sway/input/seat.h b/include/sway/input/seat.h index d703f94c..b21cbccb 100644 --- a/include/sway/input/seat.h +++ b/include/sway/input/seat.h @@ -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); diff --git a/sway/config.c b/sway/config.c index cb22f664..0f91cce6 100644 --- a/sway/config.c +++ b/sway/config.c @@ -21,6 +21,7 @@ #endif #include #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; diff --git a/sway/input/cursor.c b/sway/input/cursor.c index e6a4eca8..73a8ec5c 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -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")) { diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c index 2d119cf2..12b3a430 100644 --- a/sway/input/input-manager.c +++ b/sway/input/input-manager.c @@ -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) { diff --git a/sway/input/seat.c b/sway/input/seat.c index e9b375e0..9ea08eec 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -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)); From 6259831d3168898a3f1560fb832106d194b582b4 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Mon, 22 Jan 2018 07:19:12 +0100 Subject: [PATCH 3/3] commands/reload: remove unimplemented 'load_swaybars' call --- sway/commands/reload.c | 2 +- sway/config.c | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/sway/commands/reload.c b/sway/commands/reload.c index 2b553845..419c7de3 100644 --- a/sway/commands/reload.c +++ b/sway/commands/reload.c @@ -14,7 +14,7 @@ struct cmd_results *cmd_reload(int argc, char **argv) { return cmd_results_new(CMD_FAILURE, "reload", "Error(s) reloading config."); } - load_swaybars(); + /* load_swaybars(); -- for when it's implemented */ arrange_windows(&root_container, -1, -1); return cmd_results_new(CMD_SUCCESS, NULL, NULL); diff --git a/sway/config.c b/sway/config.c index 0f91cce6..a67322d1 100644 --- a/sway/config.c +++ b/sway/config.c @@ -717,7 +717,3 @@ char *do_var_replacement(char *str) { } return str; } - -void load_swaybars() { - /* stub function for reload commnd, to fill when we restore swaybars */ -}