[gtk/wip/readonly-events: 24/25] gdk: Add event constructors



commit 6195cea772e8caa1e22dbea54328ea2f8ebedf22
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Feb 14 08:09:59 2020 -0500

    gdk: Add event constructors
    
    Add private API to construct events. This is a step towards
    making events readonly, and not objects anymore.
    
    The constructors here are sufficient to convert the Wayland
    backend over. More may be added for other backends as needed.
    
    Open issues:
     - axes
     - history

 gdk/gdkevents.c        | 445 +++++++++++++++++++++++++++++++++++++++++++++++++
 gdk/gdkeventsprivate.h | 150 +++++++++++++++++
 2 files changed, 595 insertions(+)
---
diff --git a/gdk/gdkevents.c b/gdk/gdkevents.c
index e306d1c39c2..f93150fed71 100644
--- a/gdk/gdkevents.c
+++ b/gdk/gdkevents.c
@@ -2415,3 +2415,448 @@ gdk_event_get_motion_history (const GdkEvent *event)
     return NULL;
   return g_list_reverse (g_list_copy (event->motion.history));
 }
+
+GdkEvent *
+gdk_event_button_new (GdkEventType     type,
+                      GdkSurface      *surface,
+                      GdkDevice       *device,
+                      GdkDevice       *source_device,
+                      GdkDeviceTool   *tool,
+                      guint32          time,
+                      double           x,
+                      double           y,
+                      guint            button,
+                      GdkModifierType  state)
+{
+  GdkEvent *event;
+
+  g_return_val_if_fail (type == GDK_BUTTON_PRESS || 
+                        type == GDK_BUTTON_RELEASE, NULL);
+
+  event = gdk_event_new (type);
+
+  event->any.surface = g_object_ref (surface);
+  event->button.time = time;
+  event->button.axes = NULL;
+  event->button.state = state;
+  event->button.button = button;
+  event->button.x = x;
+  event->button.y = y;
+  event->button.x_root = NAN;
+  event->button.y_root = NAN;
+  gdk_event_set_device (event, device);
+  gdk_event_set_source_device (event, device);
+  gdk_event_set_device_tool (event, tool);
+
+  return event;
+}
+
+GdkEvent *
+gdk_event_motion_new (GdkSurface      *surface,
+                      GdkDevice       *device,
+                      GdkDevice       *source_device,
+                      GdkDeviceTool   *tool,
+                      guint32          time,
+                      GdkModifierType  state,
+                      double           x,
+                      double           y)
+{
+  GdkEvent *event = gdk_event_new (GDK_MOTION_NOTIFY);
+
+  event->any.surface = g_object_ref (surface);
+  event->motion.time = time;
+  event->motion.x = x;
+  event->motion.y = y;
+  event->motion.x_root = NAN;
+  event->motion.y_root = NAN;
+  event->motion.state = state;
+  gdk_event_set_device (event, device);
+  gdk_event_set_source_device (event, device);
+  gdk_event_set_device_tool (event, tool);
+
+  return event;
+}
+
+GdkEvent *
+gdk_event_crossing_new (GdkEventType     type,
+                        GdkSurface      *surface,
+                        GdkDevice       *device,
+                        GdkDevice       *source_device,
+                        guint32          time,
+                        GdkModifierType  state,
+                        double           x,
+                        double           y,
+                        GdkCrossingMode  mode,
+                        GdkNotifyType    detail)
+{
+  GdkEvent *event;
+
+  g_return_val_if_fail (type == GDK_ENTER_NOTIFY ||
+                        type == GDK_LEAVE_NOTIFY, NULL);
+
+  event = gdk_event_new (type);
+
+  event->any.surface = g_object_ref (surface);
+  event->crossing.time = time;
+  event->crossing.state = state;
+  event->crossing.x = x;
+  event->crossing.y = y;
+  event->crossing.x_root = NAN;
+  event->crossing.y_root = NAN;
+  event->crossing.mode = mode;
+  event->crossing.detail = detail;
+  gdk_event_set_device (event, device);
+  gdk_event_set_source_device (event, device);
+
+  return event;
+}
+
+GdkEvent *
+gdk_event_proximity_new (GdkEventType   type,
+                         GdkSurface    *surface,
+                         GdkDevice     *device,
+                         GdkDevice     *source_device,
+                         GdkDeviceTool *tool,
+                         guint32        time)
+{
+  GdkEvent *event;
+
+  g_return_val_if_fail (type == GDK_PROXIMITY_IN ||
+                        type == GDK_PROXIMITY_OUT, NULL);
+
+  event = gdk_event_new (type);
+
+  event->any.surface = g_object_ref (surface);
+  event->proximity.time = time;
+  gdk_event_set_device (event, device);
+  gdk_event_set_source_device (event, device);
+  gdk_event_set_device_tool (event, tool);
+
+  return event;
+}
+
+GdkEvent *
+gdk_event_key_new (GdkEventType     type,
+                   GdkSurface      *surface,
+                   GdkDevice       *device,
+                   GdkDevice       *source_device,
+                   guint32          time,
+                   GdkModifierType  state,
+                   guint            keyval,
+                   guint16          keycode,
+                   guint16          scancode,
+                   guint8           group,
+                   gboolean         is_modifier)
+{
+  GdkEvent *event;
+
+  g_return_val_if_fail (type == GDK_KEY_PRESS ||
+                        type == GDK_KEY_RELEASE, NULL);
+
+  event = gdk_event_new (type);
+  
+  event->any.surface = g_object_ref (surface);
+  event->key.time = time;
+  event->key.state = state;
+  event->key.keyval = keyval;
+  event->key.hardware_keycode = keycode;
+  event->key.group = group;
+  event->key.is_modifier = is_modifier;
+  gdk_event_set_scancode (event, scancode);
+  gdk_event_set_device (event, device);
+  gdk_event_set_source_device (event, device);
+
+  return event;
+}
+
+GdkEvent *
+gdk_event_configure_new (GdkSurface *surface,
+                         int         width,
+                         int         height)
+{
+  GdkEvent *event = gdk_event_new (GDK_CONFIGURE);
+
+  event->any.surface = g_object_ref (surface);
+
+  event->configure.width = width;
+  event->configure.height = height;
+
+  return event;
+}
+
+GdkEvent *
+gdk_event_delete_new (GdkSurface *surface)
+{
+  GdkEvent *event = gdk_event_new (GDK_DELETE);
+
+  event->any.surface = g_object_ref (surface);
+
+  return event;
+}
+
+GdkEvent *
+gdk_event_focus_new (GdkSurface *surface,
+                     GdkDevice  *device,
+                     GdkDevice  *source_device,
+                     gboolean    focus_in)
+{
+  GdkEvent *event = gdk_event_new (GDK_FOCUS_CHANGE);
+
+  event->any.surface = g_object_ref (surface);
+  event->focus_change.in = focus_in;
+  gdk_event_set_device (event, device);
+  gdk_event_set_source_device (event, device);
+
+  return  event;
+}
+
+GdkEvent *
+gdk_event_scroll_new (GdkSurface      *surface,
+                      GdkDevice       *device,
+                      GdkDevice       *source_device,
+                      GdkDeviceTool   *tool,
+                      guint32          time,
+                      GdkModifierType  state,
+                      double           delta_x,
+                      double           delta_y,
+                      gboolean         is_stop)
+{
+  GdkEvent *event = gdk_event_new (GDK_SCROLL);
+
+  event->any.surface = g_object_ref (surface);
+  event->scroll.time = time;
+  event->scroll.state = state;
+  event->scroll.x = NAN;
+  event->scroll.y = NAN;
+  event->scroll.x_root = NAN;
+  event->scroll.y_root = NAN;
+  event->scroll.direction = GDK_SCROLL_SMOOTH;
+  event->scroll.delta_x = delta_x;
+  event->scroll.delta_y = delta_y;
+  gdk_event_set_device (event, device);
+  gdk_event_set_source_device (event, device);
+  gdk_event_set_device_tool (event, tool);
+
+  return event;
+}
+
+GdkEvent *
+gdk_event_discrete_scroll_new (GdkSurface         *surface,
+                               GdkDevice          *device,
+                               GdkDevice          *source_device,
+                               GdkDeviceTool      *tool,
+                               guint32             time,
+                               GdkModifierType     state,
+                               GdkScrollDirection  direction,
+                               gboolean            emulated)
+{
+  GdkEvent *event = gdk_event_new (GDK_SCROLL);
+
+  event->any.surface = g_object_ref (surface);
+  event->scroll.time = time;
+  event->scroll.state = state;
+  event->scroll.x = NAN;
+  event->scroll.y = NAN;
+  event->scroll.x_root = NAN;
+  event->scroll.y_root = NAN;
+  event->scroll.direction = direction;
+  gdk_event_set_device (event, device);
+  gdk_event_set_source_device (event, device);
+  gdk_event_set_device_tool (event, tool);
+  gdk_event_set_pointer_emulated (event, emulated);
+
+  return event;
+}
+
+GdkEvent *
+gdk_event_touch_new (GdkEventType     type,
+                     GdkSurface      *surface,
+                     GdkDevice       *device,
+                     GdkDevice       *source_device,
+                     guint32          time,
+                     GdkModifierType  state,
+                     double           x,
+                     double           y,
+                     gboolean         emulating)
+{
+  GdkEvent *event;
+
+  g_return_val_if_fail (type == GDK_TOUCH_BEGIN ||
+                        type == GDK_TOUCH_END ||
+                        type == GDK_TOUCH_UPDATE ||
+                        type == GDK_TOUCH_CANCEL, NULL);
+
+  event = gdk_event_new (type);
+
+  event->any.surface = g_object_ref (surface);
+  event->touch.time = time;
+  event->touch.state = state;
+  event->touch.x = x;
+  event->touch.y = y;
+  event->touch.x_root = NAN;
+  event->touch.y_root = NAN;
+  event->touch.emulating_pointer = emulating;
+  gdk_event_set_pointer_emulated (event, emulating);
+  gdk_event_set_device (event, device);
+  gdk_event_set_source_device (event, device);
+
+  return event;
+}
+
+GdkEvent *
+gdk_event_touchpad_swipe_new (GdkSurface *surface,
+                              GdkDevice  *device,
+                              GdkDevice  *source_device,
+                              guint32     time,
+                              GdkModifierType state,
+                              double      x,
+                              double      y,
+                              int         n_fingers,
+                              double      dx,
+                              double      dy)
+{
+  GdkEvent *event = gdk_event_new (GDK_TOUCHPAD_SWIPE);
+
+  event->any.surface = g_object_ref (surface);
+  event->touchpad_swipe.time = time;
+  event->touchpad_swipe.state = state;
+  event->touchpad_swipe.x = x;
+  event->touchpad_swipe.y = y;
+  event->touchpad_swipe.dx = dx;
+  event->touchpad_swipe.dy = dy;
+  event->touchpad_swipe.n_fingers = n_fingers;
+  gdk_event_set_device (event, device);
+  gdk_event_set_source_device (event, device);
+
+  return event;
+}
+
+GdkEvent *
+gdk_event_touchpad_pinch_new (GdkSurface *surface,
+                              GdkDevice  *device,
+                              GdkDevice  *source_device,
+                              guint32     time,
+                              GdkModifierType state,
+                              GdkTouchpadGesturePhase phase,
+                              double      x,
+                              double      y,
+                              int         n_fingers,
+                              double      dx,
+                              double      dy,
+                              double      scale,
+                              double      angle_delta)
+{
+  GdkEvent *event = gdk_event_new (GDK_TOUCHPAD_PINCH);
+
+  event->any.surface = g_object_ref (surface);
+  event->touchpad_pinch.time = time;
+  event->touchpad_pinch.state = state;
+  event->touchpad_pinch.phase = phase;
+  event->touchpad_pinch.x = x;
+  event->touchpad_pinch.y = y;
+  event->touchpad_pinch.dx = dx;
+  event->touchpad_pinch.dy = dy;
+  event->touchpad_pinch.n_fingers = n_fingers;
+  event->touchpad_pinch.scale = scale;
+  event->touchpad_pinch.angle_delta = angle_delta;
+  gdk_event_set_device (event, device);
+  gdk_event_set_source_device (event, device);
+
+  return event;
+}
+
+GdkEvent *
+gdk_event_pad_ring_new (GdkSurface *surface,
+                        GdkDevice  *device,
+                        GdkDevice  *source_device,
+                        guint32     time,
+                        guint       group,
+                        guint       index,
+                        guint       mode,
+                        double      value)
+{
+  GdkEvent *event = gdk_event_new (GDK_PAD_RING);
+
+  event->any.surface = g_object_ref (surface);
+  event->pad_axis.time = time;
+  event->pad_axis.group = group;
+  event->pad_axis.index = index;
+  event->pad_axis.mode = mode;
+  event->pad_axis.value = value;
+  gdk_event_set_device (event, device);
+  gdk_event_set_source_device (event, device);
+
+  return event;
+}
+
+GdkEvent *
+gdk_event_pad_strip_new (GdkSurface *surface,
+                         GdkDevice  *device,
+                         GdkDevice  *source_device,
+                         guint32     time,
+                         guint       group,
+                         guint       index,
+                         guint       mode,
+                         double      value)
+{
+  GdkEvent *event = gdk_event_new (GDK_PAD_STRIP);
+
+  event->any.surface = g_object_ref (surface);
+  event->pad_axis.time = time;
+  event->pad_axis.group = group;
+  event->pad_axis.index = index;
+  event->pad_axis.mode = mode;
+  event->pad_axis.value = value;
+  gdk_event_set_device (event, device);
+  gdk_event_set_source_device (event, device);
+
+  return event;
+}
+
+GdkEvent *
+gdk_event_pad_button_new (GdkEventType  type,
+                          GdkSurface   *surface,
+                          GdkDevice    *device,
+                          GdkDevice    *source_device,
+                          guint32       time,
+                          guint         group,
+                          guint         button,
+                          guint         mode)
+{
+  GdkEvent *event;
+
+  g_return_val_if_fail (type == GDK_PAD_BUTTON_PRESS ||
+                        type == GDK_PAD_BUTTON_RELEASE, NULL);
+
+  event = gdk_event_new (type);
+
+  event->any.surface = g_object_ref (surface);
+  event->pad_button.time = time;
+  event->pad_button.group = group;
+  event->pad_button.button = button;
+  event->pad_axis.mode = mode;
+  gdk_event_set_device (event, device);
+  gdk_event_set_source_device (event, device);
+
+  return event;
+}
+
+GdkEvent *
+gdk_event_pad_group_mode_new (GdkSurface *surface,
+                              GdkDevice  *device,
+                              GdkDevice  *source_device,
+                              guint32     time,
+                              guint       group,
+                              guint       mode)
+{
+  GdkEvent *event = gdk_event_new (GDK_PAD_GROUP_MODE);
+
+  event->any.surface = g_object_ref (surface);
+  event->pad_group_mode.time = time;
+  event->pad_group_mode.group = group;
+  event->pad_group_mode.mode = mode;
+  gdk_event_set_device (event, device);
+  gdk_event_set_source_device (event, device);
+
+  return event;
+}
diff --git a/gdk/gdkeventsprivate.h b/gdk/gdkeventsprivate.h
index 191fcb2f4d1..8c8f4974b43 100644
--- a/gdk/gdkeventsprivate.h
+++ b/gdk/gdkeventsprivate.h
@@ -651,5 +651,155 @@ GObject *      gdk_event_get_related_target      (const GdkEvent *event);
 
 gboolean       check_event_sanity (GdkEvent *event);
 
