device: Add gdk_device_get_axes(), and ::axes property
authorCarlos Garnacho <carlosg@gnome.org>
Tue, 27 Jan 2015 21:35:40 +0000 (21:35 +0000)
committerCarlos Garnacho <carlosg@gnome.org>
Wed, 6 Apr 2016 13:43:29 +0000 (15:43 +0200)
This returns a GdkAxisFlags, holding the axes currently available
through this device.

docs/reference/gdk/gdk3-sections.txt
gdk/gdkdevice.c
gdk/gdkdevice.h
gdk/gdkdeviceprivate.h

index 48fcd3c3019531dbc91da6a99e428969505813ee..097779421b1a568dc033467fa547d47106575aef 100644 (file)
@@ -715,6 +715,7 @@ GdkDevice
 GdkInputSource
 GdkInputMode
 GdkAxisUse
+GdkAxisFlags
 GdkDeviceType
 GdkGrabOwnership
 
@@ -736,6 +737,7 @@ gdk_device_get_display
 gdk_device_get_has_cursor
 gdk_device_get_n_axes
 gdk_device_get_n_keys
+gdk_device_get_axes
 gdk_device_warp
 gdk_device_get_seat
 
index 3edaa526f05bd0fae61bb1107c9f5634508ffd23..0ede56cd4372492fc0a2dbe092eea69638b02dec 100644 (file)
@@ -92,6 +92,7 @@ enum {
   PROP_PRODUCT_ID,
   PROP_SEAT,
   PROP_NUM_TOUCHES,
+  PROP_AXES,
   LAST_PROP
 };
 
@@ -305,6 +306,19 @@ gdk_device_class_init (GdkDeviceClass *klass)
                          0,
                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
                          G_PARAM_STATIC_STRINGS);
+  /**
+   * GdkDevice:axes:
+   *
+   * The axes currently available for this device.
+   *
+   * Since: 3.22
+   */
+  device_props[PROP_AXES] =
+    g_param_spec_flags ("axes",
+                        P_("Axes"),
+                        P_("Axes"),
+                        GDK_TYPE_AXIS_FLAGS, 0,
+                        G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
 
   g_object_class_install_properties (object_class, LAST_PROP, device_props);
 
@@ -477,6 +491,9 @@ gdk_device_get_property (GObject    *object,
     case PROP_NUM_TOUCHES:
       g_value_set_uint (value, device->num_touches);
       break;
+    case PROP_AXES:
+      g_value_set_flags (value, device->axis_flags);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -1515,7 +1532,10 @@ _gdk_device_reset_axes (GdkDevice *device)
   for (i = device->axes->len - 1; i >= 0; i--)
     g_array_remove_index (device->axes, i);
 
+  device->axis_flags = 0;
+
   g_object_notify_by_pspec (G_OBJECT (device), device_props[PROP_N_AXES]);
+  g_object_notify_by_pspec (G_OBJECT (device), device_props[PROP_AXES]);
 }
 
 guint
@@ -1556,7 +1576,10 @@ _gdk_device_add_axis (GdkDevice   *device,
   device->axes = g_array_append_val (device->axes, axis_info);
   pos = device->axes->len - 1;
 
+  device->axis_flags |= (1 << use);
+
   g_object_notify_by_pspec (G_OBJECT (device), device_props[PROP_N_AXES]);
+  g_object_notify_by_pspec (G_OBJECT (device), device_props[PROP_AXES]);
 
   return pos;
 }
@@ -1964,3 +1987,19 @@ gdk_device_get_seat (GdkDevice *device)
 
   return device->seat;
 }
+
+/**
+ * gdk_device_get_axes:
+ * @device: a #GdkDevice
+ *
+ * Returns the axes currently available on the device.
+ *
+ * Since: 3.22
+ **/
+GdkAxisFlags
+gdk_device_get_axes (GdkDevice *device)
+{
+  g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
+
+  return device->axis_flags;
+}
index d171f8fc011e06b9c1df9acda2a368950a4cfd83..ad5bf66e94ec27b96fe2375de4c69af1f0b05284 100644 (file)
@@ -113,6 +113,35 @@ typedef enum
   GDK_AXIS_LAST
 } GdkAxisUse;
 
+/**
+ * GdkAxisFlags:
+ * @GDK_AXIS_FLAG_X: X axis is present
+ * @GDK_AXIS_FLAG_Y: Y axis is present
+ * @GDK_AXIS_FLAG_PRESSURE: Pressure axis is present
+ * @GDK_AXIS_FLAG_XTILT: X tilt axis is present
+ * @GDK_AXIS_FLAG_YTILT: Y tilt axis is present
+ * @GDK_AXIS_FLAG_WHEEL: Wheel axis is present
+ * @GDK_AXIS_FLAG_DISTANCE: Distance axis is present
+ * @GDK_AXIS_FLAG_ROTATION: Z-axis rotation is present
+ * @GDK_AXIS_FLAG_SLIDER: Slider axis is present
+ *
+ * Flags describing the current capabilities of a device/tool.
+ *
+ * Since: 3.22
+ */
+typedef enum
+{
+  GDK_AXIS_FLAG_X        = 1 << GDK_AXIS_X,
+  GDK_AXIS_FLAG_Y        = 1 << GDK_AXIS_Y,
+  GDK_AXIS_FLAG_PRESSURE = 1 << GDK_AXIS_PRESSURE,
+  GDK_AXIS_FLAG_XTILT    = 1 << GDK_AXIS_XTILT,
+  GDK_AXIS_FLAG_YTILT    = 1 << GDK_AXIS_YTILT,
+  GDK_AXIS_FLAG_WHEEL    = 1 << GDK_AXIS_WHEEL,
+  GDK_AXIS_FLAG_DISTANCE = 1 << GDK_AXIS_DISTANCE,
+  GDK_AXIS_FLAG_ROTATION = 1 << GDK_AXIS_ROTATION,
+  GDK_AXIS_FLAG_SLIDER   = 1 << GDK_AXIS_SLIDER,
+} GdkAxisFlags;
+
 /**
  * GdkDeviceType:
  * @GDK_DEVICE_TYPE_MASTER: Device is a master (or virtual) device. There will
@@ -288,6 +317,9 @@ const gchar *gdk_device_get_product_id      (GdkDevice *device);
 GDK_AVAILABLE_IN_3_20
 GdkSeat     *gdk_device_get_seat            (GdkDevice *device);
 
+GDK_AVAILABLE_IN_3_22
+GdkAxisFlags gdk_device_get_axes            (GdkDevice *device);
+
 G_END_DECLS
 
 #endif /* __GDK_DEVICE_H__ */
index 2350d0288664715f5b99651b366b26e4af9c7403..bdfc93a1e08776c90e8a14937ae527c53765646d 100644 (file)
@@ -47,6 +47,7 @@ struct _GdkDevice
   GdkInputMode mode;
   gboolean has_cursor;
   gint num_keys;
+  GdkAxisFlags axis_flags;
   GdkDeviceKey *keys;
   GdkDeviceManager *manager;
   GdkDisplay *display;