[gtk+] gdk: Add touch event types and mask



commit 7f35708ceeef47cef6807a8a5edc86f4229e1a80
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Feb 28 20:53:42 2011 +0100

    gdk: Add touch event types and mask
    
    This commit introduces GDK_TOUCH_BEGIN/UPDATE/END/CANCEL
    and a separate GdkEventTouch struct that they use. This
    is closer to the touch event API of other platforms and
    matches the xi2 events closely, too.

 docs/reference/gdk/gdk3-sections.txt |    1 +
 gdk/gdkevents.c                      |   92 ++++++++++++++++++++++++++++++++-
 gdk/gdkevents.h                      |   67 ++++++++++++++++++++++++-
 gdk/gdktypes.h                       |   11 ++++-
 gdk/gdkwindow.c                      |   14 +++++
 5 files changed, 180 insertions(+), 5 deletions(-)
---
diff --git a/docs/reference/gdk/gdk3-sections.txt b/docs/reference/gdk/gdk3-sections.txt
index cea9153..2e064fe 100644
--- a/docs/reference/gdk/gdk3-sections.txt
+++ b/docs/reference/gdk/gdk3-sections.txt
@@ -829,6 +829,7 @@ GdkEvent
 GdkEventAny
 GdkEventKey
 GdkEventButton
+GdkEventTouch
 GdkEventScroll
 GdkEventMotion
 GdkEventExpose
diff --git a/gdk/gdkevents.c b/gdk/gdkevents.c
index 295a63e..688fec2 100644
--- a/gdk/gdkevents.c
+++ b/gdk/gdkevents.c
@@ -457,6 +457,15 @@ gdk_event_new (GdkEventType type)
       new_event->button.x_root = 0.;
       new_event->button.y_root = 0.;
       break;
+    case GDK_TOUCH_BEGIN:
+    case GDK_TOUCH_UPDATE:
+    case GDK_TOUCH_END:
+    case GDK_TOUCH_CANCEL:
+      new_event->touch.x = 0.;
+      new_event->touch.y = 0.;
+      new_event->touch.x_root = 0.;
+      new_event->touch.y_root = 0.;
+      break;
     case GDK_SCROLL:
       new_event->scroll.x = 0.;
       new_event->scroll.y = 0.;
@@ -585,6 +594,15 @@ gdk_event_copy (const GdkEvent *event)
                                            sizeof (gdouble) * gdk_device_get_n_axes (event->button.device));
       break;
 
