[mutter] backends/x11: Add enum for scroll methods



commit cfe5d7429ab248a75ea5be94c597fdd387a5e02f
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Jul 27 19:33:47 2016 +0200

    backends/x11: Add enum for scroll methods
    
    This way the "libinput Scroll Method Enabled" property manipulation
    is made clearer.

 src/backends/x11/meta-input-settings-x11.c |   38 +++++++++++++++++-----------
 1 files changed, 23 insertions(+), 15 deletions(-)
---
diff --git a/src/backends/x11/meta-input-settings-x11.c b/src/backends/x11/meta-input-settings-x11.c
index f81d087..8645570 100644
--- a/src/backends/x11/meta-input-settings-x11.c
+++ b/src/backends/x11/meta-input-settings-x11.c
@@ -36,6 +36,13 @@
 
 G_DEFINE_TYPE (MetaInputSettingsX11, meta_input_settings_x11, META_TYPE_INPUT_SETTINGS)
 
+enum {
+  SCROLL_METHOD_FIELD_2FG,
+  SCROLL_METHOD_FIELD_EDGE,
+  SCROLL_METHOD_FIELD_BUTTON,
+  SCROLL_METHOD_NUM_FIELDS
+};
+
 static void *
 get_property (ClutterInputDevice *device,
               const gchar        *property,
@@ -203,25 +210,26 @@ meta_input_settings_x11_set_edge_scroll (MetaInputSettings            *settings,
                                          ClutterInputDevice           *device,
                                          gboolean                      edge_scroll_enabled)
 {
-  guchar values[3] = { 0 }; /* 2fg, edge, button. The last value is unused */
+  guchar values[SCROLL_METHOD_NUM_FIELDS] = { 0 }; /* 2fg, edge, button. The last value is unused */
   guchar *defaults;
   guchar *available;
 
   available = get_property (device, "libinput Scroll Methods Available",
-                            XA_INTEGER, 8, 3);
+                            XA_INTEGER, 8, SCROLL_METHOD_NUM_FIELDS);
   defaults = get_property (device, "libinput Scroll Method Enabled",
-                           XA_INTEGER, 8, 3);
+                           XA_INTEGER, 8, SCROLL_METHOD_NUM_FIELDS);
   if (!available || !defaults)
     goto out;
 
-  memcpy (values, defaults, 3);
+  memcpy (values, defaults, SCROLL_METHOD_NUM_FIELDS);
 
   /* Don't set edge scrolling if two-finger scrolling is enabled and available */
-  if (available[1] && !(available[0] && values[0]))
+  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, 3);
+                       XA_INTEGER, 8, &values, SCROLL_METHOD_NUM_FIELDS);
     }
 
 out:
@@ -236,38 +244,38 @@ meta_input_settings_x11_set_two_finger_scroll (MetaInputSettings            *set
                                                ClutterInputDevice           *device,
                                                gboolean                      two_finger_scroll_enabled)
 {
-  guchar values[3] = { 0 }; /* 2fg, edge, button. The last value is unused */
+  guchar values[SCROLL_METHOD_NUM_FIELDS] = { 0 }; /* 2fg, edge, button. The last value is unused */
   guchar *defaults;
   guchar *available;
   gboolean changed;
 
   available = get_property (device, "libinput Scroll Methods Available",
-                            XA_INTEGER, 8, 3);
+                            XA_INTEGER, 8, SCROLL_METHOD_NUM_FIELDS);
   defaults = get_property (device, "libinput Scroll Method Enabled",
-                           XA_INTEGER, 8, 3);
+                           XA_INTEGER, 8, SCROLL_METHOD_NUM_FIELDS);
   if (!available || !defaults)
     goto out;
 
-  memcpy (values, defaults, 3);
+  memcpy (values, defaults, SCROLL_METHOD_NUM_FIELDS);
   changed = FALSE;
 
-  if (available[0])
+  if (available[SCROLL_METHOD_FIELD_2FG])
     {
-      values[0] = !!two_finger_scroll_enabled;
+      values[SCROLL_METHOD_FIELD_2FG] = !!two_finger_scroll_enabled;
       changed = TRUE;
     }
 
   /* Disable edge scrolling when two-finger scrolling is enabled */
-  if (values[0] && values[1])
+  if (values[SCROLL_METHOD_FIELD_2FG] && values[SCROLL_METHOD_FIELD_EDGE])
     {
-      values[1] = 0;
+      values[SCROLL_METHOD_FIELD_EDGE] = 0;
       changed = TRUE;
     }
 
   if (changed)
     {
       change_property (device, "libinput Scroll Method Enabled",
-                       XA_INTEGER, 8, &values, 3);
+                       XA_INTEGER, 8, &values, SCROLL_METHOD_NUM_FIELDS);
     }
 
 out:


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