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

commitdfedc50f5d694027e6f3be1baae69b877a41a230
parent409f51f4d0
authorIsaac Freund <[email protected]>
date2025-01-01 18:39
InputConfig: do default input mapping for nested sessions

This improves pointer/touch behavior for nested sessions.

 river/InputConfig.zig | 33 +++++++++++++++++----------------
 1 file changed, 17 insertions(+), 16 deletions(-)

diff --git a/river/InputConfig.zig b/river/InputConfig.zig
index fa2421c..a98ff0e 100644
--- a/river/InputConfig.zig
+++ b/river/InputConfig.zig
@@ -219,8 +219,16 @@ pub const MapToOutput = struct {
     output_name: ?[]const u8,
 
     fn apply(map_to_output: MapToOutput, device: *InputDevice) void {
+        const output_name = map_to_output.output_name orelse switch (device.wlr_device.type) {
+            .pointer => mem.sliceTo(device.wlr_device.toPointer().output_name, 0),
+            .touch => mem.sliceTo(device.wlr_device.toTouch().output_name, 0),
+            .tablet => null,
+            // These devices do not support being mapped to outputs.
+            .keyboard, .tablet_pad, .@"switch" => return,
+        };
+
         const wlr_output = blk: {
-            if (map_to_output.output_name) |name| {
+            if (output_name) |name| {
                 var it = server.om.output_layout.outputs.iterator(.forward);
                 while (it.next()) |layout_output| {
                     if (mem.eql(u8, mem.span(layout_output.output.name), name)) {
@@ -231,23 +239,16 @@ pub const MapToOutput = struct {
             break :blk null;
         };
 
-        switch (device.wlr_device.type) {
-            .pointer, .touch, .tablet => {
-                log.debug("mapping input '{s}' -> '{s}'", .{
-                    device.identifier,
-                    if (wlr_output) |o| o.name else "<no output>",
-                });
-
-                device.seat.cursor.wlr_cursor.mapInputToOutput(device.wlr_device, wlr_output);
+        log.debug("mapping input '{s}' -> '{s}'", .{
+            device.identifier,
+            if (wlr_output) |o| o.name else "<no output>",
+        });
 
-                if (device.wlr_device.type == .tablet) {
-                    const tablet: *Tablet = @fieldParentPtr("device", device);
-                    tablet.output_mapping = wlr_output;
-                }
-            },
+        device.seat.cursor.wlr_cursor.mapInputToOutput(device.wlr_device, wlr_output);
 
-            // These devices do not support being mapped to outputs.
-            .keyboard, .tablet_pad, .@"switch" => {},
+        if (device.wlr_device.type == .tablet) {
+            const tablet: *Tablet = @fieldParentPtr("device", device);
+            tablet.output_mapping = wlr_output;
         }
     }
 };