[gnome-settings-daemon] common: Add X11-based GsdDeviceManager implementation
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon] common: Add X11-based GsdDeviceManager implementation
- Date: Mon, 19 Jan 2015 15:57:34 +0000 (UTC)
commit a8f097c3df60ed05fc0e5c1edfc10f14907b77f6
Author: Carlos Garnacho <carlosg gnome org>
Date: Tue Jan 13 21:25:45 2015 +0100
common: Add X11-based GsdDeviceManager implementation
This will be used on X11 environments, poking device capabilities
through device properties. This will be the default backend on
X11.
https://bugzilla.gnome.org/show_bug.cgi?id=742593
configure.ac | 2 +-
plugins/common/Makefile.am | 2 +
plugins/common/gsd-device-manager-x11.c | 261 +++++++++++++++++++++++++++++++
plugins/common/gsd-device-manager-x11.h | 50 ++++++
plugins/common/gsd-device-manager.c | 7 +-
5 files changed, 320 insertions(+), 2 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 9a90ed9..6be5ddc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -45,7 +45,7 @@ dnl ---------------------------------------------------------------------------
GLIB_REQUIRED_VERSION=2.37.7
GIO_REQUIRED_VERSION=${GLIB_REQUIRED_VERSION}
-GTK_REQUIRED_VERSION=3.7.8
+GTK_REQUIRED_VERSION=3.15.3
GCONF_REQUIRED_VERSION=2.6.1
GNOME_DESKTOP_REQUIRED_VERSION=3.11.1
LIBGWEATHER_REQUIRED_VERSION=3.9.5
diff --git a/plugins/common/Makefile.am b/plugins/common/Makefile.am
index ebb4f13..6f232c8 100644
--- a/plugins/common/Makefile.am
+++ b/plugins/common/Makefile.am
@@ -26,6 +26,8 @@ libcommon_la_SOURCES = \
gsd-common-enums.h \
gsd-device-manager.c \
gsd-device-manager.h \
+ gsd-device-manager-x11.c \
+ gsd-device-manager-x11.h \
gsd-device-manager-udev.c \
gsd-device-manager-udev.h \
gsd-device-mapper.c \
diff --git a/plugins/common/gsd-device-manager-x11.c b/plugins/common/gsd-device-manager-x11.c
new file mode 100644
index 0000000..afd3747
--- /dev/null
+++ b/plugins/common/gsd-device-manager-x11.c
@@ -0,0 +1,261 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2015 Red Hat
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Author: Carlos Garnacho <carlosg gnome org>
+ */
+
+#include "config.h"
+
+#include <gdk/gdk.h>
+#include <gdk/gdkx.h>
+
+#include "gsd-input-helper.h"
+#include "gsd-device-manager-x11.h"
+
+struct _GsdX11DeviceManager
+{
+ GsdDeviceManager parent_instance;
+ GdkDeviceManager *device_manager;
+ GHashTable *devices;
+ GHashTable *gdk_devices;
+};
+
+struct _GsdX11DeviceManagerClass
+{
+ GsdDeviceManagerClass parent_class;
+};
+
+G_DEFINE_TYPE (GsdX11DeviceManager, gsd_x11_device_manager, GSD_TYPE_DEVICE_MANAGER)
+
+static GsdDeviceType
+device_get_device_type (GdkDevice *gdk_device)
+{
+ GdkInputSource source;
+
+ source = gdk_device_get_source (gdk_device);
+
+ switch (source) {
+ case GDK_SOURCE_MOUSE:
+ return GSD_DEVICE_TYPE_MOUSE;
+ case GDK_SOURCE_PEN:
+ case GDK_SOURCE_ERASER:
+ case GDK_SOURCE_CURSOR:
+ return GSD_DEVICE_TYPE_TABLET;
+ case GDK_SOURCE_KEYBOARD:
+ return GSD_DEVICE_TYPE_KEYBOARD;
+ case GDK_SOURCE_TOUCHSCREEN:
+ return GSD_DEVICE_TYPE_TOUCHSCREEN;
+ case GDK_SOURCE_TOUCHPAD:
+ return GSD_DEVICE_TYPE_TOUCHPAD;
+ default:
+ g_warning ("Unhandled input source %d\n", source);
+ }
+
+ return 0;
+}
+
+static GsdDevice *
+create_device (GdkDevice *gdk_device,
+ const gchar *device_file)
+{
+ guint width, height;
+ GsdDevice *device;
+ gint id;
+
+ id = gdk_x11_device_get_id (gdk_device);
+ xdevice_get_dimensions (id, &width, &height);
+
+ device = g_object_new (GSD_TYPE_DEVICE,
+ "name", gdk_device_get_name (gdk_device),
+ "device-file", device_file,
+ "type", device_get_device_type (gdk_device),
+ "vendor-id", gdk_device_get_vendor_id (gdk_device),
+ "product-id", gdk_device_get_product_id (gdk_device),
+ "width", width,
+ "height", height,
+ NULL);
+ return device;
+}
+
+static void
+add_device (GsdX11DeviceManager *manager,
+ GdkDevice *gdk_device)
+{
+ gchar *device_file;
+ GsdDevice *device;
+ gint id;
+
+ if (gdk_device_get_device_type (gdk_device) == GDK_DEVICE_TYPE_MASTER)
+ return;
+
+ id = gdk_x11_device_get_id (gdk_device);
+ device_file = xdevice_get_device_node (id);
+
+ if (!device_file)
+ return;
+
+ if (!g_hash_table_lookup (manager->devices, device_file)) {
+ device = create_device (gdk_device, device_file);
+ g_hash_table_insert (manager->devices, g_strdup (device_file), device);
+ g_signal_emit_by_name (manager, "device-added", device);
+ }
+
+ /* Takes ownership of device_file */
+ g_hash_table_insert (manager->gdk_devices, gdk_device, device_file);
+}
+
+static void
+remove_device (GsdX11DeviceManager *manager,
+ GdkDevice *gdk_device)
+{
+ const gchar *device_file;
+ GsdDevice *device;
+
+ device_file = g_hash_table_lookup (manager->gdk_devices, gdk_device);
+
+ if (!device_file)
+ return;
+
+ device = g_hash_table_lookup (manager->devices, device_file);
+
+ if (device)
+ g_object_ref (device);
+
+ g_hash_table_remove (manager->devices, device_file);
+ g_hash_table_remove (manager->gdk_devices, gdk_device);
+
+ if (device) {
+ g_signal_emit_by_name (manager, "device-removed", device);
+ g_object_unref (device);
+ }
+}
+
+static void
+init_devices (GsdX11DeviceManager *manager,
+ GdkDeviceType device_type)
+{
+ GList *devices, *l;
+
+ devices = gdk_device_manager_list_devices (manager->device_manager,
+ device_type);
+
+ for (l = devices; l; l = l->next)
+ add_device (manager, l->data);
+
+ g_list_free (devices);
+}
+
+static void
+gsd_x11_device_manager_init (GsdX11DeviceManager *manager)
+{
+ GdkDisplay *display;
+
+ manager->devices = g_hash_table_new_full (g_str_hash, g_str_equal,
+ (GDestroyNotify) g_free,
+ (GDestroyNotify) g_object_unref);
+ manager->gdk_devices = g_hash_table_new_full (NULL, NULL, NULL,
+ (GDestroyNotify) g_free);
+
+ display = gdk_display_get_default ();
+ manager->device_manager = gdk_display_get_device_manager (display);
+
+ g_signal_connect_swapped (manager->device_manager, "device-added",
+ G_CALLBACK (add_device), manager);
+ g_signal_connect_swapped (manager->device_manager, "device-removed",
+ G_CALLBACK (remove_device), manager);
+
+ init_devices (manager, GDK_DEVICE_TYPE_SLAVE);
+ init_devices (manager, GDK_DEVICE_TYPE_FLOATING);
+}
+
+static GList *
+gsd_x11_device_manager_list_devices (GsdDeviceManager *manager,
+ GsdDeviceType type)
+{
+ GsdX11DeviceManager *manager_x11 = GSD_X11_DEVICE_MANAGER (manager);
+ GsdDeviceType device_type;
+ GList *devices = NULL;
+ GHashTableIter iter;
+ GsdDevice *device;
+
+ g_hash_table_iter_init (&iter, manager_x11->devices);
+
+ while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &device)) {
+ device_type = gsd_device_get_device_type (device);
+
+ if ((device_type & type) == type)
+ devices = g_list_prepend (devices, device);
+ }
+
+ return devices;
+}
+
+static void
+gsd_x11_device_manager_class_init (GsdX11DeviceManagerClass *klass)
+{
+ GsdDeviceManagerClass *manager_class = GSD_DEVICE_MANAGER_CLASS (klass);
+
+ manager_class->list_devices = gsd_x11_device_manager_list_devices;
+}
+
+GdkDevice **
+gsd_x11_device_manager_get_gdk_devices (GsdX11DeviceManager *manager,
+ GsdDevice *device,
+ guint *n_gdk_devices)
+{
+ const gchar *device_node;
+ GPtrArray *gdk_devices;
+ GdkDevice *gdk_device;
+ GHashTableIter iter;
+
+ if (n_gdk_devices)
+ *n_gdk_devices = 0;
+
+ g_return_val_if_fail (GSD_IS_X11_DEVICE_MANAGER (manager), NULL);
+ g_return_val_if_fail (GSD_IS_DEVICE (device), NULL);
+
+ gdk_devices = g_ptr_array_new ();
+ g_hash_table_iter_init (&iter, manager->gdk_devices);
+
+ while (g_hash_table_iter_next (&iter, (gpointer *) &gdk_device, (gpointer *) &device_node)) {
+ if (g_strcmp0 (gsd_device_get_device_file (device), device_node) == 0)
+ g_ptr_array_add (gdk_devices, gdk_device);
+ }
+
+ if (n_gdk_devices)
+ *n_gdk_devices = gdk_devices->len;
+
+ return (GdkDevice **) g_ptr_array_free (gdk_devices, FALSE);
+}
+
+GsdDevice *
+gsd_x11_device_manager_lookup_gdk_device (GsdX11DeviceManager *manager,
+ GdkDevice *gdk_device)
+{
+ const gchar *device_node;
+
+ g_return_val_if_fail (GSD_IS_X11_DEVICE_MANAGER (manager), NULL);
+ g_return_val_if_fail (GDK_IS_DEVICE (manager), NULL);
+
+ device_node = g_hash_table_lookup (manager->gdk_devices, gdk_device);
+
+ if (!device_node)
+ return NULL;
+
+ return g_hash_table_lookup (manager->devices, device_node);
+}
diff --git a/plugins/common/gsd-device-manager-x11.h b/plugins/common/gsd-device-manager-x11.h
new file mode 100644
index 0000000..876bf50
--- /dev/null
+++ b/plugins/common/gsd-device-manager-x11.h
@@ -0,0 +1,50 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2015 Red Hat
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Author: Carlos Garnacho <carlosg gnome org>
+ */
+
+#ifndef __GSD_X11_DEVICE_MANAGER_H__
+#define __GSD_X11_DEVICE_MANAGER_H__
+
+#include <gdk/gdk.h>
+#include "gsd-device-manager.h"
+
+G_BEGIN_DECLS
+
+#define GSD_TYPE_X11_DEVICE_MANAGER (gsd_x11_device_manager_get_type ())
+#define GSD_X11_DEVICE_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_X11_DEVICE_MANAGER,
GsdX11DeviceManager))
+#define GSD_X11_DEVICE_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_X11_DEVICE_MANAGER,
GsdX11DeviceManagerClass))
+#define GSD_IS_X11_DEVICE_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_X11_DEVICE_MANAGER))
+#define GSD_IS_X11_DEVICE_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_X11_DEVICE_MANAGER))
+#define GSD_X11_DEVICE_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_X11_DEVICE_MANAGER,
GsdX11DeviceManagerClass))
+
+typedef struct _GsdX11DeviceManager GsdX11DeviceManager;
+typedef struct _GsdX11DeviceManagerClass GsdX11DeviceManagerClass;
+
+GType gsd_x11_device_manager_get_type (void) G_GNUC_CONST;
+
+GdkDevice ** gsd_x11_device_manager_get_gdk_devices (GsdX11DeviceManager *manager,
+ GsdDevice *device,
+ guint *n_gdk_devices);
+GsdDevice * gsd_x11_device_manager_lookup_gdk_device (GsdX11DeviceManager *manager,
+ GdkDevice *gdk_device);
+
+G_END_DECLS
+
+#endif /* __GSD_X11_DEVICE_MANAGER_H__ */
diff --git a/plugins/common/gsd-device-manager.c b/plugins/common/gsd-device-manager.c
index ef0a25c..aaf70bf 100644
--- a/plugins/common/gsd-device-manager.c
+++ b/plugins/common/gsd-device-manager.c
@@ -23,6 +23,7 @@
#include <string.h>
+#include "gsd-device-manager-x11.h"
#include "gsd-device-manager-udev.h"
#include "gsd-common-enums.h"
#include "gnome-settings-bus.h"
@@ -268,8 +269,12 @@ gsd_device_manager_get (void)
if (gnome_settings_is_wayland ()) {
manager = g_object_new (GSD_TYPE_UDEV_DEVICE_MANAGER,
NULL);
- }
+ } else
#endif /* HAVE_WAYLAND */
+ {
+ manager = g_object_new (GSD_TYPE_X11_DEVICE_MANAGER,
+ NULL);
+ }
g_object_set_data_full (G_OBJECT (screen), "gsd-device-manager-data",
manager, (GDestroyNotify) g_object_unref);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]