[gnome-flashback] input-settings: fix two finger preference over edge scrolling logic



commit aa40f0a9ccd189a2b50c5945c54ad8008b954f89
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Sat May 13 11:02:33 2017 +0300

    input-settings: 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
    
    https://git.gnome.org/browse/mutter/commit/?id=2641b364e81b4d404acc96f3fba2978fd4a021e7
    https://git.gnome.org/browse/mutter/commit/?id=925b1aec641fe57f53cd06860b97db25bb415b7a

 .../libinput-settings/gf-input-settings.c          |   99 +++++++++----------
 1 files changed, 47 insertions(+), 52 deletions(-)
---
diff --git a/gnome-flashback/libinput-settings/gf-input-settings.c 
b/gnome-flashback/libinput-settings/gf-input-settings.c
index 2b8dcce..dfa7753 100644
--- a/gnome-flashback/libinput-settings/gf-input-settings.c
+++ b/gnome-flashback/libinput-settings/gf-input-settings.c
@@ -402,46 +402,41 @@ set_edge_scroll (GfInputSettings *settings,
                  GdkDevice       *device,
                  gboolean         edge_scroll_enabled)
 {
-  guchar *available;
-  guchar *defaults;
   guchar values[SCROLL_METHOD_NUM_FIELDS] = { 0 }; /* 2fg, edge, button. The last value is unused */
+  guchar *available = NULL;
+  guchar *current = NULL;
 
   available = get_property (settings, device,
                             "libinput Scroll Methods Available",
                             XA_INTEGER, 8, SCROLL_METHOD_NUM_FIELDS);
 
-  defaults = get_property (settings, device,
-                           "libinput Scroll Method Enabled",
-                           XA_INTEGER, 8, SCROLL_METHOD_NUM_FIELDS);
-
-  if (!available || !defaults)
+  if (!available || !available[SCROLL_METHOD_FIELD_EDGE])
     {
       if (available)
         XFree (available);
 
-      if (defaults)
-        XFree (defaults);
-
       return;
     }
 
-  memcpy (values, defaults, SCROLL_METHOD_NUM_FIELDS);
+  current = get_property (settings, device,
+                          "libinput Scroll Method Enabled",
+                          XA_INTEGER, 8, 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]))
+  if (!current)
     {
-      values[1] = !!edge_scroll_enabled;
+      XFree (available);
 
-      change_property (settings, device, "libinput Scroll Method Enabled",
-                       XA_INTEGER, 8, &values, SCROLL_METHOD_NUM_FIELDS);
+      return;
     }
 
-  if (available)
-    XFree (available);
+  memcpy (values, current, SCROLL_METHOD_NUM_FIELDS);
 
-  if (defaults)
-    XFree (defaults);
+  values[SCROLL_METHOD_FIELD_EDGE] = !!edge_scroll_enabled;
+  change_property (settings, device, "libinput Scroll Method Enabled",
+                   XA_INTEGER, 8, &values, SCROLL_METHOD_NUM_FIELDS);
+
+  XFree (available);
+  XFree (current);
 }
 
 static void
@@ -449,57 +444,41 @@ set_two_finger_scroll (GfInputSettings *settings,
                        GdkDevice       *device,
                        gboolean         two_finger_scroll_enabled)
 {
-  guchar *available;
-  gboolean changed;
-  guchar *defaults;
   guchar values[SCROLL_METHOD_NUM_FIELDS] = { 0 }; /* 2fg, edge, button. The last value is unused */
+  guchar *available = NULL;
+  guchar *current = NULL;
 
   available = get_property (settings, device,
                             "libinput Scroll Methods Available",
                             XA_INTEGER, 8, SCROLL_METHOD_NUM_FIELDS);
 
-  defaults = get_property (settings, device,
-                           "libinput Scroll Method Enabled",
-                           XA_INTEGER, 8, SCROLL_METHOD_NUM_FIELDS);
-
-  if (!available || !defaults)
+  if (!available || !available[SCROLL_METHOD_FIELD_2FG])
     {
       if (available)
         XFree (available);
 
-      if (defaults)
-        XFree (defaults);
-
       return;
     }
 
-  memcpy (values, defaults, SCROLL_METHOD_NUM_FIELDS);
-  changed = FALSE;
+  current = get_property (settings, device,
+                          "libinput Scroll Method Enabled",
+                          XA_INTEGER, 8, SCROLL_METHOD_NUM_FIELDS);
 
-  if (available[SCROLL_METHOD_FIELD_2FG])
+  if (!current)
     {
-      values[SCROLL_METHOD_FIELD_2FG] = !!two_finger_scroll_enabled;
-      changed = TRUE;
-    }
+      XFree (available);
 
-  /* 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;
+      return;
     }
 
-  if (changed)
-    {
-      change_property (settings, device, "libinput Scroll Method Enabled",
-                       XA_INTEGER, 8, &values, SCROLL_METHOD_NUM_FIELDS);
-    }
+  memcpy (values, current, SCROLL_METHOD_NUM_FIELDS);
 
-  if (available)
-    XFree (available);
+  values[SCROLL_METHOD_FIELD_2FG] = !!two_finger_scroll_enabled;
+  change_property (settings, device, "libinput Scroll Method Enabled",
+                   XA_INTEGER, 8, &values, SCROLL_METHOD_NUM_FIELDS);
 
-  if (defaults)
-    XFree (defaults);
+  XFree (available);
+  XFree (current);
 }
 
 static void
@@ -807,6 +786,7 @@ update_touchpad_edge_scroll (GfInputSettings *settings,
                              GdkDevice       *device)
 {
   gboolean edge_scroll_enabled;
+  gboolean two_finger_scroll_enabled;
 
   if (device && gdk_device_get_source (device) != GDK_SOURCE_TOUCHPAD)
     return;
@@ -814,6 +794,13 @@ update_touchpad_edge_scroll (GfInputSettings *settings,
   edge_scroll_enabled = g_settings_get_boolean (settings->touchpad,
                                                 "edge-scrolling-enabled");
 
+  two_finger_scroll_enabled = g_settings_get_boolean (settings->touchpad,
+                                                      "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)
     {
       device_set_bool_setting (settings, device,
@@ -838,6 +825,10 @@ update_touchpad_two_finger_scroll (GfInputSettings *settings,
   two_finger_scroll_enabled = g_settings_get_boolean (settings->touchpad,
                                                       "two-finger-scrolling-enabled");
 
+  /* Disable edge since they can't both be set. */
+  if (two_finger_scroll_enabled)
+    update_touchpad_edge_scroll (settings, device);
+
   if (device)
     {
       device_set_bool_setting (settings, device,
@@ -848,6 +839,10 @@ update_touchpad_two_finger_scroll (GfInputSettings *settings,
       set_bool_setting (settings, GDK_SOURCE_TOUCHPAD,
                         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 (settings, device);
 }
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]