[mutter] window: Add is_focusable class method



commit 43633d6b2f6f602ba87956d5c20ee336b8b56236
Author: Marco Trevisan (Treviño) <mail 3v1n0 net>
Date:   Tue Nov 13 08:56:53 2018 +0100

    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.
    
    https://gitlab.gnome.org/GNOME/mutter/merge_requests/421

 src/core/stack.c                  |  5 +----
 src/core/window-private.h         |  3 +++
 src/core/window.c                 | 11 ++++++++++-
 src/wayland/meta-window-wayland.c |  9 ++++++++-
 src/x11/window-x11.c              | 10 ++++++++--
 5 files changed, 30 insertions(+), 8 deletions(-)
---
diff --git a/src/core/stack.c b/src/core/stack.c
index 619d27a49..6dd1ccb9e 100644
--- a/src/core/stack.c
+++ b/src/core/stack.c
@@ -1224,10 +1224,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 1babd307f..170d230ce 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 f99caaee5..4fcae7598 100644
--- a/src/core/window.c
+++ b/src/core/window.c
@@ -2223,7 +2223,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;
@@ -8529,6 +8529,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/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 c2103aa14..7e3d66dcc 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);
@@ -1629,6 +1628,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)
 {
@@ -1671,6 +1676,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;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]