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