Compare commits

...

2 Commits

Author SHA1 Message Date
c7b8f26cad compositor: Add an API to query if the stage is focused
gnome-shell needs to know whether the stage window is focused so
it can synchronize between stage window focus and Clutter key actor
focus. Track all X windows, even those without MetaWindows, when
tracking the focus window, and add a compositor-level API to determine
when the stage is focused.
2013-05-28 15:07:13 -04:00
8747b97ba3 display: Ensure that we ignore our own focus events for focus predictions
When we set the input focus, we first set the predicted window,
and then try to process focus events. But as XI_FocusOut on the
existing window comes before XI_FocusIn on the new window, we'll
see the focus out on the old window and think the focus is going
to nothing, which makes mutter think the prediction failed.

This didn't really matter as nothing paid attention to the focus
window changing, but with gnome-shell's focus rework, we'll try
and drop keyboard focus in events like these.

Fix this by making sure that we ignore focus window changes of our
own cause when updating the focus window field, by ignoring all
focus events that have a serial the same as the focus request or
lower. Note that if mutter doens't make any requests after the
focus request, this could be racy, as another client could steal
the focus, but mutter would ignore it as the serial was the same.
Bump the serial by making a dummy ChangeProperty request to the
root window in this case.

https://bugzilla.gnome.org/show_bug.cgi?id=701017
2013-05-28 14:59:20 -04:00
5 changed files with 61 additions and 5 deletions

View File

@ -391,6 +391,24 @@ meta_focus_stage_window (MetaScreen *screen,
timestamp);
}
gboolean
meta_stage_is_focused (MetaScreen *screen)
{
ClutterStage *stage;
Window window;
stage = CLUTTER_STAGE (meta_get_stage_for_screen (screen));
if (!stage)
return FALSE;
window = clutter_x11_get_stage_window (stage);
if (window == None)
return FALSE;
return (screen->display->focus_xwindow == window);
}
gboolean
meta_begin_modal_for_plugin (MetaScreen *screen,
MetaPlugin *plugin,

View File

@ -113,6 +113,9 @@ struct _MetaDisplay
* or event that caused this.
*/
MetaWindow *focus_window;
/* For windows we've focused that don't necessarily have an X window,
* like the no_focus_window or the stage X window. */
Window focus_xwindow;
gulong focus_serial;
/* last timestamp passed to XSetInputFocus */

View File

@ -1876,11 +1876,12 @@ get_input_event (MetaDisplay *display,
static void
update_focus_window (MetaDisplay *display,
MetaWindow *window,
Window xwindow,
gulong serial)
{
display->focus_serial = serial;
if (window == display->focus_window)
if (display->focus_xwindow == xwindow)
return;
if (display->focus_window)
@ -1897,11 +1898,13 @@ update_focus_window (MetaDisplay *display,
*/
previous = display->focus_window;
display->focus_window = NULL;
display->focus_xwindow = None;
meta_window_set_focused_internal (previous, FALSE);
}
display->focus_window = window;
display->focus_xwindow = xwindow;
if (display->focus_window)
{
@ -1952,6 +1955,7 @@ request_xserver_input_focus_change (MetaDisplay *display,
guint32 timestamp)
{
MetaWindow *meta_window;
gulong serial;
if (timestamp_too_old (display, &timestamp))
return;
@ -1959,14 +1963,40 @@ request_xserver_input_focus_change (MetaDisplay *display,
meta_window = meta_display_lookup_x_window (display, xwindow);
meta_error_trap_push (display);
update_focus_window (display,
meta_window,
XNextRequest (display->xdisplay));
/* In order for mutter to know that the focus request succeeded, we track
* the serial of the "focus request" we made, but if we take the serial
* of the XSetInputFocus request, then there's no way to determine the
* difference between focus events as a result of the SetInputFocus and
* focus events that other clients send around the same time. Ensure that
* we know which is which by making two requests that the server will
* process at the same time.
*/
meta_display_grab (display);
XSetInputFocus (display->xdisplay,
xwindow,
RevertToPointerRoot,
timestamp);
serial = XNextRequest (display->xdisplay);
{
unsigned long data[1] = { 0 };
XChangeProperty (display->xdisplay, display->timestamp_pinging_window,
display->atom__MUTTER_FOCUS_SET,
XA_CARDINAL,
32, PropModeReplace, (guchar*) data, 1);
}
meta_display_ungrab (display);
update_focus_window (display,
meta_window,
xwindow,
serial);
meta_error_trap_pop (display);
display->last_focus_time = timestamp;
@ -2081,7 +2111,9 @@ handle_window_focus_event (MetaDisplay *display,
if (display->server_focus_serial >= display->focus_serial)
{
update_focus_window (display, focus_window,
update_focus_window (display,
focus_window,
focus_window ? focus_window->xwindow : None,
display->server_focus_serial);
}
}
@ -2137,6 +2169,7 @@ event_callback (XEvent *event,
display->focus_window->desc);
update_focus_window (display,
meta_display_lookup_x_window (display, display->server_focus_window),
display->server_focus_window,
display->server_focus_serial);
}

View File

@ -70,6 +70,7 @@ item(_GNOME_WM_KEYBINDINGS)
item(_GNOME_PANEL_ACTION)
item(_GNOME_PANEL_ACTION_MAIN_MENU)
item(_GNOME_PANEL_ACTION_RUN_DIALOG)
item(_MUTTER_FOCUS_SET)
item(_MUTTER_SENTINEL)
item(_MUTTER_VERSION)
item(WM_CLIENT_MACHINE)

View File

@ -48,5 +48,6 @@ void meta_set_stage_input_region (MetaScreen *screen,
void meta_empty_stage_input_region (MetaScreen *screen);
void meta_focus_stage_window (MetaScreen *screen,
guint32 timestamp);
gboolean meta_stage_is_focused (MetaScreen *screen);
#endif