[gtk+/wip/events: 1/16] API: gdk: Add gdk_device_get_axis_label()



commit b596c735440b6b77591b95f0506954d761a3ff59
Author: Benjamin Otte <otte redhat com>
Date:   Mon Mar 5 11:28:20 2012 +0100

    API: gdk: Add gdk_device_get_axis_label()

 docs/reference/gdk/gdk3-sections.txt |    1 +
 gdk/broadway/gdkdevice-broadway.c    |    4 +-
 gdk/gdk.symbols                      |    1 +
 gdk/gdkdevice.c                      |   45 ++++++++++++++++++++++++++++++++++
 gdk/gdkdevice.h                      |    2 +
 gdk/gdkdeviceprivate.h               |    1 +
 gdk/quartz/gdkdevice-core-quartz.c   |    4 +-
 gdk/wayland/gdkdevice-wayland.c      |    4 +-
 gdk/win32/gdkdevice-win32.c          |    4 +-
 gdk/win32/gdkdevicemanager-win32.c   |    5 ++++
 gdk/x11/gdkdevice-core-x11.c         |    4 +-
 gdk/x11/gdkdevicemanager-xi2.c       |   15 ++++++++---
 12 files changed, 76 insertions(+), 14 deletions(-)
---
diff --git a/docs/reference/gdk/gdk3-sections.txt b/docs/reference/gdk/gdk3-sections.txt
index b46e17e..ff0150e 100644
--- a/docs/reference/gdk/gdk3-sections.txt
+++ b/docs/reference/gdk/gdk3-sections.txt
@@ -691,6 +691,7 @@ gdk_device_set_key
 gdk_device_get_key
 gdk_device_set_axis_use
 gdk_device_get_axis_use
+gdk_device_get_axis_label
 gdk_device_get_associated_device
 gdk_device_list_slave_devices
 gdk_device_get_device_type
diff --git a/gdk/broadway/gdkdevice-broadway.c b/gdk/broadway/gdkdevice-broadway.c
index e5f88ee..5468fc6 100644
--- a/gdk/broadway/gdkdevice-broadway.c
+++ b/gdk/broadway/gdkdevice-broadway.c
@@ -93,8 +93,8 @@ gdk_broadway_device_init (GdkBroadwayDevice *device_core)
 
   device = GDK_DEVICE (device_core);
 
-  _gdk_device_add_axis (device, GDK_NONE, GDK_AXIS_X, 0, 0, 1);
-  _gdk_device_add_axis (device, GDK_NONE, GDK_AXIS_Y, 0, 0, 1);
+  _gdk_device_add_axis (device, GDK_NONE, NULL, GDK_AXIS_X, 0, 0, 1);
+  _gdk_device_add_axis (device, GDK_NONE, NULL, GDK_AXIS_Y, 0, 0, 1);
 }
 
 static gboolean
diff --git a/gdk/gdk.symbols b/gdk/gdk.symbols
index 1f1936a..a57e6b2 100644
--- a/gdk/gdk.symbols
+++ b/gdk/gdk.symbols
@@ -47,6 +47,7 @@ gdk_cursor_unref
 gdk_device_free_history
 gdk_device_get_associated_device
 gdk_device_get_axis
+gdk_device_get_axis_label
 gdk_device_get_axis_use
 gdk_device_get_axis_value
 gdk_device_get_device_type
diff --git a/gdk/gdkdevice.c b/gdk/gdkdevice.c
index cd8bda2..88e6f29 100644
--- a/gdk/gdkdevice.c
+++ b/gdk/gdkdevice.c
@@ -43,6 +43,7 @@ typedef struct _GdkAxisInfo GdkAxisInfo;
 struct _GdkAxisInfo
 {
   GdkAtom label;
+  gchar *label_string;
   GdkAxisUse use;
 
   gdouble min_axis;
@@ -256,9 +257,18 @@ gdk_device_class_init (GdkDeviceClass *klass)
 }
 
 static void
+gdk_axis_info_clear (gpointer data)
+{
+  GdkAxisInfo *info = data;
+
+  g_free (info->label_string);
+}
+
+static void
 gdk_device_init (GdkDevice *device)
 {
   device->axes = g_array_new (FALSE, TRUE, sizeof (GdkAxisInfo));
+  g_array_set_clear_func (device->axes, gdk_axis_info_clear);
 }
 
 static void
