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 /sway/commands/seat.c | |
parent | input config handler context (diff) | |
download | sway-cc3c713889e529c74888d9cd89af7039bfbae20c.tar.gz sway-cc3c713889e529c74888d9cd89af7039bfbae20c.tar.zst sway-cc3c713889e529c74888d9cd89af7039bfbae20c.zip |
seat config handler context
Diffstat (limited to 'sway/commands/seat.c')
-rw-r--r-- | sway/commands/seat.c | 25 |
1 files changed, 21 insertions, 4 deletions
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 | } |