diff options
-rw-r--r-- | include/sway/config.h | 2 | ||||
-rw-r--r-- | sway/commands.c | 15 | ||||
-rw-r--r-- | sway/commands/seat.c | 13 | ||||
-rw-r--r-- | sway/commands/seat/attach.c | 21 | ||||
-rw-r--r-- | sway/commands/seat/fallback.c | 19 | ||||
-rw-r--r-- | sway/config/seat.c | 52 | ||||
-rw-r--r-- | sway/input/input-manager.c | 39 |
7 files changed, 96 insertions, 65 deletions
diff --git a/include/sway/config.h b/include/sway/config.h index 7ee2ec71..6610f009 100644 --- a/include/sway/config.h +++ b/include/sway/config.h | |||
@@ -536,7 +536,7 @@ struct seat_attachment_config *seat_attachment_config_new(void); | |||
536 | struct seat_attachment_config *seat_config_get_attachment( | 536 | struct seat_attachment_config *seat_config_get_attachment( |
537 | struct seat_config *seat_config, char *identifier); | 537 | struct seat_config *seat_config, char *identifier); |
538 | 538 | ||
539 | void apply_seat_config(struct seat_config *seat); | 539 | struct seat_config *store_seat_config(struct seat_config *seat); |
540 | 540 | ||
541 | int output_name_cmp(const void *item, const void *data); | 541 | int output_name_cmp(const void *item, const void *data); |
542 | 542 | ||
diff --git a/sway/commands.c b/sway/commands.c index eda29c65..51bfe13a 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -42,21 +42,6 @@ struct cmd_results *checkarg(int argc, const char *name, enum expected_args type | |||
42 | : NULL; | 42 | : NULL; |
43 | } | 43 | } |
44 | 44 | ||
45 | void apply_seat_config(struct seat_config *seat_config) { | ||
46 | int i = list_seq_find(config->seat_configs, seat_name_cmp, seat_config->name); | ||
47 | if (i >= 0) { | ||
48 | // merge existing config | ||
49 | struct seat_config *sc = config->seat_configs->items[i]; | ||
50 | merge_seat_config(sc, seat_config); | ||
51 | free_seat_config(seat_config); | ||
52 | seat_config = sc; | ||
53 | } else { | ||
54 | list_add(config->seat_configs, seat_config); | ||
55 | } | ||
56 | |||
57 | input_manager_apply_seat_config(seat_config); | ||
58 | } | ||
59 | |||
60 | /* Keep alphabetized */ | 45 | /* Keep alphabetized */ |
61 | static struct cmd_handler handlers[] = { | 46 | static struct cmd_handler handlers[] = { |
62 | { "assign", cmd_assign }, | 47 | { "assign", cmd_assign }, |
diff --git a/sway/commands/seat.c b/sway/commands/seat.c index 5abb19b0..56acd204 100644 --- a/sway/commands/seat.c +++ b/sway/commands/seat.c | |||
@@ -26,9 +26,16 @@ struct cmd_results *cmd_seat(int argc, char **argv) { | |||
26 | 26 | ||
27 | struct cmd_results *res = config_subcommand(argv + 1, argc - 1, | 27 | struct cmd_results *res = config_subcommand(argv + 1, argc - 1, |
28 | seat_handlers, sizeof(seat_handlers)); | 28 | seat_handlers, sizeof(seat_handlers)); |
29 | if (res && res->status != CMD_SUCCESS) { | ||
30 | free_seat_config(config->handler_context.seat_config); | ||
31 | config->handler_context.seat_config = NULL; | ||
32 | return res; | ||
33 | } | ||
29 | 34 | ||
30 | free_seat_config(config->handler_context.seat_config); | 35 | struct seat_config *sc = |
31 | config->handler_context.seat_config = NULL; | 36 | store_seat_config(config->handler_context.seat_config); |
37 | input_manager_apply_seat_config(sc); | ||
32 | 38 | ||
33 | return res; | 39 | config->handler_context.seat_config = NULL; |
40 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
34 | } | 41 | } |
diff --git a/sway/commands/seat/attach.c b/sway/commands/seat/attach.c index 8d646c2d..0fb17f1d 100644 --- a/sway/commands/seat/attach.c +++ b/sway/commands/seat/attach.c | |||
@@ -1,10 +1,7 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | 1 | #define _POSIX_C_SOURCE 200809L |
2 | #include <string.h> | 2 | #include <string.h> |
3 | #include <strings.h> | ||
4 | #include "sway/input/input-manager.h" | ||
5 | #include "sway/commands.h" | 3 | #include "sway/commands.h" |
6 | #include "sway/config.h" | 4 | #include "sway/config.h" |
7 | #include "log.h" | ||
8 | #include "stringop.h" | 5 | #include "stringop.h" |
9 | 6 | ||
10 | struct cmd_results *seat_cmd_attach(int argc, char **argv) { | 7 | struct cmd_results *seat_cmd_attach(int argc, char **argv) { |
@@ -12,19 +9,17 @@ struct cmd_results *seat_cmd_attach(int argc, char **argv) { | |||
12 | if ((error = checkarg(argc, "attach", EXPECTED_AT_LEAST, 1))) { | 9 | if ((error = checkarg(argc, "attach", EXPECTED_AT_LEAST, 1))) { |
13 | return error; | 10 | return error; |
14 | } | 11 | } |
15 | struct seat_config *current_seat_config = | 12 | if (!config->handler_context.seat_config) { |
16 | config->handler_context.seat_config; | ||
17 | if (!current_seat_config) { | ||
18 | return cmd_results_new(CMD_FAILURE, "attach", "No seat defined"); | 13 | return cmd_results_new(CMD_FAILURE, "attach", "No seat defined"); |
19 | } | 14 | } |
20 | 15 | ||
21 | struct seat_config *new_config = new_seat_config(current_seat_config->name); | 16 | struct seat_attachment_config *attachment = seat_attachment_config_new(); |
22 | struct seat_attachment_config *new_attachment = seat_attachment_config_new(); | 17 | if (!attachment) { |
23 | new_attachment->identifier = strdup(argv[0]); | 18 | return cmd_results_new(CMD_FAILURE, "attach", |
24 | list_add(new_config->attachments, new_attachment); | 19 | "Failed to allocate seat attachment config"); |
25 | |||
26 | if (!config->validating) { | ||
27 | apply_seat_config(new_config); | ||
28 | } | 20 | } |
21 | attachment->identifier = strdup(argv[0]); | ||
22 | list_add(config->handler_context.seat_config->attachments, attachment); | ||
23 | |||
29 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 24 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
30 | } | 25 | } |
diff --git a/sway/commands/seat/fallback.c b/sway/commands/seat/fallback.c index a0ddf3ef..8f1ab12c 100644 --- a/sway/commands/seat/fallback.c +++ b/sway/commands/seat/fallback.c | |||
@@ -1,27 +1,18 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/config.h" | 1 | #include "sway/config.h" |
4 | #include "sway/commands.h" | 2 | #include "sway/commands.h" |
5 | #include "sway/input/input-manager.h" | ||
6 | #include "util.h" | 3 | #include "util.h" |
7 | 4 | ||
8 | struct cmd_results *seat_cmd_fallback(int argc, char **argv) { | 5 | struct cmd_results *seat_cmd_fallback(int argc, char **argv) { |
9 | struct cmd_results *error = NULL; | 6 | struct cmd_results *error = NULL; |
10 | if ((error = checkarg(argc, "fallback", EXPECTED_AT_LEAST, 1))) { | 7 | if ((error = checkarg(argc, "fallback", EXPECTED_EQUAL_TO, 1))) { |
11 | return error; | 8 | return error; |
12 | } | 9 | } |
13 | struct seat_config *current_seat_config = | 10 | if (!config->handler_context.seat_config) { |
14 | config->handler_context.seat_config; | ||
15 | if (!current_seat_config) { | ||
16 | return cmd_results_new(CMD_FAILURE, "fallback", "No seat defined"); | 11 | return cmd_results_new(CMD_FAILURE, "fallback", "No seat defined"); |
17 | } | 12 | } |
18 | struct seat_config *new_config = | ||
19 | new_seat_config(current_seat_config->name); | ||
20 | |||
21 | new_config->fallback = parse_boolean(argv[0], false); | ||
22 | 13 | ||
23 | if (!config->validating) { | 14 | config->handler_context.seat_config->fallback = |
24 | apply_seat_config(new_config); | 15 | parse_boolean(argv[0], false); |
25 | } | 16 | |
26 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 17 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
27 | } | 18 | } |
diff --git a/sway/config/seat.c b/sway/config/seat.c index 1cb4c363..c248990a 100644 --- a/sway/config/seat.c +++ b/sway/config/seat.c | |||
@@ -11,7 +11,6 @@ struct seat_config *new_seat_config(const char* name) { | |||
11 | return NULL; | 11 | return NULL; |
12 | } | 12 | } |
13 | 13 | ||
14 | wlr_log(WLR_DEBUG, "new_seat_config(%s)", name); | ||
15 | seat->name = strdup(name); | 14 | seat->name = strdup(name); |
16 | if (!sway_assert(seat->name, "could not allocate name for seat")) { | 15 | if (!sway_assert(seat->name, "could not allocate name for seat")) { |
17 | free(seat); | 16 | free(seat); |
@@ -30,6 +29,52 @@ struct seat_config *new_seat_config(const char* name) { | |||
30 | return seat; | 29 | return seat; |
31 | } | 30 | } |
32 | 31 | ||
32 | static void merge_wildcard_on_all(struct seat_config *wildcard) { | ||
33 | for (int i = 0; i < config->seat_configs->length; i++) { | ||
34 | struct seat_config *sc = config->seat_configs->items[i]; | ||
35 | if (strcmp(wildcard->name, sc->name) != 0) { | ||
36 | wlr_log(WLR_DEBUG, "Merging seat * config on %s", sc->name); | ||
37 | merge_seat_config(sc, wildcard); | ||
38 | } | ||
39 | } | ||
40 | } | ||
41 | |||
42 | struct seat_config *store_seat_config(struct seat_config *sc) { | ||
43 | bool wildcard = strcmp(sc->name, "*") == 0; | ||
44 | if (wildcard) { | ||
45 | merge_wildcard_on_all(sc); | ||
46 | } | ||
47 | |||
48 | int i = list_seq_find(config->seat_configs, seat_name_cmp, sc->name); | ||
49 | if (i >= 0) { | ||
50 | wlr_log(WLR_DEBUG, "Merging on top of existing seat config"); | ||
51 | struct seat_config *current = config->seat_configs->items[i]; | ||
52 | merge_seat_config(current, sc); | ||
53 | free_seat_config(sc); | ||
54 | sc = current; | ||
55 | } else if (!wildcard) { | ||
56 | wlr_log(WLR_DEBUG, "Adding non-wildcard seat config"); | ||
57 | i = list_seq_find(config->seat_configs, seat_name_cmp, "*"); | ||
58 | if (i >= 0) { | ||
59 | wlr_log(WLR_DEBUG, "Merging on top of seat * config"); | ||
60 | struct seat_config *current = new_seat_config(sc->name); | ||
61 | merge_seat_config(current, config->seat_configs->items[i]); | ||
62 | merge_seat_config(current, sc); | ||
63 | free_seat_config(sc); | ||
64 | sc = current; | ||
65 | } | ||
66 | list_add(config->seat_configs, sc); | ||
67 | } else { | ||
68 | // New wildcard config. Just add it | ||
69 | wlr_log(WLR_DEBUG, "Adding seat * config"); | ||
70 | list_add(config->seat_configs, sc); | ||
71 | } | ||
72 | |||
73 | wlr_log(WLR_DEBUG, "Config stored for seat %s", sc->name); | ||
74 | |||
75 | return sc; | ||
76 | } | ||
77 | |||
33 | struct seat_attachment_config *seat_attachment_config_new(void) { | 78 | struct seat_attachment_config *seat_attachment_config_new(void) { |
34 | struct seat_attachment_config *attachment = | 79 | struct seat_attachment_config *attachment = |
35 | calloc(1, sizeof(struct seat_attachment_config)); | 80 | calloc(1, sizeof(struct seat_attachment_config)); |
@@ -65,11 +110,6 @@ static void merge_seat_attachment_config(struct seat_attachment_config *dest, | |||
65 | } | 110 | } |
66 | 111 | ||
67 | void merge_seat_config(struct seat_config *dest, struct seat_config *source) { | 112 | void merge_seat_config(struct seat_config *dest, struct seat_config *source) { |
68 | if (source->name) { | ||
69 | free(dest->name); | ||
70 | dest->name = strdup(source->name); | ||
71 | } | ||
72 | |||
73 | if (source->fallback != -1) { | 113 | if (source->fallback != -1) { |
74 | dest->fallback = source->fallback; | 114 | dest->fallback = source->fallback; |
75 | } | 115 | } |
diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c index 89146d5b..055f6752 100644 --- a/sway/input/input-manager.c +++ b/sway/input/input-manager.c | |||
@@ -82,11 +82,12 @@ static struct sway_input_device *input_sway_device_from_wlr( | |||
82 | return NULL; | 82 | return NULL; |
83 | } | 83 | } |
84 | 84 | ||
85 | static bool input_has_seat_configuration(void) { | 85 | static bool input_has_seat_fallback_configuration(void) { |
86 | struct sway_seat *seat = NULL; | 86 | struct sway_seat *seat = NULL; |
87 | wl_list_for_each(seat, &server.input->seats, link) { | 87 | wl_list_for_each(seat, &server.input->seats, link) { |
88 | struct seat_config *seat_config = seat_get_config(seat); | 88 | struct seat_config *seat_config = seat_get_config(seat); |
89 | if (seat_config) { | 89 | if (seat_config && strcmp(seat_config->name, "*") != 0 |
90 | && seat_config->fallback != -1) { | ||
90 | return true; | 91 | return true; |
91 | } | 92 | } |
92 | } | 93 | } |
@@ -296,11 +297,12 @@ static void handle_new_input(struct wl_listener *listener, void *data) { | |||
296 | input_device->device_destroy.notify = handle_device_destroy; | 297 | input_device->device_destroy.notify = handle_device_destroy; |
297 | 298 | ||
298 | struct sway_seat *seat = NULL; | 299 | struct sway_seat *seat = NULL; |
299 | if (!input_has_seat_configuration()) { | 300 | if (!input_has_seat_fallback_configuration()) { |
300 | wlr_log(WLR_DEBUG, "no seat configuration, using default seat"); | 301 | wlr_log(WLR_DEBUG, "no seat config - creating default seat config"); |
301 | seat = input_manager_get_default_seat(); | 302 | seat = input_manager_get_default_seat(); |
302 | seat_add_device(seat, input_device); | 303 | struct seat_config *sc = new_seat_config(seat->wlr_seat->name); |
303 | return; | 304 | sc->fallback = true; |
305 | store_seat_config(sc); | ||
304 | } | 306 | } |
305 | 307 | ||
306 | bool added = false; | 308 | bool added = false; |
@@ -459,15 +461,26 @@ void input_manager_apply_input_config(struct input_config *input_config) { | |||
459 | } | 461 | } |
460 | 462 | ||
461 | void input_manager_apply_seat_config(struct seat_config *seat_config) { | 463 | void input_manager_apply_seat_config(struct seat_config *seat_config) { |
462 | wlr_log(WLR_DEBUG, "applying new seat config for seat %s", | 464 | wlr_log(WLR_DEBUG, "applying seat config for seat %s", seat_config->name); |
463 | seat_config->name); | 465 | if (strcmp(seat_config->name, "*") == 0) { |
464 | struct sway_seat *seat = input_manager_get_seat(seat_config->name); | 466 | struct sway_seat *seat = NULL; |
465 | if (!seat) { | 467 | wl_list_for_each(seat, &server.input->seats, link) { |
466 | return; | 468 | // Only apply the wildcard config directly if there is no seat |
469 | // specific config | ||
470 | struct seat_config *sc = seat_get_config(seat); | ||
471 | if (!sc) { | ||
472 | sc = seat_config; | ||
473 | } | ||
474 | seat_apply_config(seat, sc); | ||
475 | } | ||
476 | } else { | ||
477 | struct sway_seat *seat = input_manager_get_seat(seat_config->name); | ||
478 | if (!seat) { | ||
479 | return; | ||
480 | } | ||
481 | seat_apply_config(seat, seat_config); | ||
467 | } | 482 | } |
468 | 483 | ||
469 | seat_apply_config(seat, seat_config); | ||
470 | |||
471 | // for every device, try to add it to a seat and if no seat has it | 484 | // for every device, try to add it to a seat and if no seat has it |
472 | // attached, add it to the fallback seats. | 485 | // attached, add it to the fallback seats. |
473 | struct sway_input_device *input_device = NULL; | 486 | struct sway_input_device *input_device = NULL; |