From e078a007d6e5378c259df68779df2350db2eaffc Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 8 Sep 2020 11:08:05 +1000 Subject: [PATCH] backends: add support for scroll button locking Where enabled, the first click of the scroll button sets the button logically down, the second click sets the button logically up. This is an accessibility feature, it doesn't require users to keep holding the button down while scrolling which is hard or impossible for some users. gsettings-desktop-schemas merge request: https://gitlab.gnome.org/GNOME/gsettings-desktop-schemas/-/merge_requests/39 https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1432 --- meson.build | 2 +- src/backends/meta-input-settings-private.h | 3 ++- src/backends/meta-input-settings.c | 9 ++++++--- src/backends/native/meta-input-settings-native.c | 11 ++++++++++- src/backends/x11/meta-input-settings-x11.c | 7 ++++++- 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/meson.build b/meson.build index 4697bd40d..885437931 100644 --- a/meson.build +++ b/meson.build @@ -44,7 +44,7 @@ wayland_server_req = '>= 1.18' wayland_protocols_req = '>= 1.19' # native backend version requirements -libinput_req = '>= 1.7' +libinput_req = '>= 1.15.0' gbm_req = '>= 17.3' # screen cast version requirements diff --git a/src/backends/meta-input-settings-private.h b/src/backends/meta-input-settings-private.h index 675a3837b..3cf7b5f0e 100644 --- a/src/backends/meta-input-settings-private.h +++ b/src/backends/meta-input-settings-private.h @@ -78,7 +78,8 @@ struct _MetaInputSettingsClass gboolean enabled); void (* set_scroll_button) (MetaInputSettings *settings, ClutterInputDevice *device, - guint button); + guint button, + gboolean button_lock); void (* set_click_method) (MetaInputSettings *settings, ClutterInputDevice *device, diff --git a/src/backends/meta-input-settings.c b/src/backends/meta-input-settings.c index 0efaeb655..272e77b67 100644 --- a/src/backends/meta-input-settings.c +++ b/src/backends/meta-input-settings.c @@ -858,6 +858,7 @@ update_trackball_scroll_button (MetaInputSettings *input_settings, MetaInputSettingsClass *input_settings_class; MetaInputSettingsPrivate *priv; guint button; + gboolean button_lock; priv = meta_input_settings_get_instance_private (input_settings); input_settings_class = META_INPUT_SETTINGS_GET_CLASS (input_settings); @@ -868,10 +869,11 @@ update_trackball_scroll_button (MetaInputSettings *input_settings, /* This key is 'i' in the schema but it also specifies a minimum * range of 0 so the cast here is safe. */ button = (guint) g_settings_get_int (priv->trackball_settings, "scroll-wheel-emulation-button"); + button_lock = g_settings_get_boolean (priv->trackball_settings, "scroll-wheel-emulation-button-lock"); if (device) { - input_settings_class->set_scroll_button (input_settings, device, button); + input_settings_class->set_scroll_button (input_settings, device, button, button_lock); } else if (!device) { @@ -884,7 +886,7 @@ update_trackball_scroll_button (MetaInputSettings *input_settings, device = l->data; if (input_settings_class->is_trackball_device (input_settings, device)) - input_settings_class->set_scroll_button (input_settings, device, button); + input_settings_class->set_scroll_button (input_settings, device, button, button_lock); } g_list_free (devices); @@ -1282,7 +1284,8 @@ meta_input_settings_changed_cb (GSettings *settings, } else if (settings == priv->trackball_settings) { - if (strcmp (key, "scroll-wheel-emulation-button") == 0) + if (strcmp (key, "scroll-wheel-emulation-button") == 0 || + strcmp (key, "scroll-wheel-emulation-button-lock") == 0) update_trackball_scroll_button (input_settings, NULL); else if (strcmp (key, "accel-profile") == 0) update_pointer_accel_profile (input_settings, settings, NULL); diff --git a/src/backends/native/meta-input-settings-native.c b/src/backends/native/meta-input-settings-native.c index 82719e7d8..417481c19 100644 --- a/src/backends/native/meta-input-settings-native.c +++ b/src/backends/native/meta-input-settings-native.c @@ -270,10 +270,12 @@ meta_input_settings_native_has_two_finger_scroll (MetaInputSettings *settings, static void meta_input_settings_native_set_scroll_button (MetaInputSettings *settings, ClutterInputDevice *device, - guint button) + guint button, + gboolean button_lock) { struct libinput_device *libinput_device; enum libinput_config_scroll_method method; + enum libinput_config_scroll_button_lock_state lock_state; guint evcode; libinput_device = meta_input_device_native_get_libinput_device (device); @@ -314,6 +316,13 @@ meta_input_settings_native_set_scroll_button (MetaInputSettings *settings, return; libinput_device_config_scroll_set_button (libinput_device, evcode); + + if (button_lock) + lock_state = LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_ENABLED; + else + lock_state = LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_DISABLED; + + libinput_device_config_scroll_set_button_lock (libinput_device, lock_state); } static void diff --git a/src/backends/x11/meta-input-settings-x11.c b/src/backends/x11/meta-input-settings-x11.c index d9870bab0..08ba81f0d 100644 --- a/src/backends/x11/meta-input-settings-x11.c +++ b/src/backends/x11/meta-input-settings-x11.c @@ -375,11 +375,16 @@ meta_input_settings_x11_has_two_finger_scroll (MetaInputSettings *settings, static void meta_input_settings_x11_set_scroll_button (MetaInputSettings *settings, ClutterInputDevice *device, - guint button) + guint button, + gboolean button_lock) { + gchar lock = button_lock; + change_scroll_method (device, SCROLL_METHOD_FIELD_BUTTON, button != 0); change_property (device, "libinput Button Scrolling Button", XA_CARDINAL, 32, &button, 1); + change_property (device, "libinput Button Scrolling Button Lock Enabled", + XA_INTEGER, 8, &lock, 1); } static void