From 2641b364e81b4d404acc96f3fba2978fd4a021e7 Mon Sep 17 00:00:00 2001 From: Rui Matos Date: Thu, 27 Oct 2016 19:25:16 +0200 Subject: [PATCH] MetaInputSettings: fix two finger preference over edge scrolling logic Enabling edge scrolling before disabling two finger would result in edge scrolling not actually being enabled because two finger is still enabled at the time and we bail out. This patch moves this logic to common code for both the native and X backends and fixes it by ensuring that both settings are never set at the same time and still re-checking if edge scrolling should be enabled after two finger scrolling gets disabled. We also simplify the code by not checking for supported/available settings since the underlying devices will just reject those values and there isn't anything we can do about it here. It's the UI's job to only show supported/available settings to users. https://bugzilla.gnome.org/show_bug.cgi?id=771744 --- src/backends/meta-input-settings.c | 14 ++++ .../native/meta-input-settings-native.c | 51 +++--------- src/backends/x11/meta-input-settings-x11.c | 78 +++++-------------- 3 files changed, 44 insertions(+), 99 deletions(-) diff --git a/src/backends/meta-input-settings.c b/src/backends/meta-input-settings.c index 74cf30afd..9fc6f6089 100644 --- a/src/backends/meta-input-settings.c +++ b/src/backends/meta-input-settings.c @@ -483,6 +483,7 @@ update_touchpad_edge_scroll (MetaInputSettings *input_settings, { MetaInputSettingsClass *input_settings_class; gboolean edge_scroll_enabled; + gboolean two_finger_scroll_enabled; MetaInputSettingsPrivate *priv; if (device && @@ -492,6 +493,11 @@ update_touchpad_edge_scroll (MetaInputSettings *input_settings, priv = meta_input_settings_get_instance_private (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"); + + /* If both are enabled we prefer two finger. */ + if (edge_scroll_enabled && two_finger_scroll_enabled) + edge_scroll_enabled = FALSE; if (device) { @@ -523,6 +529,10 @@ update_touchpad_two_finger_scroll (MetaInputSettings *input_settings, input_settings_class = META_INPUT_SETTINGS_GET_CLASS (input_settings); two_finger_scroll_enabled = g_settings_get_boolean (priv->touchpad_settings, "two-finger-scrolling-enabled"); + /* Disable edge since they can't both be set. */ + if (two_finger_scroll_enabled) + update_touchpad_edge_scroll (input_settings, device); + if (device) { settings_device_set_bool_setting (input_settings, device, @@ -535,6 +545,10 @@ update_touchpad_two_finger_scroll (MetaInputSettings *input_settings, (ConfigBoolFunc) input_settings_class->set_two_finger_scroll, two_finger_scroll_enabled); } + + /* Edge might have been disabled because two finger was on. */ + if (!two_finger_scroll_enabled) + update_touchpad_edge_scroll (input_settings, device); } static void diff --git a/src/backends/native/meta-input-settings-native.c b/src/backends/native/meta-input-settings-native.c index 5a142f77b..266d224d9 100644 --- a/src/backends/native/meta-input-settings-native.c +++ b/src/backends/native/meta-input-settings-native.c @@ -160,32 +160,16 @@ meta_input_settings_native_set_edge_scroll (MetaInputSettings *settin ClutterInputDevice *device, gboolean edge_scrolling_enabled) { - enum libinput_config_scroll_method scroll_method = 0; struct libinput_device *libinput_device; - enum libinput_config_scroll_method supported; - enum libinput_config_scroll_method current; + enum libinput_config_scroll_method current, method; libinput_device = clutter_evdev_input_device_get_libinput_device (device); - if (!libinput_device) - return; - supported = libinput_device_config_scroll_get_methods (libinput_device); + + method = edge_scrolling_enabled ? LIBINPUT_CONFIG_SCROLL_EDGE : LIBINPUT_CONFIG_SCROLL_NO_SCROLL; current = libinput_device_config_scroll_get_method (libinput_device); + current &= ~LIBINPUT_CONFIG_SCROLL_EDGE; - /* Don't set edge scrolling if two-finger scrolling is enabled and available */ - if (current == LIBINPUT_CONFIG_SCROLL_2FG) - return; - - if (supported & LIBINPUT_CONFIG_SCROLL_EDGE && - edge_scrolling_enabled) - { - scroll_method = LIBINPUT_CONFIG_SCROLL_EDGE; - } - else - { - scroll_method = LIBINPUT_CONFIG_SCROLL_NO_SCROLL; - } - - device_set_scroll_method (libinput_device, scroll_method); + device_set_scroll_method (libinput_device, current | method); } static void @@ -193,31 +177,16 @@ meta_input_settings_native_set_two_finger_scroll (MetaInputSettings * ClutterInputDevice *device, gboolean two_finger_scroll_enabled) { - enum libinput_config_scroll_method scroll_method = 0; struct libinput_device *libinput_device; - enum libinput_config_scroll_method supported; - enum libinput_config_scroll_method current; + enum libinput_config_scroll_method current, method; libinput_device = clutter_evdev_input_device_get_libinput_device (device); - supported = libinput_device_config_scroll_get_methods (libinput_device); + + method = two_finger_scroll_enabled ? LIBINPUT_CONFIG_SCROLL_2FG : LIBINPUT_CONFIG_SCROLL_NO_SCROLL; current = libinput_device_config_scroll_get_method (libinput_device); + current &= ~LIBINPUT_CONFIG_SCROLL_2FG; - if (two_finger_scroll_enabled && - !(supported & LIBINPUT_CONFIG_SCROLL_2FG)) - return; - - if (two_finger_scroll_enabled) - { - scroll_method = LIBINPUT_CONFIG_SCROLL_2FG; - } - else if (current != LIBINPUT_CONFIG_SCROLL_EDGE) - { - scroll_method = LIBINPUT_CONFIG_SCROLL_NO_SCROLL; - } - else - return; - - device_set_scroll_method (libinput_device, scroll_method); + device_set_scroll_method (libinput_device, current | method); } static void diff --git a/src/backends/x11/meta-input-settings-x11.c b/src/backends/x11/meta-input-settings-x11.c index f595d4232..332997b47 100644 --- a/src/backends/x11/meta-input-settings-x11.c +++ b/src/backends/x11/meta-input-settings-x11.c @@ -222,32 +222,19 @@ meta_input_settings_x11_set_edge_scroll (MetaInputSettings *settings, gboolean edge_scroll_enabled) { guchar values[SCROLL_METHOD_NUM_FIELDS] = { 0 }; /* 2fg, edge, button. The last value is unused */ - guchar *defaults; - guchar *available; + guchar *current; - available = get_property (device, "libinput Scroll Methods Available", - XA_INTEGER, 8, SCROLL_METHOD_NUM_FIELDS); - defaults = get_property (device, "libinput Scroll Method Enabled", - XA_INTEGER, 8, SCROLL_METHOD_NUM_FIELDS); - if (!available || !defaults) - goto out; + current = get_property (device, "libinput Scroll Method Enabled", + XA_INTEGER, 8, SCROLL_METHOD_NUM_FIELDS); + if (!current) + return; - memcpy (values, defaults, SCROLL_METHOD_NUM_FIELDS); + memcpy (values, current, SCROLL_METHOD_NUM_FIELDS); - /* Don't set edge scrolling if two-finger scrolling is enabled and available */ - if (available[SCROLL_METHOD_FIELD_EDGE] && - !(available[SCROLL_METHOD_FIELD_2FG] && values[SCROLL_METHOD_FIELD_2FG])) - { - values[1] = !!edge_scroll_enabled; - change_property (device, "libinput Scroll Method Enabled", - XA_INTEGER, 8, &values, SCROLL_METHOD_NUM_FIELDS); - } - -out: - if (available) - meta_XFree (available); - if (defaults) - meta_XFree (defaults); + values[SCROLL_METHOD_FIELD_EDGE] = !!edge_scroll_enabled; + change_property (device, "libinput Scroll Method Enabled", + XA_INTEGER, 8, &values, SCROLL_METHOD_NUM_FIELDS); + meta_XFree (current); } static void @@ -256,44 +243,19 @@ meta_input_settings_x11_set_two_finger_scroll (MetaInputSettings *set gboolean two_finger_scroll_enabled) { guchar values[SCROLL_METHOD_NUM_FIELDS] = { 0 }; /* 2fg, edge, button. The last value is unused */ - guchar *defaults; - guchar *available; - gboolean changed; + guchar *current; - available = get_property (device, "libinput Scroll Methods Available", - XA_INTEGER, 8, SCROLL_METHOD_NUM_FIELDS); - defaults = get_property (device, "libinput Scroll Method Enabled", - XA_INTEGER, 8, SCROLL_METHOD_NUM_FIELDS); - if (!available || !defaults) - goto out; + current = get_property (device, "libinput Scroll Method Enabled", + XA_INTEGER, 8, SCROLL_METHOD_NUM_FIELDS); + if (!current) + return; - memcpy (values, defaults, SCROLL_METHOD_NUM_FIELDS); - changed = FALSE; + memcpy (values, current, SCROLL_METHOD_NUM_FIELDS); - if (available[SCROLL_METHOD_FIELD_2FG]) - { - values[SCROLL_METHOD_FIELD_2FG] = !!two_finger_scroll_enabled; - changed = TRUE; - } - - /* Disable edge scrolling when two-finger scrolling is enabled */ - if (values[SCROLL_METHOD_FIELD_2FG] && values[SCROLL_METHOD_FIELD_EDGE]) - { - values[SCROLL_METHOD_FIELD_EDGE] = 0; - changed = TRUE; - } - - if (changed) - { - change_property (device, "libinput Scroll Method Enabled", - XA_INTEGER, 8, &values, SCROLL_METHOD_NUM_FIELDS); - } - -out: - if (available) - meta_XFree (available); - if (defaults) - meta_XFree (defaults); + values[SCROLL_METHOD_FIELD_2FG] = !!two_finger_scroll_enabled; + change_property (device, "libinput Scroll Method Enabled", + XA_INTEGER, 8, &values, SCROLL_METHOD_NUM_FIELDS); + meta_XFree (current); } static void