Add clientAt api

This commit is contained in:
2023-12-31 01:06:26 +01:00
parent 294cfd3078
commit 4488fe0895

View File

@@ -34,3 +34,32 @@ pub fn focus(server: *Server, client: *Client) !void {
&wlr_keyboard.modifiers,
);
}
pub const ClientAtResult = struct {
view: *Client,
surface: *wlr.Surface,
x: f64,
y: f64,
};
pub fn clientAt(server: *Server, lx: f64, ly: f64) ?ClientAtResult {
var sx: f64 = undefined;
var sy: f64 = undefined;
if (server.scene.tree.node.at(lx, ly, &sx, &sy)) |node| {
if (node.type != .buffer) return null;
const scene_buffer = wlr.SceneBuffer.fromNode(node);
const scene_surface = wlr.SceneSurface.tryFromBuffer(scene_buffer) orelse return null;
var it: ?*wlr.SceneTree = node.parent;
while (it) |n| : (it = n.node.parent) {
if (@as(?*Client, @ptrFromInt(n.node.data))) |client| {
return ClientAtResult{
.view = client,
.surface = scene_surface.surface,
.x = sx,
.y = sy,
};
}
}
}
return null;
}