diff --git a/src/core/display.c b/src/core/display.c index 413b62a04..01e97dafd 100644 --- a/src/core/display.c +++ b/src/core/display.c @@ -779,10 +779,12 @@ meta_display_open (void) if (old_active_window) meta_window_focus (old_active_window, timestamp); else - meta_x11_display_focus_the_no_focus_window (display->x11_display, timestamp); + meta_display_unset_input_focus (display, timestamp); + } + else + { + meta_display_unset_input_focus (display, timestamp); } - else if (display->x11_display) - meta_x11_display_focus_the_no_focus_window (display->x11_display, timestamp); meta_idle_monitor_init_dbus (); @@ -1307,6 +1309,51 @@ meta_display_timestamp_too_old (MetaDisplay *display, return FALSE; } +void +meta_display_set_input_focus (MetaDisplay *display, + MetaWindow *window, + gboolean focus_frame, + guint32 timestamp) +{ + if (meta_display_timestamp_too_old (display, ×tamp)) + return; + + if (display->x11_display) + { + MetaX11Display *x11_display = display->x11_display; + Window xwindow; + gulong serial; + + meta_x11_error_trap_push (x11_display); + + if (window) + xwindow = focus_frame ? window->frame->xwindow : window->xwindow; + else + xwindow = x11_display->no_focus_window; + + meta_x11_display_set_input_focus (x11_display, xwindow, timestamp); + serial = XNextRequest (x11_display->xdisplay); + + meta_x11_display_update_focus_window (x11_display, xwindow, serial, TRUE); + + meta_x11_error_trap_pop (display->x11_display); + } + + meta_display_update_focus_window (display, window); + + display->last_focus_time = timestamp; + + if (window == NULL || window != display->autoraise_window) + meta_display_remove_autoraise_callback (display); +} + +void +meta_display_unset_input_focus (MetaDisplay *display, + guint32 timestamp) +{ + meta_display_set_input_focus (display, NULL, FALSE, timestamp); +} + void meta_display_register_wayland_window (MetaDisplay *display, MetaWindow *window) diff --git a/src/core/window.c b/src/core/window.c index 5721dadf1..caa1059e3 100644 --- a/src/core/window.c +++ b/src/core/window.c @@ -8088,8 +8088,7 @@ mouse_mode_focus (MetaWindow *window, "Unsetting focus from %s due to mouse entering " "the DESKTOP window\n", display->focus_window->desc); - meta_x11_display_focus_the_no_focus_window (display->x11_display, - timestamp); + meta_display_unset_input_focus (display, timestamp); } } } diff --git a/src/core/workspace.c b/src/core/workspace.c index b4fd836c9..71c54d229 100644 --- a/src/core/workspace.c +++ b/src/core/workspace.c @@ -1308,8 +1308,7 @@ meta_workspace_focus_default_window (MetaWorkspace *workspace, meta_topic (META_DEBUG_FOCUS, "Setting focus to no_focus_window, since no valid " "window to focus found.\n"); - meta_x11_display_focus_the_no_focus_window (workspace->display->x11_display, - timestamp); + meta_display_unset_input_focus (workspace->display, timestamp); } } } @@ -1381,8 +1380,7 @@ focus_ancestor_or_top_window (MetaWorkspace *workspace, else { meta_topic (META_DEBUG_FOCUS, "No MRU window to focus found; focusing no_focus_window.\n"); - meta_x11_display_focus_the_no_focus_window (workspace->display->x11_display, - timestamp); + meta_display_unset_input_focus (workspace->display, timestamp); } } diff --git a/src/meta/display.h b/src/meta/display.h index 09c1f99ec..5cf99cfea 100644 --- a/src/meta/display.h +++ b/src/meta/display.h @@ -297,4 +297,13 @@ MetaSoundPlayer * meta_display_get_sound_player (MetaDisplay *display); META_EXPORT MetaSelection * meta_display_get_selection (MetaDisplay *display); +META_EXPORT +void meta_display_set_input_focus (MetaDisplay *display, + MetaWindow *window, + gboolean focus_frame, + guint32 timestamp); +META_EXPORT +void meta_display_unset_input_focus (MetaDisplay *display, + guint32 timestamp); + #endif diff --git a/src/meta/meta-x11-display.h b/src/meta/meta-x11-display.h index f5167af7d..9c9adf9b7 100644 --- a/src/meta/meta-x11-display.h +++ b/src/meta/meta-x11-display.h @@ -63,27 +63,4 @@ META_EXPORT gboolean meta_x11_display_xwindow_is_a_no_focus_window (MetaX11Display *x11_display, Window xwindow); -/* meta_x11_display_set_input_focus_window is like XSetInputFocus, except - * that (a) it can't detect timestamps later than the current time, - * since Mutter isn't part of the XServer, and thus gives erroneous - * behavior in this circumstance (so don't do it), (b) it uses - * display->last_focus_time since we don't have access to the true - * Xserver one, (c) it makes use of display->user_time since checking - * whether a window should be allowed to be focused should depend - * on user_time events (see bug 167358, comment 15 in particular) - */ -META_EXPORT -void meta_x11_display_set_input_focus_window (MetaX11Display *x11_display, - MetaWindow *window, - gboolean focus_frame, - guint32 timestamp); - -/* meta_x11_display_focus_the_no_focus_window is called when the - * designated no_focus_window should be focused, but is otherwise the - * same as meta_display_set_input_focus_window - */ -META_EXPORT -void meta_x11_display_focus_the_no_focus_window (MetaX11Display *x11_display, - guint32 timestamp); - #endif /* META_X11_DISPLAY_H */ diff --git a/src/wayland/meta-window-wayland.c b/src/wayland/meta-window-wayland.c index 0b0f6bb66..8191adadd 100644 --- a/src/wayland/meta-window-wayland.c +++ b/src/wayland/meta-window-wayland.c @@ -142,10 +142,12 @@ meta_window_wayland_focus (MetaWindow *window, guint32 timestamp) { if (meta_window_is_focusable (window)) - meta_x11_display_set_input_focus_window (window->display->x11_display, - window, - FALSE, - timestamp); + { + meta_display_set_input_focus (window->display, + window, + FALSE, + timestamp); + } } static void diff --git a/src/x11/meta-x11-display-private.h b/src/x11/meta-x11-display-private.h index 0a6cafda0..3f545ce28 100644 --- a/src/x11/meta-x11-display-private.h +++ b/src/x11/meta-x11-display-private.h @@ -245,5 +245,8 @@ void meta_x11_display_update_focus_window (MetaX11Display *x11_display, Window xwindow, gulong serial, gboolean focused_by_us); +void meta_x11_display_set_input_focus (MetaX11Display *x11_display, + Window xwindow, + guint32 timestamp); #endif /* META_X11_DISPLAY_PRIVATE_H */ diff --git a/src/x11/meta-x11-display.c b/src/x11/meta-x11-display.c index 4711ca0aa..f7e0c2f56 100644 --- a/src/x11/meta-x11-display.c +++ b/src/x11/meta-x11-display.c @@ -1838,17 +1838,11 @@ meta_x11_display_update_focus_window (MetaX11Display *x11_display, meta_x11_display_update_active_window_hint (x11_display); } -static void -request_xserver_input_focus_change (MetaX11Display *x11_display, - MetaWindow *meta_window, - Window xwindow, - guint32 timestamp) +void +meta_x11_display_set_input_focus (MetaX11Display *x11_display, + Window xwindow, + guint32 timestamp) { - gulong serial; - - if (meta_display_timestamp_too_old (x11_display->display, ×tamp)) - return; - meta_x11_error_trap_push (x11_display); /* In order for mutter to know that the focus request succeeded, we track @@ -1861,8 +1855,6 @@ request_xserver_input_focus_change (MetaX11Display *x11_display, */ XGrabServer (x11_display->xdisplay); - serial = XNextRequest (x11_display->xdisplay); - XSetInputFocus (x11_display->xdisplay, xwindow, RevertToPointerRoot, @@ -1876,27 +1868,7 @@ request_xserver_input_focus_change (MetaX11Display *x11_display, XUngrabServer (x11_display->xdisplay); XFlush (x11_display->xdisplay); - meta_display_update_focus_window (x11_display->display, meta_window); - meta_x11_display_update_focus_window (x11_display, xwindow, serial, TRUE); - meta_x11_error_trap_pop (x11_display); - - x11_display->display->last_focus_time = timestamp; - - if (meta_window == NULL || meta_window != x11_display->display->autoraise_window) - meta_display_remove_autoraise_callback (x11_display->display); -} - -void -meta_x11_display_set_input_focus_window (MetaX11Display *x11_display, - MetaWindow *window, - gboolean focus_frame, - guint32 timestamp) -{ - request_xserver_input_focus_change (x11_display, - window, - focus_frame ? window->frame->xwindow : window->xwindow, - timestamp); } void @@ -1904,20 +1876,12 @@ meta_x11_display_set_input_focus_xwindow (MetaX11Display *x11_display, Window window, guint32 timestamp) { - request_xserver_input_focus_change (x11_display, - NULL, - window, - timestamp); -} + gulong serial; -void -meta_x11_display_focus_the_no_focus_window (MetaX11Display *x11_display, - guint32 timestamp) -{ - request_xserver_input_focus_change (x11_display, - NULL, - x11_display->no_focus_window, - timestamp); + meta_display_unset_input_focus (x11_display->display, timestamp); + serial = XNextRequest (x11_display->xdisplay); + meta_x11_display_set_input_focus (x11_display, window, timestamp); + meta_x11_display_update_focus_window (x11_display, window, serial, TRUE); } static MetaX11DisplayLogicalMonitorData * diff --git a/src/x11/window-x11.c b/src/x11/window-x11.c index fd19766bb..1f492984e 100644 --- a/src/x11/window-x11.c +++ b/src/x11/window-x11.c @@ -794,10 +794,10 @@ meta_window_x11_focus (MetaWindow *window, { meta_topic (META_DEBUG_FOCUS, "Focusing frame of %s\n", window->desc); - meta_x11_display_set_input_focus_window (window->display->x11_display, - window, - TRUE, - timestamp); + meta_display_set_input_focus (window->display, + window, + TRUE, + timestamp); } else { @@ -806,10 +806,10 @@ meta_window_x11_focus (MetaWindow *window, meta_topic (META_DEBUG_FOCUS, "Setting input focus on %s since input = true\n", window->desc); - meta_x11_display_set_input_focus_window (window->display->x11_display, - window, - FALSE, - timestamp); + meta_display_set_input_focus (window->display, + window, + FALSE, + timestamp); } if (priv->wm_take_focus) @@ -832,8 +832,7 @@ meta_window_x11_focus (MetaWindow *window, */ if (window->display->focus_window != NULL && window->display->focus_window->unmanaging) - meta_x11_display_focus_the_no_focus_window (window->display->x11_display, - timestamp); + meta_display_unset_input_focus (window->display, timestamp); } request_take_focus (window, timestamp);