[gnome-control-center] mouse: decouple the scroll-methods detection code from the UI file
- From: Felipe Borges <felipeborges src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] mouse: decouple the scroll-methods detection code from the UI file
- Date: Thu, 22 Oct 2015 13:19:17 +0000 (UTC)
commit 5cd231fd59075bf3f727d05b19d9abf7deac90c8
Author: Felipe Borges <feborges redhat com>
Date: Thu Oct 22 11:48:25 2015 +0200
mouse: decouple the scroll-methods detection code from the UI file
https://bugzilla.gnome.org/show_bug.cgi?id=756863
panels/mouse/Makefile.am | 2 +
panels/mouse/cc-mouse-caps-helper.c | 113 +++++++++++++++++++++++++++++++++
panels/mouse/cc-mouse-caps-helper.h | 33 ++++++++++
panels/mouse/gnome-mouse-properties.c | 104 +++----------------------------
4 files changed, 156 insertions(+), 96 deletions(-)
---
diff --git a/panels/mouse/Makefile.am b/panels/mouse/Makefile.am
index 84b5ce7..27b3028 100644
--- a/panels/mouse/Makefile.am
+++ b/panels/mouse/Makefile.am
@@ -16,6 +16,8 @@ BUILT_SOURCES = \
libmouse_properties_la_SOURCES = \
$(BUILT_SOURCES) \
+ cc-mouse-caps-helper.c \
+ cc-mouse-caps-helper.h \
cc-mouse-panel.c \
cc-mouse-panel.h \
gnome-mouse-properties.c \
diff --git a/panels/mouse/cc-mouse-caps-helper.c b/panels/mouse/cc-mouse-caps-helper.c
new file mode 100644
index 0000000..e2c7f32
--- /dev/null
+++ b/panels/mouse/cc-mouse-caps-helper.c
@@ -0,0 +1,113 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright 2015 Red Hat, Inc,
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Felipe Borges <feborges redhat com>
+ */
+
+#include "cc-mouse-caps-helper.h"
+
+static gboolean
+synaptics_check_capabilities_x11 (gboolean *have_two_finger_scrolling,
+ gboolean *have_tap_to_click)
+{
+ int numdevices, i;
+ XDeviceInfo *devicelist;
+ Atom realtype, prop_capabilities, prop_scroll_methods, prop_tapping_enabled;
+ int realformat;
+ unsigned long nitems, bytes_after;
+ unsigned char *data;
+
+ prop_capabilities = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "Synaptics
Capabilities", False);
+ prop_scroll_methods = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "libinput
Scroll Methods Available", False);
+ prop_tapping_enabled = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "libinput
Tapping Enabled", False);
+ if (!prop_capabilities || !prop_scroll_methods || !prop_tapping_enabled)
+ return FALSE;
+
+ *have_two_finger_scrolling = FALSE;
+ *have_tap_to_click = FALSE;
+
+ devicelist = XListInputDevices (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), &numdevices);
+ for (i = 0; i < numdevices; i++) {
+ if (devicelist[i].use != IsXExtensionPointer)
+ continue;
+
+ gdk_error_trap_push ();
+ XDevice *device = XOpenDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
+ devicelist[i].id);
+ if (gdk_error_trap_pop ())
+ continue;
+
+ gdk_error_trap_push ();
+
+ /* xorg-x11-drv-synaptics */
+ if ((XGetDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device,
prop_capabilities,
+ 0, 2, False, XA_INTEGER, &realtype, &realformat, &nitems,
+ &bytes_after, &data) == Success) && (realtype != None)) {
+ /* Property data is booleans for has_left, has_middle, has_right, has_double,
has_triple.
+ * Newer drivers (X.org/kerrnel) will also include has_pressure and has_width. */
+
+ /* Set tap_to_click_toggle sensitive only if the device has hardware buttons */
+ if (data[0])
+ *have_tap_to_click = TRUE;
+
+ /* Set two_finger_scroll_toggle sensitive if the hardware supports double touch */
+ if (data[3])
+ *have_two_finger_scrolling = TRUE;
+
+ XFree (data);
+ }
+
+ /* xorg-x11-drv-libinput */
+ if ((XGetDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device,
prop_scroll_methods,
+ 0, 2, False, XA_INTEGER, &realtype, &realformat, &nitems,
+ &bytes_after, &data) == Success) && (realtype != None)) {
+ /* Property data is booleans for two-finger, edge, on-button scroll available. */
+
+ if (data[0] && data[1])
+ *have_two_finger_scrolling = TRUE;
+
+ XFree (data);
+ }
+
+ if ((XGetDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device,
prop_tapping_enabled,
+ 0, 1, False, XA_INTEGER, &realtype, &realformat, &nitems,
+ &bytes_after, &data) == Success) && (realtype != None)) {
+ /* Property data is boolean for tapping enabled. */
+ *have_tap_to_click = TRUE;
+
+ XFree (data);
+ }
+
+ gdk_error_trap_pop_ignored ();
+
+ XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device);
+ }
+ XFreeDeviceList (devicelist);
+
+ return TRUE;
+}
+
+gboolean
+synaptics_check_capabilities (gboolean *have_two_finger_scrolling,
+ gboolean *have_tap_to_click)
+{
+ if (GDK_IS_X11_DISPLAY (gdk_display_get_default ()))
+ return synaptics_check_capabilities_x11 (have_two_finger_scrolling,
+ have_tap_to_click);
+ /* else we unconditionally show all touchpad knobs */
+ return FALSE;
+}
diff --git a/panels/mouse/cc-mouse-caps-helper.h b/panels/mouse/cc-mouse-caps-helper.h
new file mode 100644
index 0000000..a5f9802
--- /dev/null
+++ b/panels/mouse/cc-mouse-caps-helper.h
@@ -0,0 +1,33 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright 2015 Red Hat, Inc,
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Felipe Borges <feborges redhat com>
+ */
+
+#ifndef _CC_MOUSE_CAPS_HELPER_H_
+#define _CC_MOUSE_CAPS_HELPER_H_
+
+#include <gdk/gdk.h>
+#include <gdk/gdkx.h>
+
+#include <X11/Xatom.h>
+#include <X11/extensions/XInput.h>
+
+gboolean synaptics_check_capabilities (gboolean *have_two_finger_scrolling,
+ gboolean *have_tap_to_click);
+
+#endif /* _CC_MOUSE_CAPS_HELPER_H_ */
diff --git a/panels/mouse/gnome-mouse-properties.c b/panels/mouse/gnome-mouse-properties.c
index 2eb3531..c8b9a70 100644
--- a/panels/mouse/gnome-mouse-properties.c
+++ b/panels/mouse/gnome-mouse-properties.c
@@ -35,14 +35,12 @@
#include "gnome-mouse-properties.h"
#include "gsd-input-helper.h"
#include "gsd-device-manager.h"
+#include "cc-mouse-caps-helper.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
-#include <X11/Xatom.h>
-#include <X11/extensions/XInput.h>
-
#define WID(x) (GtkWidget *) gtk_builder_get_object (d->builder, x)
#define CC_MOUSE_PROPERTIES_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), CC_TYPE_MOUSE_PROPERTIES,
CcMousePropertiesPrivate))
@@ -80,6 +78,13 @@ setup_scrollmethod_radios (CcMousePropertiesPrivate *d)
{
GsdTouchpadScrollMethod method;
gboolean active;
+ gboolean two_finger_scrolling;
+ gboolean tap_to_click;
+
+ if (synaptics_check_capabilities (&two_finger_scrolling, &tap_to_click)) {
+ gtk_widget_set_sensitive (WID ("two_finger_scroll_toggle"), two_finger_scrolling);
+ gtk_widget_set_sensitive (WID ("tap_to_click_toggle"), tap_to_click);
+ }
method = g_settings_get_enum (d->touchpad_settings, "scroll-method");
active = (method == GSD_TOUCHPAD_SCROLL_METHOD_TWO_FINGER_SCROLLING);
@@ -102,97 +107,6 @@ scrollmethod_changed_event (GtkToggleButton *button, CcMousePropertiesPrivate *d
g_settings_set_enum (d->touchpad_settings, "scroll-method", method);
}
-static void
-synaptics_check_capabilities_x11 (CcMousePropertiesPrivate *d)
-{
- int numdevices, i;
- XDeviceInfo *devicelist;
- Atom realtype, prop_capabilities, prop_scroll_methods, prop_tapping_enabled;
- int realformat;
- unsigned long nitems, bytes_after;
- unsigned char *data;
- gboolean tap_to_click, two_finger_scroll;
-
- prop_capabilities = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "Synaptics
Capabilities", False);
- prop_scroll_methods = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "libinput
Scroll Methods Available", False);
- prop_tapping_enabled = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "libinput
Tapping Enabled", False);
- if (!prop_capabilities || !prop_scroll_methods || !prop_tapping_enabled)
- return;
-
- tap_to_click = FALSE;
- two_finger_scroll = FALSE;
-
- devicelist = XListInputDevices (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), &numdevices);
- for (i = 0; i < numdevices; i++) {
- if (devicelist[i].use != IsXExtensionPointer)
- continue;
-
- gdk_error_trap_push ();
- XDevice *device = XOpenDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
- devicelist[i].id);
- if (gdk_error_trap_pop ())
- continue;
-
- gdk_error_trap_push ();
-
- /* xorg-x11-drv-synaptics */
- if ((XGetDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device,
prop_capabilities,
- 0, 2, False, XA_INTEGER, &realtype, &realformat, &nitems,
- &bytes_after, &data) == Success) && (realtype != None)) {
- /* Property data is booleans for has_left, has_middle, has_right, has_double,
has_triple.
- * Newer drivers (X.org/kerrnel) will also include has_pressure and has_width. */
-
- /* Set tap_to_click_toggle sensitive only if the device has hardware buttons */
- if (data[0])
- tap_to_click = TRUE;
-
- /* Set two_finger_scroll_toggle sensitive if the hardware supports double touch */
- if (data[3])
- two_finger_scroll = TRUE;
-
- XFree (data);
- }
-
- /* xorg-x11-drv-libinput */
- if ((XGetDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device,
prop_scroll_methods,
- 0, 2, False, XA_INTEGER, &realtype, &realformat, &nitems,
- &bytes_after, &data) == Success) && (realtype != None)) {
- /* Property data is booleans for two-finger, edge, on-button scroll available. */
-
- if (data[0] && data[1])
- two_finger_scroll = TRUE;
-
- XFree (data);
- }
-
- if ((XGetDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device,
prop_tapping_enabled,
- 0, 1, False, XA_INTEGER, &realtype, &realformat, &nitems,
- &bytes_after, &data) == Success) && (realtype != None)) {
- /* Property data is boolean for tapping enabled. */
-
- tap_to_click = TRUE;
-
- XFree (data);
- }
-
- gdk_error_trap_pop_ignored ();
-
- XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device);
- }
- XFreeDeviceList (devicelist);
-
- gtk_widget_set_sensitive (WID ("tap_to_click_toggle"), tap_to_click);
- gtk_widget_set_sensitive (WID ("two_finger_scroll_toggle"), two_finger_scroll);
-}
-
-static void
-synaptics_check_capabilities (CcMousePropertiesPrivate *d)
-{
- if (GDK_IS_X11_DISPLAY (gdk_display_get_default ()))
- synaptics_check_capabilities_x11 (d);
- /* else we unconditionally show all touchpad knobs */
-}
-
static gboolean
get_touchpad_enabled (GSettings *settings)
{
@@ -306,7 +220,6 @@ setup_dialog (CcMousePropertiesPrivate *d)
G_SETTINGS_BIND_DEFAULT);
if (d->have_touchpad) {
- synaptics_check_capabilities (d);
setup_scrollmethod_radios (d);
}
@@ -352,7 +265,6 @@ device_changed (GsdDeviceManager *device_manager,
if (d->have_touchpad) {
d->changing_scroll = TRUE;
- synaptics_check_capabilities (d);
setup_scrollmethod_radios (d);
d->changing_scroll = FALSE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]