aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Cezary Drożak <cezary@drozak.net>2023-06-16 11:28:30 +0200
committerLibravatar Simon Ser <contact@emersion.fr>2023-06-16 15:30:04 +0200
commitc08762901e9840d8dca008dcc8d0b5602602fd0a (patch)
treeaa275ee79e2e356ffcd6ebcaf54c417dd47494a5
parentgamma_control_v1: handle destroyed output (diff)
downloadsway-c08762901e9840d8dca008dcc8d0b5602602fd0a.tar.gz
sway-c08762901e9840d8dca008dcc8d0b5602602fd0a.tar.zst
sway-c08762901e9840d8dca008dcc8d0b5602602fd0a.zip
input/libinput: add scroll_button_lock method
Closes https://github.com/swaywm/sway/issues/6987 Co-authored-by: JJGadgets <git@jjgadgets.tech> Co-authored-by: DeltaWhy <mike5713@gmail.com>
-rw-r--r--include/sway/commands.h1
-rw-r--r--include/sway/config.h1
-rw-r--r--sway/commands/input.c1
-rw-r--r--sway/commands/input/scroll_button_lock.c26
-rw-r--r--sway/config/input.c4
-rw-r--r--sway/input/libinput.c15
-rw-r--r--sway/ipc-json.c11
-rw-r--r--sway/meson.build1
-rw-r--r--sway/sway-input.5.scd3
-rw-r--r--sway/sway-ipc.7.scd3
10 files changed, 66 insertions, 0 deletions
diff --git a/include/sway/commands.h b/include/sway/commands.h
index 3212c2cf..27058587 100644
--- a/include/sway/commands.h
+++ b/include/sway/commands.h
@@ -266,6 +266,7 @@ sway_cmd input_cmd_scroll_factor;
266sway_cmd input_cmd_repeat_delay; 266sway_cmd input_cmd_repeat_delay;
267sway_cmd input_cmd_repeat_rate; 267sway_cmd input_cmd_repeat_rate;
268sway_cmd input_cmd_scroll_button; 268sway_cmd input_cmd_scroll_button;
269sway_cmd input_cmd_scroll_button_lock;
269sway_cmd input_cmd_scroll_method; 270sway_cmd input_cmd_scroll_method;
270sway_cmd input_cmd_tap; 271sway_cmd input_cmd_tap;
271sway_cmd input_cmd_tap_button_map; 272sway_cmd input_cmd_tap_button_map;
diff --git a/include/sway/config.h b/include/sway/config.h
index aa58da53..f9da1967 100644
--- a/include/sway/config.h
+++ b/include/sway/config.h
@@ -161,6 +161,7 @@ struct input_config {
161 int repeat_delay; 161 int repeat_delay;
162 int repeat_rate; 162 int repeat_rate;
163 int scroll_button; 163 int scroll_button;
164 int scroll_button_lock;
164 int scroll_method; 165 int scroll_method;
165 int send_events; 166 int send_events;
166 int tap; 167 int tap;
diff --git a/sway/commands/input.c b/sway/commands/input.c
index 3075b5f4..306c40f7 100644
--- a/sway/commands/input.c
+++ b/sway/commands/input.c
@@ -27,6 +27,7 @@ static const struct cmd_handler input_handlers[] = {
27 { "repeat_rate", input_cmd_repeat_rate }, 27 { "repeat_rate", input_cmd_repeat_rate },
28 { "rotation_angle", input_cmd_rotation_angle }, 28 { "rotation_angle", input_cmd_rotation_angle },
29 { "scroll_button", input_cmd_scroll_button }, 29 { "scroll_button", input_cmd_scroll_button },
30 { "scroll_button_lock", input_cmd_scroll_button_lock },
30 { "scroll_factor", input_cmd_scroll_factor }, 31 { "scroll_factor", input_cmd_scroll_factor },
31 { "scroll_method", input_cmd_scroll_method }, 32 { "scroll_method", input_cmd_scroll_method },
32 { "tap", input_cmd_tap }, 33 { "tap", input_cmd_tap },
diff --git a/sway/commands/input/scroll_button_lock.c b/sway/commands/input/scroll_button_lock.c
new file mode 100644
index 00000000..f96b6514
--- /dev/null
+++ b/sway/commands/input/scroll_button_lock.c
@@ -0,0 +1,26 @@
1#include <libinput.h>
2#include <string.h>
3#include <strings.h>
4#include "sway/config.h"
5#include "sway/commands.h"
6#include "sway/input/input-manager.h"
7#include "util.h"
8
9struct cmd_results *input_cmd_scroll_button_lock(int argc, char **argv) {
10 struct cmd_results *error = NULL;
11 if ((error = checkarg(argc, "scroll_button_lock", EXPECTED_AT_LEAST, 1))) {
12 return error;
13 }
14 struct input_config *ic = config->handler_context.input_config;
15 if (!ic) {
16 return cmd_results_new(CMD_FAILURE, "No input device defined.");
17 }
18
19 if (parse_boolean(argv[0], true)) {
20 ic->scroll_button_lock = LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_ENABLED;
21 } else {
22 ic->scroll_button_lock = LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_DISABLED;
23 }
24
25 return cmd_results_new(CMD_SUCCESS, NULL);
26}
diff --git a/sway/config/input.c b/sway/config/input.c
index 2ee165c9..44c2be28 100644
--- a/sway/config/input.c
+++ b/sway/config/input.c
@@ -35,6 +35,7 @@ struct input_config *new_input_config(const char* identifier) {
35 input->pointer_accel = FLT_MIN; 35 input->pointer_accel = FLT_MIN;
36 input->scroll_factor = FLT_MIN; 36 input->scroll_factor = FLT_MIN;
37 input->scroll_button = INT_MIN; 37 input->scroll_button = INT_MIN;
38 input->scroll_button_lock = INT_MIN;
38 input->scroll_method = INT_MIN; 39 input->scroll_method = INT_MIN;
39 input->left_handed = INT_MIN; 40 input->left_handed = INT_MIN;
40 input->repeat_delay = INT_MIN; 41 input->repeat_delay = INT_MIN;
@@ -96,6 +97,9 @@ void merge_input_config(struct input_config *dst, struct input_config *src) {
96 if (src->scroll_button != INT_MIN) { 97 if (src->scroll_button != INT_MIN) {
97 dst->scroll_button = src->scroll_button; 98 dst->scroll_button = src->scroll_button;
98 } 99 }
100 if (src->scroll_button_lock != INT_MIN) {
101 dst->scroll_button_lock = src->scroll_button_lock;
102 }
99 if (src->send_events != INT_MIN) { 103 if (src->send_events != INT_MIN) {
100 dst->send_events = src->send_events; 104 dst->send_events = src->send_events;
101 } 105 }
diff --git a/sway/input/libinput.c b/sway/input/libinput.c
index dd4fc0be..43875634 100644
--- a/sway/input/libinput.c
+++ b/sway/input/libinput.c
@@ -166,6 +166,18 @@ static bool set_scroll_button(struct libinput_device *dev, uint32_t button) {
166 return true; 166 return true;
167} 167}
168 168
169static bool set_scroll_button_lock(struct libinput_device *dev,
170 enum libinput_config_scroll_button_lock_state lock) {
171 uint32_t scroll = libinput_device_config_scroll_get_methods(dev);
172 if ((scroll & ~LIBINPUT_CONFIG_SCROLL_NO_SCROLL) == 0 ||
173 libinput_device_config_scroll_get_button_lock(dev) == lock) {
174 return false;
175 }
176 sway_log(SWAY_DEBUG, "scroll_set_button_lock(%" PRIu32 ")", lock);
177 log_status(libinput_device_config_scroll_set_button_lock(dev, lock));
178 return true;
179}
180
169static bool set_dwt(struct libinput_device *device, bool dwt) { 181static bool set_dwt(struct libinput_device *device, bool dwt) {
170 if (!libinput_device_config_dwt_is_available(device) || 182 if (!libinput_device_config_dwt_is_available(device) ||
171 libinput_device_config_dwt_get_enabled(device) == dwt) { 183 libinput_device_config_dwt_get_enabled(device) == dwt) {
@@ -276,6 +288,9 @@ bool sway_input_configure_libinput_device(struct sway_input_device *input_device
276 if (ic->scroll_button != INT_MIN) { 288 if (ic->scroll_button != INT_MIN) {
277 changed |= set_scroll_button(device, ic->scroll_button); 289 changed |= set_scroll_button(device, ic->scroll_button);
278 } 290 }
291 if (ic->scroll_button_lock != INT_MIN) {
292 changed |= set_scroll_button_lock(device, ic->scroll_button_lock);
293 }
279 if (ic->dwt != INT_MIN) { 294 if (ic->dwt != INT_MIN) {
280 changed |= set_dwt(device, ic->dwt); 295 changed |= set_dwt(device, ic->dwt);
281 } 296 }
diff --git a/sway/ipc-json.c b/sway/ipc-json.c
index c7cbea01..58356d4e 100644
--- a/sway/ipc-json.c
+++ b/sway/ipc-json.c
@@ -1019,6 +1019,17 @@ static json_object *describe_libinput_device(struct libinput_device *device) {
1019 uint32_t button = libinput_device_config_scroll_get_button(device); 1019 uint32_t button = libinput_device_config_scroll_get_button(device);
1020 json_object_object_add(object, "scroll_button", 1020 json_object_object_add(object, "scroll_button",
1021 json_object_new_int(button)); 1021 json_object_new_int(button));
1022 const char *lock = "unknown";
1023 switch (libinput_device_config_scroll_get_button_lock(device)) {
1024 case LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_ENABLED:
1025 lock = "enabled";
1026 break;
1027 case LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_DISABLED:
1028 lock = "disabled";
1029 break;
1030 }
1031 json_object_object_add(object, "scroll_button_lock",
1032 json_object_new_string(lock));
1022 } 1033 }
1023 } 1034 }
1024 1035
diff --git a/sway/meson.build b/sway/meson.build
index c6a27434..bc193bf9 100644
--- a/sway/meson.build
+++ b/sway/meson.build
@@ -171,6 +171,7 @@ sway_sources = files(
171 'commands/input/repeat_delay.c', 171 'commands/input/repeat_delay.c',
172 'commands/input/repeat_rate.c', 172 'commands/input/repeat_rate.c',
173 'commands/input/scroll_button.c', 173 'commands/input/scroll_button.c',
174 'commands/input/scroll_button_lock.c',
174 'commands/input/scroll_factor.c', 175 'commands/input/scroll_factor.c',
175 'commands/input/scroll_method.c', 176 'commands/input/scroll_method.c',
176 'commands/input/tap.c', 177 'commands/input/tap.c',
diff --git a/sway/sway-input.5.scd b/sway/sway-input.5.scd
index 1662d55a..082b68c2 100644
--- a/sway/sway-input.5.scd
+++ b/sway/sway-input.5.scd
@@ -185,6 +185,9 @@ The following commands may only be used in the configuration file.
185 debug-events*, or as a x11 mouse button (button[1-3,8,9]). If set to 185 debug-events*, or as a x11 mouse button (button[1-3,8,9]). If set to
186 _disable_, it disables the scroll_method on_button_down. 186 _disable_, it disables the scroll_method on_button_down.
187 187
188*input* <identifier> scroll_button_lock enabled|disabled
189 Enables or disables scroll button lock for specified input device.
190
188*input* <identifier> scroll_factor <floating point value> 191*input* <identifier> scroll_factor <floating point value>
189 Changes the scroll factor for the specified input device. Scroll speed will 192 Changes the scroll factor for the specified input device. Scroll speed will
190 be scaled by the given value, which must be non-negative. 193 be scaled by the given value, which must be non-negative.
diff --git a/sway/sway-ipc.7.scd b/sway/sway-ipc.7.scd
index 42aaaab6..f4a5ccff 100644
--- a/sway/sway-ipc.7.scd
+++ b/sway/sway-ipc.7.scd
@@ -1195,6 +1195,9 @@ following properties will be included for devices that support them:
1195: int 1195: int
1196: The scroll button to use when _scroll_method_ is _on_button_down_. This 1196: The scroll button to use when _scroll_method_ is _on_button_down_. This
1197 will be given as an input event code 1197 will be given as an input event code
1198|- scroll_button_lock
1199: string
1200: Whether scroll button lock is enabled. It can be _enabled_ or _disabled_
1198|- dwt 1201|- dwt
1199: string 1202: string
1200: Whether disable-while-typing is enabled. It can be _enabled_ or _disabled_ 1203: Whether disable-while-typing is enabled. It can be _enabled_ or _disabled_