mirror of
https://github.com/swaywm/sway.git
synced 2024-11-10 12:33:50 +01:00
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>
This commit is contained in:
parent
8b4b65d665
commit
c08762901e
@ -266,6 +266,7 @@ sway_cmd input_cmd_scroll_factor;
|
||||
sway_cmd input_cmd_repeat_delay;
|
||||
sway_cmd input_cmd_repeat_rate;
|
||||
sway_cmd input_cmd_scroll_button;
|
||||
sway_cmd input_cmd_scroll_button_lock;
|
||||
sway_cmd input_cmd_scroll_method;
|
||||
sway_cmd input_cmd_tap;
|
||||
sway_cmd input_cmd_tap_button_map;
|
||||
|
@ -161,6 +161,7 @@ struct input_config {
|
||||
int repeat_delay;
|
||||
int repeat_rate;
|
||||
int scroll_button;
|
||||
int scroll_button_lock;
|
||||
int scroll_method;
|
||||
int send_events;
|
||||
int tap;
|
||||
|
@ -27,6 +27,7 @@ static const struct cmd_handler input_handlers[] = {
|
||||
{ "repeat_rate", input_cmd_repeat_rate },
|
||||
{ "rotation_angle", input_cmd_rotation_angle },
|
||||
{ "scroll_button", input_cmd_scroll_button },
|
||||
{ "scroll_button_lock", input_cmd_scroll_button_lock },
|
||||
{ "scroll_factor", input_cmd_scroll_factor },
|
||||
{ "scroll_method", input_cmd_scroll_method },
|
||||
{ "tap", input_cmd_tap },
|
||||
|
26
sway/commands/input/scroll_button_lock.c
Normal file
26
sway/commands/input/scroll_button_lock.c
Normal file
@ -0,0 +1,26 @@
|
||||
#include <libinput.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include "sway/config.h"
|
||||
#include "sway/commands.h"
|
||||
#include "sway/input/input-manager.h"
|
||||
#include "util.h"
|
||||
|
||||
struct cmd_results *input_cmd_scroll_button_lock(int argc, char **argv) {
|
||||
struct cmd_results *error = NULL;
|
||||
if ((error = checkarg(argc, "scroll_button_lock", EXPECTED_AT_LEAST, 1))) {
|
||||
return error;
|
||||
}
|
||||
struct input_config *ic = config->handler_context.input_config;
|
||||
if (!ic) {
|
||||
return cmd_results_new(CMD_FAILURE, "No input device defined.");
|
||||
}
|
||||
|
||||
if (parse_boolean(argv[0], true)) {
|
||||
ic->scroll_button_lock = LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_ENABLED;
|
||||
} else {
|
||||
ic->scroll_button_lock = LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_DISABLED;
|
||||
}
|
||||
|
||||
return cmd_results_new(CMD_SUCCESS, NULL);
|
||||
}
|
@ -35,6 +35,7 @@ struct input_config *new_input_config(const char* identifier) {
|
||||
input->pointer_accel = FLT_MIN;
|
||||
input->scroll_factor = FLT_MIN;
|
||||
input->scroll_button = INT_MIN;
|
||||
input->scroll_button_lock = INT_MIN;
|
||||
input->scroll_method = INT_MIN;
|
||||
input->left_handed = INT_MIN;
|
||||
input->repeat_delay = INT_MIN;
|
||||
@ -96,6 +97,9 @@ void merge_input_config(struct input_config *dst, struct input_config *src) {
|
||||
if (src->scroll_button != INT_MIN) {
|
||||
dst->scroll_button = src->scroll_button;
|
||||
}
|
||||
if (src->scroll_button_lock != INT_MIN) {
|
||||
dst->scroll_button_lock = src->scroll_button_lock;
|
||||
}
|
||||
if (src->send_events != INT_MIN) {
|
||||
dst->send_events = src->send_events;
|
||||
}
|
||||
|
@ -166,6 +166,18 @@ static bool set_scroll_button(struct libinput_device *dev, uint32_t button) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool set_scroll_button_lock(struct libinput_device *dev,
|
||||
enum libinput_config_scroll_button_lock_state lock) {
|
||||
uint32_t scroll = libinput_device_config_scroll_get_methods(dev);
|
||||
if ((scroll & ~LIBINPUT_CONFIG_SCROLL_NO_SCROLL) == 0 ||
|
||||
libinput_device_config_scroll_get_button_lock(dev) == lock) {
|
||||
return false;
|
||||
}
|
||||
sway_log(SWAY_DEBUG, "scroll_set_button_lock(%" PRIu32 ")", lock);
|
||||
log_status(libinput_device_config_scroll_set_button_lock(dev, lock));
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool set_dwt(struct libinput_device *device, bool dwt) {
|
||||
if (!libinput_device_config_dwt_is_available(device) ||
|
||||
libinput_device_config_dwt_get_enabled(device) == dwt) {
|
||||
@ -276,6 +288,9 @@ bool sway_input_configure_libinput_device(struct sway_input_device *input_device
|
||||
if (ic->scroll_button != INT_MIN) {
|
||||
changed |= set_scroll_button(device, ic->scroll_button);
|
||||
}
|
||||
if (ic->scroll_button_lock != INT_MIN) {
|
||||
changed |= set_scroll_button_lock(device, ic->scroll_button_lock);
|
||||
}
|
||||
if (ic->dwt != INT_MIN) {
|
||||
changed |= set_dwt(device, ic->dwt);
|
||||
}
|
||||
|
@ -1019,6 +1019,17 @@ static json_object *describe_libinput_device(struct libinput_device *device) {
|
||||
uint32_t button = libinput_device_config_scroll_get_button(device);
|
||||
json_object_object_add(object, "scroll_button",
|
||||
json_object_new_int(button));
|
||||
const char *lock = "unknown";
|
||||
switch (libinput_device_config_scroll_get_button_lock(device)) {
|
||||
case LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_ENABLED:
|
||||
lock = "enabled";
|
||||
break;
|
||||
case LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_DISABLED:
|
||||
lock = "disabled";
|
||||
break;
|
||||
}
|
||||
json_object_object_add(object, "scroll_button_lock",
|
||||
json_object_new_string(lock));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -171,6 +171,7 @@ sway_sources = files(
|
||||
'commands/input/repeat_delay.c',
|
||||
'commands/input/repeat_rate.c',
|
||||
'commands/input/scroll_button.c',
|
||||
'commands/input/scroll_button_lock.c',
|
||||
'commands/input/scroll_factor.c',
|
||||
'commands/input/scroll_method.c',
|
||||
'commands/input/tap.c',
|
||||
|
@ -185,6 +185,9 @@ The following commands may only be used in the configuration file.
|
||||
debug-events*, or as a x11 mouse button (button[1-3,8,9]). If set to
|
||||
_disable_, it disables the scroll_method on_button_down.
|
||||
|
||||
*input* <identifier> scroll_button_lock enabled|disabled
|
||||
Enables or disables scroll button lock for specified input device.
|
||||
|
||||
*input* <identifier> scroll_factor <floating point value>
|
||||
Changes the scroll factor for the specified input device. Scroll speed will
|
||||
be scaled by the given value, which must be non-negative.
|
||||
|
@ -1195,6 +1195,9 @@ following properties will be included for devices that support them:
|
||||
: int
|
||||
: The scroll button to use when _scroll_method_ is _on_button_down_. This
|
||||
will be given as an input event code
|
||||
|- scroll_button_lock
|
||||
: string
|
||||
: Whether scroll button lock is enabled. It can be _enabled_ or _disabled_
|
||||
|- dwt
|
||||
: string
|
||||
: Whether disable-while-typing is enabled. It can be _enabled_ or _disabled_
|
||||
|
Loading…
Reference in New Issue
Block a user