diff options
-rw-r--r-- | include/sway/commands.h | 4 | ||||
-rw-r--r-- | include/sway/input/input-manager.h | 2 | ||||
-rw-r--r-- | sway/commands.c | 90 | ||||
-rw-r--r-- | sway/commands/input.c | 55 | ||||
-rw-r--r-- | sway/commands/input/accel_profile.c | 27 | ||||
-rw-r--r-- | sway/commands/input/click_method.c | 30 | ||||
-rw-r--r-- | sway/commands/input/drag_lock.c | 26 | ||||
-rw-r--r-- | sway/commands/input/dwt.c | 26 | ||||
-rw-r--r-- | sway/commands/input/events.c | 30 | ||||
-rw-r--r-- | sway/commands/input/left_handed.c | 26 | ||||
-rw-r--r-- | sway/commands/input/middle_emulation.c | 26 | ||||
-rw-r--r-- | sway/commands/input/natural_scroll.c | 26 | ||||
-rw-r--r-- | sway/commands/input/pointer_accel.c | 24 | ||||
-rw-r--r-- | sway/commands/input/scroll_method.c | 30 | ||||
-rw-r--r-- | sway/commands/input/tap.c | 29 | ||||
-rw-r--r-- | sway/config.c | 53 | ||||
-rw-r--r-- | sway/meson.build | 12 |
17 files changed, 490 insertions, 26 deletions
diff --git a/include/sway/commands.h b/include/sway/commands.h index b1f0423d..138e3c29 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h | |||
@@ -1,6 +1,8 @@ | |||
1 | #ifndef _SWAY_COMMANDS_H | 1 | #ifndef _SWAY_COMMANDS_H |
2 | #define _SWAY_COMMANDS_H | 2 | #define _SWAY_COMMANDS_H |
3 | 3 | ||
4 | #include "config.h" | ||
5 | |||
4 | /** | 6 | /** |
5 | * Indicates the result of a command's execution. | 7 | * Indicates the result of a command's execution. |
6 | */ | 8 | */ |
@@ -39,6 +41,8 @@ enum expected_args { | |||
39 | EXPECTED_EQUAL_TO | 41 | EXPECTED_EQUAL_TO |
40 | }; | 42 | }; |
41 | 43 | ||
44 | void input_cmd_apply(struct input_config *input); | ||
45 | |||
42 | struct cmd_results *checkarg(int argc, const char *name, | 46 | struct cmd_results *checkarg(int argc, const char *name, |
43 | enum expected_args type, int val); | 47 | enum expected_args type, int val); |
44 | 48 | ||
diff --git a/include/sway/input/input-manager.h b/include/sway/input/input-manager.h index 9548c170..78bc161f 100644 --- a/include/sway/input/input-manager.h +++ b/include/sway/input/input-manager.h | |||
@@ -5,6 +5,8 @@ | |||
5 | #include "sway/config.h" | 5 | #include "sway/config.h" |
6 | #include "list.h" | 6 | #include "list.h" |
7 | 7 | ||
8 | extern struct input_config *current_input_config; | ||
9 | |||
8 | struct sway_input_manager { | 10 | struct sway_input_manager { |
9 | struct wl_listener input_add; | 11 | struct wl_listener input_add; |
10 | struct wl_listener input_remove; | 12 | struct wl_listener input_remove; |
diff --git a/sway/commands.c b/sway/commands.c index 05a66a7f..7710c6ab 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -9,6 +9,7 @@ | |||
9 | #include "sway/commands.h" | 9 | #include "sway/commands.h" |
10 | #include "sway/config.h" | 10 | #include "sway/config.h" |
11 | #include "sway/security.h" | 11 | #include "sway/security.h" |
12 | #include "sway/input/input-manager.h" | ||
12 | #include "stringop.h" | 13 | #include "stringop.h" |
13 | #include "log.h" | 14 | #include "log.h" |
14 | 15 | ||
@@ -56,6 +57,44 @@ struct cmd_results *checkarg(int argc, const char *name, enum expected_args type | |||
56 | return error; | 57 | return error; |
57 | } | 58 | } |
58 | 59 | ||
60 | void input_cmd_apply(struct input_config *input) { | ||
61 | int i; | ||
62 | i = list_seq_find(config->input_configs, input_identifier_cmp, input->identifier); | ||
63 | if (i >= 0) { | ||
64 | // merge existing config | ||
65 | struct input_config *ic = config->input_configs->items[i]; | ||
66 | merge_input_config(ic, input); | ||
67 | free_input_config(input); | ||
68 | input = ic; | ||
69 | } else { | ||
70 | list_add(config->input_configs, input); | ||
71 | } | ||
72 | |||
73 | current_input_config = input; | ||
74 | |||
75 | if (input->identifier) { | ||
76 | // Try to find the input device and apply configuration now. If | ||
77 | // this is during startup then there will be no container and config | ||
78 | // will be applied during normal "new input" event from wlc. | ||
79 | /* TODO WLR | ||
80 | struct libinput_device *device = NULL; | ||
81 | for (int i = 0; i < input_devices->length; ++i) { | ||
82 | device = input_devices->items[i]; | ||
83 | char* dev_identifier = libinput_dev_unique_id(device); | ||
84 | if (!dev_identifier) { | ||
85 | break; | ||
86 | } | ||
87 | int match = dev_identifier && strcmp(dev_identifier, input->identifier) == 0; | ||
88 | free(dev_identifier); | ||
89 | if (match) { | ||
90 | apply_input_config(input, device); | ||
91 | break; | ||
92 | } | ||
93 | } | ||
94 | */ | ||
95 | } | ||
96 | } | ||
97 | |||
59 | /** | 98 | /** |
60 | * Check and add color to buffer. | 99 | * Check and add color to buffer. |
61 | * | 100 | * |
@@ -96,6 +135,7 @@ static struct cmd_handler handlers[] = { | |||
96 | { "exec_always", cmd_exec_always }, | 135 | { "exec_always", cmd_exec_always }, |
97 | { "exit", cmd_exit }, | 136 | { "exit", cmd_exit }, |
98 | { "include", cmd_include }, | 137 | { "include", cmd_include }, |
138 | { "input", cmd_input }, | ||
99 | }; | 139 | }; |
100 | 140 | ||
101 | static int handler_compare(const void *_a, const void *_b) { | 141 | static int handler_compare(const void *_a, const void *_b) { |
@@ -104,37 +144,35 @@ static int handler_compare(const void *_a, const void *_b) { | |||
104 | return strcasecmp(a->command, b->command); | 144 | return strcasecmp(a->command, b->command); |
105 | } | 145 | } |
106 | 146 | ||
147 | static struct cmd_handler input_handlers[] = { | ||
148 | { "accel_profile", input_cmd_accel_profile }, | ||
149 | { "click_method", input_cmd_click_method }, | ||
150 | { "drag_lock", input_cmd_drag_lock }, | ||
151 | { "dwt", input_cmd_dwt }, | ||
152 | { "events", input_cmd_events }, | ||
153 | { "left_handed", input_cmd_left_handed }, | ||
154 | { "middle_emulation", input_cmd_middle_emulation }, | ||
155 | { "natural_scroll", input_cmd_natural_scroll }, | ||
156 | { "pointer_accel", input_cmd_pointer_accel }, | ||
157 | { "scroll_method", input_cmd_scroll_method }, | ||
158 | { "tap", input_cmd_tap }, | ||
159 | }; | ||
160 | |||
107 | static struct cmd_handler *find_handler(char *line, enum cmd_status block) { | 161 | static struct cmd_handler *find_handler(char *line, enum cmd_status block) { |
108 | struct cmd_handler d = { .command=line }; | 162 | struct cmd_handler d = { .command=line }; |
109 | struct cmd_handler *res = NULL; | 163 | struct cmd_handler *res = NULL; |
110 | sway_log(L_DEBUG, "find_handler(%s) %d", line, block == CMD_BLOCK_INPUT); | 164 | sway_log(L_DEBUG, "find_handler(%s) %d", line, block == CMD_BLOCK_INPUT); |
111 | /* TODO | 165 | |
112 | if (block == CMD_BLOCK_BAR) { | 166 | if (block == CMD_BLOCK_INPUT) { |
113 | res = bsearch(&d, bar_handlers, | ||
114 | sizeof(bar_handlers) / sizeof(struct cmd_handler), | ||
115 | sizeof(struct cmd_handler), handler_compare); | ||
116 | } else if (block == CMD_BLOCK_BAR_COLORS){ | ||
117 | res = bsearch(&d, bar_colors_handlers, | ||
118 | sizeof(bar_colors_handlers) / sizeof(struct cmd_handler), | ||
119 | sizeof(struct cmd_handler), handler_compare); | ||
120 | } else if (block == CMD_BLOCK_INPUT) { | ||
121 | res = bsearch(&d, input_handlers, | 167 | res = bsearch(&d, input_handlers, |
122 | sizeof(input_handlers) / sizeof(struct cmd_handler), | 168 | sizeof(input_handlers) / sizeof(struct cmd_handler), |
123 | sizeof(struct cmd_handler), handler_compare); | 169 | sizeof(struct cmd_handler), handler_compare); |
124 | } else if (block == CMD_BLOCK_IPC) { | ||
125 | res = bsearch(&d, ipc_handlers, | ||
126 | sizeof(ipc_handlers) / sizeof(struct cmd_handler), | ||
127 | sizeof(struct cmd_handler), handler_compare); | ||
128 | } else if (block == CMD_BLOCK_IPC_EVENTS) { | ||
129 | res = bsearch(&d, ipc_event_handlers, | ||
130 | sizeof(ipc_event_handlers) / sizeof(struct cmd_handler), | ||
131 | sizeof(struct cmd_handler), handler_compare); | ||
132 | } else { | 170 | } else { |
133 | */ | ||
134 | res = bsearch(&d, handlers, | 171 | res = bsearch(&d, handlers, |
135 | sizeof(handlers) / sizeof(struct cmd_handler), | 172 | sizeof(handlers) / sizeof(struct cmd_handler), |
136 | sizeof(struct cmd_handler), handler_compare); | 173 | sizeof(struct cmd_handler), handler_compare); |
137 | //} | 174 | } |
175 | |||
138 | return res; | 176 | return res; |
139 | } | 177 | } |
140 | 178 | ||
@@ -238,8 +276,8 @@ struct cmd_results *config_command(char *exec, enum cmd_status block) { | |||
238 | argv[i] = do_var_replacement(argv[i]); | 276 | argv[i] = do_var_replacement(argv[i]); |
239 | unescape_string(argv[i]); | 277 | unescape_string(argv[i]); |
240 | } | 278 | } |
241 | /* Strip quotes for first argument. | 279 | // Strip quotes for first argument. |
242 | * TODO This part needs to be handled much better */ | 280 | // TODO This part needs to be handled much better |
243 | if (argc>1 && (*argv[1] == '\"' || *argv[1] == '\'')) { | 281 | if (argc>1 && (*argv[1] == '\"' || *argv[1] == '\'')) { |
244 | strip_quotes(argv[1]); | 282 | strip_quotes(argv[1]); |
245 | } | 283 | } |
diff --git a/sway/commands/input.c b/sway/commands/input.c new file mode 100644 index 00000000..5ca9c2e6 --- /dev/null +++ b/sway/commands/input.c | |||
@@ -0,0 +1,55 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "sway/input/input-manager.h" | ||
5 | #include "log.h" | ||
6 | |||
7 | struct cmd_results *cmd_input(int argc, char **argv) { | ||
8 | struct cmd_results *error = NULL; | ||
9 | if ((error = checkarg(argc, "input", EXPECTED_AT_LEAST, 2))) { | ||
10 | return error; | ||
11 | } | ||
12 | |||
13 | if (config->reading && strcmp("{", argv[1]) == 0) { | ||
14 | current_input_config = new_input_config(argv[0]); | ||
15 | sway_log(L_DEBUG, "entering input block: %s", current_input_config->identifier); | ||
16 | return cmd_results_new(CMD_BLOCK_INPUT, NULL, NULL); | ||
17 | } | ||
18 | |||
19 | if (argc > 2) { | ||
20 | int argc_new = argc-2; | ||
21 | char **argv_new = argv+2; | ||
22 | |||
23 | struct cmd_results *res; | ||
24 | current_input_config = new_input_config(argv[0]); | ||
25 | if (strcasecmp("accel_profile", argv[1]) == 0) { | ||
26 | res = input_cmd_accel_profile(argc_new, argv_new); | ||
27 | } else if (strcasecmp("click_method", argv[1]) == 0) { | ||
28 | res = input_cmd_click_method(argc_new, argv_new); | ||
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 | } | ||
50 | current_input_config = NULL; | ||
51 | return res; | ||
52 | } | ||
53 | |||
54 | return cmd_results_new(CMD_BLOCK_INPUT, NULL, NULL); | ||
55 | } | ||
diff --git a/sway/commands/input/accel_profile.c b/sway/commands/input/accel_profile.c new file mode 100644 index 00000000..13ded431 --- /dev/null +++ b/sway/commands/input/accel_profile.c | |||
@@ -0,0 +1,27 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "sway/input/input-manager.h" | ||
5 | |||
6 | struct cmd_results *input_cmd_accel_profile(int argc, char **argv) { | ||
7 | struct cmd_results *error = NULL; | ||
8 | if ((error = checkarg(argc, "accel_profile", EXPECTED_AT_LEAST, 1))) { | ||
9 | return error; | ||
10 | } | ||
11 | if (!current_input_config) { | ||
12 | return cmd_results_new(CMD_FAILURE, "accel_profile", "No input device defined."); | ||
13 | } | ||
14 | struct input_config *new_config = new_input_config(current_input_config->identifier); | ||
15 | |||
16 | if (strcasecmp(argv[0], "adaptive") == 0) { | ||
17 | new_config->accel_profile = LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE; | ||
18 | } else if (strcasecmp(argv[0], "flat") == 0) { | ||
19 | new_config->accel_profile = LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT; | ||
20 | } else { | ||
21 | return cmd_results_new(CMD_INVALID, "accel_profile", | ||
22 | "Expected 'accel_profile <adaptive|flat>'"); | ||
23 | } | ||
24 | |||
25 | input_cmd_apply(new_config); | ||
26 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
27 | } | ||
diff --git a/sway/commands/input/click_method.c b/sway/commands/input/click_method.c new file mode 100644 index 00000000..40f075ce --- /dev/null +++ b/sway/commands/input/click_method.c | |||
@@ -0,0 +1,30 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "sway/input/input-manager.h" | ||
5 | #include "log.h" | ||
6 | |||
7 | struct cmd_results *input_cmd_click_method(int argc, char **argv) { | ||
8 | sway_log(L_DEBUG, "click_method for device: %d %s", current_input_config==NULL, current_input_config->identifier); | ||
9 | struct cmd_results *error = NULL; | ||
10 | if ((error = checkarg(argc, "click_method", EXPECTED_AT_LEAST, 1))) { | ||
11 | return error; | ||
12 | } | ||
13 | if (!current_input_config) { | ||
14 | return cmd_results_new(CMD_FAILURE, "click_method", "No input device defined."); | ||
15 | } | ||
16 | struct input_config *new_config = new_input_config(current_input_config->identifier); | ||
17 | |||
18 | if (strcasecmp(argv[0], "none") == 0) { | ||
19 | new_config->click_method = LIBINPUT_CONFIG_CLICK_METHOD_NONE; | ||
20 | } else if (strcasecmp(argv[0], "button_areas") == 0) { | ||
21 | new_config->click_method = LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS; | ||
22 | } else if (strcasecmp(argv[0], "clickfinger") == 0) { | ||
23 | new_config->click_method = LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER; | ||
24 | } else { | ||
25 | return cmd_results_new(CMD_INVALID, "click_method", "Expected 'click_method <none|button_areas|clickfinger'"); | ||
26 | } | ||
27 | |||
28 | input_cmd_apply(new_config); | ||
29 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
30 | } | ||
diff --git a/sway/commands/input/drag_lock.c b/sway/commands/input/drag_lock.c new file mode 100644 index 00000000..11e7fbea --- /dev/null +++ b/sway/commands/input/drag_lock.c | |||
@@ -0,0 +1,26 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "sway/input/input-manager.h" | ||
5 | |||
6 | struct cmd_results *input_cmd_drag_lock(int argc, char **argv) { | ||
7 | struct cmd_results *error = NULL; | ||
8 | if ((error = checkarg(argc, "drag_lock", EXPECTED_AT_LEAST, 1))) { | ||
9 | return error; | ||
10 | } | ||
11 | if (!current_input_config) { | ||
12 | return cmd_results_new(CMD_FAILURE, "drag_lock", "No input device defined."); | ||
13 | } | ||
14 | struct input_config *new_config = new_input_config(current_input_config->identifier); | ||
15 | |||
16 | if (strcasecmp(argv[0], "enabled") == 0) { | ||
17 | new_config->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_ENABLED; | ||
18 | } else if (strcasecmp(argv[0], "disabled") == 0) { | ||
19 | new_config->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_DISABLED; | ||
20 | } else { | ||
21 | return cmd_results_new(CMD_INVALID, "drag_lock", "Expected 'drag_lock <enabled|disabled>'"); | ||
22 | } | ||
23 | |||
24 | input_cmd_apply(new_config); | ||
25 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
26 | } | ||
diff --git a/sway/commands/input/dwt.c b/sway/commands/input/dwt.c new file mode 100644 index 00000000..f3cbf252 --- /dev/null +++ b/sway/commands/input/dwt.c | |||
@@ -0,0 +1,26 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "sway/input/input-manager.h" | ||
5 | |||
6 | struct cmd_results *input_cmd_dwt(int argc, char **argv) { | ||
7 | struct cmd_results *error = NULL; | ||
8 | if ((error = checkarg(argc, "dwt", EXPECTED_AT_LEAST, 1))) { | ||
9 | return error; | ||
10 | } | ||
11 | if (!current_input_config) { | ||
12 | return cmd_results_new(CMD_FAILURE, "dwt", "No input device defined."); | ||
13 | } | ||
14 | struct input_config *new_config = new_input_config(current_input_config->identifier); | ||
15 | |||
16 | if (strcasecmp(argv[0], "enabled") == 0) { | ||
17 | new_config->dwt = LIBINPUT_CONFIG_DWT_ENABLED; | ||
18 | } else if (strcasecmp(argv[0], "disabled") == 0) { | ||
19 | new_config->dwt = LIBINPUT_CONFIG_DWT_DISABLED; | ||
20 | } else { | ||
21 | return cmd_results_new(CMD_INVALID, "dwt", "Expected 'dwt <enabled|disabled>'"); | ||
22 | } | ||
23 | |||
24 | input_cmd_apply(new_config); | ||
25 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
26 | } | ||
diff --git a/sway/commands/input/events.c b/sway/commands/input/events.c new file mode 100644 index 00000000..4b2fdff5 --- /dev/null +++ b/sway/commands/input/events.c | |||
@@ -0,0 +1,30 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "sway/input/input-manager.h" | ||
5 | #include "log.h" | ||
6 | |||
7 | struct cmd_results *input_cmd_events(int argc, char **argv) { | ||
8 | sway_log(L_DEBUG, "events for device: %s", current_input_config->identifier); | ||
9 | struct cmd_results *error = NULL; | ||
10 | if ((error = checkarg(argc, "events", EXPECTED_AT_LEAST, 1))) { | ||
11 | return error; | ||
12 | } | ||
13 | if (!current_input_config) { | ||
14 | return cmd_results_new(CMD_FAILURE, "events", "No input device defined."); | ||
15 | } | ||
16 | struct input_config *new_config = new_input_config(current_input_config->identifier); | ||
17 | |||
18 | if (strcasecmp(argv[0], "enabled") == 0) { | ||
19 | new_config->send_events = LIBINPUT_CONFIG_SEND_EVENTS_ENABLED; | ||
20 | } else if (strcasecmp(argv[0], "disabled") == 0) { | ||
21 | new_config->send_events = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED; | ||
22 | } else if (strcasecmp(argv[0], "disabled_on_external_mouse") == 0) { | ||
23 | new_config->send_events = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE; | ||
24 | } else { | ||
25 | return cmd_results_new(CMD_INVALID, "events", "Expected 'events <enabled|disabled|disabled_on_external_mouse>'"); | ||
26 | } | ||
27 | |||
28 | input_cmd_apply(new_config); | ||
29 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
30 | } | ||
diff --git a/sway/commands/input/left_handed.c b/sway/commands/input/left_handed.c new file mode 100644 index 00000000..715df2a1 --- /dev/null +++ b/sway/commands/input/left_handed.c | |||
@@ -0,0 +1,26 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "sway/input/input-manager.h" | ||
5 | |||
6 | struct cmd_results *input_cmd_left_handed(int argc, char **argv) { | ||
7 | struct cmd_results *error = NULL; | ||
8 | if ((error = checkarg(argc, "left_handed", EXPECTED_AT_LEAST, 1))) { | ||
9 | return error; | ||
10 | } | ||
11 | if (!current_input_config) { | ||
12 | return cmd_results_new(CMD_FAILURE, "left_handed", "No input device defined."); | ||
13 | } | ||
14 | struct input_config *new_config = new_input_config(current_input_config->identifier); | ||
15 | |||
16 | if (strcasecmp(argv[0], "enabled") == 0) { | ||
17 | new_config->left_handed = 1; | ||
18 | } else if (strcasecmp(argv[0], "disabled") == 0) { | ||
19 | new_config->left_handed = 0; | ||
20 | } else { | ||
21 | return cmd_results_new(CMD_INVALID, "left_handed", "Expected 'left_handed <enabled|disabled>'"); | ||
22 | } | ||
23 | |||
24 | input_cmd_apply(new_config); | ||
25 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
26 | } | ||
diff --git a/sway/commands/input/middle_emulation.c b/sway/commands/input/middle_emulation.c new file mode 100644 index 00000000..d31ce950 --- /dev/null +++ b/sway/commands/input/middle_emulation.c | |||
@@ -0,0 +1,26 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "sway/input/input-manager.h" | ||
5 | |||
6 | struct cmd_results *input_cmd_middle_emulation(int argc, char **argv) { | ||
7 | struct cmd_results *error = NULL; | ||
8 | if ((error = checkarg(argc, "middle_emulation", EXPECTED_AT_LEAST, 1))) { | ||
9 | return error; | ||
10 | } | ||
11 | if (!current_input_config) { | ||
12 | return cmd_results_new(CMD_FAILURE, "middle_emulation", "No input device defined."); | ||
13 | } | ||
14 | struct input_config *new_config = new_input_config(current_input_config->identifier); | ||
15 | |||
16 | if (strcasecmp(argv[0], "enabled") == 0) { | ||
17 | new_config->middle_emulation = LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED; | ||
18 | } else if (strcasecmp(argv[0], "disabled") == 0) { | ||
19 | new_config->middle_emulation = LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED; | ||
20 | } else { | ||
21 | return cmd_results_new(CMD_INVALID, "middle_emulation", "Expected 'middle_emulation <enabled|disabled>'"); | ||
22 | } | ||
23 | |||
24 | input_cmd_apply(new_config); | ||
25 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
26 | } | ||
diff --git a/sway/commands/input/natural_scroll.c b/sway/commands/input/natural_scroll.c new file mode 100644 index 00000000..9d1dc506 --- /dev/null +++ b/sway/commands/input/natural_scroll.c | |||
@@ -0,0 +1,26 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "sway/input/input-manager.h" | ||
5 | |||
6 | struct cmd_results *input_cmd_natural_scroll(int argc, char **argv) { | ||
7 | struct cmd_results *error = NULL; | ||
8 | if ((error = checkarg(argc, "natural_scroll", EXPECTED_AT_LEAST, 1))) { | ||
9 | return error; | ||
10 | } | ||
11 | if (!current_input_config) { | ||
12 | return cmd_results_new(CMD_FAILURE, "natural_scoll", "No input device defined."); | ||
13 | } | ||
14 | struct input_config *new_config = new_input_config(current_input_config->identifier); | ||
15 | |||
16 | if (strcasecmp(argv[0], "enabled") == 0) { | ||
17 | new_config->natural_scroll = 1; | ||
18 | } else if (strcasecmp(argv[0], "disabled") == 0) { | ||
19 | new_config->natural_scroll = 0; | ||
20 | } else { | ||
21 | return cmd_results_new(CMD_INVALID, "natural_scroll", "Expected 'natural_scroll <enabled|disabled>'"); | ||
22 | } | ||
23 | |||
24 | input_cmd_apply(new_config); | ||
25 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
26 | } | ||
diff --git a/sway/commands/input/pointer_accel.c b/sway/commands/input/pointer_accel.c new file mode 100644 index 00000000..87fb5cff --- /dev/null +++ b/sway/commands/input/pointer_accel.c | |||
@@ -0,0 +1,24 @@ | |||
1 | #include <stdlib.h> | ||
2 | #include <string.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "sway/input/input-manager.h" | ||
5 | |||
6 | struct cmd_results *input_cmd_pointer_accel(int argc, char **argv) { | ||
7 | struct cmd_results *error = NULL; | ||
8 | if ((error = checkarg(argc, "pointer_accel", EXPECTED_AT_LEAST, 1))) { | ||
9 | return error; | ||
10 | } | ||
11 | if (!current_input_config) { | ||
12 | return cmd_results_new(CMD_FAILURE, "pointer_accel", "No input device defined."); | ||
13 | } | ||
14 | struct input_config *new_config = new_input_config(current_input_config->identifier); | ||
15 | |||
16 | float pointer_accel = atof(argv[0]); | ||
17 | if (pointer_accel < -1 || pointer_accel > 1) { | ||
18 | return cmd_results_new(CMD_INVALID, "pointer_accel", "Input out of range [-1, 1]"); | ||
19 | } | ||
20 | new_config->pointer_accel = pointer_accel; | ||
21 | |||
22 | input_cmd_apply(new_config); | ||
23 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
24 | } | ||
diff --git a/sway/commands/input/scroll_method.c b/sway/commands/input/scroll_method.c new file mode 100644 index 00000000..98873938 --- /dev/null +++ b/sway/commands/input/scroll_method.c | |||
@@ -0,0 +1,30 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "sway/input/input-manager.h" | ||
5 | |||
6 | struct cmd_results *input_cmd_scroll_method(int argc, char **argv) { | ||
7 | struct cmd_results *error = NULL; | ||
8 | if ((error = checkarg(argc, "scroll_method", EXPECTED_AT_LEAST, 1))) { | ||
9 | return error; | ||
10 | } | ||
11 | if (!current_input_config) { | ||
12 | return cmd_results_new(CMD_FAILURE, "scroll_method", "No input device defined."); | ||
13 | } | ||
14 | struct input_config *new_config = new_input_config(current_input_config->identifier); | ||
15 | |||
16 | if (strcasecmp(argv[0], "none") == 0) { | ||
17 | new_config->scroll_method = LIBINPUT_CONFIG_SCROLL_NO_SCROLL; | ||
18 | } else if (strcasecmp(argv[0], "two_finger") == 0) { | ||
19 | new_config->scroll_method = LIBINPUT_CONFIG_SCROLL_2FG; | ||
20 | } else if (strcasecmp(argv[0], "edge") == 0) { | ||
21 | new_config->scroll_method = LIBINPUT_CONFIG_SCROLL_EDGE; | ||
22 | } else if (strcasecmp(argv[0], "on_button_down") == 0) { | ||
23 | new_config->scroll_method = LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN; | ||
24 | } else { | ||
25 | return cmd_results_new(CMD_INVALID, "scroll_method", "Expected 'scroll_method <none|two_finger|edge|on_button_down>'"); | ||
26 | } | ||
27 | |||
28 | input_cmd_apply(new_config); | ||
29 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
30 | } | ||
diff --git a/sway/commands/input/tap.c b/sway/commands/input/tap.c new file mode 100644 index 00000000..1109466f --- /dev/null +++ b/sway/commands/input/tap.c | |||
@@ -0,0 +1,29 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "sway/input/input-manager.h" | ||
5 | #include "log.h" | ||
6 | |||
7 | struct cmd_results *input_cmd_tap(int argc, char **argv) { | ||
8 | sway_log(L_DEBUG, "tap for device: %s", current_input_config->identifier); | ||
9 | struct cmd_results *error = NULL; | ||
10 | if ((error = checkarg(argc, "tap", EXPECTED_AT_LEAST, 1))) { | ||
11 | return error; | ||
12 | } | ||
13 | if (!current_input_config) { | ||
14 | return cmd_results_new(CMD_FAILURE, "tap", "No input device defined."); | ||
15 | } | ||
16 | struct input_config *new_config = new_input_config(current_input_config->identifier); | ||
17 | |||
18 | if (strcasecmp(argv[0], "enabled") == 0) { | ||
19 | new_config->tap = LIBINPUT_CONFIG_TAP_ENABLED; | ||
20 | } else if (strcasecmp(argv[0], "disabled") == 0) { | ||
21 | new_config->tap = LIBINPUT_CONFIG_TAP_DISABLED; | ||
22 | } else { | ||
23 | return cmd_results_new(CMD_INVALID, "tap", "Expected 'tap <enabled|disabled>'"); | ||
24 | } | ||
25 | |||
26 | sway_log(L_DEBUG, "apply-tap for device: %s", current_input_config->identifier); | ||
27 | input_cmd_apply(new_config); | ||
28 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
29 | } | ||
diff --git a/sway/config.c b/sway/config.c index 61131845..ec8e89b4 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -226,6 +226,59 @@ static int qstrcmp(const void* a, const void* b) { | |||
226 | return strcmp(*((char**) a), *((char**) b)); | 226 | return strcmp(*((char**) a), *((char**) b)); |
227 | } | 227 | } |
228 | 228 | ||
229 | void merge_input_config(struct input_config *dst, struct input_config *src) { | ||
230 | if (src->identifier) { | ||
231 | if (dst->identifier) { | ||
232 | free(dst->identifier); | ||
233 | } | ||
234 | dst->identifier = strdup(src->identifier); | ||
235 | } | ||
236 | if (src->accel_profile != INT_MIN) { | ||
237 | dst->accel_profile = src->accel_profile; | ||
238 | } | ||
239 | if (src->click_method != INT_MIN) { | ||
240 | dst->click_method = src->click_method; | ||
241 | } | ||
242 | if (src->drag_lock != INT_MIN) { | ||
243 | dst->drag_lock = src->drag_lock; | ||
244 | } | ||
245 | if (src->dwt != INT_MIN) { | ||
246 | dst->dwt = src->dwt; | ||
247 | } | ||
248 | if (src->middle_emulation != INT_MIN) { | ||
249 | dst->middle_emulation = src->middle_emulation; | ||
250 | } | ||
251 | if (src->natural_scroll != INT_MIN) { | ||
252 | dst->natural_scroll = src->natural_scroll; | ||
253 | } | ||
254 | if (src->pointer_accel != FLT_MIN) { | ||
255 | dst->pointer_accel = src->pointer_accel; | ||
256 | } | ||
257 | if (src->scroll_method != INT_MIN) { | ||
258 | dst->scroll_method = src->scroll_method; | ||
259 | } | ||
260 | if (src->send_events != INT_MIN) { | ||
261 | dst->send_events = src->send_events; | ||
262 | } | ||
263 | if (src->tap != INT_MIN) { | ||
264 | dst->tap = src->tap; | ||
265 | } | ||
266 | } | ||
267 | |||
268 | void free_input_config(struct input_config *ic) { | ||
269 | if (!ic) { | ||
270 | return; | ||
271 | } | ||
272 | free(ic->identifier); | ||
273 | free(ic); | ||
274 | } | ||
275 | |||
276 | int input_identifier_cmp(const void *item, const void *data) { | ||
277 | const struct input_config *ic = item; | ||
278 | const char *identifier = data; | ||
279 | return strcmp(ic->identifier, identifier); | ||
280 | } | ||
281 | |||
229 | bool load_main_config(const char *file, bool is_active) { | 282 | bool load_main_config(const char *file, bool is_active) { |
230 | char *path; | 283 | char *path; |
231 | if (file != NULL) { | 284 | if (file != NULL) { |
diff --git a/sway/meson.build b/sway/meson.build index 79201f3a..aa3dd2a7 100644 --- a/sway/meson.build +++ b/sway/meson.build | |||
@@ -10,6 +10,18 @@ sway_sources = files( | |||
10 | 'commands/exec.c', | 10 | 'commands/exec.c', |
11 | 'commands/exec_always.c', | 11 | 'commands/exec_always.c', |
12 | 'commands/include.c', | 12 | 'commands/include.c', |
13 | 'commands/input.c', | ||
14 | 'commands/input/accel_profile.c', | ||
15 | 'commands/input/click_method.c', | ||
16 | 'commands/input/drag_lock.c', | ||
17 | 'commands/input/dwt.c', | ||
18 | 'commands/input/events.c', | ||
19 | 'commands/input/left_handed.c', | ||
20 | 'commands/input/middle_emulation.c', | ||
21 | 'commands/input/natural_scroll.c', | ||
22 | 'commands/input/pointer_accel.c', | ||
23 | 'commands/input/scroll_method.c', | ||
24 | 'commands/input/tap.c', | ||
13 | 'config.c', | 25 | 'config.c', |
14 | 'ipc-json.c', | 26 | 'ipc-json.c', |
15 | 'ipc-server.c', | 27 | 'ipc-server.c', |