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.
This commit is contained in:
Marco Trevisan (Treviño) 2018-11-13 01:56:53 -06:00
parent 08f920606e
commit 4c607164fd
6 changed files with 31 additions and 9 deletions

View File

@ -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))

View File

@ -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,

View File

@ -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)
{

View File

@ -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))
{

View File

@ -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;
}

View File

@ -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;
}