[gtk/wip/matthiasc/popup4: 45/79] gdk: Stop using surface->parent



commit 0a0ac572b8f8a7b761d935fd48bc789fbc97e011
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Mar 23 09:13:37 2019 -0400

    gdk: Stop using surface->parent
    
    It is always NULL.

 gdk/gdkdisplay.c     |   4 +-
 gdk/gdkinternals.h   |   2 -
 gdk/gdksurface.c     | 275 +++++----------------------------------------------
 gdk/gdksurfaceimpl.c |  28 +-----
 4 files changed, 27 insertions(+), 282 deletions(-)
---
diff --git a/gdk/gdkdisplay.c b/gdk/gdkdisplay.c
index 81e9d8aff8..b623593fe4 100644
--- a/gdk/gdkdisplay.c
+++ b/gdk/gdkdisplay.c
@@ -845,9 +845,7 @@ _gdk_display_end_device_grab (GdkDisplay *display,
     return FALSE;
 
   grab = l->data;
-  if (grab &&
-      (if_child == NULL ||
-       _gdk_surface_event_parent_of (if_child, grab->surface)))
+  if (grab && (if_child == NULL || if_child == grab->surface))
     {
       grab->serial_end = serial;
       grab->implicit_ungrab = implicit;
diff --git a/gdk/gdkinternals.h b/gdk/gdkinternals.h
index 68c3662a2d..8b2c027de0 100644
--- a/gdk/gdkinternals.h
+++ b/gdk/gdkinternals.h
@@ -318,8 +318,6 @@ GdkEvent * _gdk_make_event (GdkSurface    *surface,
                             GdkEventType  type,
                             GdkEvent     *event_in_queue,
                             gboolean      before_event);
-gboolean _gdk_surface_event_parent_of (GdkSurface *parent,
-                                       GdkSurface *child);
 
 void _gdk_synthesize_crossing_events (GdkDisplay                 *display,
                                       GdkSurface                  *src,
diff --git a/gdk/gdksurface.c b/gdk/gdksurface.c
index bbe1484780..6cfbcd53c0 100644
--- a/gdk/gdksurface.c
+++ b/gdk/gdksurface.c
@@ -547,15 +547,9 @@ recompute_visible_regions_internal (GdkSurface *private,
   /* Update absolute position */
   if (gdk_surface_has_impl (private))
     {
-      /* Native surfaces and toplevel subsurfaces start here */
       private->abs_x = 0;
       private->abs_y = 0;
     }
-  else
-    {
-      private->abs_x = private->parent->abs_x + private->x;
-      private->abs_y = private->parent->abs_y + private->y;
-    }
 
   abs_pos_changed =
     private->abs_x != old_abs_x ||
@@ -628,8 +622,6 @@ gdk_surface_new (GdkDisplay     *display,
 
   surface = _gdk_display_create_surface (display);
 
-  surface->parent = NULL;
-
   surface->accept_focus = TRUE;
   surface->focus_on_map = TRUE;
   surface->alpha = 255;
@@ -809,15 +801,6 @@ _gdk_surface_destroy_hierarchy (GdkSurface *surface,
 
     case GDK_SURFACE_TOPLEVEL:
     case GDK_SURFACE_TEMP:
-      if (surface->parent)
-        {
-          if (surface->parent->children)
-            surface->parent->children = g_list_remove_link (surface->parent->children, 
&surface->children_list_node);
-
-          if (!recursing && GDK_SURFACE_IS_MAPPED (surface))
-            recompute_visible_regions (surface, FALSE);
-        }
-
       if (surface->gl_paint_context)
         {
           /* Make sure to destroy if current */
@@ -861,7 +844,6 @@ _gdk_surface_destroy_hierarchy (GdkSurface *surface,
         }
 
       surface->state |= GDK_SURFACE_STATE_WITHDRAWN;
-      surface->parent = NULL;
       surface->destroyed = TRUE;
 
       surface_remove_from_pointer_info (surface, display);
@@ -1207,29 +1189,10 @@ gdk_surface_create_vulkan_context (GdkSurface  *surface,
  */
 static GSList *update_surfaces = NULL;
 
-static inline gboolean
-gdk_surface_is_ancestor (GdkSurface *surface,
-                         GdkSurface *ancestor)
-{
-  while (surface)
-    {
-      GdkSurface *parent = surface->parent;
-
-      if (parent == ancestor)
-        return TRUE;
-
-      surface = parent;
-    }
-
-  return FALSE;
-}
-
 static void
 gdk_surface_add_update_surface (GdkSurface *surface)
 {
   GSList *tmp;
-  GSList *prev = NULL;
-  gboolean has_ancestor_in_list = FALSE;
 
   /*  Check whether "surface" is already in "update_surfaces" list.
    *  It could be added during execution of gtk_widget_destroy() when
@@ -1240,72 +1203,6 @@ gdk_surface_add_update_surface (GdkSurface *surface)
   if (tmp != NULL)
     return;
 
-  for (tmp = update_surfaces; tmp; tmp = tmp->next)
-    {
-      GdkSurface *parent = surface->parent;
-
-      /*  check if tmp is an ancestor of "surface"; if it is, set a
-       *  flag indicating that all following surfaces are either
-       *  children of "surface" or from a differen hierarchy
-       */
-      if (!has_ancestor_in_list && gdk_surface_is_ancestor (surface, tmp->data))
-        has_ancestor_in_list = TRUE;
-
-      /* insert in reverse stacking order when adding around siblings,
-       * so processing updates properly paints over lower stacked surfaces
-       */
-      if (parent == GDK_SURFACE (tmp->data)->parent)
-        {
-          if (parent != NULL)
-            {
-              gint index = g_list_index (parent->children, surface);
-              for (; tmp && parent == GDK_SURFACE (tmp->data)->parent; tmp = tmp->next)
-                {
-                  gint sibling_index = g_list_index (parent->children, tmp->data);
-                  if (index > sibling_index)
-                    break;
-                  prev = tmp;
-                }
-            }
-          /* here, tmp got advanced past all lower stacked siblings */
-          tmp = g_slist_prepend (tmp, g_object_ref (surface));
-          if (prev)
-            prev->next = tmp;
-          else
-            update_surfaces = tmp;
-          return;
-        }
-
-      /*  if "surface" has an ancestor in the list and tmp is one of
-       *  "surface's" children, insert "surface" before tmp
-       */
-      if (has_ancestor_in_list && gdk_surface_is_ancestor (tmp->data, surface))
-        {
-          tmp = g_slist_prepend (tmp, g_object_ref (surface));
-
-          if (prev)
-            prev->next = tmp;
-          else
-            update_surfaces = tmp;
-          return;
-        }
-
-      /*  if we're at the end of the list and had an ancestor it it,
-       *  append to the list
-       */
-      if (! tmp->next && has_ancestor_in_list)
-        {
-          tmp = g_slist_append (tmp, g_object_ref (surface));
-          return;
-        }
-
-      prev = tmp;
-    }
-
-  /*  if all above checks failed ("surface" is from a different
-   *  hierarchy than what is already in the list) or the list is
-   *  empty, prepend
-   */
   update_surfaces = g_slist_prepend (update_surfaces, g_object_ref (surface));
 }
 
@@ -1505,9 +1402,6 @@ gdk_surface_queue_expose (GdkSurface *surface)
 
   g_return_if_fail (GDK_IS_SURFACE (surface));
 
-  while (!gdk_surface_has_impl (surface))
-    surface = surface->parent;
-
   region = cairo_region_create ();
   impl_surface_add_update_area (surface, region);
   cairo_region_destroy (region);
@@ -1549,28 +1443,13 @@ gdk_surface_invalidate_region (GdkSurface          *surface,
 
   r.x = 0;
   r.y = 0;
+  r.width = surface->width;
+  r.height = surface->height;
 
   visible_region = cairo_region_copy (region);
 
-  while (surface != NULL &&
-         !cairo_region_is_empty (visible_region))
-    {
-      r.width = surface->width;
-      r.height = surface->height;
-      cairo_region_intersect_rectangle (visible_region, &r);
-
-      if (gdk_surface_has_impl (surface))
-        {
-          impl_surface_add_update_area (surface, visible_region);
-          break;
-        }
-      else
-        {
-          cairo_region_translate (visible_region,
-                                  surface->x, surface->y);
-          surface = surface->parent;
-        }
-    }
+  cairo_region_intersect_rectangle (visible_region, &r);
+  impl_surface_add_update_area (surface, visible_region);
 
   cairo_region_destroy (visible_region);
 }
@@ -1834,27 +1713,13 @@ gdk_surface_get_device_position (GdkSurface       *surface,
   return NULL;
 }
 
-static gboolean
+static void
 gdk_surface_raise_internal (GdkSurface *surface)
 {
-  GdkSurface *parent = surface->parent;
   GdkSurfaceImplClass *impl_class;
-  gboolean did_raise = FALSE;
-
-  if (parent && parent->children->data != surface)
-    {
-      parent->children = g_list_remove_link (parent->children, &surface->children_list_node);
-      parent->children = g_list_concat (&surface->children_list_node, parent->children);
-      did_raise = TRUE;
-    }
 
   impl_class = GDK_SURFACE_IMPL_GET_CLASS (surface->impl);
-
-  /* Just do native raise for toplevels */
-  if (gdk_surface_has_impl (surface))
-      impl_class->raise (surface);
-
-  return did_raise;
+  impl_class->raise (surface);
 }
 
 /* Returns TRUE If the native surface was mapped or unmapped */
@@ -1895,7 +1760,7 @@ gdk_surface_show_internal (GdkSurface *surface, gboolean raise)
 {
   GdkSurfaceImplClass *impl_class;
   gboolean was_mapped, was_viewable;
-  gboolean did_show, did_raise = FALSE;
+  gboolean did_show;
 
   g_return_if_fail (GDK_IS_SURFACE (surface));
 
@@ -1906,10 +1771,7 @@ gdk_surface_show_internal (GdkSurface *surface, gboolean raise)
   was_viewable = surface->viewable;
 
   if (raise)
-    {
-      /* Keep children in (reverse) stacking order */
-      did_raise = gdk_surface_raise_internal (surface);
-    }
+    gdk_surface_raise_internal (surface);
 
   if (gdk_surface_has_impl (surface))
     {
@@ -1938,7 +1800,7 @@ gdk_surface_show_internal (GdkSurface *surface, gboolean raise)
       impl_class->show (surface, !did_show ? was_mapped : TRUE);
     }
 
-  if (!was_mapped || did_raise)
+  if (!was_mapped)
     {
       recompute_visible_regions (surface, FALSE);
 
@@ -1991,20 +1853,10 @@ gdk_surface_raise (GdkSurface *surface)
 static void
 gdk_surface_lower_internal (GdkSurface *surface)
 {
-  GdkSurface *parent = surface->parent;
   GdkSurfaceImplClass *impl_class;
 
-  if (parent)
-    {
-      parent->children = g_list_remove_link (parent->children, &surface->children_list_node);
-      parent->children = g_list_concat (parent->children, &surface->children_list_node);
-    }
-
   impl_class = GDK_SURFACE_IMPL_GET_CLASS (surface->impl);
-
-  /* Just do native lower for toplevels */
-  if (gdk_surface_has_impl (surface))
-    impl_class->lower (surface);
+  impl_class->lower (surface);
 }
 
 /**
@@ -2353,12 +2205,13 @@ gdk_surface_set_cursor_internal (GdkSurface *surface,
   if (GDK_SURFACE_DESTROYED (surface))
     return;
 
-  g_assert (gdk_surface_get_display (surface) == gdk_device_get_display (device));
-
   display = gdk_surface_get_display (surface);
+
+  g_assert (display == gdk_device_get_display (device));
+
   pointer_info = _gdk_display_get_pointer_info (display, device);
 
-  if (_gdk_surface_event_parent_of (surface, pointer_info->surface_under_pointer))
+  if (surface == pointer_info->surface_under_pointer)
     update_cursor (display, device);
 }
 
@@ -2540,41 +2393,15 @@ gdk_surface_get_geometry (GdkSurface *surface,
                           gint      *width,
                           gint      *height)
 {
-  GdkSurface *parent;
   GdkSurfaceImplClass *impl_class;
 
   g_return_if_fail (GDK_IS_SURFACE (surface));
 
-  if (!GDK_SURFACE_DESTROYED (surface))
-    {
-      if (gdk_surface_has_impl (surface))
-        {
-          impl_class = GDK_SURFACE_IMPL_GET_CLASS (surface->impl);
-          impl_class->get_geometry (surface, x, y,
-                                    width, height);
-          /* This reports the position wrt to the native parent, we need to convert
-             it to be relative to the client side parent */
-          parent = surface->parent;
-          if (parent && !gdk_surface_has_impl (parent))
-            {
-              if (x)
-                *x -= parent->abs_x;
-              if (y)
-                *y -= parent->abs_y;
-            }
-        }
-      else
-        {
-          if (x)
-            *x = surface->x;
-          if (y)
-            *y = surface->y;
-          if (width)
-            *width = surface->width;
-          if (height)
-            *height = surface->height;
-        }
-    }
+  if (GDK_SURFACE_DESTROYED (surface))
+    return;
+
+  impl_class = GDK_SURFACE_IMPL_GET_CLASS (surface->impl);
+  impl_class->get_geometry (surface, x, y, width, height);
 }
 
 /**
@@ -2985,43 +2812,11 @@ gdk_surface_is_input_only (GdkSurface *surface)
   return surface->input_only;
 }
 
-/* Gets the toplevel for a surface as used for events,
-   i.e. including offscreen parents going up to the native
-   toplevel */
-static GdkSurface *
-get_event_toplevel (GdkSurface *surface)
-{
-  GdkSurface *parent;
-
-  while ((parent = surface->parent) != NULL)
-    surface = parent;
-
-  return surface;
-}
-
-gboolean
-_gdk_surface_event_parent_of (GdkSurface *parent,
-                              GdkSurface *child)
-{
-  GdkSurface *w;
-
-  w = child;
-  while (w != NULL)
-    {
-      if (w == parent)
-        return TRUE;
-
-      w = w->parent;
-    }
-
-  return FALSE;
-}
-
 static void
 update_cursor (GdkDisplay *display,
                GdkDevice  *device)
 {
-  GdkSurface *cursor_surface, *parent, *toplevel;
+  GdkSurface *cursor_surface;
   GdkSurface *pointer_surface;
   GdkPointerSurfaceInfo *pointer_info;
   GdkDeviceGrabInfo *grab;
@@ -3033,10 +2828,7 @@ update_cursor (GdkDisplay *display,
   /* We ignore the serials here and just pick the last grab
      we've sent, as that would shortly be used anyway. */
   grab = _gdk_display_get_last_device_grab (display, device);
-  if (/* have grab */
-      grab != NULL &&
-      /* the pointer is not in a descendant of the grab surface */
-      !_gdk_surface_event_parent_of (grab->surface, pointer_surface))
+  if (grab != NULL)
     {
       /* use the cursor from the grab surface */
       cursor_surface = grab->surface;
@@ -3047,22 +2839,12 @@ update_cursor (GdkDisplay *display,
       cursor_surface = pointer_surface;
     }
 
-  /* Find the first surface with the cursor actually set, as
-     the cursor is inherited from the parent */
-  while (cursor_surface->cursor == NULL &&
-         !g_hash_table_contains (cursor_surface->device_cursor, device) &&
-         (parent = cursor_surface->parent) != NULL)
-    cursor_surface = parent;
-
   cursor = g_hash_table_lookup (cursor_surface->device_cursor, device);
 
   if (!cursor)
     cursor = cursor_surface->cursor;
 
-  /* Set all cursors on toplevel, otherwise its tricky to keep track of
-   * which native surface has what cursor set. */
-  toplevel = get_event_toplevel (pointer_surface);
-  GDK_DEVICE_GET_CLASS (device)->set_surface_cursor (device, toplevel, cursor);
+  GDK_DEVICE_GET_CLASS (device)->set_surface_cursor (device, pointer_surface, cursor);
 }
 
 static gboolean
@@ -3233,23 +3015,16 @@ void
 gdk_surface_beep (GdkSurface *surface)
 {
   GdkDisplay *display;
-  GdkSurface *toplevel;
 
   g_return_if_fail (GDK_IS_SURFACE (surface));
 
   if (GDK_SURFACE_DESTROYED (surface))
     return;
 
-  toplevel = get_event_toplevel (surface);
-  display = gdk_surface_get_display (surface);
-
-  if (toplevel)
-    {
-      if (GDK_SURFACE_IMPL_GET_CLASS (toplevel->impl)->beep (toplevel))
-        return;
-    }
+  if (GDK_SURFACE_IMPL_GET_CLASS (surface->impl)->beep (surface))
+    return;
 
-  /* If surfaces fail to beep, we beep the display. */
+  display = gdk_surface_get_display (surface);
   gdk_display_beep (display);
 }
 
diff --git a/gdk/gdksurfaceimpl.c b/gdk/gdksurfaceimpl.c
index 0ca16f7dbc..0cacdb72ae 100644
--- a/gdk/gdksurfaceimpl.c
+++ b/gdk/gdksurfaceimpl.c
@@ -173,28 +173,6 @@ maybe_flip_position (gint      bounds_pos,
   return primary;
 }
 
-static GdkSurface *
-traverse_to_toplevel (GdkSurface *surface,
-                      gint       x,
-                      gint       y,
-                      gint      *toplevel_x,
-                      gint      *toplevel_y)
-{
-  GdkSurface *parent;
-  gdouble xf = x;
-  gdouble yf = y;
-
-  while ((parent = surface->parent) != NULL)
-    {
-      gdk_surface_coords_to_parent (surface, xf, yf, &xf, &yf);
-      surface = parent;
-    }
-
-  *toplevel_x = (gint) xf;
-  *toplevel_y = (gint) yf;
-  return surface;
-}
-
 static void
 gdk_surface_impl_move_to_rect (GdkSurface          *surface,
                               const GdkRectangle *rect,
@@ -219,11 +197,7 @@ gdk_surface_impl_move_to_rect (GdkSurface          *surface,
    * because not all backends will be able to get root coordinates for
    * non-toplevel surfaces.
    */
-  transient_for_toplevel = traverse_to_toplevel (surface->transient_for,
-                                                 root_rect.x,
-                                                 root_rect.y,
-                                                 &root_rect.x,
-                                                 &root_rect.y);
+  transient_for_toplevel = surface->transient_for;
 
   gdk_surface_get_root_coords (transient_for_toplevel,
                               root_rect.x,


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