window: Defer stack placement without a buffer

When closing a window and showing a new one, the new one may not be
granted input focus until it gets a buffer on Wayland.

If another window is chosen to receive focus and raised on top of stack,
the newly mapped window is focused but placed underneath that other
window.

Meaning that for Wayland surfaces, we need to defer adding the window to
the stack until we actually get to show it, once we have a buffer
attached.

Rather that checking the windowing backend prior to decide if a window
is stackable or not, introduce a new vfunc is_stackable() which tells
if a window should be added to the stack regardless of the underlying
windowing system.

Also add meta_window_is_in_stack() API rather than checking the stack
position directly (replacing the define WINDOW_IN_STACK only available
in stack.c) and remove a window from the stack only if it is present
in the stack, so that the test in meta_stack_remote() becomes
irrelevant.

https://bugzilla.gnome.org/show_bug.cgi?id=780820
This commit is contained in:
Olivier Fourdan 2018-01-09 13:19:40 +01:00
parent 2d090f9232
commit bd9a300801
5 changed files with 42 additions and 14 deletions

View File

@ -49,8 +49,6 @@
#define WINDOW_TRANSIENT_FOR_WHOLE_GROUP(w) \
(WINDOW_HAS_TRANSIENT_TYPE (w) && w->transient_for == NULL)
#define WINDOW_IN_STACK(w) (w->stack_position >= 0)
static void stack_sync_to_xserver (MetaStack *stack);
static void meta_window_set_stack_position_no_sync (MetaWindow *window,
int position);
@ -102,11 +100,11 @@ void
meta_stack_add (MetaStack *stack,
MetaWindow *window)
{
g_return_if_fail (!window->override_redirect);
g_return_if_fail (meta_window_is_stackable (window));
meta_topic (META_DEBUG_STACK, "Adding window %s to the stack\n", window->desc);
if (window->stack_position >= 0)
if (meta_window_is_in_stack (window))
meta_bug ("Window %s had stack position already\n", window->desc);
stack->added = g_list_prepend (stack->added, window);
@ -127,10 +125,6 @@ meta_stack_remove (MetaStack *stack,
{
meta_topic (META_DEBUG_STACK, "Removing window %s from the stack\n", window->desc);
if (window->stack_position < 0)
meta_bug ("Window %s removed from stack but had no stack position\n",
window->desc);
/* Set window to top position, so removing it will not leave gaps
* in the set of positions
*/
@ -530,7 +524,7 @@ create_constraints (Constraint **constraints,
{
MetaWindow *w = tmp->data;
if (!WINDOW_IN_STACK (w))
if (!meta_window_is_in_stack (w))
{
meta_topic (META_DEBUG_STACK, "Window %s not in the stack, not constraining it\n",
w->desc);
@ -557,7 +551,7 @@ create_constraints (Constraint **constraints,
{
MetaWindow *group_window = tmp2->data;
if (!WINDOW_IN_STACK (group_window) ||
if (!meta_window_is_in_stack (group_window) ||
w->screen != group_window->screen ||
group_window->override_redirect)
{
@ -592,7 +586,7 @@ create_constraints (Constraint **constraints,
parent = w->transient_for;
if (parent && WINDOW_IN_STACK (parent))
if (parent && meta_window_is_in_stack (parent))
{
meta_topic (META_DEBUG_STACK, "Constraining %s above %s due to transiency\n",
w->desc, parent->desc);

View File

@ -553,6 +553,7 @@ struct _MetaWindowClass
ClutterInputDevice *source);
gboolean (*shortcuts_inhibited) (MetaWindow *window,
ClutterInputDevice *source);
gboolean (*is_stackable) (MetaWindow *window);
};
/* These differ from window->has_foo_func in that they consider
@ -699,6 +700,8 @@ void meta_window_set_type (MetaWindow *window,
void meta_window_frame_size_changed (MetaWindow *window);
gboolean meta_window_is_in_stack (MetaWindow *window);
void meta_window_stack_just_below (MetaWindow *window,
MetaWindow *below_this_one);
@ -795,4 +798,5 @@ void meta_window_force_restore_shortcuts (MetaWindow *window,
gboolean meta_window_shortcuts_inhibited (MetaWindow *window,
ClutterInputDevice *source);
gboolean meta_window_is_stackable (MetaWindow *window);
#endif

View File

@ -1298,10 +1298,10 @@ _meta_window_shared_new (MetaDisplay *display,
* and thus constraints may try to auto-fullscreen it which also
* means restacking it.
*/
if (!window->override_redirect)
if (meta_window_is_stackable (window))
meta_stack_add (window->screen->stack,
window);
else
else if (window->override_redirect)
window->layer = META_LAYER_OVERRIDE_REDIRECT; /* otherwise set by MetaStack */
if (!window->override_redirect)
@ -1535,7 +1535,7 @@ meta_window_unmanage (MetaWindow *window,
meta_window_main_monitor_changed (window, old);
}
if (!window->override_redirect)
if (meta_window_is_in_stack (window))
meta_stack_remove (window->screen->stack, window);
/* If an undecorated window is being withdrawn, that will change the
@ -1698,6 +1698,10 @@ implement_showing (MetaWindow *window,
meta_verbose ("Implement showing = %d for window %s\n",
showing, window->desc);
/* Some windows are not stackable until being showed, so add those now. */
if (meta_window_is_stackable (window) && !meta_window_is_in_stack (window))
meta_stack_add (window->screen->stack, window);
if (!showing)
{
/* When we manage a new window, we normally delay placing it
@ -6897,6 +6901,12 @@ ensure_mru_position_after (MetaWindow *window,
}
}
gboolean
meta_window_is_in_stack (MetaWindow *window)
{
return window->stack_position >= 0;
}
void
meta_window_stack_just_below (MetaWindow *window,
MetaWindow *below_this_one)
@ -8425,3 +8435,9 @@ meta_window_shortcuts_inhibited (MetaWindow *window,
{
return META_WINDOW_GET_CLASS (window)->shortcuts_inhibited (window, source);
}
gboolean
meta_window_is_stackable (MetaWindow *window)
{
return META_WINDOW_GET_CLASS (window)->is_stackable (window);
}

View File

@ -543,6 +543,12 @@ meta_window_wayland_shortcuts_inhibited (MetaWindow *window,
return meta_wayland_compositor_is_shortcuts_inhibited (compositor, source);
}
static gboolean
meta_window_wayland_is_stackable (MetaWindow *window)
{
return meta_wayland_surface_get_buffer (window->surface) != NULL;
}
static void
meta_window_wayland_class_init (MetaWindowWaylandClass *klass)
{
@ -562,6 +568,7 @@ meta_window_wayland_class_init (MetaWindowWaylandClass *klass)
window_class->get_client_pid = meta_window_wayland_get_client_pid;
window_class->force_restore_shortcuts = meta_window_wayland_force_restore_shortcuts;
window_class->shortcuts_inhibited = meta_window_wayland_shortcuts_inhibited;
window_class->is_stackable = meta_window_wayland_is_stackable;
}
MetaWindow *

View File

@ -1549,6 +1549,12 @@ meta_window_x11_shortcuts_inhibited (MetaWindow *window,
return FALSE;
}
static gboolean
meta_window_x11_is_stackable (MetaWindow *window)
{
return !window->override_redirect;
}
static void
meta_window_x11_class_init (MetaWindowX11Class *klass)
{
@ -1572,6 +1578,7 @@ meta_window_x11_class_init (MetaWindowX11Class *klass)
window_class->get_client_pid = meta_window_x11_get_client_pid;
window_class->force_restore_shortcuts = meta_window_x11_force_restore_shortcuts;
window_class->shortcuts_inhibited = meta_window_x11_shortcuts_inhibited;
window_class->is_stackable = meta_window_x11_is_stackable;
}
void