staring to get the cursor focus working

This commit is contained in:
Squibid 2025-10-19 21:24:49 -04:00
parent ee7c89721f
commit 008b9defce
Signed by: squibid
GPG key ID: BECE5684D3C4005D
2 changed files with 44 additions and 24 deletions

View file

@ -50,9 +50,11 @@ pub fn deinit(self: *Cursor) void {
pub fn processCursorMotion(self: *Cursor, time_msec: u32) void { pub fn processCursorMotion(self: *Cursor, time_msec: u32) void {
if (server.root.viewAt(self.wlr_cursor.x, self.wlr_cursor.y)) |res| { if (server.root.viewAt(self.wlr_cursor.x, self.wlr_cursor.y)) |res| {
std.log.debug("we found a view", .{});
server.seat.wlr_seat.pointerNotifyEnter(res.surface, res.sx, res.sy); server.seat.wlr_seat.pointerNotifyEnter(res.surface, res.sx, res.sy);
server.seat.wlr_seat.pointerNotifyMotion(time_msec, res.sx, res.sy); server.seat.wlr_seat.pointerNotifyMotion(time_msec, res.sx, res.sy);
} else { } else {
std.log.debug("no view found", .{});
self.wlr_cursor.setXcursor(self.x_cursor_manager, "default"); self.wlr_cursor.setXcursor(self.x_cursor_manager, "default");
server.seat.wlr_seat.pointerClearFocus(); server.seat.wlr_seat.pointerClearFocus();
} }
@ -79,14 +81,10 @@ fn handleButton(
_: *wl.Listener(*wlr.Pointer.event.Button), _: *wl.Listener(*wlr.Pointer.event.Button),
event: *wlr.Pointer.event.Button, event: *wlr.Pointer.event.Button,
) void { ) void {
_ = server.seat.wlr_seat.pointerNotifyButton(event.time_msec, event.button, event.state); _ = server.seat.pointerNotifyButton(event.time_msec, event.button, event.state);
// TODO: figure out what this listener is supposed to do if (server.root.viewAt(server.cursor.wlr_cursor.x, server.cursor.wlr_cursor.y)) |res| {
server.root.focusView(res.toplevel);
// if (event.state == .released) { }
// server.cursor_mode = .passthrough;
// } else if (server.viewAt(server.cursor.x, server.cursor.y)) |res| {
// server.focusView(res.toplevel, res.surface);
// }
} }
fn handleHoldBegin( fn handleHoldBegin(

View file

@ -64,8 +64,7 @@ pub fn addView(self: *Root, view: *View) void {
} }
const ViewAtResult = struct { const ViewAtResult = struct {
// TODO: uncomment when we have toplevels toplevel: *View,
// toplevel: *Toplevel,
surface: *wlr.Surface, surface: *wlr.Surface,
sx: f64, sx: f64,
sy: f64, sy: f64,
@ -76,21 +75,44 @@ pub fn viewAt(self: *Root, lx: f64, ly: f64) ?ViewAtResult {
var sy: f64 = undefined; var sy: f64 = undefined;
if (self.scene.tree.node.at(lx, ly, &sx, &sy)) |node| { if (self.scene.tree.node.at(lx, ly, &sx, &sy)) |node| {
if (node.type != .buffer) return null; if (node.type != .buffer) return null;
// TODO: uncomment when we have toplevels const scene_buffer = wlr.SceneBuffer.fromNode(node);
// const scene_buffer = wlr.SceneBuffer.fromNode(node); const scene_surface = wlr.SceneSurface.tryFromBuffer(scene_buffer) orelse return null;
// const scene_surface = wlr.SceneSurface.tryFromBuffer(scene_buffer) orelse return null;
var it: ?*wlr.SceneTree = node.parent; var it: ?*wlr.SceneTree = node.parent;
while (it) |n| : (it = n.node.parent) { while (it) |n| : (it = n.node.parent) {
// if (@as(?*Toplevel, @ptrCast(@alignCast(n.node.data)))) |toplevel| { if (@as(?*View, @ptrCast(@alignCast(n.node.data)))) |toplevel| {
// return ViewAtResult{ return ViewAtResult{
// .toplevel = toplevel, .toplevel = toplevel,
// .surface = scene_surface.surface, .surface = scene_surface.surface,
// .sx = sx, .sx = sx,
// .sy = sy, .sy = sy,
// }; };
// } }
} }
} }
return null; return null;
} }
pub fn focusView(_: *Root, view: *View) void {
if (server.seat.wlr_seat.keyboard_state.focused_surface) |previous_surface| {
if (previous_surface == view.xdg_toplevel.base.surface) return;
if (wlr.XdgSurface.tryFromWlrSurface(previous_surface)) |xdg_surface| {
_ = xdg_surface.role_data.toplevel.?.setActivated(false);
}
}
view.scene_tree.?.node.raiseToTop();
// view.link.remove();
_ = server.root.all_views.append(gpa, view) catch {
unreachable;
};
_ = view.xdg_toplevel.setActivated(true);
const wlr_keyboard = server.seat.wlr_seat.getKeyboard() orelse return;
server.seat.wlr_seat.keyboardNotifyEnter(
view.xdg_toplevel.base.surface,
wlr_keyboard.keycodes[0..wlr_keyboard.num_keycodes],
&wlr_keyboard.modifiers,
);
}