git.lucas.co / cce-compositor
Wayland compositor (wlroots)
git clone https://git.lucas.co/cce-compositor.git

commitbb04980921c693cc9950ee0e69d8cae5e9194e76
parent5177377962
authorIsaac Freund <[email protected]>
date2023-12-04 23:46
SceneNodeData: fix fromNode()

This currently fails to check the node passed and skips directly to the
parent.

 river/SceneNodeData.zig | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/river/SceneNodeData.zig b/river/SceneNodeData.zig
index 536a714..fa079c1 100644
--- a/river/SceneNodeData.zig
+++ b/river/SceneNodeData.zig
@@ -51,13 +51,17 @@ pub fn attach(node: *wlr.SceneNode, data: Data) error{OutOfMemory}!void {
 }
 
 pub fn fromNode(node: *wlr.SceneNode) ?*SceneNodeData {
-    var it: ?*wlr.SceneTree = node.parent;
-    while (it) |tree| : (it = tree.node.parent) {
-        if (@as(?*SceneNodeData, @ptrFromInt(tree.node.data))) |scene_node_data| {
+    var n = node;
+    while (true) {
+        if (@as(?*SceneNodeData, @ptrFromInt(n.data))) |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 {