diff options
Diffstat (limited to 'sway/commands/input/events.c')
-rw-r--r-- | sway/commands/input/events.c | 65 |
1 files changed, 56 insertions, 9 deletions
diff --git a/sway/commands/input/events.c b/sway/commands/input/events.c index 2c6505d8..44bc9e74 100644 --- a/sway/commands/input/events.c +++ b/sway/commands/input/events.c | |||
@@ -7,14 +7,14 @@ | |||
7 | #include "sway/input/input-manager.h" | 7 | #include "sway/input/input-manager.h" |
8 | #include "log.h" | 8 | #include "log.h" |
9 | 9 | ||
10 | static void toggle_send_events_for_device(struct input_config *ic, | 10 | static void toggle_supported_send_events_for_device(struct input_config *ic, |
11 | struct sway_input_device *input_device) { | 11 | struct sway_input_device *input_device) { |
12 | struct wlr_input_device *wlr_device = input_device->wlr_device; | 12 | struct wlr_input_device *wlr_device = input_device->wlr_device; |
13 | if (!wlr_input_device_is_libinput(wlr_device)) { | 13 | if (!wlr_input_device_is_libinput(wlr_device)) { |
14 | return; | 14 | return; |
15 | } | 15 | } |
16 | struct libinput_device *libinput_dev | 16 | struct libinput_device *libinput_dev = |
17 | = wlr_libinput_get_device_handle(wlr_device); | 17 | wlr_libinput_get_device_handle(wlr_device); |
18 | 18 | ||
19 | enum libinput_config_send_events_mode mode = | 19 | enum libinput_config_send_events_mode mode = |
20 | libinput_device_config_send_events_get_mode(libinput_dev); | 20 | libinput_device_config_send_events_get_mode(libinput_dev); |
@@ -43,23 +43,64 @@ static void toggle_send_events_for_device(struct input_config *ic, | |||
43 | ic->send_events = mode; | 43 | ic->send_events = mode; |
44 | } | 44 | } |
45 | 45 | ||
46 | static void toggle_send_events(struct input_config *ic) { | 46 | static int mode_for_name(const char *name) { |
47 | if (!strcmp(name, "enabled")) { | ||
48 | return LIBINPUT_CONFIG_SEND_EVENTS_ENABLED; | ||
49 | } else if (!strcmp(name, "disabled_on_external_mouse")) { | ||
50 | return LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE; | ||
51 | } else if (!strcmp(name, "disabled")) { | ||
52 | return LIBINPUT_CONFIG_SEND_EVENTS_DISABLED; | ||
53 | } | ||
54 | return -1; | ||
55 | } | ||
56 | |||
57 | static void toggle_select_send_events_for_device(struct input_config *ic, | ||
58 | struct sway_input_device *input_device, int argc, char **argv) { | ||
59 | if (!wlr_input_device_is_libinput(input_device->wlr_device)) { | ||
60 | return; | ||
61 | } | ||
62 | // Get the currently set event mode since ic is a new config that will be | ||
63 | // merged on the existing later. It should be set to INT_MIN before this. | ||
64 | ic->send_events = libinput_device_config_send_events_get_mode( | ||
65 | wlr_libinput_get_device_handle(input_device->wlr_device)); | ||
66 | |||
67 | int index; | ||
68 | for (index = 0; index < argc; ++index) { | ||
69 | if (mode_for_name(argv[index]) == ic->send_events) { | ||
70 | ++index; | ||
71 | break; | ||
72 | } | ||
73 | } | ||
74 | ic->send_events = mode_for_name(argv[index % argc]); | ||
75 | } | ||
76 | |||
77 | static void toggle_send_events(struct input_config *ic, int argc, char **argv) { | ||
47 | struct sway_input_device *input_device = NULL; | 78 | struct sway_input_device *input_device = NULL; |
48 | wl_list_for_each(input_device, &server.input->devices, link) { | 79 | wl_list_for_each(input_device, &server.input->devices, link) { |
49 | if (strcmp(input_device->identifier, ic->identifier) == 0) { | 80 | if (strcmp(input_device->identifier, ic->identifier) == 0) { |
50 | toggle_send_events_for_device(ic, input_device); | 81 | if (argc) { |
82 | toggle_select_send_events_for_device(ic, input_device, | ||
83 | argc, argv); | ||
84 | } else { | ||
85 | toggle_supported_send_events_for_device(ic, input_device); | ||
86 | } | ||
87 | return; | ||
51 | } | 88 | } |
52 | } | 89 | } |
53 | } | 90 | } |
54 | 91 | ||
55 | static void toggle_wildcard_send_events() { | 92 | static void toggle_wildcard_send_events(int argc, char **argv) { |
56 | struct sway_input_device *input_device = NULL; | 93 | struct sway_input_device *input_device = NULL; |
57 | wl_list_for_each(input_device, &server.input->devices, link) { | 94 | wl_list_for_each(input_device, &server.input->devices, link) { |
58 | struct input_config *ic = new_input_config(input_device->identifier); | 95 | struct input_config *ic = new_input_config(input_device->identifier); |
59 | if (!ic) { | 96 | if (!ic) { |
60 | break; | 97 | break; |
61 | } | 98 | } |
62 | toggle_send_events_for_device(ic, input_device); | 99 | if (argc) { |
100 | toggle_select_send_events_for_device(ic, input_device, argc, argv); | ||
101 | } else { | ||
102 | toggle_supported_send_events_for_device(ic, input_device); | ||
103 | } | ||
63 | store_input_config(ic); | 104 | store_input_config(ic); |
64 | } | 105 | } |
65 | } | 106 | } |
@@ -85,15 +126,21 @@ struct cmd_results *input_cmd_events(int argc, char **argv) { | |||
85 | return cmd_results_new(CMD_INVALID, | 126 | return cmd_results_new(CMD_INVALID, |
86 | "Expected 'events <enabled|disabled|disabled_on_external_mouse>'"); | 127 | "Expected 'events <enabled|disabled|disabled_on_external_mouse>'"); |
87 | } else if (strcasecmp(argv[0], "toggle") == 0) { | 128 | } else if (strcasecmp(argv[0], "toggle") == 0) { |
129 | for (int i = 1; i < argc; ++i) { | ||
130 | if (mode_for_name(argv[i]) == -1) { | ||
131 | return cmd_results_new(CMD_INVALID, | ||
132 | "Invalid toggle mode %s", argv[i]); | ||
133 | } | ||
134 | } | ||
88 | if (strcmp(ic->identifier, "*") == 0) { | 135 | if (strcmp(ic->identifier, "*") == 0) { |
89 | // Update the device input configs and then reset the wildcard | 136 | // Update the device input configs and then reset the wildcard |
90 | // config send events mode so that is does not override the device | 137 | // config send events mode so that is does not override the device |
91 | // ones. The device ones will be applied when attempting to apply | 138 | // ones. The device ones will be applied when attempting to apply |
92 | // the wildcard config | 139 | // the wildcard config |
93 | toggle_wildcard_send_events(); | 140 | toggle_wildcard_send_events(argc - 1, argv + 1); |
94 | ic->send_events = INT_MIN; | 141 | ic->send_events = INT_MIN; |
95 | } else { | 142 | } else { |
96 | toggle_send_events(ic); | 143 | toggle_send_events(ic, argc - 1, argv + 1); |
97 | } | 144 | } |
98 | } else { | 145 | } else { |
99 | return cmd_results_new(CMD_INVALID, | 146 | return cmd_results_new(CMD_INVALID, |