core: Preserve focus across decoration changes

Changes in window decoration result in the window being reparented
in and out its frame. This in turn causes unmap/map events, and
XI_FocusOut if the window happened to be focused.

In order to preserve the focused window across the decoration change,
add a flag so that the focus may be restored on MapNotify.

Closes: 

(cherry picked from commit 8dcac664faf03ac2ea382e44d587d1f7dc92f7a3)
This commit is contained in:
Carlos Garnacho 2018-08-22 00:58:06 +02:00 committed by Olivier Fourdan
parent f7658ac5f0
commit 49c06fd9b1
4 changed files with 24 additions and 0 deletions

@ -105,6 +105,12 @@ meta_window_ensure_frame (MetaWindow *window)
/* FIXME handle this error */
meta_error_trap_pop (window->display);
/* Ensure focus is restored after the unmap/map events triggered
* by XReparentWindow().
*/
if (meta_window_has_focus (window))
window->restore_focus_on_map = TRUE;
/* stick frame to the window */
window->frame = frame;
@ -194,6 +200,12 @@ meta_window_destroy_frame (MetaWindow *window)
meta_ui_frame_unmanage (frame->ui_frame);
/* Ensure focus is restored after the unmap/map events triggered
* by XReparentWindow().
*/
if (meta_window_has_focus (window))
window->restore_focus_on_map = TRUE;
meta_display_unregister_x_window (window->display,
frame->xwindow);

@ -416,6 +416,9 @@ struct _MetaWindow
/* whether or not the window is from a program running on another machine */
guint is_remote : 1;
/* whether focus should be restored on map */
guint restore_focus_on_map : 1;
/* if non-NULL, the bounds of the window frame */
cairo_region_t *frame_bounds;

@ -4629,6 +4629,9 @@ meta_window_focus (MetaWindow *window,
g_return_if_fail (!window->override_redirect);
/* This is a oneshot flag */
window->restore_focus_on_map = FALSE;
meta_topic (META_DEBUG_FOCUS,
"Setting input focus to window %s, input: %d take_focus: %d\n",
window->desc, window->input, window->take_focus);

@ -1365,6 +1365,12 @@ handle_other_xevent (MetaDisplay *display,
window = meta_window_x11_new (display, event->xmap.window,
FALSE, META_COMP_EFFECT_CREATE);
}
else if (window && window->restore_focus_on_map)
{
meta_window_focus (window,
meta_display_get_current_time_roundtrip (display));
}
break;
case MapRequest:
if (window == NULL)