diff options
author | Brian Ashworth <bosrsf04@gmail.com> | 2018-09-23 19:56:52 -0400 |
---|---|---|
committer | Brian Ashworth <bosrsf04@gmail.com> | 2018-09-23 19:56:52 -0400 |
commit | baeb28ea6230ef9aa409ee52abe208720120e45c (patch) | |
tree | d5a6fffc3470b3fbbb18a6ae01851451bea1dbb2 /sway | |
parent | Merge pull request #2699 from RedSoxFan/fix-2667 (diff) | |
download | sway-baeb28ea6230ef9aa409ee52abe208720120e45c.tar.gz sway-baeb28ea6230ef9aa409ee52abe208720120e45c.tar.zst sway-baeb28ea6230ef9aa409ee52abe208720120e45c.zip |
Implement support for input wildcard
Diffstat (limited to 'sway')
28 files changed, 182 insertions, 263 deletions
diff --git a/sway/commands.c b/sway/commands.c index 5b61f73a..bff230f7 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -55,22 +55,6 @@ struct cmd_results *checkarg(int argc, const char *name, enum expected_args type | |||
55 | return error; | 55 | return error; |
56 | } | 56 | } |
57 | 57 | ||
58 | void apply_input_config(struct input_config *input) { | ||
59 | int i; | ||
60 | i = list_seq_find(config->input_configs, input_identifier_cmp, input->identifier); | ||
61 | if (i >= 0) { | ||
62 | // merge existing config | ||
63 | struct input_config *ic = config->input_configs->items[i]; | ||
64 | merge_input_config(ic, input); | ||
65 | free_input_config(input); | ||
66 | input = ic; | ||
67 | } else { | ||
68 | list_add(config->input_configs, input); | ||
69 | } | ||
70 | |||
71 | input_manager_apply_input_config(input_manager, input); | ||
72 | } | ||
73 | |||
74 | void apply_seat_config(struct seat_config *seat_config) { | 58 | void apply_seat_config(struct seat_config *seat_config) { |
75 | int i; | 59 | int i; |
76 | i = list_seq_find(config->seat_configs, seat_name_cmp, seat_config->name); | 60 | i = list_seq_find(config->seat_configs, seat_name_cmp, seat_config->name); |
diff --git a/sway/commands/input.c b/sway/commands/input.c index 84888fbb..9091da2a 100644 --- a/sway/commands/input.c +++ b/sway/commands/input.c | |||
@@ -66,7 +66,15 @@ struct cmd_results *cmd_input(int argc, char **argv) { | |||
66 | input_handlers, sizeof(input_handlers)); | 66 | input_handlers, sizeof(input_handlers)); |
67 | } | 67 | } |
68 | 68 | ||
69 | free_input_config(config->handler_context.input_config); | 69 | if (!res || res->status == CMD_SUCCESS) { |
70 | struct input_config *ic = | ||
71 | store_input_config(config->handler_context.input_config); | ||
72 | |||
73 | input_manager_apply_input_config(input_manager, ic); | ||
74 | } else { | ||
75 | free_input_config(config->handler_context.input_config); | ||
76 | } | ||
77 | |||
70 | config->handler_context.input_config = NULL; | 78 | config->handler_context.input_config = NULL; |
71 | 79 | ||
72 | return res; | 80 | return res; |
diff --git a/sway/commands/input/accel_profile.c b/sway/commands/input/accel_profile.c index a4108ec3..f7016790 100644 --- a/sway/commands/input/accel_profile.c +++ b/sway/commands/input/accel_profile.c | |||
@@ -9,25 +9,20 @@ struct cmd_results *input_cmd_accel_profile(int argc, char **argv) { | |||
9 | if ((error = checkarg(argc, "accel_profile", EXPECTED_AT_LEAST, 1))) { | 9 | if ((error = checkarg(argc, "accel_profile", EXPECTED_AT_LEAST, 1))) { |
10 | return error; | 10 | return error; |
11 | } | 11 | } |
12 | struct input_config *current_input_config = | 12 | struct input_config *ic = config->handler_context.input_config; |
13 | config->handler_context.input_config; | 13 | if (!ic) { |
14 | if (!current_input_config) { | ||
15 | return cmd_results_new(CMD_FAILURE, "accel_profile", | 14 | return cmd_results_new(CMD_FAILURE, "accel_profile", |
16 | "No input device defined."); | 15 | "No input device defined."); |
17 | } | 16 | } |
18 | struct input_config *new_config = | ||
19 | new_input_config(current_input_config->identifier); | ||
20 | 17 | ||
21 | if (strcasecmp(argv[0], "adaptive") == 0) { | 18 | if (strcasecmp(argv[0], "adaptive") == 0) { |
22 | new_config->accel_profile = LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE; | 19 | ic->accel_profile = LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE; |
23 | } else if (strcasecmp(argv[0], "flat") == 0) { | 20 | } else if (strcasecmp(argv[0], "flat") == 0) { |
24 | new_config->accel_profile = LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT; | 21 | ic->accel_profile = LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT; |
25 | } else { | 22 | } else { |
26 | free_input_config(new_config); | ||
27 | return cmd_results_new(CMD_INVALID, "accel_profile", | 23 | return cmd_results_new(CMD_INVALID, "accel_profile", |
28 | "Expected 'accel_profile <adaptive|flat>'"); | 24 | "Expected 'accel_profile <adaptive|flat>'"); |
29 | } | 25 | } |
30 | 26 | ||
31 | apply_input_config(new_config); | ||
32 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 27 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
33 | } | 28 | } |
diff --git a/sway/commands/input/click_method.c b/sway/commands/input/click_method.c index 5d0d8cc2..4d7e1c93 100644 --- a/sway/commands/input/click_method.c +++ b/sway/commands/input/click_method.c | |||
@@ -10,27 +10,22 @@ struct cmd_results *input_cmd_click_method(int argc, char **argv) { | |||
10 | if ((error = checkarg(argc, "click_method", EXPECTED_AT_LEAST, 1))) { | 10 | if ((error = checkarg(argc, "click_method", EXPECTED_AT_LEAST, 1))) { |
11 | return error; | 11 | return error; |
12 | } | 12 | } |
13 | struct input_config *current_input_config = | 13 | struct input_config *ic = config->handler_context.input_config; |
14 | config->handler_context.input_config; | 14 | if (!ic) { |
15 | if (!current_input_config) { | ||
16 | return cmd_results_new(CMD_FAILURE, "click_method", | 15 | return cmd_results_new(CMD_FAILURE, "click_method", |
17 | "No input device defined."); | 16 | "No input device defined."); |
18 | } | 17 | } |
19 | struct input_config *new_config = | ||
20 | new_input_config(current_input_config->identifier); | ||
21 | 18 | ||
22 | if (strcasecmp(argv[0], "none") == 0) { | 19 | if (strcasecmp(argv[0], "none") == 0) { |
23 | new_config->click_method = LIBINPUT_CONFIG_CLICK_METHOD_NONE; | 20 | ic->click_method = LIBINPUT_CONFIG_CLICK_METHOD_NONE; |
24 | } else if (strcasecmp(argv[0], "button_areas") == 0) { | 21 | } else if (strcasecmp(argv[0], "button_areas") == 0) { |
25 | new_config->click_method = LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS; | 22 | ic->click_method = LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS; |
26 | } else if (strcasecmp(argv[0], "clickfinger") == 0) { | 23 | } else if (strcasecmp(argv[0], "clickfinger") == 0) { |
27 | new_config->click_method = LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER; | 24 | ic->click_method = LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER; |
28 | } else { | 25 | } else { |
29 | free_input_config(new_config); | ||
30 | return cmd_results_new(CMD_INVALID, "click_method", | 26 | return cmd_results_new(CMD_INVALID, "click_method", |
31 | "Expected 'click_method <none|button_areas|clickfinger'"); | 27 | "Expected 'click_method <none|button_areas|clickfinger'"); |
32 | } | 28 | } |
33 | 29 | ||
34 | apply_input_config(new_config); | ||
35 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 30 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
36 | } | 31 | } |
diff --git a/sway/commands/input/drag_lock.c b/sway/commands/input/drag_lock.c index f9ddeef2..db5d5afa 100644 --- a/sway/commands/input/drag_lock.c +++ b/sway/commands/input/drag_lock.c | |||
@@ -10,21 +10,17 @@ struct cmd_results *input_cmd_drag_lock(int argc, char **argv) { | |||
10 | if ((error = checkarg(argc, "drag_lock", EXPECTED_AT_LEAST, 1))) { | 10 | if ((error = checkarg(argc, "drag_lock", EXPECTED_AT_LEAST, 1))) { |
11 | return error; | 11 | return error; |
12 | } | 12 | } |
13 | struct input_config *current_input_config = | 13 | struct input_config *ic = config->handler_context.input_config; |
14 | config->handler_context.input_config; | 14 | if (!ic) { |
15 | if (!current_input_config) { | ||
16 | return cmd_results_new(CMD_FAILURE, | 15 | return cmd_results_new(CMD_FAILURE, |
17 | "drag_lock", "No input device defined."); | 16 | "drag_lock", "No input device defined."); |
18 | } | 17 | } |
19 | struct input_config *new_config = | ||
20 | new_input_config(current_input_config->identifier); | ||
21 | 18 | ||
22 | if (parse_boolean(argv[0], true)) { | 19 | if (parse_boolean(argv[0], true)) { |
23 | new_config->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_ENABLED; | 20 | ic->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_ENABLED; |
24 | } else { | 21 | } else { |
25 | new_config->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_DISABLED; | 22 | ic->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_DISABLED; |
26 | } | 23 | } |
27 | 24 | ||
28 | apply_input_config(new_config); | ||
29 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 25 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
30 | } | 26 | } |
diff --git a/sway/commands/input/dwt.c b/sway/commands/input/dwt.c index 15134268..0c3881dd 100644 --- a/sway/commands/input/dwt.c +++ b/sway/commands/input/dwt.c | |||
@@ -10,20 +10,16 @@ struct cmd_results *input_cmd_dwt(int argc, char **argv) { | |||
10 | if ((error = checkarg(argc, "dwt", EXPECTED_AT_LEAST, 1))) { | 10 | if ((error = checkarg(argc, "dwt", EXPECTED_AT_LEAST, 1))) { |
11 | return error; | 11 | return error; |
12 | } | 12 | } |
13 | struct input_config *current_input_config = | 13 | struct input_config *ic = config->handler_context.input_config; |
14 | config->handler_context.input_config; | 14 | if (!ic) { |
15 | if (!current_input_config) { | ||
16 | return cmd_results_new(CMD_FAILURE, "dwt", "No input device defined."); | 15 | return cmd_results_new(CMD_FAILURE, "dwt", "No input device defined."); |
17 | } | 16 | } |
18 | struct input_config *new_config = | ||
19 | new_input_config(current_input_config->identifier); | ||
20 | 17 | ||
21 | if (parse_boolean(argv[0], true)) { | 18 | if (parse_boolean(argv[0], true)) { |
22 | new_config->dwt = LIBINPUT_CONFIG_DWT_ENABLED; | 19 | ic->dwt = LIBINPUT_CONFIG_DWT_ENABLED; |
23 | } else { | 20 | } else { |
24 | new_config->dwt = LIBINPUT_CONFIG_DWT_DISABLED; | 21 | ic->dwt = LIBINPUT_CONFIG_DWT_DISABLED; |
25 | } | 22 | } |
26 | 23 | ||
27 | apply_input_config(new_config); | ||
28 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 24 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
29 | } | 25 | } |
diff --git a/sway/commands/input/events.c b/sway/commands/input/events.c index abfe3b12..e7ed69c6 100644 --- a/sway/commands/input/events.c +++ b/sway/commands/input/events.c | |||
@@ -10,30 +10,23 @@ struct cmd_results *input_cmd_events(int argc, char **argv) { | |||
10 | if ((error = checkarg(argc, "events", EXPECTED_AT_LEAST, 1))) { | 10 | if ((error = checkarg(argc, "events", EXPECTED_AT_LEAST, 1))) { |
11 | return error; | 11 | return error; |
12 | } | 12 | } |
13 | struct input_config *current_input_config = | 13 | struct input_config *ic = config->handler_context.input_config; |
14 | config->handler_context.input_config; | 14 | if (!ic) { |
15 | if (!current_input_config) { | ||
16 | return cmd_results_new(CMD_FAILURE, "events", | 15 | return cmd_results_new(CMD_FAILURE, "events", |
17 | "No input device defined."); | 16 | "No input device defined."); |
18 | } | 17 | } |
19 | wlr_log(WLR_DEBUG, "events for device: %s", | ||
20 | current_input_config->identifier); | ||
21 | struct input_config *new_config = | ||
22 | new_input_config(current_input_config->identifier); | ||
23 | 18 | ||
24 | if (strcasecmp(argv[0], "enabled") == 0) { | 19 | if (strcasecmp(argv[0], "enabled") == 0) { |
25 | new_config->send_events = LIBINPUT_CONFIG_SEND_EVENTS_ENABLED; | 20 | ic->send_events = LIBINPUT_CONFIG_SEND_EVENTS_ENABLED; |
26 | } else if (strcasecmp(argv[0], "disabled") == 0) { | 21 | } else if (strcasecmp(argv[0], "disabled") == 0) { |
27 | new_config->send_events = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED; | 22 | ic->send_events = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED; |
28 | } else if (strcasecmp(argv[0], "disabled_on_external_mouse") == 0) { | 23 | } else if (strcasecmp(argv[0], "disabled_on_external_mouse") == 0) { |
29 | new_config->send_events = | 24 | ic->send_events = |
30 | LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE; | 25 | LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE; |
31 | } else { | 26 | } else { |
32 | free_input_config(new_config); | ||
33 | return cmd_results_new(CMD_INVALID, "events", | 27 | return cmd_results_new(CMD_INVALID, "events", |
34 | "Expected 'events <enabled|disabled|disabled_on_external_mouse>'"); | 28 | "Expected 'events <enabled|disabled|disabled_on_external_mouse>'"); |
35 | } | 29 | } |
36 | 30 | ||
37 | apply_input_config(new_config); | ||
38 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 31 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
39 | } | 32 | } |
diff --git a/sway/commands/input/left_handed.c b/sway/commands/input/left_handed.c index e770043a..2e0f757b 100644 --- a/sway/commands/input/left_handed.c +++ b/sway/commands/input/left_handed.c | |||
@@ -10,17 +10,13 @@ struct cmd_results *input_cmd_left_handed(int argc, char **argv) { | |||
10 | if ((error = checkarg(argc, "left_handed", EXPECTED_AT_LEAST, 1))) { | 10 | if ((error = checkarg(argc, "left_handed", EXPECTED_AT_LEAST, 1))) { |
11 | return error; | 11 | return error; |
12 | } | 12 | } |
13 | struct input_config *current_input_config = | 13 | struct input_config *ic = config->handler_context.input_config; |
14 | config->handler_context.input_config; | 14 | if (!ic) { |
15 | if (!current_input_config) { | ||
16 | return cmd_results_new(CMD_FAILURE, "left_handed", | 15 | return cmd_results_new(CMD_FAILURE, "left_handed", |
17 | "No input device defined."); | 16 | "No input device defined."); |
18 | } | 17 | } |
19 | struct input_config *new_config = | ||
20 | new_input_config(current_input_config->identifier); | ||
21 | 18 | ||
22 | new_config->left_handed = parse_boolean(argv[0], true); | 19 | ic->left_handed = parse_boolean(argv[0], true); |
23 | 20 | ||
24 | apply_input_config(new_config); | ||
25 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 21 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
26 | } | 22 | } |
diff --git a/sway/commands/input/map_from_region.c b/sway/commands/input/map_from_region.c index 40f04214..53608a67 100644 --- a/sway/commands/input/map_from_region.c +++ b/sway/commands/input/map_from_region.c | |||
@@ -38,50 +38,44 @@ struct cmd_results *input_cmd_map_from_region(int argc, char **argv) { | |||
38 | if ((error = checkarg(argc, "map_from_region", EXPECTED_EQUAL_TO, 2))) { | 38 | if ((error = checkarg(argc, "map_from_region", EXPECTED_EQUAL_TO, 2))) { |
39 | return error; | 39 | return error; |
40 | } | 40 | } |
41 | struct input_config *current_input_config = | 41 | struct input_config *ic = config->handler_context.input_config; |
42 | config->handler_context.input_config; | 42 | if (!ic) { |
43 | if (!current_input_config) { | ||
44 | return cmd_results_new(CMD_FAILURE, "map_from_region", | 43 | return cmd_results_new(CMD_FAILURE, "map_from_region", |
45 | "No input device defined"); | 44 | "No input device defined"); |
46 | } | 45 | } |
47 | 46 | ||
48 | struct input_config *new_config = | 47 | ic->mapped_from_region = |
49 | new_input_config(current_input_config->identifier); | ||
50 | |||
51 | new_config->mapped_from_region = | ||
52 | calloc(1, sizeof(struct input_config_mapped_from_region)); | 48 | calloc(1, sizeof(struct input_config_mapped_from_region)); |
53 | 49 | ||
54 | bool mm1, mm2; | 50 | bool mm1, mm2; |
55 | if (!parse_coords(argv[0], &new_config->mapped_from_region->x1, | 51 | if (!parse_coords(argv[0], &ic->mapped_from_region->x1, |
56 | &new_config->mapped_from_region->y1, &mm1)) { | 52 | &ic->mapped_from_region->y1, &mm1)) { |
57 | free(new_config->mapped_from_region); | 53 | free(ic->mapped_from_region); |
58 | free_input_config(new_config); | 54 | ic->mapped_from_region = NULL; |
59 | return cmd_results_new(CMD_FAILURE, "map_from_region", | 55 | return cmd_results_new(CMD_FAILURE, "map_from_region", |
60 | "Invalid top-left coordinates"); | 56 | "Invalid top-left coordinates"); |
61 | } | 57 | } |
62 | if (!parse_coords(argv[1], &new_config->mapped_from_region->x2, | 58 | if (!parse_coords(argv[1], &ic->mapped_from_region->x2, |
63 | &new_config->mapped_from_region->y2, &mm2)) { | 59 | &ic->mapped_from_region->y2, &mm2)) { |
64 | free(new_config->mapped_from_region); | 60 | free(ic->mapped_from_region); |
65 | free_input_config(new_config); | 61 | ic->mapped_from_region = NULL; |
66 | return cmd_results_new(CMD_FAILURE, "map_from_region", | 62 | return cmd_results_new(CMD_FAILURE, "map_from_region", |
67 | "Invalid bottom-right coordinates"); | 63 | "Invalid bottom-right coordinates"); |
68 | } | 64 | } |
69 | if (new_config->mapped_from_region->x1 > new_config->mapped_from_region->x2 || | 65 | if (ic->mapped_from_region->x1 > ic->mapped_from_region->x2 || |
70 | new_config->mapped_from_region->y1 > new_config->mapped_from_region->y2) { | 66 | ic->mapped_from_region->y1 > ic->mapped_from_region->y2) { |
71 | free(new_config->mapped_from_region); | 67 | free(ic->mapped_from_region); |
72 | free_input_config(new_config); | 68 | ic->mapped_from_region = NULL; |
73 | return cmd_results_new(CMD_FAILURE, "map_from_region", | 69 | return cmd_results_new(CMD_FAILURE, "map_from_region", |
74 | "Invalid rectangle"); | 70 | "Invalid rectangle"); |
75 | } | 71 | } |
76 | if (mm1 != mm2) { | 72 | if (mm1 != mm2) { |
77 | free(new_config->mapped_from_region); | 73 | free(ic->mapped_from_region); |
78 | free_input_config(new_config); | 74 | ic->mapped_from_region = NULL; |
79 | return cmd_results_new(CMD_FAILURE, "map_from_region", | 75 | return cmd_results_new(CMD_FAILURE, "map_from_region", |
80 | "Both coordinates must be in the same unit"); | 76 | "Both coordinates must be in the same unit"); |
81 | } | 77 | } |
82 | new_config->mapped_from_region->mm = mm1; | 78 | ic->mapped_from_region->mm = mm1; |
83 | |||
84 | apply_input_config(new_config); | ||
85 | 79 | ||
86 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 80 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
87 | } | 81 | } |
diff --git a/sway/commands/input/map_to_output.c b/sway/commands/input/map_to_output.c index 68439bec..8b16c557 100644 --- a/sway/commands/input/map_to_output.c +++ b/sway/commands/input/map_to_output.c | |||
@@ -11,17 +11,13 @@ struct cmd_results *input_cmd_map_to_output(int argc, char **argv) { | |||
11 | if ((error = checkarg(argc, "map_to_output", EXPECTED_EQUAL_TO, 1))) { | 11 | if ((error = checkarg(argc, "map_to_output", EXPECTED_EQUAL_TO, 1))) { |
12 | return error; | 12 | return error; |
13 | } | 13 | } |
14 | struct input_config *current_input_config = | 14 | struct input_config *ic = config->handler_context.input_config; |
15 | config->handler_context.input_config; | 15 | if (!ic) { |
16 | if (!current_input_config) { | ||
17 | return cmd_results_new(CMD_FAILURE, "map_to_output", | 16 | return cmd_results_new(CMD_FAILURE, "map_to_output", |
18 | "No input device defined."); | 17 | "No input device defined."); |
19 | } | 18 | } |
20 | struct input_config *new_config = | ||
21 | new_input_config(current_input_config->identifier); | ||
22 | 19 | ||
23 | new_config->mapped_to_output = strdup(argv[0]); | 20 | ic->mapped_to_output = strdup(argv[0]); |
24 | apply_input_config(new_config); | ||
25 | 21 | ||
26 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 22 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
27 | } | 23 | } |
diff --git a/sway/commands/input/middle_emulation.c b/sway/commands/input/middle_emulation.c index 414d4d2b..80d26838 100644 --- a/sway/commands/input/middle_emulation.c +++ b/sway/commands/input/middle_emulation.c | |||
@@ -10,22 +10,17 @@ struct cmd_results *input_cmd_middle_emulation(int argc, char **argv) { | |||
10 | if ((error = checkarg(argc, "middle_emulation", EXPECTED_AT_LEAST, 1))) { | 10 | if ((error = checkarg(argc, "middle_emulation", EXPECTED_AT_LEAST, 1))) { |
11 | return error; | 11 | return error; |
12 | } | 12 | } |
13 | struct input_config *current_input_config = | 13 | struct input_config *ic = config->handler_context.input_config; |
14 | config->handler_context.input_config; | 14 | if (!ic) { |
15 | if (!current_input_config) { | ||
16 | return cmd_results_new(CMD_FAILURE, "middle_emulation", | 15 | return cmd_results_new(CMD_FAILURE, "middle_emulation", |
17 | "No input device defined."); | 16 | "No input device defined."); |
18 | } | 17 | } |
19 | struct input_config *new_config = | ||
20 | new_input_config(current_input_config->identifier); | ||
21 | 18 | ||
22 | if (parse_boolean(argv[0], true)) { | 19 | if (parse_boolean(argv[0], true)) { |
23 | new_config->middle_emulation = LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED; | 20 | ic->middle_emulation = LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED; |
24 | } else { | 21 | } else { |
25 | new_config->middle_emulation = | 22 | ic->middle_emulation = LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED; |
26 | LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED; | ||
27 | } | 23 | } |
28 | 24 | ||
29 | apply_input_config(new_config); | ||
30 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 25 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
31 | } | 26 | } |
diff --git a/sway/commands/input/natural_scroll.c b/sway/commands/input/natural_scroll.c index 77c3ff00..e2a93500 100644 --- a/sway/commands/input/natural_scroll.c +++ b/sway/commands/input/natural_scroll.c | |||
@@ -10,17 +10,13 @@ struct cmd_results *input_cmd_natural_scroll(int argc, char **argv) { | |||
10 | if ((error = checkarg(argc, "natural_scroll", EXPECTED_AT_LEAST, 1))) { | 10 | if ((error = checkarg(argc, "natural_scroll", EXPECTED_AT_LEAST, 1))) { |
11 | return error; | 11 | return error; |
12 | } | 12 | } |
13 | struct input_config *current_input_config = | 13 | struct input_config *ic = config->handler_context.input_config; |
14 | config->handler_context.input_config; | 14 | if (!ic) { |
15 | if (!current_input_config) { | ||
16 | return cmd_results_new(CMD_FAILURE, "natural_scoll", | 15 | return cmd_results_new(CMD_FAILURE, "natural_scoll", |
17 | "No input device defined."); | 16 | "No input device defined."); |
18 | } | 17 | } |
19 | struct input_config *new_config = | ||
20 | new_input_config(current_input_config->identifier); | ||
21 | 18 | ||
22 | new_config->natural_scroll = parse_boolean(argv[0], true); | 19 | ic->natural_scroll = parse_boolean(argv[0], true); |
23 | 20 | ||
24 | apply_input_config(new_config); | ||
25 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 21 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
26 | } | 22 | } |
diff --git a/sway/commands/input/pointer_accel.c b/sway/commands/input/pointer_accel.c index 8bbd0724..df487b1c 100644 --- a/sway/commands/input/pointer_accel.c +++ b/sway/commands/input/pointer_accel.c | |||
@@ -9,23 +9,18 @@ struct cmd_results *input_cmd_pointer_accel(int argc, char **argv) { | |||
9 | if ((error = checkarg(argc, "pointer_accel", EXPECTED_AT_LEAST, 1))) { | 9 | if ((error = checkarg(argc, "pointer_accel", EXPECTED_AT_LEAST, 1))) { |
10 | return error; | 10 | return error; |
11 | } | 11 | } |
12 | struct input_config *current_input_config = | 12 | struct input_config *ic = config->handler_context.input_config; |
13 | config->handler_context.input_config; | 13 | if (!ic) { |
14 | if (!current_input_config) { | ||
15 | return cmd_results_new(CMD_FAILURE, | 14 | return cmd_results_new(CMD_FAILURE, |
16 | "pointer_accel", "No input device defined."); | 15 | "pointer_accel", "No input device defined."); |
17 | } | 16 | } |
18 | struct input_config *new_config = | ||
19 | new_input_config(current_input_config->identifier); | ||
20 | 17 | ||
21 | float pointer_accel = atof(argv[0]); | 18 | float pointer_accel = atof(argv[0]); |
22 | if (pointer_accel < -1 || pointer_accel > 1) { | 19 | if (pointer_accel < -1 || pointer_accel > 1) { |
23 | free_input_config(new_config); | ||
24 | return cmd_results_new(CMD_INVALID, "pointer_accel", | 20 | return cmd_results_new(CMD_INVALID, "pointer_accel", |
25 | "Input out of range [-1, 1]"); | 21 | "Input out of range [-1, 1]"); |
26 | } | 22 | } |
27 | new_config->pointer_accel = pointer_accel; | 23 | ic->pointer_accel = pointer_accel; |
28 | 24 | ||
29 | apply_input_config(new_config); | ||
30 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 25 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
31 | } | 26 | } |
diff --git a/sway/commands/input/repeat_delay.c b/sway/commands/input/repeat_delay.c index c9ddbf0e..d94b3e4d 100644 --- a/sway/commands/input/repeat_delay.c +++ b/sway/commands/input/repeat_delay.c | |||
@@ -9,23 +9,18 @@ struct cmd_results *input_cmd_repeat_delay(int argc, char **argv) { | |||
9 | if ((error = checkarg(argc, "repeat_delay", EXPECTED_EQUAL_TO, 1))) { | 9 | if ((error = checkarg(argc, "repeat_delay", EXPECTED_EQUAL_TO, 1))) { |
10 | return error; | 10 | return error; |
11 | } | 11 | } |
12 | struct input_config *current_input_config = | 12 | struct input_config *ic = config->handler_context.input_config; |
13 | config->handler_context.input_config; | 13 | if (!ic) { |
14 | if (!current_input_config) { | ||
15 | return cmd_results_new(CMD_FAILURE, | 14 | return cmd_results_new(CMD_FAILURE, |
16 | "repeat_delay", "No input device defined."); | 15 | "repeat_delay", "No input device defined."); |
17 | } | 16 | } |
18 | struct input_config *new_config = | ||
19 | new_input_config(current_input_config->identifier); | ||
20 | 17 | ||
21 | int repeat_delay = atoi(argv[0]); | 18 | int repeat_delay = atoi(argv[0]); |
22 | if (repeat_delay < 0) { | 19 | if (repeat_delay < 0) { |
23 | free_input_config(new_config); | ||
24 | return cmd_results_new(CMD_INVALID, "repeat_delay", | 20 | return cmd_results_new(CMD_INVALID, "repeat_delay", |
25 | "Repeat delay cannot be negative"); | 21 | "Repeat delay cannot be negative"); |
26 | } | 22 | } |
27 | new_config->repeat_delay = repeat_delay; | 23 | ic->repeat_delay = repeat_delay; |
28 | 24 | ||
29 | apply_input_config(new_config); | ||
30 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 25 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
31 | } | 26 | } |
diff --git a/sway/commands/input/repeat_rate.c b/sway/commands/input/repeat_rate.c index 56878176..ebec4cdb 100644 --- a/sway/commands/input/repeat_rate.c +++ b/sway/commands/input/repeat_rate.c | |||
@@ -9,23 +9,18 @@ struct cmd_results *input_cmd_repeat_rate(int argc, char **argv) { | |||
9 | if ((error = checkarg(argc, "repeat_rate", EXPECTED_EQUAL_TO, 1))) { | 9 | if ((error = checkarg(argc, "repeat_rate", EXPECTED_EQUAL_TO, 1))) { |
10 | return error; | 10 | return error; |
11 | } | 11 | } |
12 | struct input_config *current_input_config = | 12 | struct input_config *ic = config->handler_context.input_config; |
13 | config->handler_context.input_config; | 13 | if (!ic) { |
14 | if (!current_input_config) { | ||
15 | return cmd_results_new(CMD_FAILURE, | 14 | return cmd_results_new(CMD_FAILURE, |
16 | "repeat_rate", "No input device defined."); | 15 | "repeat_rate", "No input device defined."); |
17 | } | 16 | } |
18 | struct input_config *new_config = | ||
19 | new_input_config(current_input_config->identifier); | ||
20 | 17 | ||
21 | int repeat_rate = atoi(argv[0]); | 18 | int repeat_rate = atoi(argv[0]); |
22 | if (repeat_rate < 0) { | 19 | if (repeat_rate < 0) { |
23 | free_input_config(new_config); | ||
24 | return cmd_results_new(CMD_INVALID, "repeat_rate", | 20 | return cmd_results_new(CMD_INVALID, "repeat_rate", |
25 | "Repeat rate cannot be negative"); | 21 | "Repeat rate cannot be negative"); |
26 | } | 22 | } |
27 | new_config->repeat_rate = repeat_rate; | 23 | ic->repeat_rate = repeat_rate; |
28 | 24 | ||
29 | apply_input_config(new_config); | ||
30 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 25 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
31 | } | 26 | } |
diff --git a/sway/commands/input/scroll_button.c b/sway/commands/input/scroll_button.c index 350fcca2..1958f23c 100644 --- a/sway/commands/input/scroll_button.c +++ b/sway/commands/input/scroll_button.c | |||
@@ -10,35 +10,28 @@ struct cmd_results *input_cmd_scroll_button(int argc, char **argv) { | |||
10 | if ((error = checkarg(argc, "scroll_button", EXPECTED_AT_LEAST, 1))) { | 10 | if ((error = checkarg(argc, "scroll_button", EXPECTED_AT_LEAST, 1))) { |
11 | return error; | 11 | return error; |
12 | } | 12 | } |
13 | struct input_config *current_input_config = | 13 | struct input_config *ic = config->handler_context.input_config; |
14 | config->handler_context.input_config; | 14 | if (!ic) { |
15 | if (!current_input_config) { | ||
16 | return cmd_results_new(CMD_FAILURE, "scroll_button", | 15 | return cmd_results_new(CMD_FAILURE, "scroll_button", |
17 | "No input device defined."); | 16 | "No input device defined."); |
18 | } | 17 | } |
19 | struct input_config *new_config = | ||
20 | new_input_config(current_input_config->identifier); | ||
21 | 18 | ||
22 | errno = 0; | 19 | errno = 0; |
23 | char *endptr; | 20 | char *endptr; |
24 | int scroll_button = strtol(*argv, &endptr, 10); | 21 | int scroll_button = strtol(*argv, &endptr, 10); |
25 | if (endptr == *argv && scroll_button == 0) { | 22 | if (endptr == *argv && scroll_button == 0) { |
26 | free_input_config(new_config); | ||
27 | return cmd_results_new(CMD_INVALID, "scroll_button", | 23 | return cmd_results_new(CMD_INVALID, "scroll_button", |
28 | "Scroll button identifier must be an integer."); | 24 | "Scroll button identifier must be an integer."); |
29 | } | 25 | } |
30 | if (errno == ERANGE) { | 26 | if (errno == ERANGE) { |
31 | free_input_config(new_config); | ||
32 | return cmd_results_new(CMD_INVALID, "scroll_button", | 27 | return cmd_results_new(CMD_INVALID, "scroll_button", |
33 | "Scroll button identifier out of range."); | 28 | "Scroll button identifier out of range."); |
34 | } | 29 | } |
35 | if (scroll_button < 0) { | 30 | if (scroll_button < 0) { |
36 | free_input_config(new_config); | ||
37 | return cmd_results_new(CMD_INVALID, "scroll_button", | 31 | return cmd_results_new(CMD_INVALID, "scroll_button", |
38 | "Scroll button identifier cannot be negative."); | 32 | "Scroll button identifier cannot be negative."); |
39 | } | 33 | } |
40 | new_config->scroll_button = scroll_button; | 34 | ic->scroll_button = scroll_button; |
41 | 35 | ||
42 | apply_input_config(new_config); | ||
43 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 36 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
44 | } | 37 | } |
diff --git a/sway/commands/input/scroll_method.c b/sway/commands/input/scroll_method.c index 4c6ac6b6..c116b052 100644 --- a/sway/commands/input/scroll_method.c +++ b/sway/commands/input/scroll_method.c | |||
@@ -9,29 +9,24 @@ struct cmd_results *input_cmd_scroll_method(int argc, char **argv) { | |||
9 | if ((error = checkarg(argc, "scroll_method", EXPECTED_AT_LEAST, 1))) { | 9 | if ((error = checkarg(argc, "scroll_method", EXPECTED_AT_LEAST, 1))) { |
10 | return error; | 10 | return error; |
11 | } | 11 | } |
12 | struct input_config *current_input_config = | 12 | struct input_config *ic = config->handler_context.input_config; |
13 | config->handler_context.input_config; | 13 | if (!ic) { |
14 | if (!current_input_config) { | ||
15 | return cmd_results_new(CMD_FAILURE, "scroll_method", | 14 | return cmd_results_new(CMD_FAILURE, "scroll_method", |
16 | "No input device defined."); | 15 | "No input device defined."); |
17 | } | 16 | } |
18 | struct input_config *new_config = | ||
19 | new_input_config(current_input_config->identifier); | ||
20 | 17 | ||
21 | if (strcasecmp(argv[0], "none") == 0) { | 18 | if (strcasecmp(argv[0], "none") == 0) { |
22 | new_config->scroll_method = LIBINPUT_CONFIG_SCROLL_NO_SCROLL; | 19 | ic->scroll_method = LIBINPUT_CONFIG_SCROLL_NO_SCROLL; |
23 | } else if (strcasecmp(argv[0], "two_finger") == 0) { | 20 | } else if (strcasecmp(argv[0], "two_finger") == 0) { |
24 | new_config->scroll_method = LIBINPUT_CONFIG_SCROLL_2FG; | 21 | ic->scroll_method = LIBINPUT_CONFIG_SCROLL_2FG; |
25 | } else if (strcasecmp(argv[0], "edge") == 0) { | 22 | } else if (strcasecmp(argv[0], "edge") == 0) { |
26 | new_config->scroll_method = LIBINPUT_CONFIG_SCROLL_EDGE; | 23 | ic->scroll_method = LIBINPUT_CONFIG_SCROLL_EDGE; |
27 | } else if (strcasecmp(argv[0], "on_button_down") == 0) { | 24 | } else if (strcasecmp(argv[0], "on_button_down") == 0) { |
28 | new_config->scroll_method = LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN; | 25 | ic->scroll_method = LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN; |
29 | } else { | 26 | } else { |
30 | free_input_config(new_config); | ||
31 | return cmd_results_new(CMD_INVALID, "scroll_method", | 27 | return cmd_results_new(CMD_INVALID, "scroll_method", |
32 | "Expected 'scroll_method <none|two_finger|edge|on_button_down>'"); | 28 | "Expected 'scroll_method <none|two_finger|edge|on_button_down>'"); |
33 | } | 29 | } |
34 | 30 | ||
35 | apply_input_config(new_config); | ||
36 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 31 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
37 | } | 32 | } |
diff --git a/sway/commands/input/tap.c b/sway/commands/input/tap.c index ac3b8237..c455b696 100644 --- a/sway/commands/input/tap.c +++ b/sway/commands/input/tap.c | |||
@@ -11,22 +11,16 @@ struct cmd_results *input_cmd_tap(int argc, char **argv) { | |||
11 | if ((error = checkarg(argc, "tap", EXPECTED_AT_LEAST, 1))) { | 11 | if ((error = checkarg(argc, "tap", EXPECTED_AT_LEAST, 1))) { |
12 | return error; | 12 | return error; |
13 | } | 13 | } |
14 | struct input_config *current_input_config = | 14 | struct input_config *ic = config->handler_context.input_config; |
15 | config->handler_context.input_config; | 15 | if (!ic) { |
16 | if (!current_input_config) { | ||
17 | return cmd_results_new(CMD_FAILURE, "tap", "No input device defined."); | 16 | return cmd_results_new(CMD_FAILURE, "tap", "No input device defined."); |
18 | } | 17 | } |
19 | struct input_config *new_config = | ||
20 | new_input_config(current_input_config->identifier); | ||
21 | 18 | ||
22 | if (parse_boolean(argv[0], true)) { | 19 | if (parse_boolean(argv[0], true)) { |
23 | new_config->tap = LIBINPUT_CONFIG_TAP_ENABLED; | 20 | ic->tap = LIBINPUT_CONFIG_TAP_ENABLED; |
24 | } else { | 21 | } else { |
25 | new_config->tap = LIBINPUT_CONFIG_TAP_DISABLED; | 22 | ic->tap = LIBINPUT_CONFIG_TAP_DISABLED; |
26 | } | 23 | } |
27 | 24 | ||
28 | wlr_log(WLR_DEBUG, "apply-tap for device: %s", | ||
29 | current_input_config->identifier); | ||
30 | apply_input_config(new_config); | ||
31 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 25 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
32 | } | 26 | } |
diff --git a/sway/commands/input/tap_button_map.c b/sway/commands/input/tap_button_map.c index bdbba472..dff2985b 100644 --- a/sway/commands/input/tap_button_map.c +++ b/sway/commands/input/tap_button_map.c | |||
@@ -9,25 +9,20 @@ struct cmd_results *input_cmd_tap_button_map(int argc, char **argv) { | |||
9 | if ((error = checkarg(argc, "tap_button_map", EXPECTED_AT_LEAST, 1))) { | 9 | if ((error = checkarg(argc, "tap_button_map", EXPECTED_AT_LEAST, 1))) { |
10 | return error; | 10 | return error; |
11 | } | 11 | } |
12 | struct input_config *current_input_config = | 12 | struct input_config *ic = config->handler_context.input_config; |
13 | config->handler_context.input_config; | 13 | if (!ic) { |
14 | if (!current_input_config) { | ||
15 | return cmd_results_new(CMD_FAILURE, "tap_button_map", | 14 | return cmd_results_new(CMD_FAILURE, "tap_button_map", |
16 | "No input device defined."); | 15 | "No input device defined."); |
17 | } | 16 | } |
18 | struct input_config *new_config = | ||
19 | new_input_config(current_input_config->identifier); | ||
20 | 17 | ||
21 | if (strcasecmp(argv[0], "lrm") == 0) { | 18 | if (strcasecmp(argv[0], "lrm") == 0) { |
22 | new_config->tap_button_map = LIBINPUT_CONFIG_TAP_MAP_LRM; | 19 | ic->tap_button_map = LIBINPUT_CONFIG_TAP_MAP_LRM; |
23 | } else if (strcasecmp(argv[0], "lmr") == 0) { | 20 | } else if (strcasecmp(argv[0], "lmr") == 0) { |
24 | new_config->tap_button_map = LIBINPUT_CONFIG_TAP_MAP_LMR; | 21 | ic->tap_button_map = LIBINPUT_CONFIG_TAP_MAP_LMR; |
25 | } else { | 22 | } else { |
26 | free_input_config(new_config); | ||
27 | return cmd_results_new(CMD_INVALID, "tap_button_map", | 23 | return cmd_results_new(CMD_INVALID, "tap_button_map", |
28 | "Expected 'tap_button_map <lrm|lmr>'"); | 24 | "Expected 'tap_button_map <lrm|lmr>'"); |
29 | } | 25 | } |
30 | 26 | ||
31 | apply_input_config(new_config); | ||
32 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 27 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
33 | } | 28 | } |
diff --git a/sway/commands/input/xkb_capslock.c b/sway/commands/input/xkb_capslock.c index 5442c463..669b4ea9 100644 --- a/sway/commands/input/xkb_capslock.c +++ b/sway/commands/input/xkb_capslock.c | |||
@@ -9,25 +9,20 @@ struct cmd_results *input_cmd_xkb_capslock(int argc, char **argv) { | |||
9 | if ((error = checkarg(argc, "xkb_capslock", EXPECTED_AT_LEAST, 1))) { | 9 | if ((error = checkarg(argc, "xkb_capslock", EXPECTED_AT_LEAST, 1))) { |
10 | return error; | 10 | return error; |
11 | } | 11 | } |
12 | struct input_config *current_input_config = | 12 | struct input_config *ic = config->handler_context.input_config; |
13 | config->handler_context.input_config; | 13 | if (!ic) { |
14 | if (!current_input_config) { | ||
15 | return cmd_results_new(CMD_FAILURE, "xkb_capslock", | 14 | return cmd_results_new(CMD_FAILURE, "xkb_capslock", |
16 | "No input device defined."); | 15 | "No input device defined."); |
17 | } | 16 | } |
18 | struct input_config *new_config = | ||
19 | new_input_config(current_input_config->identifier); | ||
20 | 17 | ||
21 | if (strcasecmp(argv[0], "enabled") == 0) { | 18 | if (strcasecmp(argv[0], "enabled") == 0) { |
22 | new_config->xkb_capslock = 1; | 19 | ic->xkb_capslock = 1; |
23 | } else if (strcasecmp(argv[0], "disabled") == 0) { | 20 | } else if (strcasecmp(argv[0], "disabled") == 0) { |
24 | new_config->xkb_capslock = 0; | 21 | ic->xkb_capslock = 0; |
25 | } else { | 22 | } else { |
26 | free_input_config(new_config); | ||
27 | return cmd_results_new(CMD_INVALID, "xkb_capslock", | 23 | return cmd_results_new(CMD_INVALID, "xkb_capslock", |
28 | "Expected 'xkb_capslock <enabled|disabled>'"); | 24 | "Expected 'xkb_capslock <enabled|disabled>'"); |
29 | } | 25 | } |
30 | 26 | ||
31 | apply_input_config(new_config); | ||
32 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 27 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
33 | } | 28 | } |
diff --git a/sway/commands/input/xkb_layout.c b/sway/commands/input/xkb_layout.c index 9fa5a344..5fccd4a3 100644 --- a/sway/commands/input/xkb_layout.c +++ b/sway/commands/input/xkb_layout.c | |||
@@ -9,18 +9,15 @@ struct cmd_results *input_cmd_xkb_layout(int argc, char **argv) { | |||
9 | if ((error = checkarg(argc, "xkb_layout", EXPECTED_EQUAL_TO, 1))) { | 9 | if ((error = checkarg(argc, "xkb_layout", EXPECTED_EQUAL_TO, 1))) { |
10 | return error; | 10 | return error; |
11 | } | 11 | } |
12 | struct input_config *current_input_config = | 12 | struct input_config *ic = config->handler_context.input_config; |
13 | config->handler_context.input_config; | 13 | if (!ic) { |
14 | if (!current_input_config) { | 14 | return cmd_results_new(CMD_FAILURE, "xkb_layout", |
15 | return cmd_results_new(CMD_FAILURE, "xkb_layout", "No input device defined."); | 15 | "No input device defined."); |
16 | } | 16 | } |
17 | struct input_config *new_config = | ||
18 | new_input_config(current_input_config->identifier); | ||
19 | 17 | ||
20 | new_config->xkb_layout = strdup(argv[0]); | 18 | ic->xkb_layout = strdup(argv[0]); |
21 | 19 | ||
22 | wlr_log(WLR_DEBUG, "apply-xkb_layout for device: %s layout: %s", | 20 | wlr_log(WLR_DEBUG, "set-xkb_layout for config: %s layout: %s", |
23 | current_input_config->identifier, new_config->xkb_layout); | 21 | ic->identifier, ic->xkb_layout); |
24 | apply_input_config(new_config); | ||
25 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 22 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
26 | } | 23 | } |
diff --git a/sway/commands/input/xkb_model.c b/sway/commands/input/xkb_model.c index 0d082625..c4d04638 100644 --- a/sway/commands/input/xkb_model.c +++ b/sway/commands/input/xkb_model.c | |||
@@ -9,18 +9,15 @@ struct cmd_results *input_cmd_xkb_model(int argc, char **argv) { | |||
9 | if ((error = checkarg(argc, "xkb_model", EXPECTED_EQUAL_TO, 1))) { | 9 | if ((error = checkarg(argc, "xkb_model", EXPECTED_EQUAL_TO, 1))) { |
10 | return error; | 10 | return error; |
11 | } | 11 | } |
12 | struct input_config *current_input_config = | 12 | struct input_config *ic = config->handler_context.input_config; |
13 | config->handler_context.input_config; | 13 | if (!ic) { |
14 | if (!current_input_config) { | 14 | return cmd_results_new(CMD_FAILURE, "xkb_model", |
15 | return cmd_results_new(CMD_FAILURE, "xkb_model", "No input device defined."); | 15 | "No input device defined."); |
16 | } | 16 | } |
17 | struct input_config *new_config = | ||
18 | new_input_config(current_input_config->identifier); | ||
19 | 17 | ||
20 | new_config->xkb_model = strdup(argv[0]); | 18 | ic->xkb_model = strdup(argv[0]); |
21 | 19 | ||
22 | wlr_log(WLR_DEBUG, "apply-xkb_model for device: %s model: %s", | 20 | wlr_log(WLR_DEBUG, "set-xkb_model for config: %s model: %s", |
23 | current_input_config->identifier, new_config->xkb_model); | 21 | ic->identifier, ic->xkb_model); |
24 | apply_input_config(new_config); | ||
25 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 22 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
26 | } | 23 | } |
diff --git a/sway/commands/input/xkb_numlock.c b/sway/commands/input/xkb_numlock.c index 39675366..1367da44 100644 --- a/sway/commands/input/xkb_numlock.c +++ b/sway/commands/input/xkb_numlock.c | |||
@@ -9,25 +9,20 @@ struct cmd_results *input_cmd_xkb_numlock(int argc, char **argv) { | |||
9 | if ((error = checkarg(argc, "xkb_numlock", EXPECTED_AT_LEAST, 1))) { | 9 | if ((error = checkarg(argc, "xkb_numlock", EXPECTED_AT_LEAST, 1))) { |
10 | return error; | 10 | return error; |
11 | } | 11 | } |
12 | struct input_config *current_input_config = | 12 | struct input_config *ic = config->handler_context.input_config; |
13 | config->handler_context.input_config; | 13 | if (!ic) { |
14 | if (!current_input_config) { | ||
15 | return cmd_results_new(CMD_FAILURE, "xkb_numlock", | 14 | return cmd_results_new(CMD_FAILURE, "xkb_numlock", |
16 | "No input device defined."); | 15 | "No input device defined."); |
17 | } | 16 | } |
18 | struct input_config *new_config = | ||
19 | new_input_config(current_input_config->identifier); | ||
20 | 17 | ||
21 | if (strcasecmp(argv[0], "enabled") == 0) { | 18 | if (strcasecmp(argv[0], "enabled") == 0) { |
22 | new_config->xkb_numlock = 1; | 19 | ic->xkb_numlock = 1; |
23 | } else if (strcasecmp(argv[0], "disabled") == 0) { | 20 | } else if (strcasecmp(argv[0], "disabled") == 0) { |
24 | new_config->xkb_numlock = 0; | 21 | ic->xkb_numlock = 0; |
25 | } else { | 22 | } else { |
26 | free_input_config(new_config); | ||
27 | return cmd_results_new(CMD_INVALID, "xkb_numlock", | 23 | return cmd_results_new(CMD_INVALID, "xkb_numlock", |
28 | "Expected 'xkb_numlock <enabled|disabled>'"); | 24 | "Expected 'xkb_numlock <enabled|disabled>'"); |
29 | } | 25 | } |
30 | 26 | ||
31 | apply_input_config(new_config); | ||
32 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 27 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
33 | } | 28 | } |
diff --git a/sway/commands/input/xkb_options.c b/sway/commands/input/xkb_options.c index 3059d941..794ab6e9 100644 --- a/sway/commands/input/xkb_options.c +++ b/sway/commands/input/xkb_options.c | |||
@@ -9,18 +9,15 @@ struct cmd_results *input_cmd_xkb_options(int argc, char **argv) { | |||
9 | if ((error = checkarg(argc, "xkb_options", EXPECTED_EQUAL_TO, 1))) { | 9 | if ((error = checkarg(argc, "xkb_options", EXPECTED_EQUAL_TO, 1))) { |
10 | return error; | 10 | return error; |
11 | } | 11 | } |
12 | struct input_config *current_input_config = | 12 | struct input_config *ic = config->handler_context.input_config; |
13 | config->handler_context.input_config; | 13 | if (!ic) { |
14 | if (!current_input_config) { | 14 | return cmd_results_new(CMD_FAILURE, "xkb_options", |
15 | return cmd_results_new(CMD_FAILURE, "xkb_options", "No input device defined."); | 15 | "No input device defined."); |
16 | } | 16 | } |
17 | struct input_config *new_config = | ||
18 | new_input_config(current_input_config->identifier); | ||
19 | 17 | ||
20 | new_config->xkb_options = strdup(argv[0]); | 18 | ic->xkb_options = strdup(argv[0]); |
21 | 19 | ||
22 | wlr_log(WLR_DEBUG, "apply-xkb_options for device: %s options: %s", | 20 | wlr_log(WLR_DEBUG, "set-xkb_options for config: %s options: %s", |
23 | current_input_config->identifier, new_config->xkb_options); | 21 | ic->identifier, ic->xkb_options); |
24 | apply_input_config(new_config); | ||
25 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 22 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
26 | } | 23 | } |
diff --git a/sway/commands/input/xkb_rules.c b/sway/commands/input/xkb_rules.c index 560f088e..257c3288 100644 --- a/sway/commands/input/xkb_rules.c +++ b/sway/commands/input/xkb_rules.c | |||
@@ -9,18 +9,15 @@ struct cmd_results *input_cmd_xkb_rules(int argc, char **argv) { | |||
9 | if ((error = checkarg(argc, "xkb_rules", EXPECTED_EQUAL_TO, 1))) { | 9 | if ((error = checkarg(argc, "xkb_rules", EXPECTED_EQUAL_TO, 1))) { |
10 | return error; | 10 | return error; |
11 | } | 11 | } |
12 | struct input_config *current_input_config = | 12 | struct input_config *ic = config->handler_context.input_config; |
13 | config->handler_context.input_config; | 13 | if (!ic) { |
14 | if (!current_input_config) { | 14 | return cmd_results_new(CMD_FAILURE, "xkb_rules", |
15 | return cmd_results_new(CMD_FAILURE, "xkb_rules", "No input device defined."); | 15 | "No input device defined."); |
16 | } | 16 | } |
17 | struct input_config *new_config = | ||
18 | new_input_config(current_input_config->identifier); | ||
19 | 17 | ||
20 | new_config->xkb_rules = strdup(argv[0]); | 18 | ic->xkb_rules = strdup(argv[0]); |
21 | 19 | ||
22 | wlr_log(WLR_DEBUG, "apply-xkb_rules for device: %s rules: %s", | 20 | wlr_log(WLR_DEBUG, "set-xkb_rules for config: %s rules: %s", |
23 | current_input_config->identifier, new_config->xkb_rules); | 21 | ic->identifier, ic->xkb_rules); |
24 | apply_input_config(new_config); | ||
25 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 22 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
26 | } | 23 | } |
diff --git a/sway/commands/input/xkb_variant.c b/sway/commands/input/xkb_variant.c index 0aa03440..3832dc8e 100644 --- a/sway/commands/input/xkb_variant.c +++ b/sway/commands/input/xkb_variant.c | |||
@@ -9,18 +9,15 @@ struct cmd_results *input_cmd_xkb_variant(int argc, char **argv) { | |||
9 | if ((error = checkarg(argc, "xkb_variant", EXPECTED_EQUAL_TO, 1))) { | 9 | if ((error = checkarg(argc, "xkb_variant", EXPECTED_EQUAL_TO, 1))) { |
10 | return error; | 10 | return error; |
11 | } | 11 | } |
12 | struct input_config *current_input_config = | 12 | struct input_config *ic = config->handler_context.input_config; |
13 | config->handler_context.input_config; | 13 | if (!ic) { |
14 | if (!current_input_config) { | 14 | return cmd_results_new(CMD_FAILURE, "xkb_variant", |
15 | return cmd_results_new(CMD_FAILURE, "xkb_variant", "No input device defined."); | 15 | "No input device defined."); |
16 | } | 16 | } |
17 | struct input_config *new_config = | ||
18 | new_input_config(current_input_config->identifier); | ||
19 | 17 | ||
20 | new_config->xkb_variant = strdup(argv[0]); | 18 | ic->xkb_variant = strdup(argv[0]); |
21 | 19 | ||
22 | wlr_log(WLR_DEBUG, "apply-xkb_variant for device: %s variant: %s", | 20 | wlr_log(WLR_DEBUG, "set-xkb_variant for config: %s variant: %s", |
23 | current_input_config->identifier, new_config->xkb_variant); | 21 | ic->identifier, ic->xkb_variant); |
24 | apply_input_config(new_config); | ||
25 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 22 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
26 | } | 23 | } |
diff --git a/sway/config/input.c b/sway/config/input.c index ad5b96c8..fffc8518 100644 --- a/sway/config/input.c +++ b/sway/config/input.c | |||
@@ -40,10 +40,6 @@ struct input_config *new_input_config(const char* identifier) { | |||
40 | } | 40 | } |
41 | 41 | ||
42 | void merge_input_config(struct input_config *dst, struct input_config *src) { | 42 | void merge_input_config(struct input_config *dst, struct input_config *src) { |
43 | if (src->identifier) { | ||
44 | free(dst->identifier); | ||
45 | dst->identifier = strdup(src->identifier); | ||
46 | } | ||
47 | if (src->accel_profile != INT_MIN) { | 43 | if (src->accel_profile != INT_MIN) { |
48 | dst->accel_profile = src->accel_profile; | 44 | dst->accel_profile = src->accel_profile; |
49 | } | 45 | } |
@@ -125,14 +121,51 @@ void merge_input_config(struct input_config *dst, struct input_config *src) { | |||
125 | } | 121 | } |
126 | } | 122 | } |
127 | 123 | ||
128 | struct input_config *copy_input_config(struct input_config *ic) { | 124 | static void merge_wildcard_on_all(struct input_config *wildcard) { |
129 | struct input_config *copy = calloc(1, sizeof(struct input_config)); | 125 | for (int i = 0; i < config->input_configs->length; i++) { |
130 | if (copy == NULL) { | 126 | struct input_config *ic = config->input_configs->items[i]; |
131 | wlr_log(WLR_ERROR, "could not allocate input config"); | 127 | if (strcmp(wildcard->identifier, ic->identifier) != 0) { |
132 | return NULL; | 128 | wlr_log(WLR_DEBUG, "Merging input * config on %s", ic->identifier); |
129 | merge_input_config(ic, wildcard); | ||
130 | } | ||
131 | } | ||
132 | } | ||
133 | |||
134 | struct input_config *store_input_config(struct input_config *ic) { | ||
135 | bool wildcard = strcmp(ic->identifier, "*") == 0; | ||
136 | if (wildcard) { | ||
137 | merge_wildcard_on_all(ic); | ||
133 | } | 138 | } |
134 | merge_input_config(copy, ic); | 139 | |
135 | return copy; | 140 | int i = list_seq_find(config->input_configs, input_identifier_cmp, |
141 | ic->identifier); | ||
142 | if (i >= 0) { | ||
143 | wlr_log(WLR_DEBUG, "Merging on top of existing input config"); | ||
144 | struct input_config *current = config->input_configs->items[i]; | ||
145 | merge_input_config(current, ic); | ||
146 | free_input_config(ic); | ||
147 | ic = current; | ||
148 | } else if (!wildcard) { | ||
149 | wlr_log(WLR_DEBUG, "Adding non-wildcard input config"); | ||
150 | i = list_seq_find(config->input_configs, input_identifier_cmp, "*"); | ||
151 | if (i >= 0) { | ||
152 | wlr_log(WLR_DEBUG, "Merging on top of input * config"); | ||
153 | struct input_config *current = new_input_config(ic->identifier); | ||
154 | merge_input_config(current, config->input_configs->items[i]); | ||
155 | merge_input_config(current, ic); | ||
156 | free_input_config(ic); | ||
157 | ic = current; | ||
158 | } | ||
159 | list_add(config->input_configs, ic); | ||
160 | } else { | ||
161 | // New wildcard config. Just add it | ||
162 | wlr_log(WLR_DEBUG, "Adding input * config"); | ||
163 | list_add(config->input_configs, ic); | ||
164 | } | ||
165 | |||
166 | wlr_log(WLR_DEBUG, "Config stored for input %s", ic->identifier); | ||
167 | |||
168 | return ic; | ||
136 | } | 169 | } |
137 | 170 | ||
138 | void free_input_config(struct input_config *ic) { | 171 | void free_input_config(struct input_config *ic) { |
diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c index b4352c6a..f696646f 100644 --- a/sway/input/input-manager.c +++ b/sway/input/input-manager.c | |||
@@ -389,8 +389,10 @@ void input_manager_set_focus(struct sway_input_manager *input, | |||
389 | void input_manager_apply_input_config(struct sway_input_manager *input, | 389 | void input_manager_apply_input_config(struct sway_input_manager *input, |
390 | struct input_config *input_config) { | 390 | struct input_config *input_config) { |
391 | struct sway_input_device *input_device = NULL; | 391 | struct sway_input_device *input_device = NULL; |
392 | bool wildcard = strcmp(input_config->identifier, "*") == 0; | ||
392 | wl_list_for_each(input_device, &input->devices, link) { | 393 | wl_list_for_each(input_device, &input->devices, link) { |
393 | if (strcmp(input_device->identifier, input_config->identifier) == 0) { | 394 | if (strcmp(input_device->identifier, input_config->identifier) == 0 |
395 | || wildcard) { | ||
394 | if (input_device->wlr_device->type == WLR_INPUT_DEVICE_POINTER) { | 396 | if (input_device->wlr_device->type == WLR_INPUT_DEVICE_POINTER) { |
395 | input_manager_libinput_config_pointer(input_device); | 397 | input_manager_libinput_config_pointer(input_device); |
396 | } | 398 | } |
@@ -480,13 +482,16 @@ struct sway_seat *input_manager_get_default_seat( | |||
480 | } | 482 | } |
481 | 483 | ||
482 | struct input_config *input_device_get_config(struct sway_input_device *device) { | 484 | struct input_config *input_device_get_config(struct sway_input_device *device) { |
485 | struct input_config *wildcard_config = NULL; | ||
483 | struct input_config *input_config = NULL; | 486 | struct input_config *input_config = NULL; |
484 | for (int i = 0; i < config->input_configs->length; ++i) { | 487 | for (int i = 0; i < config->input_configs->length; ++i) { |
485 | input_config = config->input_configs->items[i]; | 488 | input_config = config->input_configs->items[i]; |
486 | if (strcmp(input_config->identifier, device->identifier) == 0) { | 489 | if (strcmp(input_config->identifier, device->identifier) == 0) { |
487 | return input_config; | 490 | return input_config; |
491 | } else if (strcmp(input_config->identifier, "*") == 0) { | ||
492 | wildcard_config = input_config; | ||
488 | } | 493 | } |
489 | } | 494 | } |
490 | 495 | ||
491 | return NULL; | 496 | return wildcard_config; |
492 | } | 497 | } |