1
0
Fork 0

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: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3555>
This commit is contained in:
Bilal Elmoussaoui 2024-01-31 15:52:18 +01:00
parent f0c22cb3bc
commit e1e6534eb2
9 changed files with 148 additions and 143 deletions

View file

@ -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

View file

@ -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);

View file

@ -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)

View file

@ -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);

View file

@ -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);

View file

@ -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

View file

@ -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);

View file

@ -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

View file

@ -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);
}