Skip to content

Commit

Permalink
feat(pointer): cmd: add sloppy-focus
Browse files Browse the repository at this point in the history
Signed-off-by: Shinyzenith <aakashsensharma@gmail.com>
  • Loading branch information
Shinyzenith committed Oct 29, 2023
1 parent 6b9bfba commit c81dc40
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
2 changes: 2 additions & 0 deletions next/Config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ toplevel_corner_radius: c_int = 20,
toplevel_opacity: f32 = 1, // Ranges from 0 to 1
toplevel_box_shadow_color: [4]f32 = .{ 0.0, 0.0, 0.0, 1.0 },

focus_is_sloppy: bool = true,

pub fn init() Self {
log.debug("Initialized compositor config", .{});
const self = .{};
Expand Down
1 change: 1 addition & 0 deletions next/control/command.zig
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const commands = std.ComptimeStringMap(
.{ "set-repeat-rate", inputs.setRepeat },
.{ "warp-cursor", cursor.warpCursor },
.{ "hide-cursor", cursor.hideCursor },
.{ "sloppy-focus", cursor.setSloppyFocus },
},
);
// zig fmt: on
Expand Down
18 changes: 18 additions & 0 deletions next/control/cursor.zig
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,21 @@ pub fn warpCursor(
out.* = try std.fmt.allocPrint(allocator, "Failed to parse provided state.\n", .{});
}
}

pub fn setSloppyFocus(
args: []const [:0]const u8,
out: *?[]const u8,
) !void {
if (args.len < 2) return Error.NotEnoughArguments;
if (args.len > 2) return Error.TooManyArguments;

if (std.mem.eql(u8, "true", args[1])) {
server.config.focus_is_sloppy = true;
} else if (std.mem.eql(u8, "false", args[1])) {
server.config.focus_is_sloppy = false;
} else if (std.mem.eql(u8, "toggle", args[1])) {
server.config.focus_is_sloppy = !server.config.focus_is_sloppy;
} else {
out.* = try std.fmt.allocPrint(allocator, "Failed to parse focus state: {s}\n", .{args[1]});
}
}
9 changes: 8 additions & 1 deletion next/input/Cursor.zig
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ pub fn handleButton(listener: *wl.Listener(*wlr.Pointer.event.Button), event: *w
log.debug("Signal: wlr_pointer_button", .{});

_ = self.server.seat.wlr_seat.pointerNotifyButton(event.time_msec, event.button, event.state);

if (Window.windowAt(self.server.wlr_cursor.x, self.server.wlr_cursor.y)) |window_data| {
self.server.seat.setFocus(window_data.window, window_data.surface);
}
}

pub fn handleFrame(listener: *wl.Listener(*wlr.Cursor), _: *wlr.Cursor) void {
Expand Down Expand Up @@ -146,11 +150,14 @@ pub fn processCursorMotion(self: *Self, time_msec: u32) void {
//TODO: Handle cursor modes like move, resize, etc
// for now we do very basic handling of a passthrough mode.

// Passthrough mode.
if (Window.windowAt(self.server.wlr_cursor.x, self.server.wlr_cursor.y)) |window_data| {
self.server.seat.wlr_seat.pointerNotifyEnter(window_data.surface, window_data.sx, window_data.sy);
self.server.seat.wlr_seat.pointerNotifyMotion(time_msec, window_data.sx, window_data.sy);

self.server.seat.setFocus(window_data.window, window_data.surface);
if (self.server.config.focus_is_sloppy) {
self.server.seat.setFocus(window_data.window, window_data.surface);
}
} else {
self.server.wlr_xcursor_manager.setCursorImage("left_ptr", self.server.wlr_cursor);
self.server.seat.wlr_seat.pointerClearFocus();
Expand Down

0 comments on commit c81dc40

Please sign in to comment.