[gtk+/events-refactor: 318/1085] Add GdkDeviceManager and skeleton for the default X11 implementation.
- From: Carlos Garnacho <carlosg src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gtk+/events-refactor: 318/1085] Add GdkDeviceManager and skeleton for the default X11 implementation.
- Date: Tue, 29 Sep 2009 10:44:50 +0000 (UTC)
commit c1a48f4e585c2abb47b9a6ddad1d370bccd2912d
Author: Carlos Garnacho <carlosg gnome org>
Date: Wed May 20 00:52:45 2009 +0200
Add GdkDeviceManager and skeleton for the default X11 implementation.
gdk/gdkdevicemanager.c | 225 +++++++++++++++++++++++++++++++++++++++
gdk/gdkdevicemanager.h | 82 ++++++++++++++
gdk/x11/gdkdevicemanager-core.c | 90 ++++++++++++++++
gdk/x11/gdkdevicemanager-core.h | 53 +++++++++
gdk/x11/gdkdevicemanager-x11.c | 29 +++++
5 files changed, 479 insertions(+), 0 deletions(-)
---
diff --git a/gdk/gdkdevicemanager.c b/gdk/gdkdevicemanager.c
new file mode 100644
index 0000000..284fdd7
--- /dev/null
+++ b/gdk/gdkdevicemanager.c
@@ -0,0 +1,225 @@
+/* GDK - The GIMP Drawing Kit
+ * Copyright (C) 2009 Carlos Garnacho <carlosg gnome org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "gdkdevicemanager.h"
+#include "gdkintl.h"
+
+
+static void gdk_device_manager_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void gdk_device_manager_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec);
+
+
+G_DEFINE_ABSTRACT_TYPE (GdkDeviceManager, gdk_device_manager, G_TYPE_OBJECT)
+
+enum {
+ PROP_0,
+ PROP_DISPLAY
+};
+
+enum {
+ DEVICE_ADDED,
+ DEVICE_REMOVED,
+ DEVICE_CHANGED,
+ LAST_SIGNAL
+};
+
+static guint signals [LAST_SIGNAL] = { 0 };
+static GHashTable *device_managers = NULL;
+
+typedef struct GdkDeviceManagerPrivate GdkDeviceManagerPrivate;
+
+struct GdkDeviceManagerPrivate
+{
+ GdkDisplay *display;
+};
+
+#define GDK_DEVICE_MANAGER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GDK_TYPE_DEVICE_MANAGER, GdkDeviceManagerPrivate))
+
+static void
+gdk_device_manager_class_init (GdkDeviceManagerClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->set_property = gdk_device_manager_set_property;
+ object_class->get_property = gdk_device_manager_get_property;
+
+ g_object_class_install_property (object_class,
+ PROP_DISPLAY,
+ g_param_spec_object ("display",
+ P_("Display"),
+ P_("Display for the device manager"),
+ GDK_TYPE_DISPLAY,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+ signals [DEVICE_ADDED] =
+ g_signal_new (g_intern_static_string ("device-added"),
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GdkDeviceManagerClass, device_added),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE, 1,
+ GDK_TYPE_DEVICE);
+
+ signals [DEVICE_REMOVED] =
+ g_signal_new (g_intern_static_string ("device-removed"),
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GdkDeviceManagerClass, device_removed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE, 1,
+ GDK_TYPE_DEVICE);
+
+ signals [DEVICE_CHANGED] =
+ g_signal_new (g_intern_static_string ("device-changed"),
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GdkDeviceManagerClass, device_changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE, 1,
+ GDK_TYPE_DEVICE);
+
+ g_type_class_add_private (object_class, sizeof (GdkDeviceManagerPrivate));
+}
+
+static void
+gdk_device_manager_init (GdkDeviceManager *manager)
+{
+
+}
+
+static void
+gdk_device_manager_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GdkDeviceManagerPrivate *priv;
+
+ priv = GDK_DEVICE_MANAGER_GET_PRIVATE (object);
+
+ switch (prop_id)
+ {
+ case PROP_DISPLAY:
+ priv->display = g_value_get_object (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gdk_device_manager_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GdkDeviceManagerPrivate *priv;
+
+ priv = GDK_DEVICE_MANAGER_GET_PRIVATE (object);
+
+ switch (prop_id)
+ {
+ case PROP_DISPLAY:
+ g_value_set_object (value, priv->display);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+/**
+ * gdk_device_manager_get_for_display:
+ * @display: A #GdkDisplay
+ *
+ * Returns the #GdkDeviceManager attached to @display.
+ *
+ * Returns: the #GdkDeviceManager attached to @display. This memory
+ * is owned by GTK+, and must not be freed or unreffed.
+ **/
+GdkDeviceManager *
+gdk_device_manager_get_for_display (GdkDisplay *display)
+{
+ GdkDeviceManager *device_manager;
+
+ if (G_UNLIKELY (!device_managers))
+ device_managers = g_hash_table_new (g_direct_hash,
+ g_direct_equal);
+
+ device_manager = g_hash_table_lookup (device_managers, display);
+
+ if (G_UNLIKELY (!device_manager))
+ {
+ device_manager = _gdk_device_manager_new (display);
+ g_hash_table_insert (device_managers, display, device_manager);
+ }
+
+ return device_manager;
+}
+
+/**
+ * gdk_device_manager_get_display:
+ * @device_manager: a #GdkDeviceManager
+ *
+ * Gets the #GdkDisplay associated to @device_manager.
+ *
+ * Returns: the #GdkDisplay to which @device_manager is
+ * associated to, or #NULL.
+ **/
+GdkDisplay *
+gdk_device_manager_get_display (GdkDeviceManager *device_manager)
+{
+ GdkDeviceManagerPrivate *priv;
+
+ g_return_val_if_fail (GDK_IS_DEVICE_MANAGER (device_manager), NULL);
+
+ priv = GDK_DEVICE_MANAGER_GET_PRIVATE (device_manager);
+
+ return priv->display;
+}
+
+/**
+ * gdk_device_manager_get_devices:
+ * @device_manager: a #GdkDeviceManager
+ * @type: device type to get.
+ *
+ * Returns the list of devices of type @type currently attached to
+ * @device_manager.
+ *
+ * Returns: a list of #GdkDevice<!-- -->s. The returned list must be
+ * freed with g_list_free ().
+ **/
+GList *
+gdk_device_manager_get_devices (GdkDeviceManager *device_manager,
+ GdkDeviceType type)
+{
+ g_return_val_if_fail (GDK_IS_DEVICE_MANAGER (device_manager), NULL);
+
+ return GDK_DEVICE_MANAGER_GET_CLASS (device_manager)->get_devices (device_manager, type);
+}
diff --git a/gdk/gdkdevicemanager.h b/gdk/gdkdevicemanager.h
new file mode 100644
index 0000000..4e2abef
--- /dev/null
+++ b/gdk/gdkdevicemanager.h
@@ -0,0 +1,82 @@
+/* GDK - The GIMP Drawing Kit
+ * Copyright (C) 2009 Carlos Garnacho <carlosg gnome org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#if defined(GTK_DISABLE_SINGLE_INCLUDES) && !defined (__GDK_H_INSIDE__) && !defined (GDK_COMPILATION)
+#error "Only <gdk/gdk.h> can be included directly."
+#endif
+
+#ifndef __GDK_DEVICE_MANAGER_H__
+#define __GDK_DEVICE_MANAGER_H__
+
+#include <gdk/gdktypes.h>
+#include <gdk/gdkinput.h>
+#include <gdk/gdkdisplay.h>
+
+G_BEGIN_DECLS
+
+#define GDK_TYPE_DEVICE_MANAGER (gdk_device_manager_get_type ())
+#define GDK_DEVICE_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GDK_TYPE_DEVICE_MANAGER, GdkDeviceManager))
+#define GDK_DEVICE_MANAGER_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), GDK_TYPE_DEVICE_MANAGER, GdkDeviceManagerClass))
+#define GDK_IS_DEVICE_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GDK_TYPE_DEVICE_MANAGER))
+#define GDK_IS_DEVICE_MANAGER_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), GDK_TYPE_DEVICE_MANAGER))
+#define GDK_DEVICE_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GDK_TYPE_DEVICE_MANAGER, GdkDeviceManagerClass))
+
+typedef struct _GdkDeviceManager GdkDeviceManager;
+typedef struct _GdkDeviceManagerClass GdkDeviceManagerClass;
+typedef enum _GdkDeviceType GdkDeviceType;
+
+enum _GdkDeviceType {
+ GDK_DEVICE_TYPE_MASTER,
+ GDK_DEVICE_TYPE_SLAVE,
+ GDK_DEVICE_TYPE_FLOATING
+};
+
+struct _GdkDeviceManager
+{
+ GObject parent_instance;
+};
+
+struct _GdkDeviceManagerClass
+{
+ GObjectClass parent_class;
+
+ /* Signals */
+ void (* device_added) (GdkDeviceManager *device_manager,
+ GdkDevice *device);
+ void (* device_removed) (GdkDeviceManager *device_manager,
+ GdkDevice *device);
+ void (* device_changed) (GdkDeviceManager *device_manager,
+ GdkDevice *device);
+
+ /* VMethods */
+ GList * (* get_devices) (GdkDeviceManager *device_manager,
+ GdkDeviceType type);
+};
+
+GType gdk_device_manager_get_type (void) G_GNUC_CONST;
+
+GdkDeviceManager * gdk_device_manager_get_for_display (GdkDisplay *display);
+
+GdkDisplay * gdk_device_manager_get_display (GdkDeviceManager *device_manager);
+GList * gdk_device_manager_get_devices (GdkDeviceManager *device_manager,
+ GdkDeviceType type);
+
+G_END_DECLS
+
+#endif /* __GDK_DEVICE_MANAGER_H__ */
diff --git a/gdk/x11/gdkdevicemanager-core.c b/gdk/x11/gdkdevicemanager-core.c
new file mode 100644
index 0000000..37cdb87
--- /dev/null
+++ b/gdk/x11/gdkdevicemanager-core.c
@@ -0,0 +1,90 @@
+/* GDK - The GIMP Drawing Kit
+ * Copyright (C) 2009 Carlos Garnacho <carlosg gnome org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <gdk/gdktypes.h>
+#include <gdk/gdkdevicemanager.h>
+#include "gdkdevicemanager-core.h"
+#include "gdkinputprivate.h"
+
+static GdkDeviceAxis gdk_input_core_axes[] = {
+ { GDK_AXIS_X, 0, 0 },
+ { GDK_AXIS_Y, 0, 0 }
+};
+
+static GList * gdk_device_manager_core_get_devices (GdkDeviceManager *device_manager,
+ GdkDeviceType type);
+
+
+G_DEFINE_TYPE (GdkDeviceManagerCore, gdk_device_manager_core, GDK_TYPE_DEVICE_MANAGER)
+
+static void
+gdk_device_manager_core_class_init (GdkDeviceManagerCoreClass *klass)
+{
+ GdkDeviceManagerClass *device_manager_class = GDK_DEVICE_MANAGER_CLASS (klass);
+
+ device_manager_class->get_devices = gdk_device_manager_core_get_devices;
+}
+
+static GdkDevice *
+create_core_pointer (GdkDisplay *display)
+{
+ GdkDevice *core_pointer;
+ GdkDevicePrivate *private;
+
+ core_pointer = g_object_new (GDK_TYPE_DEVICE, NULL);
+ private = (GdkDevicePrivate *) core_pointer;
+
+ core_pointer->name = "Core Pointer";
+ core_pointer->source = GDK_SOURCE_MOUSE;
+ core_pointer->mode = GDK_MODE_SCREEN;
+ core_pointer->has_cursor = TRUE;
+ core_pointer->num_axes = G_N_ELEMENTS (gdk_input_core_axes);
+ core_pointer->axes = gdk_input_core_axes;
+ core_pointer->num_keys = 0;
+ core_pointer->keys = NULL;
+
+ private->display = display;
+
+ return core_pointer;
+}
+
+static void
+gdk_device_manager_core_init (GdkDeviceManagerCore *device_manager)
+{
+ GdkDisplay *display;
+
+ display = gdk_device_manager_get_display (GDK_DEVICE_MANAGER (device_manager));
+ device_manager->core_pointer = create_core_pointer (display);
+}
+
+static GList *
+gdk_device_manager_core_get_devices (GdkDeviceManager *device_manager,
+ GdkDeviceType type)
+{
+ GdkDeviceManagerCore *device_manager_core;
+ GList *devices = NULL;
+
+ if (type == GDK_DEVICE_TYPE_MASTER)
+ {
+ device_manager_core = (GdkDeviceManagerCore *) device_manager;
+ devices = g_list_prepend (devices, device_manager_core->core_pointer);
+ }
+
+ return devices;
+}
diff --git a/gdk/x11/gdkdevicemanager-core.h b/gdk/x11/gdkdevicemanager-core.h
new file mode 100644
index 0000000..794bb66
--- /dev/null
+++ b/gdk/x11/gdkdevicemanager-core.h
@@ -0,0 +1,53 @@
+/* GDK - The GIMP Drawing Kit
+ * Copyright (C) 2009 Carlos Garnacho <carlosg gnome org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GDK_DEVICE_MANAGER_CORE_H__
+#define __GDK_DEVICE_MANAGER_CORE_H__
+
+#include <gdk/gdkdevicemanager.h>
+
+G_BEGIN_DECLS
+
+#define GDK_TYPE_DEVICE_MANAGER_CORE (gdk_device_manager_core_get_type ())
+#define GDK_DEVICE_MANAGER_CORE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GDK_TYPE_DEVICE_MANAGER_CORE, GdkDeviceManagerCore))
+#define GDK_DEVICE_MANAGER_CORE_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), GDK_TYPE_DEVICE_MANAGER_CORE, GdkDeviceManagerCoreClass))
+#define GDK_IS_DEVICE_MANAGER_CORE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GDK_TYPE_DEVICE_MANAGER_CORE))
+#define GDK_IS_DEVICE_MANAGER_CORE_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), GDK_TYPE_DEVICE_MANAGER_CORE))
+#define GDK_DEVICE_MANAGER_CORE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GDK_TYPE_DEVICE_MANAGER_CORE, GdkDeviceManagerCoreClass))
+
+typedef struct _GdkDeviceManagerCore GdkDeviceManagerCore;
+typedef struct _GdkDeviceManagerCoreClass GdkDeviceManagerCoreClass;
+
+struct _GdkDeviceManagerCore
+{
+ GdkDeviceManager parent_object;
+ GdkDevice *core_pointer;
+};
+
+struct _GdkDeviceManagerCoreClass
+{
+ GdkDeviceManagerClass parent_class;
+};
+
+GType gdk_device_manager_core_get_type (void) G_GNUC_CONST;
+
+
+G_END_DECLS
+
+#endif /* __GDK_DEVICE_MANAGER_CORE_H__ */
diff --git a/gdk/x11/gdkdevicemanager-x11.c b/gdk/x11/gdkdevicemanager-x11.c
new file mode 100644
index 0000000..5ad9512
--- /dev/null
+++ b/gdk/x11/gdkdevicemanager-x11.c
@@ -0,0 +1,29 @@
+/* GDK - The GIMP Drawing Kit
+ * Copyright (C) 2009 Carlos Garnacho <carlosg gnome org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+#include "gdkdevicemanager-core.h"
+
+GdkDeviceManager *
+_gdk_device_manager_new (GdkDisplay *display)
+{
+ return g_object_new (GDK_TYPE_DEVICE_MANAGER_CORE,
+ "display", display,
+ NULL);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]