From 443250a9f74838116e0a8746f3c567fd5560f423 Mon Sep 17 00:00:00 2001 From: Rui Matos Date: Mon, 13 Feb 2017 14:06:35 +0100 Subject: [PATCH] MetaInputSettings: allow edge scrolling without 2fg capable devices We should only force edge scrolling off if two finger is enabled *and* we actually have two finger capable devices. https://bugzilla.gnome.org/show_bug.cgi?id=778554 --- src/backends/meta-input-settings-private.h | 3 ++ src/backends/meta-input-settings.c | 40 ++++++++++++++++++- .../native/meta-input-settings-native.c | 15 +++++++ src/backends/x11/meta-input-settings-x11.c | 18 +++++++++ 4 files changed, 75 insertions(+), 1 deletion(-) diff --git a/src/backends/meta-input-settings-private.h b/src/backends/meta-input-settings-private.h index 6e5f97bd4..06aa3e9ae 100644 --- a/src/backends/meta-input-settings-private.h +++ b/src/backends/meta-input-settings-private.h @@ -107,6 +107,9 @@ struct _MetaInputSettingsClass void (* set_trackball_accel_profile) (MetaInputSettings *settings, ClutterInputDevice *device, GDesktopPointerAccelProfile profile); + + gboolean (* has_two_finger_scroll) (MetaInputSettings *settings, + ClutterInputDevice *device); }; GType meta_input_settings_get_type (void) G_GNUC_CONST; diff --git a/src/backends/meta-input-settings.c b/src/backends/meta-input-settings.c index ec9703259..e1ec42de4 100644 --- a/src/backends/meta-input-settings.c +++ b/src/backends/meta-input-settings.c @@ -83,6 +83,8 @@ struct _MetaInputSettingsPrivate #ifdef HAVE_LIBWACOM WacomDeviceDatabase *wacom_db; #endif + + GHashTable *two_finger_devices; }; typedef void (*ConfigBoolFunc) (MetaInputSettings *input_settings, @@ -148,6 +150,8 @@ meta_input_settings_dispose (GObject *object) libwacom_database_destroy (priv->wacom_db); #endif + g_clear_pointer (&priv->two_finger_devices, g_hash_table_destroy); + G_OBJECT_CLASS (meta_input_settings_parent_class)->dispose (object); } @@ -484,6 +488,7 @@ update_touchpad_edge_scroll (MetaInputSettings *input_settings, MetaInputSettingsClass *input_settings_class; gboolean edge_scroll_enabled; gboolean two_finger_scroll_enabled; + gboolean two_finger_scroll_available; MetaInputSettingsPrivate *priv; if (device && @@ -494,9 +499,10 @@ update_touchpad_edge_scroll (MetaInputSettings *input_settings, input_settings_class = META_INPUT_SETTINGS_GET_CLASS (input_settings); edge_scroll_enabled = g_settings_get_boolean (priv->touchpad_settings, "edge-scrolling-enabled"); two_finger_scroll_enabled = g_settings_get_boolean (priv->touchpad_settings, "two-finger-scrolling-enabled"); + two_finger_scroll_available = g_hash_table_size (priv->two_finger_devices) > 0; /* If both are enabled we prefer two finger. */ - if (edge_scroll_enabled && two_finger_scroll_enabled) + if (edge_scroll_enabled && two_finger_scroll_enabled && two_finger_scroll_available) edge_scroll_enabled = FALSE; if (device) @@ -1409,6 +1415,23 @@ apply_device_settings (MetaInputSettings *input_settings, device); } +static void +evaluate_two_finger_scrolling (MetaInputSettings *input_settings, + ClutterInputDevice *device) +{ + MetaInputSettingsClass *klass; + MetaInputSettingsPrivate *priv; + + if (clutter_input_device_get_device_type (device) != CLUTTER_TOUCHPAD_DEVICE) + return; + + klass = META_INPUT_SETTINGS_GET_CLASS (input_settings); + priv = meta_input_settings_get_instance_private (input_settings); + + if (klass->has_two_finger_scroll (input_settings, device)) + g_hash_table_add (priv->two_finger_devices, device); +} + static void meta_input_settings_device_added (ClutterDeviceManager *device_manager, ClutterInputDevice *device, @@ -1417,6 +1440,8 @@ meta_input_settings_device_added (ClutterDeviceManager *device_manager, if (clutter_input_device_get_device_mode (device) == CLUTTER_INPUT_MODE_MASTER) return; + evaluate_two_finger_scrolling (input_settings, device); + apply_device_settings (input_settings, device); check_add_mappable_device (input_settings, device); } @@ -1430,6 +1455,10 @@ meta_input_settings_device_removed (ClutterDeviceManager *device_manager, priv = meta_input_settings_get_instance_private (input_settings); g_hash_table_remove (priv->mappable_devices, device); + + if (g_hash_table_remove (priv->two_finger_devices, device) && + g_hash_table_size (priv->two_finger_devices) == 0) + apply_device_settings (input_settings, NULL); } static void @@ -1456,6 +1485,13 @@ static void meta_input_settings_constructed (GObject *object) { MetaInputSettings *input_settings = META_INPUT_SETTINGS (object); + GSList *devices, *d; + + devices = meta_input_settings_get_devices (input_settings, CLUTTER_TOUCHPAD_DEVICE); + for (d = devices; d; d = d->next) + evaluate_two_finger_scrolling (input_settings, d->data); + + g_slist_free (devices); apply_device_settings (input_settings, NULL); update_keyboard_repeat (input_settings); @@ -1517,6 +1553,8 @@ meta_input_settings_init (MetaInputSettings *settings) "expect tablets to misbehave"); } #endif + + priv->two_finger_devices = g_hash_table_new (NULL, NULL); } MetaInputSettings * diff --git a/src/backends/native/meta-input-settings-native.c b/src/backends/native/meta-input-settings-native.c index 266d224d9..6593e5d53 100644 --- a/src/backends/native/meta-input-settings-native.c +++ b/src/backends/native/meta-input-settings-native.c @@ -189,6 +189,19 @@ meta_input_settings_native_set_two_finger_scroll (MetaInputSettings * device_set_scroll_method (libinput_device, current | method); } +static gboolean +meta_input_settings_native_has_two_finger_scroll (MetaInputSettings *settings, + ClutterInputDevice *device) +{ + struct libinput_device *libinput_device; + + libinput_device = clutter_evdev_input_device_get_libinput_device (device); + if (!libinput_device) + return FALSE; + + return libinput_device_config_scroll_get_methods (libinput_device) & LIBINPUT_CONFIG_SCROLL_2FG; +} + static void meta_input_settings_native_set_scroll_button (MetaInputSettings *settings, ClutterInputDevice *device, @@ -418,6 +431,8 @@ meta_input_settings_native_class_init (MetaInputSettingsNativeClass *klass) input_settings_class->set_mouse_accel_profile = meta_input_settings_native_set_mouse_accel_profile; input_settings_class->set_trackball_accel_profile = meta_input_settings_native_set_trackball_accel_profile; + + input_settings_class->has_two_finger_scroll = meta_input_settings_native_has_two_finger_scroll; } static void diff --git a/src/backends/x11/meta-input-settings-x11.c b/src/backends/x11/meta-input-settings-x11.c index eccc68aa7..8f962b49a 100644 --- a/src/backends/x11/meta-input-settings-x11.c +++ b/src/backends/x11/meta-input-settings-x11.c @@ -274,6 +274,22 @@ meta_input_settings_x11_set_two_finger_scroll (MetaInputSettings *set meta_XFree (available); } +static gboolean +meta_input_settings_x11_has_two_finger_scroll (MetaInputSettings *settings, + ClutterInputDevice *device) +{ + guchar *available = NULL; + gboolean has_two_finger = TRUE; + + available = get_property (device, "libinput Scroll Methods Available", + XA_INTEGER, 8, SCROLL_METHOD_NUM_FIELDS); + if (!available || !available[SCROLL_METHOD_FIELD_2FG]) + has_two_finger = FALSE; + + meta_XFree (available); + return has_two_finger; +} + static void meta_input_settings_x11_set_scroll_button (MetaInputSettings *settings, ClutterInputDevice *device, @@ -543,6 +559,8 @@ meta_input_settings_x11_class_init (MetaInputSettingsX11Class *klass) input_settings_class->set_mouse_accel_profile = meta_input_settings_x11_set_mouse_accel_profile; input_settings_class->set_trackball_accel_profile = meta_input_settings_x11_set_trackball_accel_profile; + + input_settings_class->has_two_finger_scroll = meta_input_settings_x11_has_two_finger_scroll; } static void