[gtk+/xi2: 446/1239] Translate device axes.
- From: Carlos Garnacho <carlosg src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gtk+/xi2: 446/1239] Translate device axes.
- Date: Tue, 29 Sep 2009 10:47:29 +0000 (UTC)
commit 9827cb689c77ce4e37f0310a6fb978b961c75721
Author: Carlos Garnacho <carlos lanedo com>
Date: Sun Jul 5 11:28:02 2009 +0100
Translate device axes.
gdk/x11/gdkdevice-xi2.c | 56 ++++++++++++++++++++++++++++++++
gdk/x11/gdkdevice-xi2.h | 3 ++
gdk/x11/gdkdevicemanager-xi2.c | 69 +++++++++++++++++++++++++++++++++++----
3 files changed, 121 insertions(+), 7 deletions(-)
---
diff --git a/gdk/x11/gdkdevice-xi2.c b/gdk/x11/gdkdevice-xi2.c
index 569a1ed..957e10b 100644
--- a/gdk/x11/gdkdevice-xi2.c
+++ b/gdk/x11/gdkdevice-xi2.c
@@ -28,6 +28,7 @@ typedef struct GdkDeviceXI2Private GdkDeviceXI2Private;
struct GdkDeviceXI2Private
{
int device_id;
+ GArray *axes;
};
static void gdk_device_xi2_get_property (GObject *object,
@@ -81,6 +82,10 @@ gdk_device_xi2_class_init (GdkDeviceXI2Class *klass)
static void
gdk_device_xi2_init (GdkDeviceXI2 *device)
{
+ GdkDeviceXI2Private *priv;
+
+ priv = GDK_DEVICE_XI2_GET_PRIVATE (device);
+ priv->axes = g_array_new (FALSE, TRUE, sizeof (GdkDeviceAxis));
}
static void
@@ -139,5 +144,56 @@ gdk_device_xi2_get_axis (GdkDevice *device,
GdkAxisUse use,
gdouble *value)
{
+ GdkDeviceXI2Private *priv;
+ gint i;
+
+ priv = GDK_DEVICE_XI2_GET_PRIVATE (device);
+
+ for (i = 0; i < priv->axes->len; i++)
+ {
+ GdkDeviceAxis axis_info;
+
+ axis_info = g_array_index (priv->axes, GdkDeviceAxis, i);
+
+ if (axis_info.use == use)
+ {
+ if (value)
+ *value = axes[i];
+
+ return TRUE;
+ }
+ }
+
return FALSE;
}
+
+void
+gdk_device_xi2_add_axis (GdkDeviceXI2 *device,
+ GdkAxisUse use)
+{
+ GdkDeviceXI2Private *priv;
+ GdkDeviceAxis axis_info;
+
+ priv = GDK_DEVICE_XI2_GET_PRIVATE (device);
+ axis_info.use = use;
+
+ switch (use)
+ {
+ case GDK_AXIS_X:
+ case GDK_AXIS_Y:
+ axis_info.min = 0.;
+ axis_info.max = 0.;
+ break;
+ case GDK_AXIS_XTILT:
+ case GDK_AXIS_YTILT:
+ axis_info.min = -1.;
+ axis_info.max = 1.;
+ break;
+ default:
+ axis_info.min = 0.;
+ axis_info.max = 1.;
+ break;
+ }
+
+ g_array_append_val (priv->axes, axis_info);
+}
diff --git a/gdk/x11/gdkdevice-xi2.h b/gdk/x11/gdkdevice-xi2.h
index b4f9eba..1d0c3b8 100644
--- a/gdk/x11/gdkdevice-xi2.h
+++ b/gdk/x11/gdkdevice-xi2.h
@@ -46,6 +46,9 @@ struct _GdkDeviceXI2Class
GType gdk_device_xi2_get_type (void) G_GNUC_CONST;
+void gdk_device_xi2_add_axis (GdkDeviceXI2 *device,
+ GdkAxisUse use);
+
G_END_DECLS
#endif /* __GDK_DEVICE_CORE_H__ */
diff --git a/gdk/x11/gdkdevicemanager-xi2.c b/gdk/x11/gdkdevicemanager-xi2.c
index 811d8a3..a880928 100644
--- a/gdk/x11/gdkdevicemanager-xi2.c
+++ b/gdk/x11/gdkdevicemanager-xi2.c
@@ -144,11 +144,46 @@ _gdk_device_manager_xi2_select_events (GdkDeviceManager *device_manager,
XISelectEvents (xdisplay, xwindow, &event_mask, 1);
}
+static void
+translate_valuator_class (GdkDisplay *display,
+ GdkDevice *device,
+ XIValuatorClassInfo *info,
+ gint n_valuator)
+{
+ static gboolean initialized = FALSE;
+ static Atom label_atoms [GDK_AXIS_LAST] = { 0 };
+ GdkDeviceXI2 *device_xi2;
+ GdkAxisUse i;
+
+ device_xi2 = GDK_DEVICE_XI2 (device);
+
+ if (!initialized)
+ {
+ label_atoms [GDK_AXIS_X] = gdk_x11_get_xatom_by_name_for_display (display, "Rel X");
+ label_atoms [GDK_AXIS_Y] = gdk_x11_get_xatom_by_name_for_display (display, "Rel Y");
+ initialized = TRUE;
+ }
+
+ for (i = GDK_AXIS_IGNORE; i <= GDK_AXIS_LAST; i++)
+ {
+ if (label_atoms[i] == info->label)
+ {
+ gdk_device_xi2_add_axis (device_xi2, i);
+ return;
+ }
+ }
+
+ g_warning ("Unhandled axis");
+ gdk_device_xi2_add_axis (device_xi2, GDK_AXIS_IGNORE);
+}
+
static GdkDevice *
create_device (GdkDisplay *display,
XIDeviceInfo *dev)
{
GdkInputSource input_source;
+ GdkDevice *device;
+ gint i, n_valuator = 0;
if (dev->use == XIMasterKeyboard || dev->use == XISlaveKeyboard)
input_source = GDK_SOURCE_KEYBOARD;
@@ -158,14 +193,34 @@ create_device (GdkDisplay *display,
input_source = GDK_SOURCE_MOUSE;
}
-
/* 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);
+ device = g_object_new (GDK_TYPE_DEVICE_XI2,
+ "name", dev->name,
+ "input-source", input_source,
+ "has-cursor", (dev->use == XIMasterPointer),
+ "display", display,
+ "device-id", dev->deviceid,
+ NULL);
+
+ for (i = 0; i < dev->num_classes; i++)
+ {
+ XIAnyClassInfo *class_info = dev->classes[i];
+
+ switch (class_info->type)
+ {
+ case XIValuatorClass:
+ translate_valuator_class (display, device,
+ (XIValuatorClassInfo *) class_info,
+ n_valuator);
+ n_valuator++;
+ break;
+ default:
+ /* Ignore */
+ break;
+ }
+ }
+
+ return device;
}
static GdkDevice *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]