aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/input
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-01-21 02:13:01 -0500
committerLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-01-21 02:13:01 -0500
commit91c1f449565f3e15398472102293d44fa26364d9 (patch)
treea3adbc2e3e016d60372748d5cbf9c5bf2aed0f51 /sway/commands/input
parentAllocate minimum size necessary in pango text functions. (#3473) (diff)
downloadsway-91c1f449565f3e15398472102293d44fa26364d9.tar.gz
sway-91c1f449565f3e15398472102293d44fa26364d9.tar.zst
sway-91c1f449565f3e15398472102293d44fa26364d9.zip
input_cmd_events: allow toggle modes to be listed
This extends `input <identifier> events toggle` to allow for an optional list of modes to toggle through. If no event modes are listed, all supported modes are cycled through (current behavior). If event modes are listed, they will be cycled through, defaulting to the first mode listed when the current mode is not in the list. This modes listed will also not be checked to see if the device supports them and may fail.
Diffstat (limited to 'sway/commands/input')
-rw-r--r--sway/commands/input/events.c65
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
10static void toggle_send_events_for_device(struct input_config *ic, 10static 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
46static void toggle_send_events(struct input_config *ic) { 46static 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
57static 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
77static 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
55static void toggle_wildcard_send_events() { 92static 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,