@@ -771,6 +781,39 @@ gdk_device_set_key (GdkDevice      *device,
 }
 
 /**
+ * gdk_device_get_axis_label:
+ * @device: a pointer #GdkDevice.
+ * @index_: the index of the axis.
+ *
+ * Returns the label for the axis. If it exists, the label of
+ * an axis is a string identifying the axis. Labels for the same
+ * types of axes may differ between devices and platforms. Try to use
+ * gdk_device_get_axis_use() if possible.
+ *
+ * This function is useful as a debugging help. It should never
+ * be presented to users.
+ *
+ * Returns: a string describing the label of the axis or %NULL
+ *   if the axis has no label.
+ *
+ * Since: 3.6
+ **/
+const char *
+gdk_device_get_axis_label (GdkDevice *device,
+                           guint      index_)
+{
+  GdkAxisInfo *info;
+
+  g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
+  g_return_val_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD, NULL);
+  g_return_val_if_fail (index_ < device->axes->len, NULL);
+
+  info = &g_array_index (device->axes, GdkAxisInfo, index_);
+
+  return info->label_string;
+}
+
+/**
  * gdk_device_get_axis_use:
  * @device: a pointer #GdkDevice.
  * @index_: the index of the axis.
@@ -1329,6 +1372,7 @@ _gdk_device_reset_axes (GdkDevice *device)
 guint
 _gdk_device_add_axis (GdkDevice   *device,
                       GdkAtom      label_atom,
+                      const char  *label_string,
                       GdkAxisUse   use,
                       gdouble      min_value,
                       gdouble      max_value,
@@ -1339,6 +1383,7 @@ _gdk_device_add_axis (GdkDevice   *device,
 
   axis_info.use = use;
   axis_info.label = label_atom;
+  axis_info.label_string = g_strdup (label_string);
   axis_info.min_value = min_value;
   axis_info.max_value = max_value;
   axis_info.resolution = resolution;
diff --git a/gdk/gdkdevice.h b/gdk/gdkdevice.h
index 02c26cc..ea215f3 100644
--- a/gdk/gdkdevice.h
+++ b/gdk/gdkdevice.h
@@ -163,6 +163,8 @@ void           gdk_device_set_key       (GdkDevice      *device,
                                          guint           keyval,
                                          GdkModifierType modifiers);
 
+const char *   gdk_device_get_axis_label(GdkDevice         *device,
+                                         guint              index_);
 GdkAxisUse     gdk_device_get_axis_use  (GdkDevice         *device,
                                          guint              index_);
 void           gdk_device_set_axis_use  (GdkDevice         *device,
diff --git a/gdk/gdkdeviceprivate.h b/gdk/gdkdeviceprivate.h
index ff92ea4..53e31cd 100644
--- a/gdk/gdkdeviceprivate.h
+++ b/gdk/gdkdeviceprivate.h
@@ -117,6 +117,7 @@ void  _gdk_device_set_associated_device (GdkDevice *device,
 void  _gdk_device_reset_axes (GdkDevice   *device);
 guint _gdk_device_add_axis   (GdkDevice   *device,
                               GdkAtom      label_atom,
+                              const char  *label_string,
                               GdkAxisUse   use,
                               gdouble      min_value,
                               gdouble      max_value,
diff --git a/gdk/quartz/gdkdevice-core-quartz.c b/gdk/quartz/gdkdevice-core-quartz.c
index 8598cf6..f2380de 100644
--- a/gdk/quartz/gdkdevice-core-quartz.c
+++ b/gdk/quartz/gdkdevice-core-quartz.c
@@ -107,8 +107,8 @@ gdk_quartz_device_core_init (GdkQuartzDeviceCore *quartz_device_core)
 
   device = GDK_DEVICE (quartz_device_core);
 
-  _gdk_device_add_axis (device, GDK_NONE, GDK_AXIS_X, 0, 0, 1);
-  _gdk_device_add_axis (device, GDK_NONE, GDK_AXIS_Y, 0, 0, 1);
+  _gdk_device_add_axis (device, GDK_NONE, NULL, GDK_AXIS_X, 0, 0, 1);
+  _gdk_device_add_axis (device, GDK_NONE, NULL, GDK_AXIS_Y, 0, 0, 1);
 }
 
 static gboolean
diff --git a/gdk/wayland/gdkdevice-wayland.c b/gdk/wayland/gdkdevice-wayland.c
index dcd92a2..1f4affc 100644
--- a/gdk/wayland/gdkdevice-wayland.c
+++ b/gdk/wayland/gdkdevice-wayland.c
@@ -334,8 +334,8 @@ gdk_device_core_init (GdkDeviceCore *device_core)
 
   device = GDK_DEVICE (device_core);
 
-  _gdk_device_add_axis (device, GDK_NONE, GDK_AXIS_X, 0, 0, 1);
-  _gdk_device_add_axis (device, GDK_NONE, GDK_AXIS_Y, 0, 0, 1);
+  _gdk_device_add_axis (device, GDK_NONE, NULL, GDK_AXIS_X, 0, 0, 1);
+  _gdk_device_add_axis (device, GDK_NONE, NULL, GDK_AXIS_Y, 0, 0, 1);
 }
 
 struct wl_input_device *
diff --git a/gdk/win32/gdkdevice-win32.c b/gdk/win32/gdkdevice-win32.c
index e3d8106..11d286e 100644
--- a/gdk/win32/gdkdevice-win32.c
+++ b/gdk/win32/gdkdevice-win32.c
@@ -96,8 +96,8 @@ gdk_device_win32_init (GdkDeviceWin32 *device_win32)
 
   device = GDK_DEVICE (device_win32);
 
-  _gdk_device_add_axis (device, GDK_NONE, GDK_AXIS_X, 0, 0, 1);
-  _gdk_device_add_axis (device, GDK_NONE, GDK_AXIS_Y, 0, 0, 1);
+  _gdk_device_add_axis (device, GDK_NONE, NULL, GDK_AXIS_X, 0, 0, 1);
+  _gdk_device_add_axis (device, GDK_NONE, NULL, GDK_AXIS_Y, 0, 0, 1);
 }
 
 static gboolean
diff --git a/gdk/win32/gdkdevicemanager-win32.c b/gdk/win32/gdkdevicemanager-win32.c
index d51acbc..5c713a2 100644
--- a/gdk/win32/gdkdevicemanager-win32.c
+++ b/gdk/win32/gdkdevicemanager-win32.c
@@ -593,6 +593,7 @@ _gdk_input_wintab_init_check (GdkDeviceManager *_device_manager)
             {
               _gdk_device_add_axis (GDK_DEVICE (device),
                                     GDK_NONE,
+                                    NULL,
                                     GDK_AXIS_X,
                                     axis_x.axMin,
                                     axis_x.axMax,
@@ -604,6 +605,7 @@ _gdk_input_wintab_init_check (GdkDeviceManager *_device_manager)
             {
               _gdk_device_add_axis (GDK_DEVICE (device),
                                     GDK_NONE,
+                                    NULL,
                                     GDK_AXIS_Y,
                                     axis_y.axMin,
                                     axis_y.axMax,
@@ -616,6 +618,7 @@ _gdk_input_wintab_init_check (GdkDeviceManager *_device_manager)
             {
               _gdk_device_add_axis (GDK_DEVICE (device),
                                     GDK_NONE,
+                                    NULL,
                                     GDK_AXIS_PRESSURE,
                                     axis_npressure.axMin,
                                     axis_npressure.axMax,
@@ -638,6 +641,7 @@ _gdk_input_wintab_init_check (GdkDeviceManager *_device_manager)
                */
               _gdk_device_add_axis (GDK_DEVICE (device),
                                     GDK_NONE,
+                                    NULL,
                                     GDK_AXIS_XTILT,
                                     -1000,
                                     1000,
@@ -645,6 +649,7 @@ _gdk_input_wintab_init_check (GdkDeviceManager *_device_manager)
 
               _gdk_device_add_axis (GDK_DEVICE (device),
                                     GDK_NONE,
+                                    NULL,
                                     GDK_AXIS_YTILT,
                                     -1000,
                                     1000,
diff --git a/gdk/x11/gdkdevice-core-x11.c b/gdk/x11/gdkdevice-core-x11.c
index 51cacb8..105b1a8 100644
--- a/gdk/x11/gdkdevice-core-x11.c
+++ b/gdk/x11/gdkdevice-core-x11.c
@@ -104,8 +104,8 @@ gdk_x11_device_core_init (GdkX11DeviceCore *device_core)
 
   device = GDK_DEVICE (device_core);
 
-  _gdk_device_add_axis (device, GDK_NONE, GDK_AXIS_X, 0, 0, 1);
-  _gdk_device_add_axis (device, GDK_NONE, GDK_AXIS_Y, 0, 0, 1);
+  _gdk_device_add_axis (device, GDK_NONE, NULL, GDK_AXIS_X, 0, 0, 1);
+  _gdk_device_add_axis (device, GDK_NONE, NULL, GDK_AXIS_Y, 0, 0, 1);
 }
 
 static gboolean
diff --git a/gdk/x11/gdkdevicemanager-xi2.c b/gdk/x11/gdkdevicemanager-xi2.c
index 0ae7117..eba600e 100644
--- a/gdk/x11/gdkdevicemanager-xi2.c
+++ b/gdk/x11/gdkdevicemanager-xi2.c
@@ -167,7 +167,8 @@ translate_valuator_class (GdkDisplay          *display,
   static gboolean initialized = FALSE;
   static Atom label_atoms [GDK_AXIS_LAST] = { 0 };
   GdkAxisUse use = GDK_AXIS_IGNORE;
-  GdkAtom label;
+  GdkAtom atom;
+  const char *label;
   gint i;
 
   if (!initialized)
@@ -191,11 +192,17 @@ translate_valuator_class (GdkDisplay          *display,
     }
 
   if (valuator_label != None)
-    label = gdk_x11_xatom_to_atom_for_display (display, valuator_label);
+    {
+      atom = gdk_x11_xatom_to_atom_for_display (display, valuator_label);
+      label = gdk_x11_get_xatom_name_for_display (display, valuator_label);
+    }
   else
-    label = GDK_NONE;
+    {
+      atom = GDK_NONE;
+      label = NULL;
+    }
 
-  _gdk_device_add_axis (device, label, use, min, max, resolution);
+  _gdk_device_add_axis (device, atom, label, use, min, max, resolution);
 }
 
 static void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]