[gtk/readonly-events-1: 3/22] widget: Port emulation code to constructors



commit 144c223f0fbf0548211d2baf207763893edd246b
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Feb 14 19:29:12 2020 -0500

    widget: Port emulation code to constructors
    
    Use the new event constructors when generating events
    for emulating presses.

 gtk/gtkwidget.c | 85 +++++++++++++++++++++++++++++++--------------------------
 1 file changed, 47 insertions(+), 38 deletions(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 5ea1f97613..915edcbef5 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -2066,47 +2066,60 @@ _gtk_widget_emulate_press (GtkWidget      *widget,
       event->any.type == GDK_TOUCH_UPDATE ||
       event->any.type == GDK_TOUCH_END)
     {
-      press = gdk_event_copy (event);
-      press->any.type = GDK_TOUCH_BEGIN;
+      press = gdk_event_touch_new (GDK_TOUCH_BEGIN,
+                                   event->touch.sequence,
+                                   event->any.surface,
+                                   event->any.device,
+                                   event->any.source_device,
+                                   event->touch.time,
+                                   event->touch.state,
+                                   p.x, p.y,
+                                   NULL,
+                                   event->touch.emulating_pointer);
     }
   else if (event->any.type == GDK_BUTTON_PRESS ||
            event->any.type == GDK_BUTTON_RELEASE)
     {
-      press = gdk_event_copy (event);
-      press->any.type = GDK_BUTTON_PRESS;
+      press = gdk_event_button_new (GDK_BUTTON_PRESS,
+                                    event->any.surface,
+                                    event->any.device,
+                                    event->any.source_device,
+                                    event->button.tool,
+                                    event->button.time,
+                                    event->button.state,
+                                    event->button.button,
+                                    p.x, p.y,
+                                    NULL);
     }
   else if (event->any.type == GDK_MOTION_NOTIFY)
     {
-      press = gdk_event_new (GDK_BUTTON_PRESS);
-      press->any.surface = g_object_ref (event->any.surface);
-      press->button.time = event->motion.time;
-      press->button.state = event->motion.state;
-
-      press->button.axes = g_memdup (event->motion.axes,
-                                     sizeof (gdouble) *
-                                     gdk_device_get_n_axes (event->any.device));
-
+      int button;
       if (event->motion.state & GDK_BUTTON3_MASK)
-        press->button.button = 3;
+        button = 3;
       else if (event->motion.state & GDK_BUTTON2_MASK)
-        press->button.button = 2;
+        button = 2;
       else
         {
           if ((event->motion.state & GDK_BUTTON1_MASK) == 0)
             g_critical ("Guessing button number 1 on generated button press event");
 
-          press->button.button = 1;
+          button = 1;
         }
 
-      gdk_event_set_device (press, gdk_event_get_device (event));
-      gdk_event_set_source_device (press, gdk_event_get_source_device (event));
+      press = gdk_event_button_new (GDK_BUTTON_PRESS,
+                                    event->any.surface,
+                                    event->any.device,
+                                    event->any.source_device,
+                                    NULL,
+                                    event->motion.time,
+                                    event->motion.state,
+                                    button,
+                                    p.x, p.y,
+                                    NULL);
     }
   else
     return;
 
-  gdk_event_set_coords (press, p.x, p.y);
-
-  press->any.send_event = TRUE;
   next_child = event_widget;
   parent = _gtk_widget_get_parent (next_child);
 
@@ -7929,23 +7942,19 @@ synth_crossing (GtkWidget       *widget,
                 GdkNotifyType    detail)
 {
   GdkEvent *event;
-
-  event = gdk_event_new (type);
-
-  event->any.surface = g_object_ref (surface);
-  event->any.send_event = TRUE;
-  event->crossing.child_surface = g_object_ref (surface);
-  event->crossing.time = GDK_CURRENT_TIME;
-  gdk_surface_get_device_position (surface,
-                                   device,
-                                   &event->crossing.x,
-                                   &event->crossing.y,
-                                   NULL);
-  event->crossing.mode = mode;
-  event->crossing.detail = detail;
-  event->crossing.focus = FALSE;
-  event->crossing.state = 0;
-  gdk_event_set_device (event, device);
+  double x, y;
+  GdkModifierType state;
+
+  gdk_surface_get_device_position (surface, device, &x, &y, &state);
+  event = gdk_event_crossing_new (type,
+                                  surface,
+                                  device,
+                                  device,
+                                  GDK_CURRENT_TIME,
+                                  state,
+                                  x, y, 
+                                  mode,
+                                  detail);
 
   if (!widget)
     widget = gtk_get_event_widget (event);


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