+GdkEvent * gdk_event_button_new         (GdkEventType     type,
+                                         GdkSurface      *surface,
+                                         GdkDevice       *device,
+                                         GdkDevice       *source_device,
+                                         GdkDeviceTool   *tool,
+                                         guint32          time,
+                                         double           x,
+                                         double           y,
+                                         guint            button,
+                                         GdkModifierType  state);
+                             
+GdkEvent * gdk_event_motion_new         (GdkSurface      *surface,
+                                         GdkDevice       *device,
+                                         GdkDevice       *source_device,
+                                         GdkDeviceTool   *tool,
+                                         guint32          time,
+                                         GdkModifierType  state,
+                                         double           x,
+                                         double           y);
+
+GdkEvent * gdk_event_crossing_new       (GdkEventType     type,
+                                         GdkSurface      *surface,
+                                         GdkDevice       *device,
+                                         GdkDevice       *source_device,
+                                         guint32          time,
+                                         GdkModifierType  state,
+                                         double           x,
+                                         double           y,
+                                         GdkCrossingMode  mode,
+                                         GdkNotifyType    notify);
+                                          
+GdkEvent * gdk_event_proximity_new      (GdkEventType     type,
+                                         GdkSurface      *surface,
+                                         GdkDevice       *device,
+                                         GdkDevice       *source_device,
+                                         GdkDeviceTool   *tool,
+                                         guint32          time);
+
+GdkEvent * gdk_event_key_new            (GdkEventType     type,
+                                         GdkSurface      *surface,
+                                         GdkDevice       *device,
+                                         GdkDevice       *source_device,
+                                         guint32          time,
+                                         GdkModifierType  state,
+                                         guint            keyval,
+                                         guint16          keycode,
+                                         guint16          scancode,
+                                         guint8           group,
+                                         gboolean         is_modifier);
+
+GdkEvent * gdk_event_focus_new          (GdkSurface      *surface,
+                                         GdkDevice       *device,
+                                         GdkDevice       *source_device,
+                                         gboolean         focus_in);
+
+GdkEvent * gdk_event_configure_new      (GdkSurface      *surface,
+                                         int              width,
+                                         int              height);
+
+GdkEvent * gdk_event_delete_new         (GdkSurface      *surface);
+
+GdkEvent * gdk_event_scroll_new         (GdkSurface      *surface,
+                                         GdkDevice       *device,
+                                         GdkDevice       *source_device,
+                                         GdkDeviceTool   *tool,
+                                         guint32          time,
+                                         GdkModifierType  state,
+                                         double           delta_x,
+                                         double           delta_y,
+                                         gboolean         is_stop);
+
+GdkEvent * gdk_event_discrete_scroll_new (GdkSurface         *surface,
+                                          GdkDevice          *device,
+                                          GdkDevice          *source_device,
+                                          GdkDeviceTool      *tool,
+                                          guint32             time,
+                                          GdkModifierType     state,
+                                          GdkScrollDirection  direction,
+                                          gboolean            emulated);
+
+GdkEvent * gdk_event_touch_new          (GdkEventType     type,
+                                         GdkSurface      *surface,
+                                         GdkDevice       *device,
+                                         GdkDevice       *source_device,
+                                         guint32          time,
+                                         GdkModifierType  state,
+                                         double           x,
+                                         double           y,
+                                         gboolean         emulating);
+ 
+GdkEvent * gdk_event_touchpad_swipe_new (GdkSurface      *surface,
+                                         GdkDevice       *device,
+                                         GdkDevice       *source_device,
+                                         guint32          time,
+                                         GdkModifierType  state,
+                                         double           x,
+                                         double           y,
+                                         int              n_fingers,
+                                         double           dx,
+                                         double           dy);
+
+GdkEvent * gdk_event_touchpad_pinch_new (GdkSurface              *surface,
+                                         GdkDevice               *device,
+                                         GdkDevice               *source_device,
+                                         guint32                  time,
+                                         GdkModifierType          state,
+                                         GdkTouchpadGesturePhase  phase,
+                                         double                   x,
+                                         double                   y,
+                                         int                      n_fingers,
+                                         double                   dx,
+                                         double                   dy,
+                                         double                   scale,
+                                         double                   angle_delta);
+
+GdkEvent * gdk_event_pad_ring_new       (GdkSurface      *surface,
+                                         GdkDevice       *device,
+                                         GdkDevice       *source_device,
+                                         guint32          time,
+                                         guint            group,
+                                         guint            index,
+                                         guint            mode,
+                                         double           value);
+
+GdkEvent * gdk_event_pad_strip_new      (GdkSurface      *surface,
+                                         GdkDevice       *device,
+                                         GdkDevice       *source_device,
+                                         guint32          time,
+                                         guint            group,
+                                         guint            index,
+                                         guint            mode,
+                                         double           value);
+
+GdkEvent * gdk_event_pad_button_new     (GdkEventType     type,
+                                         GdkSurface      *surface,
+                                         GdkDevice       *device,
+                                         GdkDevice       *source_device,
+                                         guint32          time,
+                                         guint            group,
+                                         guint            button,
+                                         guint            mode);
+
+GdkEvent * gdk_event_pad_group_mode_new (GdkSurface      *surface,
+                                         GdkDevice       *device,
+                                         GdkDevice       *source_device,
+                                         guint32          time,
+                                         guint            group,
+                                         guint            mode);
+
 
 #endif /* __GDK_EVENTS_PRIVATE_H__ */
+


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