]> git.mdlowis.com Git - proto/labwc.git/commitdiff
xwayland: always offer focus in Globally Active case
authorJohn Lindgren <john@jlindgren.net>
Mon, 9 Jun 2025 15:11:32 +0000 (11:11 -0400)
committerJohn Lindgren <john@jlindgren.net>
Tue, 10 Jun 2025 15:03:54 +0000 (11:03 -0400)
In 9e3785f8cd7a, a heuristic was added to assume that NORMAL and DIALOG
window types were always focusable. (This was before we had the "offer
focus" mechanism in place.)

However, we should still call wlr_xwayland_surface_offer_focus() for
these views, in case they actually don't want focus. (This is uncommon
but has recently been seen with WeChat popups, which have both NORMAL
and UTILITY type.)

To make this possible, refine view_wants_focus() to return either
LIKELY or UNLIKELY for Globally Active input windows. This decouples
the question of "should we try to focus this view" from the actual
mechanism used to do so.

include/view.h
src/desktop.c
src/view.c
src/xwayland.c

index cf0c0471ba55181b254e60be8555a10ee3d04657..f3a0a9c2187870494a12492a69224be84cc14ef8 100644 (file)
@@ -75,13 +75,18 @@ enum view_wants_focus {
        /* View wants focus */
        VIEW_WANTS_FOCUS_ALWAYS,
        /*
-        * View should be offered focus and may accept or decline
-        * (a.k.a. ICCCM Globally Active input model). Labwc generally
-        * avoids focusing these views automatically (e.g. when another
-        * view on top is closed) but they may be focused by user action
-        * (e.g. mouse click).
+        * The following values apply only to XWayland views using the
+        * Globally Active input model per the ICCCM. These views are
+        * offered focus and will voluntarily accept or decline it.
+        *
+        * In some cases, labwc needs to decide in advance whether to
+        * focus the view. For this purpose, these views are classified
+        * (by a heuristic) as likely or unlikely to want focus. However,
+        * it is still ultimately up to the client whether the view gets
+        * focus or not.
         */
-       VIEW_WANTS_FOCUS_OFFER,
+       VIEW_WANTS_FOCUS_LIKELY,
+       VIEW_WANTS_FOCUS_UNLIKELY,
 };
 
 /*
index 47ae1fb410e398f3337e16632fae0e3750bb4232..df179eb262a9d133df2fbc42be8a11ba465d8f88 100644 (file)
@@ -84,7 +84,8 @@ desktop_focus_view(struct view *view, bool raise)
                        seat_focus_surface(seat, view->surface);
                }
                break;
-       case VIEW_WANTS_FOCUS_OFFER:
+       case VIEW_WANTS_FOCUS_LIKELY:
+       case VIEW_WANTS_FOCUS_UNLIKELY:
                view_offer_focus(view);
                break;
        case VIEW_WANTS_FOCUS_NEVER:
index 33b9ec398e07fc81343b9a3fd135e4acb5189e9f..2c4560be5ce3994d70b62af4c4e84311b84a0fb4 100644 (file)
@@ -392,10 +392,14 @@ view_is_focusable(struct view *view)
        if (!view->surface) {
                return false;
        }
-       if (view_wants_focus(view) != VIEW_WANTS_FOCUS_ALWAYS) {
+
+       switch (view_wants_focus(view)) {
+       case VIEW_WANTS_FOCUS_ALWAYS:
+       case VIEW_WANTS_FOCUS_LIKELY:
+               return (view->mapped || view->minimized);
+       default:
                return false;
        }
-       return (view->mapped || view->minimized);
 }
 
 void
index 4d2860e3fead59faba2f0ba5669f7c0a7493298e..7a4aed9bbc5d1b8aea168fba96bb7c48a063ac6f 100644 (file)
@@ -116,8 +116,8 @@ xwayland_view_wants_focus(struct view *view)
         */
        case WLR_ICCCM_INPUT_MODEL_GLOBAL:
                /*
-                * Assume that NORMAL and DIALOG windows always want
-                * focus. These window types should show up in the
+                * Assume that NORMAL and DIALOG windows are likely to
+                * want focus. These window types should show up in the
                 * Alt-Tab switcher and be automatically focused when
                 * they become topmost.
                 */
@@ -125,7 +125,7 @@ xwayland_view_wants_focus(struct view *view)
                                WLR_XWAYLAND_NET_WM_WINDOW_TYPE_NORMAL)
                        || wlr_xwayland_surface_has_window_type(xsurface,
                                WLR_XWAYLAND_NET_WM_WINDOW_TYPE_DIALOG)) ?
-                       VIEW_WANTS_FOCUS_ALWAYS : VIEW_WANTS_FOCUS_OFFER;
+                       VIEW_WANTS_FOCUS_LIKELY : VIEW_WANTS_FOCUS_UNLIKELY;
 
        /*
         * No Input - The client never expects keyboard input.