[gtk+/wip/carlosg/event-as-object: 827/844] gdk: Use allocated events



commit bd9569d8c1c41b393df5a613261687428382e0d7
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Oct 25 12:29:43 2017 +0200

    gdk: Use allocated events
    
    Stack allocated GdkEvent structs will not be ok when events become
    objects.

 gdk/gdkevents.c |   23 +++++++++++++----------
 gdk/gdkwindow.c |   17 +++++++++--------
 2 files changed, 22 insertions(+), 18 deletions(-)
---
diff --git a/gdk/gdkevents.c b/gdk/gdkevents.c
index 96b0ab8..ee498a2 100644
--- a/gdk/gdkevents.c
+++ b/gdk/gdkevents.c
@@ -1891,20 +1891,21 @@ _gdk_set_window_state (GdkWindow      *window,
                        GdkWindowState  new_state)
 {
   GdkDisplay *display = gdk_window_get_display (window);
-  GdkEvent temp_event;
+  GdkEvent *temp_event;
   GdkWindowState old;
   GList *pending_event_link;
 
   g_return_if_fail (window != NULL);
 
-  temp_event.any.window = window;
-  temp_event.any.type = GDK_WINDOW_STATE;
-  temp_event.any.send_event = FALSE;
-  temp_event.window_state.new_window_state = new_state;
-
-  if (temp_event.window_state.new_window_state == window->state)
+  if (new_state == window->state)
     return; /* No actual work to do, nothing changed. */
 
+  temp_event = gdk_event_new (GDK_WINDOW_STATE);
+
+  temp_event->any.window = g_object_ref (window);
+  temp_event->any.send_event = FALSE;
+  temp_event->window_state.new_window_state = new_state;
+
   pending_event_link = gdk_get_pending_window_state_event_link (window);
   if (pending_event_link)
     {
@@ -1919,7 +1920,7 @@ _gdk_set_window_state (GdkWindow      *window,
       window->old_state = old;
     }
 
-  temp_event.window_state.changed_mask = new_state ^ old;
+  temp_event->window_state.changed_mask = new_state ^ old;
 
   /* Actually update the field in GdkWindow, this is sort of an odd
    * place to do it, but seems like the safest since it ensures we expose no
@@ -1928,7 +1929,7 @@ _gdk_set_window_state (GdkWindow      *window,
 
   window->state = new_state;
 
-  if (temp_event.window_state.changed_mask & GDK_WINDOW_STATE_WITHDRAWN)
+  if (temp_event->window_state.changed_mask & GDK_WINDOW_STATE_WITHDRAWN)
     _gdk_window_update_viewable (window);
 
   /* We only really send the event to toplevels, since
@@ -1940,7 +1941,7 @@ _gdk_set_window_state (GdkWindow      *window,
     {
     case GDK_WINDOW_TOPLEVEL:
     case GDK_WINDOW_TEMP: /* ? */
-      gdk_display_put_event (display, &temp_event);
+      gdk_display_put_event (display, temp_event);
       break;
     case GDK_WINDOW_FOREIGN:
     case GDK_WINDOW_ROOT:
@@ -1948,6 +1949,8 @@ _gdk_set_window_state (GdkWindow      *window,
     default:
       break;
     }
+
+  gdk_event_free (temp_event);
 }
 
 void
diff --git a/gdk/gdkwindow.c b/gdk/gdkwindow.c
index 573088d..457e550 100644
--- a/gdk/gdkwindow.c
+++ b/gdk/gdkwindow.c
@@ -2525,7 +2525,7 @@ _gdk_window_process_updates_recurse (GdkWindow *window,
                                      cairo_region_t *expose_region)
 {
   cairo_region_t *clipped_expose_region;
-  GdkEvent event;
+  GdkEvent *event;
 
   if (window->destroyed)
     return;
@@ -2539,14 +2539,15 @@ _gdk_window_process_updates_recurse (GdkWindow *window,
 
   /* Paint the window before the children, clipped to the window region */
 
-  event.any.type = GDK_EXPOSE;
-  event.any.window = window; /* we already hold a ref */
-  event.any.send_event = FALSE;
-  event.expose.count = 0;
-  event.expose.region = clipped_expose_region;
-  cairo_region_get_extents (clipped_expose_region, &event.expose.area);
+  event = gdk_event_new (GDK_EXPOSE);
+  event->any.window = g_object_ref (window);
+  event->any.send_event = FALSE;
+  event->expose.count = 0;
+  event->expose.region = cairo_region_reference (clipped_expose_region);
+  cairo_region_get_extents (clipped_expose_region, &event->expose.area);
 
-  _gdk_event_emit (&event);
+  _gdk_event_emit (event);
+  gdk_event_free (event);
 
  out:
   cairo_region_destroy (clipped_expose_region);


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