+    case GDK_TOUCH_BEGIN:
+    case GDK_TOUCH_UPDATE:
+    case GDK_TOUCH_END:
+    case GDK_TOUCH_CANCEL:
+      if (event->touch.axes)
+        new_event->touch.axes = g_memdup (event->touch.axes,
+                                           sizeof (gdouble) * gdk_device_get_n_axes (event->touch.device));
+      break;
+
     case GDK_MOTION_NOTIFY:
       if (event->motion.axes)
         new_event->motion.axes = g_memdup (event->motion.axes,
@@ -663,7 +681,14 @@ gdk_event_free (GdkEvent *event)
     case GDK_BUTTON_RELEASE:
       g_free (event->button.axes);
       break;
-      
+
+    case GDK_TOUCH_BEGIN:
+    case GDK_TOUCH_UPDATE:
+    case GDK_TOUCH_END:
+    case GDK_TOUCH_CANCEL:
+      g_free (event->touch.axes);
+      break;
+
     case GDK_EXPOSE:
     case GDK_DAMAGE:
       if (event->expose.region)
@@ -724,6 +749,11 @@ gdk_event_get_time (const GdkEvent *event)
       case GDK_3BUTTON_PRESS:
       case GDK_BUTTON_RELEASE:
 	return event->button.time;
+      case GDK_TOUCH_BEGIN:
+      case GDK_TOUCH_UPDATE:
+      case GDK_TOUCH_END:
+      case GDK_TOUCH_CANCEL:
+        return event->touch.time;
       case GDK_SCROLL:
         return event->scroll.time;
       case GDK_KEY_PRESS:
@@ -799,7 +829,13 @@ gdk_event_get_state (const GdkEvent        *event,
       case GDK_2BUTTON_PRESS:
       case GDK_3BUTTON_PRESS:
       case GDK_BUTTON_RELEASE:
-        *state =  event->button.state;
+        *state = event->button.state;
+        return TRUE;
+      case GDK_TOUCH_BEGIN:
+      case GDK_TOUCH_UPDATE:
+      case GDK_TOUCH_END:
+      case GDK_TOUCH_CANCEL:
+        *state = event->touch.state;
         return TRUE;
       case GDK_SCROLL:
 	*state =  event->scroll.state;
@@ -890,6 +926,13 @@ gdk_event_get_coords (const GdkEvent *event,
       x = event->button.x;
       y = event->button.y;
       break;
+    case GDK_TOUCH_BEGIN:
+    case GDK_TOUCH_UPDATE:
+    case GDK_TOUCH_END:
+    case GDK_TOUCH_CANCEL:
+      x = event->touch.x;
+      y = event->touch.y;
+      break;
     case GDK_MOTION_NOTIFY:
       x = event->motion.x;
       y = event->motion.y;
@@ -944,6 +987,13 @@ gdk_event_get_root_coords (const GdkEvent *event,
       x = event->button.x_root;
       y = event->button.y_root;
       break;
+    case GDK_TOUCH_BEGIN:
+    case GDK_TOUCH_UPDATE:
+    case GDK_TOUCH_END:
+    case GDK_TOUCH_CANCEL:
+      x = event->touch.x_root;
+      y = event->touch.y_root;
+      break;
     case GDK_ENTER_NOTIFY:
     case GDK_LEAVE_NOTIFY:
       x = event->crossing.x_root;
@@ -1184,7 +1234,7 @@ gdk_event_get_axis (const GdkEvent *event,
       
       switch (event->type)
 	{
-	case GDK_MOTION_NOTIFY:
+        case GDK_MOTION_NOTIFY:
 	  x = event->motion.x;
 	  y = event->motion.y;
 	  break;
@@ -1197,6 +1247,13 @@ gdk_event_get_axis (const GdkEvent *event,
 	  x = event->button.x;
 	  y = event->button.y;
 	  break;
+        case GDK_TOUCH_BEGIN:
+        case GDK_TOUCH_UPDATE:
+        case GDK_TOUCH_END:
+        case GDK_TOUCH_CANCEL:
+	  x = event->touch.x;
+	  y = event->touch.y;
+	  break;
 	case GDK_ENTER_NOTIFY:
 	case GDK_LEAVE_NOTIFY:
 	  x = event->crossing.x;
@@ -1220,6 +1277,14 @@ gdk_event_get_axis (const GdkEvent *event,
       device = event->button.device;
       axes = event->button.axes;
     }
+  else if (event->type == GDK_TOUCH_BEGIN ||
+           event->type == GDK_TOUCH_UPDATE ||
+           event->type == GDK_TOUCH_END ||
+           event->type == GDK_TOUCH_CANCEL)
+    {
+      device = event->touch.device;
+      axes = event->touch.axes;
+    }
   else if (event->type == GDK_MOTION_NOTIFY)
     {
       device = event->motion.device;
@@ -1265,6 +1330,12 @@ gdk_event_set_device (GdkEvent  *event,
     case GDK_BUTTON_RELEASE:
       event->button.device = device;
       break;
+    case GDK_TOUCH_BEGIN:
+    case GDK_TOUCH_UPDATE:
+    case GDK_TOUCH_END:
+    case GDK_TOUCH_CANCEL:
+      event->touch.device = device;
+      break;
     case GDK_SCROLL:
       event->scroll.device = device;
       break;
@@ -1310,6 +1381,11 @@ gdk_event_get_device (const GdkEvent *event)
     case GDK_3BUTTON_PRESS:
     case GDK_BUTTON_RELEASE:
       return event->button.device;
+    case GDK_TOUCH_BEGIN:
+    case GDK_TOUCH_UPDATE:
+    case GDK_TOUCH_END:
+    case GDK_TOUCH_CANCEL:
+      return event->touch.device;
     case GDK_SCROLL:
       return event->scroll.device;
     case GDK_PROXIMITY_IN:
@@ -1327,6 +1403,10 @@ gdk_event_get_device (const GdkEvent *event)
     case GDK_2BUTTON_PRESS:
     case GDK_3BUTTON_PRESS:
     case GDK_BUTTON_RELEASE:
+    case GDK_TOUCH_BEGIN:
+    case GDK_TOUCH_UPDATE:
+    case GDK_TOUCH_END:
+    case GDK_TOUCH_CANCEL:
     case GDK_ENTER_NOTIFY:
     case GDK_LEAVE_NOTIFY:
     case GDK_FOCUS_CHANGE:
@@ -1726,6 +1806,12 @@ gdk_event_get_event_sequence (const GdkEvent *event)
   if (!event)
     return NULL;
 
+  if (event->type == GDK_TOUCH_BEGIN ||
+      event->type == GDK_TOUCH_UPDATE ||
+      event->type == GDK_TOUCH_END ||
+      event->type == GDK_TOUCH_CANCEL)
+    return event->touch.sequence;
+
   return NULL;
 }
 
diff --git a/gdk/gdkevents.h b/gdk/gdkevents.h
index 29eda15..e034152 100644
--- a/gdk/gdkevents.h
+++ b/gdk/gdkevents.h
@@ -129,6 +129,7 @@ typedef struct _GdkEventExpose	    GdkEventExpose;
 typedef struct _GdkEventVisibility  GdkEventVisibility;
 typedef struct _GdkEventMotion	    GdkEventMotion;
 typedef struct _GdkEventButton	    GdkEventButton;
+typedef struct _GdkEventTouch       GdkEventTouch;
 typedef struct _GdkEventScroll      GdkEventScroll;  
 typedef struct _GdkEventKey	    GdkEventKey;
 typedef struct _GdkEventFocus	    GdkEventFocus;
@@ -264,6 +265,14 @@ typedef GdkFilterReturn (*GdkFilterFunc) (GdkXEvent *xevent,
  *   was added in 2.8.
  * @GDK_DAMAGE: the content of the window has been changed. This event type
  *   was added in 2.14.
+ * @GDK_TOUCH_BEGIN: A new touch event sequence has just started. This event
+ *   type was added in 3.4.
+ * @GDK_TOUCH_UPDATE: A touch event sequence has been updated. This event type
+ *   was added in 3.4.
+ * @GDK_TOUCH_END: A touch event sequence has finished. This event type
+ *   was added in 3.4.
+ * @GDK_TOUCH_CANCEL: A touch event sequence has been canceled. This event type
+ *   was added in 3.4.
  * @GDK_EVENT_LAST: marks the end of the GdkEventType enumeration. Added in 2.18
  *
  * Specifies the type of the event.
@@ -311,6 +320,10 @@ typedef enum
   GDK_OWNER_CHANGE      = 34,
   GDK_GRAB_BROKEN       = 35,
   GDK_DAMAGE            = 36,
+  GDK_TOUCH_BEGIN       = 37,
+  GDK_TOUCH_UPDATE      = 38,
+  GDK_TOUCH_END         = 39,
+  GDK_TOUCH_CANCEL      = 40,
   GDK_EVENT_LAST        /* helper variable for decls */
 } GdkEventType;
 
@@ -598,7 +611,7 @@ struct _GdkEventMotion
  *
  * Used for button press and button release events. The
  * @type field will be one of %GDK_BUTTON_PRESS,
- * %GDK_2BUTTON_PRESS, %GDK_3BUTTON_PRESS, and %GDK_BUTTON_RELEASE.
+ * %GDK_2BUTTON_PRESS, %GDK_3BUTTON_PRESS or %GDK_BUTTON_RELEASE,
  *
  * Double and triple-clicks result in a sequence of events being received.
  * For double-clicks the order of events will be:
@@ -647,6 +660,57 @@ struct _GdkEventButton
 };
 
 /**
+ * GdkEventTouch:
+ * @type: the type of the event (%GDK_TOUCH_BEGIN, %GDK_TOUCH_UPDATE,
+ *   %GDK_TOUCH_END, %GDK_TOUCH_CANCEL)
+ * @window: the window which received the event
+ * @send_event: %TRUE if the event was sent explicitly (e.g. using
+ *   <function>XSendEvent</function>)
+ * @time: the time of the event in milliseconds.
+ * @x: the x coordinate of the pointer relative to the window
+ * @y: the y coordinate of the pointer relative to the window
+ * @axes: @x, @y translated to the axes of @device, or %NULL if @device is
+ *   the mouse
+ * @state: (type GdkModifierType): a bit-mask representing the state of
+ *   the modifier keys (e.g. Control, Shift and Alt) and the pointer
+ *   buttons. See #GdkModifierType
+ * @sequence: the event sequence that the event belongs to
+ * @emulating_pointer: whether the event should be used for emulating
+ *   pointer event
+ * @device: the device where the event originated
+ * @x_root: the x coordinate of the pointer relative to the root of the
+ *   screen
+ * @y_root: the y coordinate of the pointer relative to the root of the
+ *   screen
+ *
+ * Used for touch events.
+ * @type field will be one of %GDK_TOUCH_BEGIN, %GDK_TOUCH_UPDATE,
+ * %GDK_TOUCH_END or %GDK_TOUCH_CANCEL.
+ *
+ * Touch events are grouped into sequences by means of the @sequence
+ * field, which can also be obtained with gdk_event_get_event_sequence().
+ * Each sequence begins with a %GDK_TOUCH_BEGIN event, followed by
+ * any number of %GDK_TOUCH_UPDATE events, and ends with a %GDK_TOUCH_END
+ * (or %GDK_TOUCH_CANCEL) event. With multitouch devices, there may be
+ * several active sequences at the same time.
+ */
+struct _GdkEventTouch
+{
+  GdkEventType type;
+  GdkWindow *window;
+  gint8 send_event;
+  guint32 time;
+  gdouble x;
+  gdouble y;
+  gdouble *axes;
+  guint state;
+  GdkEventSequence *sequence;
+  gboolean emulating_pointer;
+  GdkDevice *device;
+  gdouble x_root, y_root;
+};
+
+/**
  * GdkEventScroll:
  * @type: the type of the event (%GDK_SCROLL).
  * @window: the window which received the event.
@@ -1074,6 +1138,7 @@ union _GdkEvent
   GdkEventVisibility	    visibility;
   GdkEventMotion	    motion;
   GdkEventButton	    button;
+  GdkEventTouch             touch;
   GdkEventScroll            scroll;
   GdkEventKey		    key;
   GdkEventCrossing	    crossing;
diff --git a/gdk/gdktypes.h b/gdk/gdktypes.h
index 4c60bbd..116fec9 100644
--- a/gdk/gdktypes.h
+++ b/gdk/gdktypes.h
@@ -348,6 +348,7 @@ typedef enum
  * @GDK_SUBSTRUCTURE_MASK: receive events about window configuration changes of
  *   child windows
  * @GDK_SCROLL_MASK: receive scroll events
+ * @GDK_TOUCH_MASK: receive touch events
  * @GDK_ALL_EVENTS_MASK: the combination of all the above event masks.
  *
  * A set of bit-flags to indicate which events a window is to receive.
@@ -363,6 +364,13 @@ typedef enum
  * some of which are marked as a hint (the is_hint member is %TRUE).
  * To receive more motion events after a motion hint event, the application
  * needs to asks for more, by calling gdk_event_request_motions().
+ *
+ * If %GDK_TOUCH_MASK is enabled, the window will receive touch events
+ * from touch-enabled devices. Those will come as sequences of #GdkEventTouch
+ * with type %GDK_TOUCH_UPDATE, enclosed by two events with
+ * type %GDK_TOUCH_BEGIN and %GDK_TOUCH_END (or %GDK_TOUCH_CANCEL).
+ * gdk_event_get_event_sequence() returns the event sequence for these
+ * events, so different sequences may be distinguished.
  */
 typedef enum
 {
@@ -387,7 +395,8 @@ typedef enum
   GDK_PROXIMITY_OUT_MASK        = 1 << 19,
   GDK_SUBSTRUCTURE_MASK         = 1 << 20,
   GDK_SCROLL_MASK               = 1 << 21,
-  GDK_ALL_EVENTS_MASK           = 0x3FFFFE
+  GDK_TOUCH_MASK                = 1 << 22,
+  GDK_ALL_EVENTS_MASK           = 0x7FFFFE
 } GdkEventMask;
 
 /**
diff --git a/gdk/gdkwindow.c b/gdk/gdkwindow.c
index 0fc68fe..854a972 100644
--- a/gdk/gdkwindow.c
+++ b/gdk/gdkwindow.c
@@ -8121,6 +8121,10 @@ static const guint type_masks[] = {
   0, /* GDK_OWNER_CHANGE = 34 */
   0, /* GDK_GRAB_BROKEN = 35 */
   0, /* GDK_DAMAGE = 36 */
+  GDK_TOUCH_MASK, /* GDK_TOUCH_BEGIN = 37 */
+  GDK_TOUCH_MASK, /* GDK_TOUCH_UPDATE = 38 */
+  GDK_TOUCH_MASK, /* GDK_TOUCH_END = 39 */
+  GDK_TOUCH_MASK /* GDK_TOUCH_CANCEL = 40 */
 };
 G_STATIC_ASSERT (G_N_ELEMENTS (type_masks) == GDK_EVENT_LAST);
 
@@ -8235,6 +8239,16 @@ _gdk_make_event (GdkWindow    *window,
       event->button.state = the_state;
       break;
 
+    case GDK_TOUCH_BEGIN:
+    case GDK_TOUCH_UPDATE:
+    case GDK_TOUCH_END:
+    case GDK_TOUCH_CANCEL:
+      event->touch.time = the_time;
+      event->touch.axes = NULL;
+      event->touch.state = the_state;
+      break;
+
+
     case GDK_SCROLL:
       event->scroll.time = the_time;
       event->scroll.state = the_state;



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