git.lucas.co / cce-compositor
Wayland compositor (wlroots)
git clone https://git.lucas.co/cce-compositor.git

commit6ee7101e2d792b98e13cf97d83fb30bce0ac905c
parent0900416f8c
authorLeon Henrik Plickat <[email protected]>
date2021-12-10 23:40
Cursor: improve output focus handling on button press

This patch allows to focus outputs by clicking on the empty background and by
clicking on layer surfaces without keyboard interactivity. This makes it
possible to use the cursor to focus outputs with no visible views.

This also fixes problems with pointer interactive layer surfaces (for example
launchers and docks) on non-focused outputs.

 river/Cursor.zig | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/river/Cursor.zig b/river/Cursor.zig
index e67e7d5..74f586e 100644
--- a/river/Cursor.zig
+++ b/river/Cursor.zig
@@ -255,16 +255,25 @@ fn handleButton(listener: *wl.Listener(*wlr.Pointer.event.Button), event: *wlr.P
                 }
             },
             .layer_surface => |layer_surface| {
+                self.seat.focusOutput(layer_surface.output);
                 // If a keyboard inteactive layer surface has been clicked on,
                 // give it keyboard focus.
                 if (layer_surface.wlr_layer_surface.current.keyboard_interactive == .exclusive) {
-                    self.seat.focusOutput(layer_surface.output);
                     self.seat.setFocusRaw(.{ .layer = layer_surface });
+                } else {
+                    self.seat.focus(null);
                 }
+                server.root.startTransaction();
             },
             .xwayland_unmanaged => assert(build_options.xwayland),
         }
         _ = self.seat.wlr_seat.pointerNotifyButton(event.time_msec, event.button, event.state);
+    } else if (server.root.output_layout.outputAt(self.wlr_cursor.x, self.wlr_cursor.y)) |wlr_output| {
+        // If the user clicked on empty space of an output, focus it.
+        const output = @intToPtr(*Output, wlr_output.data);
+        self.seat.focusOutput(output);
+        self.seat.focus(null);
+        server.root.startTransaction();
     }
 }