From 4c607164fd95d551014248b190c1a7962596041b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Tue, 13 Nov 2018 01:56:53 -0600 Subject: [PATCH] window: Add is_focusable class method Implement is_focusable for both x11 and wayland and just use this check so that we can abstract things more and be less dependent on window backend. --- src/core/stack.c | 5 +---- src/core/window-private.h | 3 +++ src/core/window.c | 11 ++++++++++- src/core/workspace.c | 2 +- src/wayland/meta-window-wayland.c | 9 ++++++++- src/x11/window-x11.c | 10 ++++++++-- 6 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/core/stack.c b/src/core/stack.c index 28fd94c54..a37d6e37d 100644 --- a/src/core/stack.c +++ b/src/core/stack.c @@ -1214,10 +1214,7 @@ get_default_focus_window (MetaStack *stack, if (window->unmaps_pending > 0) continue; - if (window->unmanaging) - continue; - - if (!(window->input || window->take_focus)) + if (!meta_window_is_focusable (window)) continue; if (!meta_window_should_be_showing (window)) diff --git a/src/core/window-private.h b/src/core/window-private.h index 4cc05d934..81322eb13 100644 --- a/src/core/window-private.h +++ b/src/core/window-private.h @@ -570,6 +570,7 @@ struct _MetaWindowClass ClutterInputDevice *source); gboolean (*shortcuts_inhibited) (MetaWindow *window, ClutterInputDevice *source); + gboolean (*is_focusable) (MetaWindow *window); gboolean (*is_stackable) (MetaWindow *window); gboolean (*are_updates_frozen) (MetaWindow *window); }; @@ -664,6 +665,8 @@ void meta_window_update_unfocused_button_grabs (MetaWindow *window); void meta_window_set_focused_internal (MetaWindow *window, gboolean focused); +gboolean meta_window_is_focusable (MetaWindow *window); + void meta_window_current_workspace_changed (MetaWindow *window); void meta_window_show_menu (MetaWindow *window, diff --git a/src/core/window.c b/src/core/window.c index 4d9e51d8c..6ab060756 100644 --- a/src/core/window.c +++ b/src/core/window.c @@ -2205,7 +2205,7 @@ window_state_on_map (MetaWindow *window, /* don't initially focus windows that are intended to not accept * focus */ - if (!(window->input || window->take_focus)) + if (!meta_window_is_focusable (window)) { *takes_focus = FALSE; return; @@ -8512,6 +8512,15 @@ meta_window_shortcuts_inhibited (MetaWindow *window, return META_WINDOW_GET_CLASS (window)->shortcuts_inhibited (window, source); } +gboolean +meta_window_is_focusable (MetaWindow *window) +{ + if (window->unmanaging) + return FALSE; + + return META_WINDOW_GET_CLASS (window)->is_focusable (window); +} + gboolean meta_window_is_stackable (MetaWindow *window) { diff --git a/src/core/workspace.c b/src/core/workspace.c index 1d8d8104c..231a4544b 100644 --- a/src/core/workspace.c +++ b/src/core/workspace.c @@ -1340,7 +1340,7 @@ find_focusable_ancestor (MetaWindow *window, MetaWorkspaceFocusableAncestorData *mwfa = data; MetaWindow **result = mwfa->win; - if ((window->input || window->take_focus) && + if (meta_window_is_focusable (window) && meta_window_located_on_workspace (window, mwfa->workspace) && meta_window_showing_on_its_workspace (window)) { diff --git a/src/wayland/meta-window-wayland.c b/src/wayland/meta-window-wayland.c index dffee486d..c4a888dcb 100644 --- a/src/wayland/meta-window-wayland.c +++ b/src/wayland/meta-window-wayland.c @@ -141,7 +141,7 @@ static void meta_window_wayland_focus (MetaWindow *window, guint32 timestamp) { - if (window->input) + if (meta_window_is_focusable (window)) meta_x11_display_set_input_focus_window (window->display->x11_display, window, FALSE, @@ -585,6 +585,12 @@ meta_window_wayland_shortcuts_inhibited (MetaWindow *window, return meta_wayland_compositor_is_shortcuts_inhibited (compositor, source); } +static gboolean +meta_window_wayland_is_focusable (MetaWindow *window) +{ + return window->input; +} + static gboolean meta_window_wayland_is_stackable (MetaWindow *window) { @@ -618,6 +624,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_focusable = meta_window_wayland_is_focusable; window_class->is_stackable = meta_window_wayland_is_stackable; window_class->are_updates_frozen = meta_window_wayland_are_updates_frozen; } diff --git a/src/x11/window-x11.c b/src/x11/window-x11.c index ac304e3fa..bfcbc7ad5 100644 --- a/src/x11/window-x11.c +++ b/src/x11/window-x11.c @@ -752,8 +752,7 @@ meta_window_x11_focus (MetaWindow *window, * Still, we have to do this or keynav breaks for these windows. */ if (window->frame && - (window->shaded || - !(window->input || window->take_focus))) + (window->shaded || !meta_window_is_focusable (window))) { meta_topic (META_DEBUG_FOCUS, "Focusing frame of %s\n", window->desc); @@ -1627,6 +1626,12 @@ meta_window_x11_shortcuts_inhibited (MetaWindow *window, return FALSE; } +static gboolean +meta_window_x11_is_focusable (MetaWindow *window) +{ + return window->input || window->take_focus; +} + static gboolean meta_window_x11_is_stackable (MetaWindow *window) { @@ -1669,6 +1674,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_focusable = meta_window_x11_is_focusable; window_class->is_stackable = meta_window_x11_is_stackable; window_class->are_updates_frozen = meta_window_x11_are_updates_frozen; }