diff options
Diffstat (limited to 'sway/commands/input.c')
-rw-r--r-- | sway/commands/input.c | 103 |
1 files changed, 34 insertions, 69 deletions
diff --git a/sway/commands/input.c b/sway/commands/input.c index eeb4ee75..972160e2 100644 --- a/sway/commands/input.c +++ b/sway/commands/input.c | |||
@@ -3,85 +3,50 @@ | |||
3 | #include "sway/commands.h" | 3 | #include "sway/commands.h" |
4 | #include "sway/input/input-manager.h" | 4 | #include "sway/input/input-manager.h" |
5 | #include "log.h" | 5 | #include "log.h" |
6 | #include "stringop.h" | ||
7 | |||
8 | // must be in order for the bsearch | ||
9 | static struct cmd_handler input_handlers[] = { | ||
10 | { "accel_profile", input_cmd_accel_profile }, | ||
11 | { "click_method", input_cmd_click_method }, | ||
12 | { "drag_lock", input_cmd_drag_lock }, | ||
13 | { "dwt", input_cmd_dwt }, | ||
14 | { "events", input_cmd_events }, | ||
15 | { "left_handed", input_cmd_left_handed }, | ||
16 | { "map_from_region", input_cmd_map_from_region }, | ||
17 | { "map_to_output", input_cmd_map_to_output }, | ||
18 | { "middle_emulation", input_cmd_middle_emulation }, | ||
19 | { "natural_scroll", input_cmd_natural_scroll }, | ||
20 | { "pointer_accel", input_cmd_pointer_accel }, | ||
21 | { "repeat_delay", input_cmd_repeat_delay }, | ||
22 | { "repeat_rate", input_cmd_repeat_rate }, | ||
23 | { "scroll_method", input_cmd_scroll_method }, | ||
24 | { "tap", input_cmd_tap }, | ||
25 | { "xkb_layout", input_cmd_xkb_layout }, | ||
26 | { "xkb_model", input_cmd_xkb_model }, | ||
27 | { "xkb_options", input_cmd_xkb_options }, | ||
28 | { "xkb_rules", input_cmd_xkb_rules }, | ||
29 | { "xkb_variant", input_cmd_xkb_variant }, | ||
30 | }; | ||
6 | 31 | ||
7 | struct cmd_results *cmd_input(int argc, char **argv) { | 32 | struct cmd_results *cmd_input(int argc, char **argv) { |
8 | struct cmd_results *error = NULL; | 33 | struct cmd_results *error = NULL; |
9 | if ((error = checkarg(argc, "input", EXPECTED_AT_LEAST, 2))) { | 34 | if ((error = checkarg(argc, "input", EXPECTED_AT_LEAST, 1))) { |
10 | return error; | 35 | return error; |
11 | } | 36 | } |
12 | 37 | ||
13 | if (config->reading && strcmp("{", argv[1]) == 0) { | 38 | wlr_log(L_DEBUG, "entering input block: %s", argv[0]); |
14 | free_input_config(config->handler_context.input_config); | ||
15 | config->handler_context.input_config = new_input_config(argv[0]); | ||
16 | if (!config->handler_context.input_config) { | ||
17 | return cmd_results_new(CMD_FAILURE, NULL, "Couldn't allocate config"); | ||
18 | } | ||
19 | wlr_log(L_DEBUG, "entering input block: %s", argv[0]); | ||
20 | return cmd_results_new(CMD_BLOCK_INPUT, NULL, NULL); | ||
21 | } | ||
22 | |||
23 | if ((error = checkarg(argc, "input", EXPECTED_AT_LEAST, 3))) { | ||
24 | return error; | ||
25 | } | ||
26 | 39 | ||
27 | bool has_context = (config->handler_context.input_config != NULL); | 40 | config->handler_context.input_config = new_input_config(argv[0]); |
28 | if (!has_context) { | 41 | if (!config->handler_context.input_config) { |
29 | // caller did not give a context so create one just for this command | 42 | return cmd_results_new(CMD_FAILURE, NULL, "Couldn't allocate config"); |
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 | } | ||
34 | } | 43 | } |
35 | 44 | ||
36 | int argc_new = argc-2; | 45 | struct cmd_results *res = subcommand(argv + 1, argc - 1, input_handlers, |
37 | char **argv_new = argv+2; | 46 | sizeof(input_handlers)); |
38 | 47 | ||
39 | struct cmd_results *res; | 48 | free_input_config(config->handler_context.input_config); |
40 | if (strcasecmp("accel_profile", argv[1]) == 0) { | 49 | config->handler_context.input_config = NULL; |
41 | res = input_cmd_accel_profile(argc_new, argv_new); | ||
42 | } else if (strcasecmp("click_method", argv[1]) == 0) { | ||
43 | res = input_cmd_click_method(argc_new, argv_new); | ||
44 | } else if (strcasecmp("drag_lock", argv[1]) == 0) { | ||
45 | res = input_cmd_drag_lock(argc_new, argv_new); | ||
46 | } else if (strcasecmp("dwt", argv[1]) == 0) { | ||
47 | res = input_cmd_dwt(argc_new, argv_new); | ||
48 | } else if (strcasecmp("events", argv[1]) == 0) { | ||
49 | res = input_cmd_events(argc_new, argv_new); | ||
50 | } else if (strcasecmp("left_handed", argv[1]) == 0) { | ||
51 | res = input_cmd_left_handed(argc_new, argv_new); | ||
52 | } else if (strcasecmp("middle_emulation", argv[1]) == 0) { | ||
53 | res = input_cmd_middle_emulation(argc_new, argv_new); | ||
54 | } else if (strcasecmp("natural_scroll", argv[1]) == 0) { | ||
55 | res = input_cmd_natural_scroll(argc_new, argv_new); | ||
56 | } else if (strcasecmp("pointer_accel", argv[1]) == 0) { | ||
57 | res = input_cmd_pointer_accel(argc_new, argv_new); | ||
58 | } else if (strcasecmp("repeat_delay", argv[1]) == 0) { | ||
59 | res = input_cmd_repeat_delay(argc_new, argv_new); | ||
60 | } else if (strcasecmp("repeat_rate", argv[1]) == 0) { | ||
61 | res = input_cmd_repeat_rate(argc_new, argv_new); | ||
62 | } else if (strcasecmp("scroll_method", argv[1]) == 0) { | ||
63 | res = input_cmd_scroll_method(argc_new, argv_new); | ||
64 | } else if (strcasecmp("tap", argv[1]) == 0) { | ||
65 | res = input_cmd_tap(argc_new, argv_new); | ||
66 | } else if (strcasecmp("xkb_layout", argv[1]) == 0) { | ||
67 | res = input_cmd_xkb_layout(argc_new, argv_new); | ||
68 | } else if (strcasecmp("xkb_model", argv[1]) == 0) { | ||
69 | res = input_cmd_xkb_model(argc_new, argv_new); | ||
70 | } else if (strcasecmp("xkb_options", argv[1]) == 0) { | ||
71 | res = input_cmd_xkb_options(argc_new, argv_new); | ||
72 | } else if (strcasecmp("xkb_rules", argv[1]) == 0) { | ||
73 | res = input_cmd_xkb_rules(argc_new, argv_new); | ||
74 | } else if (strcasecmp("xkb_variant", argv[1]) == 0) { | ||
75 | res = input_cmd_xkb_variant(argc_new, argv_new); | ||
76 | } else { | ||
77 | res = cmd_results_new(CMD_INVALID, "input <device>", "Unknown command %s", argv[1]); | ||
78 | } | ||
79 | |||
80 | if (!has_context) { | ||
81 | // clean up the context we created earlier | ||
82 | free_input_config(config->handler_context.input_config); | ||
83 | config->handler_context.input_config = NULL; | ||
84 | } | ||
85 | 50 | ||
86 | return res; | 51 | return res; |
87 | } | 52 | } |