SceneNodeData: fix fromNode()

This currently fails to check the node passed and skips directly to the
parent.
This commit is contained in:
Isaac Freund 2023-12-04 23:46:14 +01:00
parent 7ee6c79b6b
commit 6bfaf62cef
No known key found for this signature in database
GPG Key ID: 86DED400DDFD7A11

View File

@ -51,13 +51,17 @@ pub fn attach(node: *wlr.SceneNode, data: Data) error{OutOfMemory}!void {
} }
pub fn fromNode(node: *wlr.SceneNode) ?*SceneNodeData { pub fn fromNode(node: *wlr.SceneNode) ?*SceneNodeData {
var it: ?*wlr.SceneTree = node.parent; var n = node;
while (it) |tree| : (it = tree.node.parent) { while (true) {
if (@as(?*SceneNodeData, @ptrFromInt(tree.node.data))) |scene_node_data| { if (@as(?*SceneNodeData, @ptrFromInt(n.data))) |scene_node_data| {
return scene_node_data; return scene_node_data;
} }
} if (n.parent) |parent_tree| {
n = &parent_tree.node;
} else {
return null; return null;
}
}
} }
pub fn fromSurface(surface: *wlr.Surface) ?*SceneNodeData { pub fn fromSurface(surface: *wlr.Surface) ?*SceneNodeData {