core: Subscribe to stack changes in the stack-tracker

This removes the implicit dependency on `display->stack_tracker`
existing and being valid in `on_stack_changed()` because
now it is the stack-tracker's responsibility to subscribe
to the "changed" signal of the stack and handle the changes.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3202>
This commit is contained in:
Barnabás Pőcze
2023-06-08 02:49:35 +02:00
parent af10ead918
commit d6b3679bd3
4 changed files with 97 additions and 89 deletions

View File

@ -71,92 +71,9 @@ static guint signals[N_SIGNALS] = { 0 };
G_DEFINE_TYPE (MetaStack, meta_stack, G_TYPE_OBJECT)
static void
on_stack_changed (MetaStack *stack)
{
MetaDisplay *display = stack->display;
GArray *all_root_children_stacked;
GList *l;
GArray *hidden_stack_ids;
GList *sorted;
COGL_TRACE_BEGIN_SCOPED (StackChanged, "Stack changed");
meta_topic (META_DEBUG_STACK, "Syncing window stack to server");
all_root_children_stacked = g_array_new (FALSE, FALSE, sizeof (uint64_t));
hidden_stack_ids = g_array_new (FALSE, FALSE, sizeof (uint64_t));
meta_topic (META_DEBUG_STACK, "Bottom to top: ");
sorted = meta_stack_list_windows (stack, NULL);
for (l = sorted; l; l = l->next)
{
MetaWindow *w = l->data;
uint64_t top_level_window;
uint64_t stack_id;
if (w->unmanaging)
continue;
meta_topic (META_DEBUG_STACK, " %u:%d - %s ",
w->layer, w->stack_position, w->desc);
if (w->frame)
top_level_window = w->frame->xwindow;
else
top_level_window = w->xwindow;
if (w->client_type == META_WINDOW_CLIENT_TYPE_X11)
stack_id = top_level_window;
else
stack_id = w->stamp;
/* We don't restack hidden windows along with the rest, though they are
* reflected in the _NET hints. Hidden windows all get pushed below
* the screens fullscreen guard_window. */
if (w->hidden)
{
g_array_append_val (hidden_stack_ids, stack_id);
continue;
}
g_array_append_val (all_root_children_stacked, stack_id);
}
if (display->x11_display)
{
uint64_t guard_window_id;
/* The screen guard window sits above all hidden windows and acts as
* a barrier to input reaching these windows. */
guard_window_id = display->x11_display->guard_window;
g_array_append_val (hidden_stack_ids, guard_window_id);
}
/* Sync to server */
meta_topic (META_DEBUG_STACK, "Restacking %u windows",
all_root_children_stacked->len);
meta_stack_tracker_restack_managed (display->stack_tracker,
(uint64_t *)all_root_children_stacked->data,
all_root_children_stacked->len);
meta_stack_tracker_restack_at_bottom (display->stack_tracker,
(uint64_t *)hidden_stack_ids->data,
hidden_stack_ids->len);
g_array_free (hidden_stack_ids, TRUE);
g_array_free (all_root_children_stacked, TRUE);
g_list_free (sorted);
}
static void
meta_stack_init (MetaStack *stack)
{
g_signal_connect (stack, "changed",
G_CALLBACK (on_stack_changed), NULL);
}
static void