diff options
author | Drew DeVault <sir@cmpwn.com> | 2018-01-29 16:16:23 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-29 16:16:23 -0500 |
commit | 38903e580166b1fd4b55daa0c8b60d40f805f31c (patch) | |
tree | d74612bada10c8300d8c7f9ccdc16e57280cb03b | |
parent | Merge pull request #1574 from acrisci/config-refactor (diff) | |
parent | commands/reload: remove unimplemented 'load_swaybars' call (diff) | |
download | sway-38903e580166b1fd4b55daa0c8b60d40f805f31c.tar.gz sway-38903e580166b1fd4b55daa0c8b60d40f805f31c.tar.zst sway-38903e580166b1fd4b55daa0c8b60d40f805f31c.zip |
Merge pull request #1555 from martinetd/cmd_reload
commands: add 'reload' command
-rw-r--r-- | include/sway/input/cursor.h | 1 | ||||
-rw-r--r-- | include/sway/input/input-manager.h | 2 | ||||
-rw-r--r-- | include/sway/input/seat.h | 2 | ||||
-rw-r--r-- | sway/commands.c | 1 | ||||
-rw-r--r-- | sway/commands/reload.c | 21 | ||||
-rw-r--r-- | sway/config.c | 19 | ||||
-rw-r--r-- | sway/input/cursor.c | 10 | ||||
-rw-r--r-- | sway/input/input-manager.c | 2 | ||||
-rw-r--r-- | sway/input/seat.c | 10 | ||||
-rw-r--r-- | sway/meson.build | 1 |
10 files changed, 68 insertions, 1 deletions
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 { | |||
25 | struct wl_listener request_set_cursor; | 25 | struct wl_listener request_set_cursor; |
26 | }; | 26 | }; |
27 | 27 | ||
28 | void sway_cursor_destroy(struct sway_cursor *cursor); | ||
28 | struct sway_cursor *sway_cursor_create(struct sway_seat *seat); | 29 | struct sway_cursor *sway_cursor_create(struct sway_seat *seat); |
29 | 30 | ||
30 | #endif | 31 | #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, | |||
46 | struct sway_seat *sway_input_manager_get_default_seat( | 46 | struct sway_seat *sway_input_manager_get_default_seat( |
47 | struct sway_input_manager *input); | 47 | struct sway_input_manager *input); |
48 | 48 | ||
49 | struct sway_seat *input_manager_get_seat(struct sway_input_manager *input, | ||
50 | const char *seat_name); | ||
49 | #endif | 51 | #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 { | |||
29 | struct sway_seat *sway_seat_create(struct sway_input_manager *input, | 29 | struct sway_seat *sway_seat_create(struct sway_input_manager *input, |
30 | const char *seat_name); | 30 | const char *seat_name); |
31 | 31 | ||
32 | void sway_seat_destroy(struct sway_seat *seat); | ||
33 | |||
32 | void sway_seat_add_device(struct sway_seat *seat, | 34 | void sway_seat_add_device(struct sway_seat *seat, |
33 | struct sway_input_device *device); | 35 | struct sway_input_device *device); |
34 | 36 | ||
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[] = { | |||
136 | { "input", cmd_input }, | 136 | { "input", cmd_input }, |
137 | { "kill", cmd_kill }, | 137 | { "kill", cmd_kill }, |
138 | { "output", cmd_output }, | 138 | { "output", cmd_output }, |
139 | { "reload", cmd_reload }, | ||
139 | { "seat", cmd_seat }, | 140 | { "seat", cmd_seat }, |
140 | { "set", cmd_set }, | 141 | { "set", cmd_set }, |
141 | }; | 142 | }; |
diff --git a/sway/commands/reload.c b/sway/commands/reload.c new file mode 100644 index 00000000..419c7de3 --- /dev/null +++ b/sway/commands/reload.c | |||
@@ -0,0 +1,21 @@ | |||
1 | #include "sway/commands.h" | ||
2 | #include "sway/config.h" | ||
3 | #include "sway/layout.h" | ||
4 | |||
5 | struct cmd_results *cmd_reload(int argc, char **argv) { | ||
6 | struct cmd_results *error = NULL; | ||
7 | if (config->reading) { | ||
8 | return cmd_results_new(CMD_FAILURE, "reload", "Can't be used in config file."); | ||
9 | } | ||
10 | if ((error = checkarg(argc, "reload", EXPECTED_EQUAL_TO, 0))) { | ||
11 | return error; | ||
12 | } | ||
13 | if (!load_main_config(config->current_config, true)) { | ||
14 | return cmd_results_new(CMD_FAILURE, "reload", "Error(s) reloading config."); | ||
15 | } | ||
16 | |||
17 | /* load_swaybars(); -- for when it's implemented */ | ||
18 | |||
19 | arrange_windows(&root_container, -1, -1); | ||
20 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
21 | } | ||
diff --git a/sway/config.c b/sway/config.c index 1fd123b7..a67322d1 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -21,6 +21,7 @@ | |||
21 | #endif | 21 | #endif |
22 | #include <wlr/types/wlr_output.h> | 22 | #include <wlr/types/wlr_output.h> |
23 | #include "sway/input/input-manager.h" | 23 | #include "sway/input/input-manager.h" |
24 | #include "sway/input/seat.h" | ||
24 | #include "sway/commands.h" | 25 | #include "sway/commands.h" |
25 | #include "sway/config.h" | 26 | #include "sway/config.h" |
26 | #include "sway/layout.h" | 27 | #include "sway/layout.h" |
@@ -109,6 +110,23 @@ void free_config(struct sway_config *config) { | |||
109 | free(config); | 110 | free(config); |
110 | } | 111 | } |
111 | 112 | ||
113 | static void destroy_removed_seats(struct sway_config *old_config, | ||
114 | struct sway_config *new_config) { | ||
115 | struct seat_config *seat_config; | ||
116 | struct sway_seat *seat; | ||
117 | int i; | ||
118 | for (i = 0; i < old_config->seat_configs->length; i++) { | ||
119 | seat_config = old_config->seat_configs->items[i]; | ||
120 | /* Also destroy seats that aren't present in new config */ | ||
121 | if (new_config && list_seq_find(new_config->seat_configs, | ||
122 | seat_name_cmp, seat_config->name) < 0) { | ||
123 | seat = input_manager_get_seat(input_manager, | ||
124 | seat_config->name); | ||
125 | sway_seat_destroy(seat); | ||
126 | } | ||
127 | } | ||
128 | } | ||
129 | |||
112 | static void config_defaults(struct sway_config *config) { | 130 | static void config_defaults(struct sway_config *config) { |
113 | if (!(config->symbols = create_list())) goto cleanup; | 131 | if (!(config->symbols = create_list())) goto cleanup; |
114 | if (!(config->modes = create_list())) goto cleanup; | 132 | if (!(config->modes = create_list())) goto cleanup; |
@@ -382,6 +400,7 @@ bool load_main_config(const char *file, bool is_active) { | |||
382 | } | 400 | } |
383 | 401 | ||
384 | if (old_config) { | 402 | if (old_config) { |
403 | destroy_removed_seats(old_config, config); | ||
385 | free_config(old_config); | 404 | free_config(old_config); |
386 | } | 405 | } |
387 | config->reading = false; | 406 | 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, | |||
149 | wlr_log(L_DEBUG, "TODO: handle request set cursor event: %p", event); | 149 | wlr_log(L_DEBUG, "TODO: handle request set cursor event: %p", event); |
150 | } | 150 | } |
151 | 151 | ||
152 | void sway_cursor_destroy(struct sway_cursor *cursor) { | ||
153 | if (!cursor) { | ||
154 | return; | ||
155 | } | ||
156 | |||
157 | wlr_xcursor_manager_destroy(cursor->xcursor_manager); | ||
158 | wlr_cursor_destroy(cursor->cursor); | ||
159 | free(cursor); | ||
160 | } | ||
161 | |||
152 | struct sway_cursor *sway_cursor_create(struct sway_seat *seat) { | 162 | struct sway_cursor *sway_cursor_create(struct sway_seat *seat) { |
153 | struct sway_cursor *cursor = calloc(1, sizeof(struct sway_cursor)); | 163 | struct sway_cursor *cursor = calloc(1, sizeof(struct sway_cursor)); |
154 | if (!sway_assert(cursor, "could not allocate sway cursor")) { | 164 | 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; | |||
23 | struct input_config *current_input_config = NULL; | 23 | struct input_config *current_input_config = NULL; |
24 | struct seat_config *current_seat_config = NULL; | 24 | struct seat_config *current_seat_config = NULL; |
25 | 25 | ||
26 | static struct sway_seat *input_manager_get_seat( | 26 | struct sway_seat *input_manager_get_seat( |
27 | struct sway_input_manager *input, const char *seat_name) { | 27 | struct sway_input_manager *input, const char *seat_name) { |
28 | struct sway_seat *seat = NULL; | 28 | struct sway_seat *seat = NULL; |
29 | wl_list_for_each(seat, &input->seats, link) { | 29 | 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) { | |||
21 | free(seat_device); | 21 | free(seat_device); |
22 | } | 22 | } |
23 | 23 | ||
24 | void sway_seat_destroy(struct sway_seat *seat) { | ||
25 | struct sway_seat_device *seat_device, *next; | ||
26 | wl_list_for_each_safe(seat_device, next, &seat->devices, link) { | ||
27 | seat_device_destroy(seat_device); | ||
28 | } | ||
29 | sway_cursor_destroy(seat->cursor); | ||
30 | wl_list_remove(&seat->link); | ||
31 | wlr_seat_destroy(seat->wlr_seat); | ||
32 | } | ||
33 | |||
24 | struct sway_seat *sway_seat_create(struct sway_input_manager *input, | 34 | struct sway_seat *sway_seat_create(struct sway_input_manager *input, |
25 | const char *seat_name) { | 35 | const char *seat_name) { |
26 | struct sway_seat *seat = calloc(1, sizeof(struct sway_seat)); | 36 | struct sway_seat *seat = calloc(1, sizeof(struct sway_seat)); |
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( | |||
34 | 'commands/input/xkb_rules.c', | 34 | 'commands/input/xkb_rules.c', |
35 | 'commands/input/xkb_variant.c', | 35 | 'commands/input/xkb_variant.c', |
36 | 'commands/output.c', | 36 | 'commands/output.c', |
37 | 'commands/reload.c', | ||
37 | 'config.c', | 38 | 'config.c', |
38 | 'config/output.c', | 39 | 'config/output.c', |
39 | 'config/seat.c', | 40 | 'config/seat.c', |