diff options
author | Tony Crisci <tony@dubstepdish.com> | 2018-01-20 11:44:34 -0500 |
---|---|---|
committer | Tony Crisci <tony@dubstepdish.com> | 2018-01-20 11:44:34 -0500 |
commit | cc3c713889e529c74888d9cd89af7039bfbae20c (patch) | |
tree | f40da3a0fc2639b6a22bdb0e323106f66d27ec45 | |
parent | input config handler context (diff) | |
download | sway-cc3c713889e529c74888d9cd89af7039bfbae20c.tar.gz sway-cc3c713889e529c74888d9cd89af7039bfbae20c.tar.zst sway-cc3c713889e529c74888d9cd89af7039bfbae20c.zip |
seat config handler context
-rw-r--r-- | include/sway/config.h | 1 | ||||
-rw-r--r-- | include/sway/input/input-manager.h | 2 | ||||
-rw-r--r-- | sway/commands.c | 1 | ||||
-rw-r--r-- | sway/commands/input.c | 3 | ||||
-rw-r--r-- | sway/commands/seat.c | 25 | ||||
-rw-r--r-- | sway/commands/seat/attach.c | 2 | ||||
-rw-r--r-- | sway/commands/seat/fallback.c | 3 | ||||
-rw-r--r-- | sway/config.c | 2 |
8 files changed, 31 insertions, 8 deletions
diff --git a/include/sway/config.h b/include/sway/config.h index 1ab96b51..27fae0c6 100644 --- a/include/sway/config.h +++ b/include/sway/config.h | |||
@@ -354,6 +354,7 @@ struct sway_config { | |||
354 | // Context for command handlers | 354 | // Context for command handlers |
355 | struct { | 355 | struct { |
356 | struct input_config *input_config; | 356 | struct input_config *input_config; |
357 | struct seat_config *seat_config; | ||
357 | } handler_context; | 358 | } handler_context; |
358 | }; | 359 | }; |
359 | 360 | ||
diff --git a/include/sway/input/input-manager.h b/include/sway/input/input-manager.h index 8388f930..58a93fe3 100644 --- a/include/sway/input/input-manager.h +++ b/include/sway/input/input-manager.h | |||
@@ -5,8 +5,6 @@ | |||
5 | #include "sway/config.h" | 5 | #include "sway/config.h" |
6 | #include "list.h" | 6 | #include "list.h" |
7 | 7 | ||
8 | extern struct seat_config *current_seat_config; | ||
9 | |||
10 | /** | 8 | /** |
11 | * The global singleton input manager | 9 | * The global singleton input manager |
12 | * TODO: make me not a global | 10 | * TODO: make me not a global |
diff --git a/sway/commands.c b/sway/commands.c index fd2e1514..414ef809 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -86,7 +86,6 @@ void apply_seat_config(struct seat_config *seat) { | |||
86 | list_add(config->seat_configs, seat); | 86 | list_add(config->seat_configs, seat); |
87 | } | 87 | } |
88 | 88 | ||
89 | current_seat_config = seat; | ||
90 | sway_input_manager_apply_seat_config(input_manager, seat); | 89 | sway_input_manager_apply_seat_config(input_manager, seat); |
91 | } | 90 | } |
92 | 91 | ||
diff --git a/sway/commands/input.c b/sway/commands/input.c index 5de65621..fa9cf05a 100644 --- a/sway/commands/input.c +++ b/sway/commands/input.c | |||
@@ -28,6 +28,9 @@ struct cmd_results *cmd_input(int argc, char **argv) { | |||
28 | if (!has_context) { | 28 | if (!has_context) { |
29 | // caller did not give a context so create one just for this command | 29 | // caller did not give a context so create one just for this command |
30 | config->handler_context.input_config = new_input_config(argv[0]); | 30 | config->handler_context.input_config = new_input_config(argv[0]); |
31 | if (!config->handler_context.input_config) { | ||
32 | return cmd_results_new(CMD_FAILURE, NULL, "Couldn't allocate config"); | ||
33 | } | ||
31 | } | 34 | } |
32 | 35 | ||
33 | int argc_new = argc-2; | 36 | int argc_new = argc-2; |
diff --git a/sway/commands/seat.c b/sway/commands/seat.c index 6284002b..45079616 100644 --- a/sway/commands/seat.c +++ b/sway/commands/seat.c | |||
@@ -11,8 +11,12 @@ struct cmd_results *cmd_seat(int argc, char **argv) { | |||
11 | } | 11 | } |
12 | 12 | ||
13 | if (config->reading && strcmp("{", argv[1]) == 0) { | 13 | if (config->reading && strcmp("{", argv[1]) == 0) { |
14 | current_seat_config = new_seat_config(argv[0]); | 14 | free_seat_config(config->handler_context.seat_config); |
15 | wlr_log(L_DEBUG, "entering seat block: %s", current_seat_config->name); | 15 | config->handler_context.seat_config = new_seat_config(argv[0]); |
16 | if (!config->handler_context.seat_config) { | ||
17 | return cmd_results_new(CMD_FAILURE, NULL, "Couldn't allocate config"); | ||
18 | } | ||
19 | wlr_log(L_DEBUG, "entering seat block: %s", argv[0]); | ||
16 | return cmd_results_new(CMD_BLOCK_SEAT, NULL, NULL); | 20 | return cmd_results_new(CMD_BLOCK_SEAT, NULL, NULL); |
17 | } | 21 | } |
18 | 22 | ||
@@ -20,11 +24,18 @@ struct cmd_results *cmd_seat(int argc, char **argv) { | |||
20 | return error; | 24 | return error; |
21 | } | 25 | } |
22 | 26 | ||
27 | bool has_context = (config->handler_context.seat_config != NULL); | ||
28 | if (!has_context) { | ||
29 | config->handler_context.seat_config = new_seat_config(argv[0]); | ||
30 | if (!config->handler_context.seat_config) { | ||
31 | return cmd_results_new(CMD_FAILURE, NULL, "Couldn't allocate config"); | ||
32 | } | ||
33 | } | ||
34 | |||
23 | int argc_new = argc-2; | 35 | int argc_new = argc-2; |
24 | char **argv_new = argv+2; | 36 | char **argv_new = argv+2; |
25 | 37 | ||
26 | struct cmd_results *res; | 38 | struct cmd_results *res; |
27 | current_seat_config = new_seat_config(argv[0]); | ||
28 | if (strcasecmp("attach", argv[1]) == 0) { | 39 | if (strcasecmp("attach", argv[1]) == 0) { |
29 | res = seat_cmd_attach(argc_new, argv_new); | 40 | res = seat_cmd_attach(argc_new, argv_new); |
30 | } else if (strcasecmp("fallback", argv[1]) == 0) { | 41 | } else if (strcasecmp("fallback", argv[1]) == 0) { |
@@ -32,6 +43,12 @@ struct cmd_results *cmd_seat(int argc, char **argv) { | |||
32 | } else { | 43 | } else { |
33 | res = cmd_results_new(CMD_INVALID, "seat <name>", "Unknown command %s", argv[1]); | 44 | res = cmd_results_new(CMD_INVALID, "seat <name>", "Unknown command %s", argv[1]); |
34 | } | 45 | } |
35 | current_seat_config = NULL; | 46 | |
47 | if (!has_context) { | ||
48 | // clean up the context we created earlier | ||
49 | free_seat_config(config->handler_context.seat_config); | ||
50 | config->handler_context.seat_config = NULL; | ||
51 | } | ||
52 | |||
36 | return res; | 53 | return res; |
37 | } | 54 | } |
diff --git a/sway/commands/seat/attach.c b/sway/commands/seat/attach.c index 80ec63ce..3e771c00 100644 --- a/sway/commands/seat/attach.c +++ b/sway/commands/seat/attach.c | |||
@@ -12,6 +12,8 @@ struct cmd_results *seat_cmd_attach(int argc, char **argv) { | |||
12 | if ((error = checkarg(argc, "attach", EXPECTED_AT_LEAST, 1))) { | 12 | if ((error = checkarg(argc, "attach", EXPECTED_AT_LEAST, 1))) { |
13 | return error; | 13 | return error; |
14 | } | 14 | } |
15 | struct seat_config *current_seat_config = | ||
16 | config->handler_context.seat_config; | ||
15 | if (!current_seat_config) { | 17 | if (!current_seat_config) { |
16 | return cmd_results_new(CMD_FAILURE, "attach", "No seat defined"); | 18 | return cmd_results_new(CMD_FAILURE, "attach", "No seat defined"); |
17 | } | 19 | } |
diff --git a/sway/commands/seat/fallback.c b/sway/commands/seat/fallback.c index 7c129aae..56feaab5 100644 --- a/sway/commands/seat/fallback.c +++ b/sway/commands/seat/fallback.c | |||
@@ -9,6 +9,8 @@ struct cmd_results *seat_cmd_fallback(int argc, char **argv) { | |||
9 | if ((error = checkarg(argc, "fallback", EXPECTED_AT_LEAST, 1))) { | 9 | if ((error = checkarg(argc, "fallback", EXPECTED_AT_LEAST, 1))) { |
10 | return error; | 10 | return error; |
11 | } | 11 | } |
12 | struct seat_config *current_seat_config = | ||
13 | config->handler_context.seat_config; | ||
12 | if (!current_seat_config) { | 14 | if (!current_seat_config) { |
13 | return cmd_results_new(CMD_FAILURE, "fallback", "No seat defined"); | 15 | return cmd_results_new(CMD_FAILURE, "fallback", "No seat defined"); |
14 | } | 16 | } |
@@ -20,6 +22,7 @@ struct cmd_results *seat_cmd_fallback(int argc, char **argv) { | |||
20 | } else if (strcasecmp(argv[0], "false") == 0) { | 22 | } else if (strcasecmp(argv[0], "false") == 0) { |
21 | new_config->fallback = 0; | 23 | new_config->fallback = 0; |
22 | } else { | 24 | } else { |
25 | free_seat_config(new_config); | ||
23 | return cmd_results_new(CMD_INVALID, "fallback", | 26 | return cmd_results_new(CMD_INVALID, "fallback", |
24 | "Expected 'fallback <true|false>'"); | 27 | "Expected 'fallback <true|false>'"); |
25 | } | 28 | } |
diff --git a/sway/config.c b/sway/config.c index 54357625..2683d6bc 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -484,6 +484,7 @@ bool load_include_configs(const char *path, struct sway_config *config) { | |||
484 | 484 | ||
485 | void config_clear_handler_context(struct sway_config *config) { | 485 | void config_clear_handler_context(struct sway_config *config) { |
486 | free_input_config(config->handler_context.input_config); | 486 | free_input_config(config->handler_context.input_config); |
487 | free_seat_config(config->handler_context.seat_config); | ||
487 | 488 | ||
488 | memset(&config->handler_context, 0, sizeof(config->handler_context)); | 489 | memset(&config->handler_context, 0, sizeof(config->handler_context)); |
489 | } | 490 | } |
@@ -604,7 +605,6 @@ bool read_config(FILE *file, struct sway_config *config) { | |||
604 | 605 | ||
605 | case CMD_BLOCK_SEAT: | 606 | case CMD_BLOCK_SEAT: |
606 | wlr_log(L_DEBUG, "End of seat block"); | 607 | wlr_log(L_DEBUG, "End of seat block"); |
607 | current_seat_config = NULL; | ||
608 | block = CMD_BLOCK_END; | 608 | block = CMD_BLOCK_END; |
609 | break; | 609 | break; |
610 | 610 | ||