[gtk+/xi2: 427/1239] Adapt to latest GdkDevice changes in the events-refactor branch.
- From: Carlos Garnacho <carlosg src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gtk+/xi2: 427/1239] Adapt to latest GdkDevice changes in the events-refactor branch.
- Date: Tue, 29 Sep 2009 10:47:19 +0000 (UTC)
commit 2d4e7522a4909e6e79e4f368def65670973b1ec0
Author: Carlos Garnacho <carlosg gnome org>
Date: Fri Jul 3 11:19:50 2009 +0100
Adapt to latest GdkDevice changes in the events-refactor branch.
* We now have a GdkDeviceXI2 implementation, more interesting stuff will be
happening there in the future.
gdk/x11/Makefile.am | 2 +-
gdk/x11/gdkdevice-xi2.c | 143 ++++++++++++++++++++++++++++++++++++++++
gdk/x11/gdkdevice-xi2.h | 51 ++++++++++++++
gdk/x11/gdkdevicemanager-xi2.c | 53 +++++++--------
4 files changed, 221 insertions(+), 28 deletions(-)
---
diff --git a/gdk/x11/Makefile.am b/gdk/x11/Makefile.am
index cc067bd..abef848 100644
--- a/gdk/x11/Makefile.am
+++ b/gdk/x11/Makefile.am
@@ -65,7 +65,7 @@ libgdk_x11_la_SOURCES = \
xsettings-common.c
if XINPUT_2
-libgdk_x11_la_SOURCES += gdkdevicemanager-xi2.c
+libgdk_x11_la_SOURCES += gdkdevicemanager-xi2.c gdkdevice-xi2.c
endif
diff --git a/gdk/x11/gdkdevice-xi2.c b/gdk/x11/gdkdevice-xi2.c
new file mode 100644
index 0000000..569a1ed
--- /dev/null
+++ b/gdk/x11/gdkdevice-xi2.c
@@ -0,0 +1,143 @@
+/* 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 "gdkdevice-xi2.h"
+#include "gdkintl.h"
+
+
+#define GDK_DEVICE_XI2_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GDK_TYPE_DEVICE_XI2, GdkDeviceXI2Private))
+
+typedef struct GdkDeviceXI2Private GdkDeviceXI2Private;
+
+struct GdkDeviceXI2Private
+{
+ int device_id;
+};
+
+static void gdk_device_xi2_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec);
+static void gdk_device_xi2_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec);
+
+static void gdk_device_xi2_get_state (GdkDevice *device,
+ GdkWindow *window,
+ gdouble *axes,
+ GdkModifierType *mask);
+static gboolean gdk_device_xi2_get_axis (GdkDevice *device,
+ gdouble *axes,
+ GdkAxisUse use,
+ gdouble *value);
+
+G_DEFINE_TYPE (GdkDeviceXI2, gdk_device_xi2, GDK_TYPE_DEVICE)
+
+enum {
+ PROP_0,
+ PROP_DEVICE_ID
+};
+
+static void
+gdk_device_xi2_class_init (GdkDeviceXI2Class *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GdkDeviceClass *device_class = GDK_DEVICE_CLASS (klass);
+
+ object_class->get_property = gdk_device_xi2_get_property;
+ object_class->set_property = gdk_device_xi2_set_property;
+
+ device_class->get_state = gdk_device_xi2_get_state;
+ device_class->get_axis = gdk_device_xi2_get_axis;
+
+ g_object_class_install_property (object_class,
+ PROP_DEVICE_ID,
+ g_param_spec_int ("device-id",
+ P_("Device ID"),
+ P_("Device identifier"),
+ 0, G_MAXINT, 0,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+ g_type_class_add_private (object_class, sizeof (GdkDeviceXI2Private));
+}
+
+static void
+gdk_device_xi2_init (GdkDeviceXI2 *device)
+{
+}
+
+static void
+gdk_device_xi2_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GdkDeviceXI2Private *priv;
+
+ priv = GDK_DEVICE_XI2_GET_PRIVATE (object);
+
+ switch (prop_id)
+ {
+ case PROP_DEVICE_ID:
+ g_value_set_int (value, priv->device_id);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gdk_device_xi2_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GdkDeviceXI2Private *priv;
+
+ priv = GDK_DEVICE_XI2_GET_PRIVATE (object);
+
+ switch (prop_id)
+ {
+ case PROP_DEVICE_ID:
+ priv->device_id = g_value_get_int (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gdk_device_xi2_get_state (GdkDevice *device,
+ GdkWindow *window,
+ gdouble *axes,
+ GdkModifierType *mask)
+{
+}
+
+static gboolean
+gdk_device_xi2_get_axis (GdkDevice *device,
+ gdouble *axes,
+ GdkAxisUse use,
+ gdouble *value)
+{
+ return FALSE;
+}
diff --git a/gdk/x11/gdkdevice-xi2.h b/gdk/x11/gdkdevice-xi2.h
new file mode 100644
index 0000000..b4f9eba
--- /dev/null
+++ b/gdk/x11/gdkdevice-xi2.h
@@ -0,0 +1,51 @@
+/* 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_XI2_H__
+#define __GDK_DEVICE_XI2_H__
+
+#include <gdk/gdkdevice.h>
+
+G_BEGIN_DECLS
+
+#define GDK_TYPE_DEVICE_XI2 (gdk_device_xi2_get_type ())
+#define GDK_DEVICE_XI2(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GDK_TYPE_DEVICE_XI2, GdkDeviceXI2))
+#define GDK_DEVICE_XI2_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), GDK_TYPE_DEVICE_XI2, GdkDeviceXI2Class))
+#define GDK_IS_DEVICE_XI2(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GDK_TYPE_DEVICE_XI2))
+#define GDK_IS_DEVICE_XI2_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), GDK_TYPE_DEVICE_XI2))
+#define GDK_DEVICE_XI2_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GDK_TYPE_DEVICE_XI2, GdkDeviceXI2Class))
+
+typedef struct _GdkDeviceXI2 GdkDeviceXI2;
+typedef struct _GdkDeviceXI2Class GdkDeviceXI2Class;
+
+struct _GdkDeviceXI2
+{
+ GdkDevice parent_instance;
+};
+
+struct _GdkDeviceXI2Class
+{
+ GdkDeviceClass parent_class;
+};
+
+GType gdk_device_xi2_get_type (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif /* __GDK_DEVICE_CORE_H__ */
diff --git a/gdk/x11/gdkdevicemanager-xi2.c b/gdk/x11/gdkdevicemanager-xi2.c
index ee8c319..811d8a3 100644
--- a/gdk/x11/gdkdevicemanager-xi2.c
+++ b/gdk/x11/gdkdevicemanager-xi2.c
@@ -19,7 +19,7 @@
#include "gdkdevicemanager-xi2.h"
#include "gdkeventtranslator.h"
-#include "gdkinputprivate.h"
+#include "gdkdevice-xi2.h"
#include "gdkkeysyms.h"
#include "gdkx.h"
@@ -145,23 +145,27 @@ _gdk_device_manager_xi2_select_events (GdkDeviceManager *device_manager,
}
static GdkDevice *
-create_device (XIDeviceInfo *dev)
+create_device (GdkDisplay *display,
+ XIDeviceInfo *dev)
{
- GdkDevice *device;
-
- device = g_object_new (GDK_TYPE_DEVICE, NULL);
+ GdkInputSource input_source;
- device->name = g_strdup (dev->name);
- device->source = GDK_SOURCE_MOUSE;
+ if (dev->use == XIMasterKeyboard || dev->use == XISlaveKeyboard)
+ input_source = GDK_SOURCE_KEYBOARD;
+ else
+ {
+ /* FIXME: Set other input sources */
+ input_source = GDK_SOURCE_MOUSE;
+ }
- device->mode = (dev->use == XIMasterPointer) ? GDK_MODE_SCREEN : GDK_MODE_DISABLED;
- device->has_cursor = (dev->use == XIMasterPointer);
- device->num_axes = 0;
- device->axes = NULL;
- device->num_keys = 0;
- device->keys = NULL;
- return device;
+ /* FIXME: set mode */
+ return g_object_new (GDK_TYPE_DEVICE_XI2,
+ "name", dev->name,
+ "input-source", input_source,
+ "has-cursor", (dev->use == XIMasterPointer),
+ "display", display,
+ NULL);
}
static GdkDevice *
@@ -169,20 +173,22 @@ add_device (GdkDeviceManagerXI2 *device_manager,
XIDeviceInfo *dev,
gboolean emit_signal)
{
+ GdkDisplay *display;
GdkDevice *device;
- device = create_device (dev);
+ display = gdk_device_manager_get_display (GDK_DEVICE_MANAGER (device_manager));
+ device = create_device (display, dev);
g_hash_table_replace (device_manager->id_table,
GINT_TO_POINTER (dev->deviceid),
device);
- if (dev->use == XIMasterPointer)
- device_manager->master_devices = g_list_prepend (device_manager->master_devices, device);
- else if (dev->use == XISlavePointer)
- device_manager->slave_devices = g_list_prepend (device_manager->slave_devices, device);
+ if (dev->use == XIMasterPointer || dev->use == XIMasterKeyboard)
+ device_manager->master_devices = g_list_append (device_manager->master_devices, device);
+ else if (dev->use == XISlavePointer || dev->use == XISlaveKeyboard)
+ device_manager->slave_devices = g_list_append (device_manager->slave_devices, device);
else if (dev->use == XIFloatingSlave)
- device_manager->floating_devices = g_list_prepend (device_manager->floating_devices, device);
+ device_manager->floating_devices = g_list_append (device_manager->floating_devices, device);
else
g_warning ("Unhandled device: %s\n", device->name);
@@ -235,16 +241,9 @@ gdk_device_manager_xi2_constructed (GObject *object)
for (i = 0; i < ndevices; i++)
{
GdkDevice *device;
- GdkDevicePrivate *private;
dev = &info[i];
device = add_device (device_manager_xi2, dev, FALSE);
-
- if (device)
- {
- private = (GdkDevicePrivate *) device;
- private->display = display;
- }
}
XIFreeDeviceInfo(info);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]