aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/seat.c
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-06-19 01:34:07 -0400
committerLibravatar Simon Ser <contact@emersion.fr>2019-06-20 10:15:09 +0300
commitfc3253cc35b123ae5d21db3379ad0acf43ad0c20 (patch)
treeb4e07cc9d8d5519346e16985905158de1cd0d90c /sway/commands/seat.c
parentconfig: fix find_handler logic (diff)
downloadsway-fc3253cc35b123ae5d21db3379ad0acf43ad0c20.tar.gz
sway-fc3253cc35b123ae5d21db3379ad0acf43ad0c20.tar.zst
sway-fc3253cc35b123ae5d21db3379ad0acf43ad0c20.zip
cmd_seat: split action and config handlers
This separates the logic for seat subcommand handlers that only perform actions on the seat and handlers that alter the seat config. The former group can immediately free the seat config after running the command as it is only used by the subcommand to find the name of the seat to operate on. The latter group alters the seat config so it will need to go through the storage and application stage (assuming success).
Diffstat (limited to 'sway/commands/seat.c')
-rw-r--r--sway/commands/seat.c52
1 files changed, 37 insertions, 15 deletions
diff --git a/sway/commands/seat.c b/sway/commands/seat.c
index a827bf74..197a405e 100644
--- a/sway/commands/seat.c
+++ b/sway/commands/seat.c
@@ -7,15 +7,45 @@
7#include "stringop.h" 7#include "stringop.h"
8 8
9// must be in order for the bsearch 9// must be in order for the bsearch
10// these handlers perform actions on the seat
11static struct cmd_handler seat_action_handlers[] = {
12 { "cursor", seat_cmd_cursor },
13};
14
15// must be in order for the bsearch
16// these handlers alter the seat config
10static struct cmd_handler seat_handlers[] = { 17static struct cmd_handler seat_handlers[] = {
11 { "attach", seat_cmd_attach }, 18 { "attach", seat_cmd_attach },
12 { "cursor", seat_cmd_cursor },
13 { "fallback", seat_cmd_fallback }, 19 { "fallback", seat_cmd_fallback },
14 { "hide_cursor", seat_cmd_hide_cursor }, 20 { "hide_cursor", seat_cmd_hide_cursor },
15 { "pointer_constraint", seat_cmd_pointer_constraint }, 21 { "pointer_constraint", seat_cmd_pointer_constraint },
16 { "xcursor_theme", seat_cmd_xcursor_theme }, 22 { "xcursor_theme", seat_cmd_xcursor_theme },
17}; 23};
18 24
25static struct cmd_results *action_handlers(int argc, char **argv) {
26 struct cmd_results *res = config_subcommand(argv, argc,
27 seat_action_handlers, sizeof(seat_action_handlers));
28 free_seat_config(config->handler_context.seat_config);
29 config->handler_context.seat_config = NULL;
30 return res;
31}
32
33static struct cmd_results *config_handlers(int argc, char **argv) {
34 struct cmd_results *res = config_subcommand(argv, argc,
35 seat_handlers, sizeof(seat_handlers));
36 if (res && res->status != CMD_SUCCESS) {
37 free_seat_config(config->handler_context.seat_config);
38 } else {
39 struct seat_config *sc =
40 store_seat_config(config->handler_context.seat_config);
41 if (!config->reading) {
42 input_manager_apply_seat_config(sc);
43 }
44 }
45 config->handler_context.seat_config = NULL;
46 return res;
47}
48
19struct cmd_results *cmd_seat(int argc, char **argv) { 49struct cmd_results *cmd_seat(int argc, char **argv) {
20 struct cmd_results *error = NULL; 50 struct cmd_results *error = NULL;
21 if ((error = checkarg(argc, "seat", EXPECTED_AT_LEAST, 2))) { 51 if ((error = checkarg(argc, "seat", EXPECTED_AT_LEAST, 2))) {
@@ -36,20 +66,12 @@ struct cmd_results *cmd_seat(int argc, char **argv) {
36 return cmd_results_new(CMD_FAILURE, "Couldn't allocate config"); 66 return cmd_results_new(CMD_FAILURE, "Couldn't allocate config");
37 } 67 }
38 68
39 struct cmd_results *res = config_subcommand(argv + 1, argc - 1, 69 struct cmd_results *res = NULL;
40 seat_handlers, sizeof(seat_handlers)); 70 if (find_handler(argv[1], seat_action_handlers,
41 if (res && res->status != CMD_SUCCESS) { 71 sizeof(seat_action_handlers))) {
42 free_seat_config(config->handler_context.seat_config); 72 res = action_handlers(argc - 1, argv + 1);
43 config->handler_context.seat_config = NULL; 73 } else {
44 return res; 74 res = config_handlers(argc - 1, argv + 1);
45 }
46
47 struct seat_config *sc =
48 store_seat_config(config->handler_context.seat_config);
49 if (!config->reading) {
50 input_manager_apply_seat_config(sc);
51 } 75 }
52
53 config->handler_context.seat_config = NULL;
54 return res ? res : cmd_results_new(CMD_SUCCESS, NULL); 76 return res ? res : cmd_results_new(CMD_SUCCESS, NULL);
55} 77}