diff --git a/src/wayland/meta-wayland-actor-surface.c b/src/wayland/meta-wayland-actor-surface.c index bf93f9564..f929ff446 100644 --- a/src/wayland/meta-wayland-actor-surface.c +++ b/src/wayland/meta-wayland-actor-surface.c @@ -147,9 +147,9 @@ meta_wayland_actor_surface_real_sync_actor_state (MetaWaylandActorSurface *actor meta_wayland_surface_role_get_surface (surface_role); MetaSurfaceActor *surface_actor; MetaShapedTexture *stex; - GNode *n; cairo_rectangle_int_t surface_rect; int geometry_scale; + MetaWaylandSurface *subsurface_surface; surface_actor = priv->actor; stex = meta_surface_actor_get_texture (surface_actor); @@ -213,19 +213,12 @@ meta_wayland_actor_surface_real_sync_actor_state (MetaWaylandActorSurface *actor meta_surface_actor_reset_viewport_dst_size (surface_actor); } - for (n = g_node_first_child (surface->subsurface_branch_node); - n; - n = g_node_next_sibling (n)) + META_WAYLAND_SURFACE_FOREACH_SUBSURFACE (surface, subsurface_surface) { - MetaWaylandSurface *subsurface_surface = n->data; - MetaWaylandActorSurface *subsurface_actor_surface; + MetaWaylandActorSurface *actor_surface; - if (G_NODE_IS_LEAF (n)) - continue; - - subsurface_actor_surface = - META_WAYLAND_ACTOR_SURFACE (subsurface_surface->role); - meta_wayland_actor_surface_sync_actor_state (subsurface_actor_surface); + actor_surface = META_WAYLAND_ACTOR_SURFACE (subsurface_surface->role); + meta_wayland_actor_surface_sync_actor_state (actor_surface); } } diff --git a/src/wayland/meta-wayland-pointer.c b/src/wayland/meta-wayland-pointer.c index b69f43ab3..8b597417e 100644 --- a/src/wayland/meta-wayland-pointer.c +++ b/src/wayland/meta-wayland-pointer.c @@ -1209,20 +1209,13 @@ static gboolean pointer_can_grab_surface (MetaWaylandPointer *pointer, MetaWaylandSurface *surface) { - GNode *n; + MetaWaylandSurface *subsurface; if (pointer->focus_surface == surface) return TRUE; - for (n = g_node_first_child (surface->subsurface_branch_node); - n; - n = g_node_next_sibling (n)) + META_WAYLAND_SURFACE_FOREACH_SUBSURFACE (surface, subsurface) { - MetaWaylandSurface *subsurface = n->data; - - if (G_NODE_IS_LEAF (n)) - continue; - if (pointer_can_grab_surface (pointer, subsurface)) return TRUE; } diff --git a/src/wayland/meta-wayland-shell-surface.c b/src/wayland/meta-wayland-shell-surface.c index 7a9a804b6..9870dfb97 100644 --- a/src/wayland/meta-wayland-shell-surface.c +++ b/src/wayland/meta-wayland-shell-surface.c @@ -43,23 +43,17 @@ meta_wayland_shell_surface_calculate_geometry (MetaWaylandShellSurface *shell_su MetaWaylandSurface *surface = meta_wayland_surface_role_get_surface (surface_role); MetaRectangle geometry; - GNode *n; + MetaWaylandSurface *subsurface_surface; geometry = (MetaRectangle) { .width = meta_wayland_surface_get_width (surface), .height = meta_wayland_surface_get_height (surface), }; - for (n = g_node_first_child (surface->subsurface_branch_node); - n; - n = g_node_next_sibling (n)) + META_WAYLAND_SURFACE_FOREACH_SUBSURFACE (surface, subsurface_surface) { - MetaWaylandSurface *subsurface_surface = n->data; MetaWaylandSubsurface *subsurface; - if (G_NODE_IS_LEAF (n)) - continue; - subsurface = META_WAYLAND_SUBSURFACE (subsurface_surface->role); meta_wayland_subsurface_union_geometry (subsurface, 0, 0, diff --git a/src/wayland/meta-wayland-subsurface.c b/src/wayland/meta-wayland-subsurface.c index 6abfde19f..0d59cdf97 100644 --- a/src/wayland/meta-wayland-subsurface.c +++ b/src/wayland/meta-wayland-subsurface.c @@ -198,7 +198,7 @@ meta_wayland_subsurface_union_geometry (MetaWaylandSubsurface *subsurface, MetaWaylandSurface *surface = meta_wayland_surface_role_get_surface (surface_role); MetaRectangle geometry; - GNode *n; + MetaWaylandSurface *subsurface_surface; geometry = (MetaRectangle) { .x = surface->offset_x + surface->sub.x, @@ -209,16 +209,10 @@ meta_wayland_subsurface_union_geometry (MetaWaylandSubsurface *subsurface, meta_rectangle_union (out_geometry, &geometry, out_geometry); - for (n = g_node_first_child (surface->subsurface_branch_node); - n; - n = g_node_next_sibling (n)) + META_WAYLAND_SURFACE_FOREACH_SUBSURFACE (surface, subsurface_surface) { - MetaWaylandSurface *subsurface_surface = n->data; MetaWaylandSubsurface *subsurface; - if (G_NODE_IS_LEAF (n)) - continue; - subsurface = META_WAYLAND_SUBSURFACE (subsurface_surface->role); meta_wayland_subsurface_union_geometry (subsurface, parent_x + geometry.x, diff --git a/src/wayland/meta-wayland-surface.c b/src/wayland/meta-wayland-surface.c index 56d292517..d23105d2a 100644 --- a/src/wayland/meta-wayland-surface.c +++ b/src/wayland/meta-wayland-surface.c @@ -632,20 +632,6 @@ meta_wayland_surface_is_effectively_synchronized (MetaWaylandSurface *surface) } } -static void -parent_surface_state_applied (GNode *subsurface_node, - gpointer user_data) -{ - MetaWaylandSurface *surface = subsurface_node->data; - MetaWaylandSubsurface *subsurface; - - if (G_NODE_IS_LEAF (subsurface_node)) - return; - - subsurface = META_WAYLAND_SUBSURFACE (surface->role); - meta_wayland_subsurface_parent_state_applied (subsurface); -} - void meta_wayland_surface_cache_pending_frame_callbacks (MetaWaylandSurface *surface, MetaWaylandPendingState *pending) @@ -659,6 +645,7 @@ void meta_wayland_surface_apply_pending_state (MetaWaylandSurface *surface, MetaWaylandPendingState *pending) { + MetaWaylandSurface *subsurface_surface; gboolean had_damage = FALSE; if (surface->role) @@ -832,10 +819,13 @@ cleanup: pending_state_reset (pending); - g_node_children_foreach (surface->subsurface_branch_node, - G_TRAVERSE_ALL, - parent_surface_state_applied, - NULL); + META_WAYLAND_SURFACE_FOREACH_SUBSURFACE (surface, subsurface_surface) + { + MetaWaylandSubsurface *subsurface; + + subsurface = META_WAYLAND_SUBSURFACE (subsurface_surface->role); + meta_wayland_subsurface_parent_state_applied (subsurface); + } if (had_damage) { @@ -1276,22 +1266,14 @@ meta_wayland_surface_update_outputs (MetaWaylandSurface *surface) static void meta_wayland_surface_update_outputs_recursively (MetaWaylandSurface *surface) { - GNode *n; + MetaWaylandSurface *subsurface_surface; meta_wayland_surface_update_outputs (surface); - for (n = g_node_first_child (surface->subsurface_branch_node); - n; - n = g_node_next_sibling (n)) - { - if (G_NODE_IS_LEAF (n)) - continue; - - meta_wayland_surface_update_outputs_recursively (n->data); - } + META_WAYLAND_SURFACE_FOREACH_SUBSURFACE (surface, subsurface_surface) + meta_wayland_surface_update_outputs_recursively (subsurface_surface); } - void meta_wayland_surface_set_window (MetaWaylandSurface *surface, MetaWindow *window) diff --git a/src/wayland/meta-wayland-surface.h b/src/wayland/meta-wayland-surface.h index 5f867be9d..23d65945a 100644 --- a/src/wayland/meta-wayland-surface.h +++ b/src/wayland/meta-wayland-surface.h @@ -327,4 +327,38 @@ void meta_wayland_surface_notify_geometry_changed (MetaWaylandSur int meta_wayland_surface_get_width (MetaWaylandSurface *surface); int meta_wayland_surface_get_height (MetaWaylandSurface *surface); +static inline GNode * +meta_get_next_subsurface_sibling (GNode *n) +{ + GNode *next; + + if (!n) + return NULL; + + next = g_node_next_sibling (n); + if (!next) + return NULL; + if (!G_NODE_IS_LEAF (next)) + return next; + else + return meta_get_next_subsurface_sibling (next); +} + +static inline GNode * +meta_get_first_subsurface_node (MetaWaylandSurface *surface) +{ + GNode *n; + + n = g_node_first_child (surface->subsurface_branch_node); + if (!G_NODE_IS_LEAF (n)) + return n; + else + return meta_get_next_subsurface_sibling (n); +} + +#define META_WAYLAND_SURFACE_FOREACH_SUBSURFACE(surface, subsurface) \ + for (GNode *G_PASTE(__n, __LINE__) = meta_get_first_subsurface_node ((surface)); \ + (subsurface = (G_PASTE (__n, __LINE__) ? G_PASTE (__n, __LINE__)->data : NULL)); \ + G_PASTE (__n, __LINE__) = meta_get_next_subsurface_sibling (G_PASTE (__n, __LINE__))) + #endif diff --git a/src/wayland/meta-wayland-tablet-tool.c b/src/wayland/meta-wayland-tablet-tool.c index 065c834bb..412e541be 100644 --- a/src/wayland/meta-wayland-tablet-tool.c +++ b/src/wayland/meta-wayland-tablet-tool.c @@ -989,20 +989,13 @@ static gboolean tablet_tool_can_grab_surface (MetaWaylandTabletTool *tool, MetaWaylandSurface *surface) { - GNode *n; + MetaWaylandSurface *subsurface; if (tool->focus_surface == surface) return TRUE; - for (n = g_node_first_child (surface->subsurface_branch_node); - n; - n = g_node_next_sibling (n)) + META_WAYLAND_SURFACE_FOREACH_SUBSURFACE (surface, subsurface) { - MetaWaylandSurface *subsurface = n->data; - - if (G_NODE_IS_LEAF (n)) - continue; - if (tablet_tool_can_grab_surface (tool, subsurface)) return TRUE; }