From e1e6534eb2a604930489db609a175b9ee730c408 Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Wed, 31 Jan 2024 15:52:18 +0100 Subject: [PATCH] group: Move various functions to MetaWindowX11 Except meta_window_x11_get_group, which is still used by GNOME Shell and we can't make it a private API for now. Will need further investigation and could be done as a future step Part-of: --- src/core/display.c | 4 +- src/core/stack.c | 2 +- src/core/window.c | 8 +-- src/meta/group.h | 11 +-- src/x11/group-private.h | 5 ++ src/x11/group.c | 122 +------------------------------- src/x11/window-props.c | 2 +- src/x11/window-x11-private.h | 5 ++ src/x11/window-x11.c | 132 +++++++++++++++++++++++++++++++++-- 9 files changed, 148 insertions(+), 143 deletions(-) diff --git a/src/core/display.c b/src/core/display.c index 9f26f77af..368db23ff 100644 --- a/src/core/display.c +++ b/src/core/display.c @@ -1993,10 +1993,10 @@ in_tab_chain (MetaWindow *window, if (window->display->focus_window && window->display->focus_window->client_type == META_WINDOW_CLIENT_TYPE_X11) - focus_group = meta_window_get_group (window->display->focus_window); + focus_group = meta_window_x11_get_group (window->display->focus_window); if (window->client_type == META_WINDOW_CLIENT_TYPE_X11) - window_group = meta_window_get_group (window); + window_group = meta_window_x11_get_group (window); in_group_tab_chain = meta_window_is_focusable (window) && (!focus_group || window_group == focus_group); #endif diff --git a/src/core/stack.c b/src/core/stack.c index 3b47987fd..da8c91186 100644 --- a/src/core/stack.c +++ b/src/core/stack.c @@ -512,7 +512,7 @@ create_constraints (Constraint **constraints, GSList *tmp2; MetaGroup *group; - group = meta_window_get_group (w); + group = meta_window_x11_get_group (w); if (group != NULL) group_windows = meta_group_list_windows (group); diff --git a/src/core/window.c b/src/core/window.c index 7557ef01a..9bf30a791 100644 --- a/src/core/window.c +++ b/src/core/window.c @@ -1455,7 +1455,7 @@ meta_window_unmanage (MetaWindow *window, meta_stack_freeze (window->display->stack); if (window->client_type == META_WINDOW_CLIENT_TYPE_X11) { - group = meta_window_get_group (window); + group = meta_window_x11_get_group (window); if (group) meta_group_update_layers (group); } @@ -1469,7 +1469,7 @@ meta_window_unmanage (MetaWindow *window, * group if window->unmanaging */ #ifdef HAVE_X11_CLIENT if (window->client_type == META_WINDOW_CLIENT_TYPE_X11) - meta_window_shutdown_group (window); + meta_window_x11_shutdown_group (window); #endif /* If we have the focus, focus some other window. @@ -4470,7 +4470,7 @@ meta_window_get_startup_id (MetaWindow *window) { MetaGroup *group; - group = meta_window_get_group (window); + group = meta_window_x11_get_group (window); if (group != NULL) return meta_group_get_startup_id (group); @@ -6114,7 +6114,7 @@ meta_window_update_layer (MetaWindow *window) MetaGroup *group = NULL; if (window->client_type == META_WINDOW_CLIENT_TYPE_X11) - group = meta_window_get_group (window); + group = meta_window_x11_get_group (window); meta_stack_freeze (window->display->stack); if (group) diff --git a/src/meta/group.h b/src/meta/group.h index 0951f4897..35bb28934 100644 --- a/src/meta/group.h +++ b/src/meta/group.h @@ -31,16 +31,7 @@ /* note, can return NULL */ META_EXPORT -MetaGroup* meta_window_get_group (MetaWindow *window); - -META_EXPORT -void meta_window_compute_group (MetaWindow* window); - -META_EXPORT -void meta_window_shutdown_group (MetaWindow *window); - -META_EXPORT -void meta_window_group_leader_changed (MetaWindow *window); +MetaGroup * meta_window_x11_get_group (MetaWindow *window); META_EXPORT GSList* meta_group_list_windows (MetaGroup *group); diff --git a/src/x11/group-private.h b/src/x11/group-private.h index 741303311..fb3fa02ac 100644 --- a/src/x11/group-private.h +++ b/src/x11/group-private.h @@ -32,3 +32,8 @@ struct _MetaGroup char *startup_id; char *wm_client_machine; }; + +MetaGroup * meta_group_new (MetaX11Display *x11_display, + Window group_leader); + +void meta_group_unref (MetaGroup *group); diff --git a/src/x11/group.c b/src/x11/group.c index 454127a94..cddf85608 100644 --- a/src/x11/group.c +++ b/src/x11/group.c @@ -38,7 +38,7 @@ #include "x11/window-x11.h" #include "x11/window-x11-private.h" -static MetaGroup* +MetaGroup* meta_group_new (MetaX11Display *x11_display, Window group_leader) { @@ -95,7 +95,7 @@ meta_group_new (MetaX11Display *x11_display, return g_steal_pointer (&group); } -static void +void meta_group_unref (MetaGroup *group) { g_return_if_fail (group->refcount > 0); @@ -126,124 +126,6 @@ meta_group_unref (MetaGroup *group) } } -/** - * meta_window_get_group: (skip) - * @window: a #MetaWindow - * - * Returns: (transfer none) (nullable): the #MetaGroup of the window - */ -MetaGroup* -meta_window_get_group (MetaWindow *window) -{ - MetaWindowX11 *window_x11; - MetaWindowX11Private *priv; - - if (window->unmanaging) - return NULL; - - window_x11 = META_WINDOW_X11 (window); - priv = meta_window_x11_get_private (window_x11); - - return priv->group; -} - -void -meta_window_compute_group (MetaWindow *window) -{ - MetaGroup *group = NULL; - MetaWindow *ancestor; - MetaX11Display *x11_display = window->display->x11_display; - Window win_leader = meta_window_x11_get_xgroup_leader (window); - MetaWindowX11Private *priv = - meta_window_x11_get_private (META_WINDOW_X11 (window)); - - /* use window->xwindow if no window->xgroup_leader */ - - /* Determine the ancestor of the window; its group setting will override the - * normal grouping rules; see bug 328211. - */ - ancestor = meta_window_find_root_ancestor (window); - - if (x11_display->groups_by_leader) - { - if (ancestor != window) - group = meta_window_get_group (ancestor); - else if (win_leader != None) - group = g_hash_table_lookup (x11_display->groups_by_leader, - &win_leader); - else - { - Window xwindow = meta_window_x11_get_xwindow (window); - group = g_hash_table_lookup (x11_display->groups_by_leader, - &xwindow); - } - } - - if (group != NULL) - { - priv->group = group; - group->refcount += 1; - } - else - { - Window ancestor_leader = meta_window_x11_get_xgroup_leader (ancestor); - - if (ancestor != window && ancestor_leader != None) - group = meta_group_new (x11_display, - ancestor_leader); - else if (win_leader != None) - group = meta_group_new (x11_display, - win_leader); - else - group = meta_group_new (x11_display, - meta_window_x11_get_xwindow (window)); - - priv->group = group; - } - - if (!priv->group) - return; - - priv->group->windows = g_slist_prepend (priv->group->windows, window); - - meta_topic (META_DEBUG_GROUPS, - "Adding %s to group with leader 0x%lx", - window->desc, group->group_leader); -} - -static void -remove_window_from_group (MetaWindow *window) -{ - MetaWindowX11Private *priv = - meta_window_x11_get_private (META_WINDOW_X11 (window)); - - if (priv->group != NULL) - { - meta_topic (META_DEBUG_GROUPS, - "Removing %s from group with leader 0x%lx", - window->desc, priv->group->group_leader); - - priv->group->windows = - g_slist_remove (priv->group->windows, - window); - meta_group_unref (priv->group); - priv->group = NULL; - } -} - -void -meta_window_group_leader_changed (MetaWindow *window) -{ - remove_window_from_group (window); - meta_window_compute_group (window); -} - -void -meta_window_shutdown_group (MetaWindow *window) -{ - remove_window_from_group (window); -} - /** * meta_x11_display_lookup_group: (skip) * @x11_display: a #MetaX11Display diff --git a/src/x11/window-props.c b/src/x11/window-props.c index accbce4b4..96bf35d58 100644 --- a/src/x11/window-props.c +++ b/src/x11/window-props.c @@ -1665,7 +1665,7 @@ reload_wm_hints (MetaWindow *window, meta_verbose ("Window %s changed its group leader to 0x%lx", window->desc, priv->xgroup_leader); - meta_window_group_leader_changed (window); + meta_window_x11_group_leader_changed (window); } meta_window_set_urgent (window, urgent); diff --git a/src/x11/window-x11-private.h b/src/x11/window-x11-private.h index 522b571f0..30bde7dee 100644 --- a/src/x11/window-x11-private.h +++ b/src/x11/window-x11-private.h @@ -108,4 +108,9 @@ gboolean meta_window_x11_has_pointer (MetaWindow *window); gboolean meta_window_x11_same_application (MetaWindow *window, MetaWindow *other_window); +void meta_window_x11_shutdown_group (MetaWindow *window); + +META_EXPORT +void meta_window_x11_group_leader_changed (MetaWindow *window); + G_END_DECLS diff --git a/src/x11/window-x11.c b/src/x11/window-x11.c index b1026f537..95b6b55a0 100644 --- a/src/x11/window-x11.c +++ b/src/x11/window-x11.c @@ -52,6 +52,7 @@ #include "wayland/meta-window-xwayland.h" #endif +#include "x11/group-private.h" #include "x11/meta-sync-counter.h" #include "x11/meta-x11-display-private.h" #include "x11/session.h" @@ -95,6 +96,9 @@ static void meta_window_x11_impl_process_property_notify (MetaWindow *window, XPropertyEvent *event); +static void +meta_window_x11_compute_group (MetaWindow *window); + static void meta_window_x11_init (MetaWindowX11 *window_x11) { @@ -559,7 +563,7 @@ meta_window_x11_manage (MetaWindow *window) /* assign the window to its group, or create a new group if needed */ priv->group = NULL; priv->xgroup_leader = None; - meta_window_compute_group (window); + meta_window_x11_compute_group (window); meta_window_load_initial_properties (window); @@ -1881,7 +1885,7 @@ get_maximum_layer_in_group (MetaWindow *window) max = META_LAYER_DESKTOP; - group = meta_window_get_group (window); + group = meta_window_x11_get_group (window); if (group != NULL) members = meta_group_list_windows (group); @@ -2035,7 +2039,7 @@ meta_window_x11_set_transient_for (MetaWindow *window, if (xtransient_for != None && priv->xgroup_leader != None && xtransient_for != priv->xgroup_leader) - meta_window_group_leader_changed (window); + meta_window_x11_group_leader_changed (window); return TRUE; } @@ -4491,10 +4495,128 @@ gboolean meta_window_x11_same_application (MetaWindow *window, MetaWindow *other_window) { - MetaGroup *group = meta_window_get_group (window); - MetaGroup *other_group = meta_window_get_group (other_window); + MetaGroup *group = meta_window_x11_get_group (window); + MetaGroup *other_group = meta_window_x11_get_group (other_window); return (group != NULL && other_group != NULL && group == other_group); } + +/** + * meta_window_x11_get_group: (skip) + * @window: a #MetaWindow + * + * Returns: (transfer none) (nullable): the #MetaGroup of the window + */ +MetaGroup* +meta_window_x11_get_group (MetaWindow *window) +{ + MetaWindowX11 *window_x11; + MetaWindowX11Private *priv; + + if (window->unmanaging) + return NULL; + + window_x11 = META_WINDOW_X11 (window); + priv = meta_window_x11_get_private (window_x11); + + return priv->group; +} + +static void +meta_window_x11_compute_group (MetaWindow *window) +{ + MetaGroup *group = NULL; + MetaWindow *ancestor; + MetaX11Display *x11_display = window->display->x11_display; + Window win_leader = meta_window_x11_get_xgroup_leader (window); + MetaWindowX11Private *priv = + meta_window_x11_get_private (META_WINDOW_X11 (window)); + + /* use window->xwindow if no window->xgroup_leader */ + + /* Determine the ancestor of the window; its group setting will override the + * normal grouping rules; see bug 328211. + */ + ancestor = meta_window_find_root_ancestor (window); + + if (x11_display->groups_by_leader) + { + if (ancestor != window) + group = meta_window_x11_get_group (ancestor); + else if (win_leader != None) + group = g_hash_table_lookup (x11_display->groups_by_leader, + &win_leader); + else + { + Window xwindow = meta_window_x11_get_xwindow (window); + group = g_hash_table_lookup (x11_display->groups_by_leader, + &xwindow); + } + } + + if (group != NULL) + { + priv->group = group; + group->refcount += 1; + } + else + { + Window ancestor_leader = meta_window_x11_get_xgroup_leader (ancestor); + + if (ancestor != window && ancestor_leader != None) + group = meta_group_new (x11_display, + ancestor_leader); + else if (win_leader != None) + group = meta_group_new (x11_display, + win_leader); + else + group = meta_group_new (x11_display, + meta_window_x11_get_xwindow (window)); + + priv->group = group; + } + + if (!priv->group) + return; + + priv->group->windows = g_slist_prepend (priv->group->windows, window); + + meta_topic (META_DEBUG_GROUPS, + "Adding %s to group with leader 0x%lx", + window->desc, group->group_leader); +} + +static void +remove_window_from_group (MetaWindow *window) +{ + MetaWindowX11Private *priv = + meta_window_x11_get_private (META_WINDOW_X11 (window)); + + if (priv->group != NULL) + { + meta_topic (META_DEBUG_GROUPS, + "Removing %s from group with leader 0x%lx", + window->desc, priv->group->group_leader); + + priv->group->windows = + g_slist_remove (priv->group->windows, + window); + meta_group_unref (priv->group); + priv->group = NULL; + } +} + +void +meta_window_x11_group_leader_changed (MetaWindow *window) +{ + remove_window_from_group (window); + meta_window_x11_compute_group (window); +} + +void +meta_window_x11_shutdown_group (MetaWindow *window) +{ + remove_window_from_group (window); +}