mirror of
https://github.com/zoriya/gaze.git
synced 2025-12-06 06:26:13 +00:00
Add clientAt api
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user