RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process
Stage 7a: the compositor draws from its own scene nodes
oxydizerdeaa0183eecc
diff --git a/AGENTS.md b/AGENTS.mdindex 487ced9..55d23a6 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -31,6 +31,14 @@ panel painting. The key rules:`present` snaps edges once (`rediwm_edges_snap`), never origin plus size.New clip/opacity/placement rules belong on resolved items. Detach paint-listentries before freeing their heads.+* **Scene nodes are ours** (`node.zig`/`node.c`, wlr_scene's method names). A+ buffer or rect node keeps its pixels in a hidden wlr_scene *carrier* that the+ output pass reads; every setter keeps the two in step, and every change asks+ for a frame through the scene's hook. Client surfaces are still wlr_scene+ trees, hosted under the scene's disabled host and placed by an own `Foreign`+ node: their `data` points back at it (`Foreign.of`, `scene_data.fromWlrNode`),+ and positions inside them go through `node.wlrCoords`. Hits come from+ `Projection.nodeAt` (own node, or `foreign` for a client surface).* **The world has no second tree:** its source tree stays disabled. Pick with`rediwm_projection_node_at`, send callbacks through `Server.sendFrameDone`,and emit feedback/`output_sample` on source buffers. GLES may releasediff --git a/build.zig b/build.zigindex 7601b2b..6c74e67 100644--- a/build.zig+++ b/build.zig@@ -712,6 +712,7 @@ pub fn build(b: *std.Build) void {});projection_tests.root_module.addCSourceFile(.{ .file = b.path("src/projection_test.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra", "-Werror" } });projection_tests.root_module.addCSourceFile(.{ .file = b.path("src/scene_damage.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra", "-Werror" } });+ projection_tests.root_module.addCSourceFile(.{ .file = b.path("src/node.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra", "-Werror" } });inline for (.{ "wlroots-0.20", "wayland-server", "pixman-1" }) |lib| {projection_tests.root_module.linkSystemLibrary(lib, .{});}@@ -729,6 +730,7 @@ pub fn build(b: *std.Build) void {}glass_tests.root_module.addCSourceFile(.{ .file = b.path("src/projection.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra" } });glass_tests.root_module.addCSourceFile(.{ .file = b.path("src/scene_damage.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra", "-Werror" } });+ glass_tests.root_module.addCSourceFile(.{ .file = b.path("src/node.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra", "-Werror" } });const run_glass_tests = b.addRunArtifact(glass_tests);run_glass_tests.setEnvironmentVariable("WLR_RENDERER", "gles2");b.step("test-glass", "Test the glass registry and its geometry in the graph (no GPU)").dependOn(&run_glass_tests.step);@@ -814,6 +816,7 @@ fn addGlass(b: *std.Build, module: *std.Build.Module, damage_audit: bool) void {module.linkSystemLibrary("egl", .{});module.linkSystemLibrary("glesv2", .{});module.addCSourceFile(.{ .file = b.path("src/projection.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra" } });+ module.addCSourceFile(.{ .file = b.path("src/node.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra", "-Werror" } });module.addCSourceFile(.{ .file = b.path("src/scene_pass.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra", "-Werror" } });module.addCSourceFile(.{ .file = b.path("src/scene_output.c"), .flags = if (damage_audit) &.{ "-std=c11", "-Wall", "-Wextra", "-Werror", "-DREDIWM_DAMAGE_AUDIT" } else &.{ "-std=c11", "-Wall", "-Wextra", "-Werror" } });module.addCSourceFile(.{ .file = b.path("src/scene_damage.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra", "-Werror" } });diff --git a/docs/plans/scene-graph-stage7.md b/docs/plans/scene-graph-stage7.mdindex 518b4fb..8ef2e5e 100644--- a/docs/plans/scene-graph-stage7.md+++ b/docs/plans/scene-graph-stage7.md@@ -99,6 +99,17 @@ Revised 7a order, each step gated by identical goldens and the suites that pass1. `node.h`/`node.c` and `node_test.c` (`zig build test-node`): the data model, thechange hook, stacking, picking, teardown. **Done.**++**7a landed 2026-10-15 (steps 2 and 4 below, in one change).** Own buffer and rect+nodes keep a hidden wlr_scene *carrier* (kept in step by every setter) that+`scene_output.c` and `glass.c` read unchanged, so step 3 moves to 7c with the+carrier's removal. The projection resolves the own scene's layers (the six layout+trees and the world) into one graph, so `visit_items`, `layout_item` and the+wlroots pick are gone; layout damage comes from the projection, and+`set_buffer_with_damage` reports to it through the scene's `buffer_damaged` hook.+Gates: `test-node`, `test-projection`, `test-glass`, `test-scene-pass`, `zig build+test` pass; 100 of 136 integration scripts pass and the other 36 fail on HEAD with+the same last error line (`scene_baseline` is a benchmark, not run).2. The projection reads `rediwm_node` sources (leaf/group/addons on the own node),resolves foreign subtrees, and takes the layout trees as extra groups with anidentity transform; damage and picking for them move out of wlr_scene.diff --git a/src/Dock.zig b/src/Dock.zigindex e3c3e63..f8b58b7 100644--- a/src/Dock.zig+++ b/src/Dock.zig@@ -5,6 +5,7 @@const std = @import("std");const wl = @import("wayland").server.wl;const wlr = @import("wlroots");+const sn = @import("node.zig");const ui = @import("ui");const Output = @import("Output.zig");const Server = @import("Server.zig");@@ -89,12 +90,12 @@ const ItemAnimation = struct {};output: ?*Output = null,-tree: ?*wlr.SceneTree = null,-node: ?*wlr.SceneBuffer = null,+tree: ?*sn.Tree = null,+node: ?*sn.Buffer = null,/// Transparent, fixed-size anchor: glass follows the dock background, while/// the painted buffer may extend inward to fit a fully enlarged icon.-glass_anchor: ?*wlr.SceneBuffer = null,-tooltip: ?*wlr.SceneBuffer = null,+glass_anchor: ?*sn.Buffer = null,+tooltip: ?*sn.Buffer = null,glass_effect: ?*glass.Effect = null,/// The glass corner radius of the last paint; its opacity follows `reveal`.glass_radius: f32 = 0,@@ -194,11 +195,11 @@ fn ensureNodes(self: *Self, output: *Output) !void {self.reveal.cancel(if (output.server.config.compositor.dock_auto_hide) 0 else 1);}-fn ignoreInput(_: *wlr.SceneBuffer, _: *f64, _: *f64) callconv(.c) bool {+fn ignoreInput(_: *sn.Buffer, _: *f64, _: *f64) callconv(.c) bool {return false;}-fn acceptsInput(node: *wlr.SceneBuffer, x: *f64, y: *f64) callconv(.c) bool {+fn acceptsInput(node: *sn.Buffer, x: *f64, y: *f64) callconv(.c) bool {const self = SceneData.fromNode(&node.node).?.role.dock;const raster = self.rasterBox();const lx: f32 = @floatCast(x.* + @as(f64, @floatFromInt(raster.x)));diff --git a/src/Input.zig b/src/Input.zigindex 44e13a5..7a181b7 100644--- a/src/Input.zig+++ b/src/Input.zig@@ -4,6 +4,7 @@ const std = @import("std");const wl = @import("wayland").server.wl;const wlr = @import("wlroots");+const sn = @import("node.zig");const xkb = @import("xkbcommon");const control_center = @import("control_center/panel.zig");@@ -134,7 +135,7 @@ open_power_menu: ?*PowerMenu = null,new_input: wl.Listener(*wlr.InputDevice) = .init(newInput),request_set_cursor: wl.Listener(*wlr.Seat.event.RequestSetCursor) = .init(requestSetCursor),request_set_shape: wl.Listener(*wlr.CursorShapeManagerV1.event.RequestSetShape) = .init(requestSetShape),-drag_icon_tree: ?*wlr.SceneTree = null,+drag_icon_tree: ?*sn.Foreign = null,start_drag: wl.Listener(*wlr.Drag) = .init(startDrag),drag_icon_destroy: wl.Listener(void) = .init(dragIconDestroyed),request_start_drag: wl.Listener(*wlr.Seat.event.RequestStartDrag) = .init(requestStartDrag),diff --git a/src/KdeDecoration.zig b/src/KdeDecoration.zigindex a80a239..5a89853 100644--- a/src/KdeDecoration.zig+++ b/src/KdeDecoration.zig@@ -84,7 +84,7 @@ pub const Manager = struct {// walk popup parents or subsurface roots here.if (wlr.XdgSurface.tryFromWlrSurface(surface)) |xdg| {if (scene_data.xdgSceneTree(xdg)) |tree| {- if (scene_data.SceneData.fromNodeOrParents(&tree.node)) |data| {+ if (scene_data.fromWlrNode(&tree.node)) |data| {if (data.role == .toplevel and data.role.toplevel.surface() == surface) {decoration.toplevel = data.role.toplevel;data.role.toplevel.kde_decoration = decoration;diff --git a/src/LayerSurface.zig b/src/LayerSurface.zigindex c70c18b..81526b3 100644--- a/src/LayerSurface.zig+++ b/src/LayerSurface.zig@@ -2,6 +2,7 @@const std = @import("std");const wl = @import("wayland").server.wl;const wlr = @import("wlroots");+const sn = @import("node.zig");const Server = @import("Server.zig");const Output = @import("Output.zig");const SceneData = @import("scene_data.zig").SceneData;@@ -10,6 +11,9 @@ const Self = @This();server: *Server,layer: *wlr.LayerSurfaceV1,scene: *wlr.SceneLayerSurfaceV1,+/// Places the layer's wlr_scene subtree in our scene; the layer shell positions the+/// subtree's own root.+foreign: *sn.Foreign,identity: SceneData,link: wl.list.Link = undefined,commit: wl.Listener(*wlr.Surface) = .init(committed),@@ -25,8 +29,9 @@ pub fn create(server: *Server, layer: *wlr.LayerSurfaceV1) !void {layer.output = output;const self = try gpa.create(Self);errdefer gpa.destroy(self);- self.* = .{ .server = server, .layer = layer, .scene = try server.desktop_tree.createSceneLayerSurfaceV1(layer), .identity = .{ .role = .{ .layer = self } } };- self.identity.attach(&self.scene.tree.node);+ const created = try server.desktop_tree.createSceneLayerSurfaceV1(layer);+ self.* = .{ .server = server, .layer = layer, .scene = created.scene, .foreign = created.foreign, .identity = .{ .role = .{ .layer = self } } };+ self.identity.attach(&self.foreign.node);server.layer_surfaces.prepend(self);layer.data = self;layer.surface.events.commit.add(&self.commit);@@ -50,7 +55,10 @@ fn defaultOutput(server: *Server) ?*wlr.Output {}pub fn localPoint(self: *Self, x: f64, y: f64) @import("geometry.zig").Vec2 {- return @import("scene_data.zig").toNodeLocal(&self.scene.tree.node, x, y);+ var ox: i32 = 0;+ var oy: i32 = 0;+ _ = sn.wlrCoords(&self.scene.tree.node, &ox, &oy);+ return @import("geometry.zig").toLocal(x, y, ox, oy);}pub fn arrange(self: *Self) void {@@ -60,7 +68,7 @@ pub fn arrange(self: *Self) void {.overlay => self.server.overlay_tree,_ => self.server.desktop_tree,};- self.scene.tree.node.reparent(parent);+ self.foreign.node.reparent(parent);var full: wlr.Box = undefined;self.server.output_layout.getBox(self.layer.output, &full);const output = Output.fromWlr(self.layer.output.?);diff --git a/src/Output.zig b/src/Output.zigindex 23e4bec..8d5462f 100644--- a/src/Output.zig+++ b/src/Output.zig@@ -4,6 +4,7 @@ const posix = std.posix;const wl = @import("wayland").server.wl;const wlr = @import("wlroots");+const sn = @import("node.zig");const ControlCenter = @import("control_center/panel.zig").ControlCenter;const StartMenu = @import("start_menu/panel.zig").StartMenu;@@ -72,7 +73,7 @@ const log = std.log.scoped(.output);lock_view: @import("session/lock.zig").View,server: *Server,wlr_output: *wlr.Output,-wallpaper: ?*wlr.SceneBuffer = null,+wallpaper: ?*sn.Buffer = null,taskbar: ?*Taskbar = null,dock: @import("Dock.zig") = .{},osd: @import("osd.zig") = .{},diff --git a/src/Popup.zig b/src/Popup.zigindex 969544c..3fac536 100644--- a/src/Popup.zig+++ b/src/Popup.zig@@ -3,6 +3,7 @@ const std = @import("std");const wl = @import("wayland").server.wl;const wlr = @import("wlroots");+const sn = @import("node.zig");const gpa = @import("main.zig").gpa;const scene_data = @import("scene_data.zig");@@ -45,7 +46,7 @@ pub fn create(server: *Server, xdg_popup: *wlr.XdgPopup) !void {errdefer scene_tree.node.destroy(); // gpa.create below must not leak the node// The popup hangs under its parent's tree, which a window's rounded shape// clips; a menu is no part of that window's shape and may leave it.- _ = @import("projection.zig").setTreeUnclipped(&scene_tree.node, true);+ _ = @import("projection.zig").setWlrTreeUnclipped(&scene_tree.node, true);const popup = gpa.create(Popup) catch |err| {log.err("Popup.create: could not allocate popup: {}", .{err});@@ -87,7 +88,7 @@ fn unconstrainToOutput(server: *Server, xdg_popup: *wlr.XdgPopup) void {const root_tree = scene_data.xdgSceneTree(root) orelse return;var ox: i32 = 0;var oy: i32 = 0;- _ = root_tree.node.coords(&ox, &oy);+ _ = sn.wlrCoords(&root_tree.node, &ox, &oy);const box = (if (Toplevel.fromSurface(server, root.surface)) |toplevel|windowConstraintBox(server, toplevel, ox, oy)diff --git a/src/Server.zig b/src/Server.zigindex a4e5a91..0aaebde 100644--- a/src/Server.zig+++ b/src/Server.zig@@ -13,6 +13,7 @@ const Output = @import("Output.zig");const Taskbar = @import("Taskbar.zig");const Shell = @import("Shell.zig");const World = @import("World.zig");+const sn = @import("node.zig");const geometry = @import("geometry.zig");const icon_theme = @import("icon_theme.zig");const icon_service_mod = @import("icon_service.zig");@@ -97,7 +98,10 @@ gpu_timer: ?*@import("gpu_timing.zig").Timer = null,gpu_timer_tried: bool = false,gpu_timer_used_ns: u64 = 0,allocator: *wlr.Allocator,+/// wlroots' scene, kept for its outputs; the compositor draws from `nodes`.scene: *wlr.Scene,+/// The compositor's own scene: its layers are the trees below, bottom to top.+nodes: *sn.Scene,glass_engine: ?*glass.Engine = null,output_renderer: *scene_output_mod.Renderer = undefined,// Set when wp_linux_drm_syncobj_v1 is advertised: release points for client@@ -109,19 +113,19 @@ scene_output_layout: *wlr.SceneOutputLayout,new_output: wl.Listener(*wlr.Output) = .init(newOutput),shell: Shell,-background_tree: *wlr.SceneTree,-desktop_tree: *wlr.SceneTree,-world_desktop_tree: *wlr.SceneTree,+background_tree: *sn.Tree,+desktop_tree: *sn.Tree,+world_desktop_tree: *sn.Tree,new_layer: wl.Listener(*wlr.LayerSurfaceV1) = .init(newLayer),wallpaper: ?*ImageBuffer = null,world: World,-taskbar_tree: *wlr.SceneTree,+taskbar_tree: *sn.Tree,// While > 0 `refreshTaskbars` only records the request; see `holdTaskbars`.taskbar_hold: u32 = 0,taskbar_hold_pending: bool = false,-overlay_tree: *wlr.SceneTree,-ime_tree: *wlr.SceneTree,-lock_tree: *wlr.SceneTree,+overlay_tree: *sn.Tree,+ime_tree: *sn.Tree,+lock_tree: *sn.Tree,brightness: @import("brightness.zig") = .{},switcher: @import("Switcher.zig") = .{},night_light: @import("night_light/NightLight.zig").NightLight = .{},@@ -371,14 +375,20 @@ pub fn init(server: *Server, scale: ?f32, icon_theme_cfg: icon_theme.Config, io:// stacking alongside its scene ordering instead.scene.restack_xwayland_surfaces = false;- const background_tree = scene.tree.createSceneTree() catch return error.SceneCreateFailed;- const desktop_tree = scene.tree.createSceneTree() catch return error.SceneCreateFailed;- const world_tree = scene.tree.createSceneTree() catch return error.SceneCreateFailed;+ // Carriers and the clients' surface trees live under a disabled host, so wlroots+ // computes nothing for them: the projection resolves our scene instead.+ const host = scene.tree.createSceneTree() catch return error.SceneCreateFailed;+ host.node.setEnabled(false);+ const nodes = sn.Scene.create(host) catch return error.SceneCreateFailed;+ errdefer nodes.destroy();+ const background_tree = nodes.tree.createSceneTree() catch return error.SceneCreateFailed;+ const desktop_tree = nodes.tree.createSceneTree() catch return error.SceneCreateFailed;+ const world_tree = nodes.tree.createSceneTree() catch return error.SceneCreateFailed;const world_desktop_tree = world_tree.createSceneTree() catch return error.SceneCreateFailed;- const taskbar_tree = scene.tree.createSceneTree() catch return error.SceneCreateFailed;- const overlay_tree = scene.tree.createSceneTree() catch return error.SceneCreateFailed;- const ime_tree = scene.tree.createSceneTree() catch return error.SceneCreateFailed;- const lock_tree = scene.tree.createSceneTree() catch return error.SceneCreateFailed;+ const taskbar_tree = nodes.tree.createSceneTree() catch return error.SceneCreateFailed;+ const overlay_tree = nodes.tree.createSceneTree() catch return error.SceneCreateFailed;+ const ime_tree = nodes.tree.createSceneTree() catch return error.SceneCreateFailed;+ const lock_tree = nodes.tree.createSceneTree() catch return error.SceneCreateFailed;const scene_output_layout = scene.attachOutputLayout(output_layout) catch return error.SceneCreateFailed;const catalog = applications.Catalog.init(@import("main.zig").gpa, io, environ, !greeter) catch return error.ServerCreateFailed;@@ -420,6 +430,7 @@ pub fn init(server: *Server, scale: ?f32, icon_theme_cfg: icon_theme.Config, io:.renderer = renderer,.allocator = wlr_allocator,.scene = scene,+ .nodes = nodes,.background_tree = background_tree,.desktop_tree = desktop_tree,.world_desktop_tree = world_desktop_tree,@@ -1071,6 +1082,7 @@ pub fn deinit(server: *Server) void {server.backend.destroy();server.input.deinit();server.world.deinit();+ server.nodes.destroy();server.start_menu_catalog.deinit();glass.Engine.destroy(server.glass_engine);scene_output_mod.Renderer.destroy(server.output_renderer);diff --git a/src/Shell.zig b/src/Shell.zigindex 7b8d628..e455010 100644--- a/src/Shell.zig+++ b/src/Shell.zig@@ -70,7 +70,7 @@ fn newXdgDecoration(decoration: *wlr.XdgToplevelDecorationV1,) void {const tree = scene_data.xdgSceneTree(decoration.toplevel.base) orelse return;- const data = scene_data.SceneData.fromNodeOrParents(&tree.node) orelse return;+ const data = scene_data.fromWlrNode(&tree.node) orelse return;const toplevel = switch (data.role) {.toplevel => |t| t,.chrome => |t| t,diff --git a/src/Switcher.zig b/src/Switcher.zigindex 481e9bd..4c193ab 100644--- a/src/Switcher.zig+++ b/src/Switcher.zig@@ -2,6 +2,7 @@//! gesture; scene buffers retain preview storage independently of clients.const std = @import("std");const wlr = @import("wlroots");+const sn = @import("node.zig");const Server = @import("Server.zig");const Output = @import("Output.zig");const PanelBuffer = @import("panel_buffer.zig").PanelBuffer;@@ -18,12 +19,12 @@ const height = 284;const Card = struct {id: u64,- label: *wlr.SceneBuffer,+ label: *sn.Buffer,label_source: wlr.FBox,- icon: *wlr.SceneBuffer,+ icon: *sn.Buffer,icon_source: wlr.FBox,icon_ready: bool = false,- preview: ?*wlr.SceneBuffer = null,+ preview: ?*sn.Buffer = null,source: wlr.FBox = undefined,pw: i32 = 0,ph: i32 = 0,@@ -31,9 +32,9 @@ const Card = struct {pub const Trigger = enum { alt, ctrl };trigger: Trigger = .alt,-tree: ?*wlr.SceneTree = null,+tree: ?*sn.Tree = null,output: ?*Output = null,-background: ?*wlr.SceneBuffer = null,+background: ?*sn.Buffer = null,cards: std.ArrayList(Card) = .empty,buffers: std.ArrayList(*wlr.Buffer) = .empty,selected: usize = 0,@@ -135,7 +136,7 @@ fn open(self: *Self, server: *Server) !void {_ = self.tick(output, @import("Taskbar.zig").nowMs());}-fn makeNode(self: *Self, buffer: *wlr.Buffer, w: i32, h: i32) !*wlr.SceneBuffer {+fn makeNode(self: *Self, buffer: *wlr.Buffer, w: i32, h: i32) !*sn.Buffer {// Keep storage alive for the entire gesture, including CPU buffers whose// scene node releases its reference after the GLES2 texture upload.try self.buffers.append(gpa, buffer);@@ -149,7 +150,7 @@ fn makeNode(self: *Self, buffer: *wlr.Buffer, w: i32, h: i32) !*wlr.SceneBuffer/// Crop in source coordinates so partial cards slide cleanly behind the/// panel's edges, without allocating or repainting on animation frames.-fn place(node: *wlr.SceneBuffer, source: wlr.FBox, x: i32, y: i32, w: i32, h: i32, viewport: i32) void {+fn place(node: *sn.Buffer, source: wlr.FBox, x: i32, y: i32, w: i32, h: i32, viewport: i32) void {const left = @max(x, 16);const right = @min(x + w, viewport - 16);node.node.setEnabled(right > left);@@ -273,6 +274,6 @@ pub fn cancel(self: *Self) void {self.* = .{};}-fn ignoreInput(_: *wlr.SceneBuffer, _: *f64, _: *f64) callconv(.c) bool {+fn ignoreInput(_: *sn.Buffer, _: *f64, _: *f64) callconv(.c) bool {return false;}diff --git a/src/Taskbar.zig b/src/Taskbar.zigindex c33eabf..3071c9d 100644--- a/src/Taskbar.zig+++ b/src/Taskbar.zig@@ -12,6 +12,7 @@ const glass = @import("glass.zig");const wl = @import("wayland").server.wl;const wlr = @import("wlroots");+const sn = @import("node.zig");const col = @import("color.zig");const c_time = @cImport({@@ -170,18 +171,18 @@ const volume_scroll_step: f32 = 0.05;server: *Server,wlr_output: *wlr.Output,-tree: *wlr.SceneTree,+tree: *sn.Tree,// The background remains the taskbar's full-width glass anchor. Foreground// controls are separate scene buffers above it so their replacement damages// only their own bounds.-buffer_node: *wlr.SceneBuffer,-start_node: *wlr.SceneBuffer,-clock_node: *wlr.SceneBuffer,-tray_nodes: [tray_count]*wlr.SceneBuffer,-app_tray_node: *wlr.SceneBuffer,+buffer_node: *sn.Buffer,+start_node: *sn.Buffer,+clock_node: *sn.Buffer,+tray_nodes: [tray_count]*sn.Buffer,+app_tray_node: *sn.Buffer,app_tray_generation: u64 = 0,-capture_node: *wlr.SceneBuffer,-battery_node: *wlr.SceneBuffer,+capture_node: *sn.Buffer,+battery_node: *sn.Buffer,battery_state: battery.State = .{},battery_dirty: bool = true,battery_shimmer: battery_highlight.Highlight = .{},@@ -268,7 +269,7 @@ pub const AppKind = enum { file_explorer, notes, terminal, settings, text_doc, bconst ChipState = struct {toplevel: *Toplevel,- buffer_node: ?*wlr.SceneBuffer = null,+ buffer_node: ?*sn.Buffer = null,dirty: bool = true,kind: AppKind = .other,// A real icon found via the XDG icon theme, when one exists; falls back@@ -409,7 +410,7 @@ pub fn create(server: *Server, wlr_output: *wlr.Output) !*Taskbar {const buffer_node = try tree.createSceneBuffer(null);const start_node = try tree.createSceneBuffer(null);const clock_node = try tree.createSceneBuffer(null);- var tray_nodes: [tray_count]*wlr.SceneBuffer = undefined;+ var tray_nodes: [tray_count]*sn.Buffer = undefined;for (&tray_nodes) |*node| node.* = try tree.createSceneBuffer(null);const app_tray_node = try tree.createSceneBuffer(null);const capture_node = try tree.createSceneBuffer(null);@@ -1752,7 +1753,7 @@ fn render(bar: *Taskbar, now_ms: i64, causes: u8) void {/// `retain`, when given, keeps a reference to the new raster there (replacing/// the one it held) instead of leaving the scene node as its only owner.-fn renderPart(bar: *Taskbar, now_ms: i64, part: Part, origin_x: i32, origin_y: i32, logical_width: i32, logical_height: i32, node: *wlr.SceneBuffer, retain: ?*?*BarBuffer) void {+fn renderPart(bar: *Taskbar, now_ms: i64, part: Part, origin_x: i32, origin_y: i32, logical_width: i32, logical_height: i32, node: *sn.Buffer, retain: ?*?*BarBuffer) void {const started = stats.nowNs();const scale = bar.wlr_output.scale;const buf = BarBuffer.create(logical_width, logical_height, scale) catch |err| {@@ -2117,7 +2118,7 @@ fn paintChipTitleColumns(paint: *const ChipPaint, pixels: []u32, width: i32, hei/// the title changed, copy the previous raster and repaint only the title/// box instead of the pill's edge and icon SDFs. False means a full raster/// is needed.-fn repaintChipTitle(bar: *Taskbar, now_ms: i64, chip: *ChipState, memo: ChipMemo, key: ChipRasterKey, bar_h: i32, node: *wlr.SceneBuffer) bool {+fn repaintChipTitle(bar: *Taskbar, now_ms: i64, chip: *ChipState, memo: ChipMemo, key: ChipRasterKey, bar_h: i32, node: *sn.Buffer) bool {const previous = chip.raster orelse return false;const previous_key = chip.raster_key orelse return false;var painted = chip.painted orelse return false;diff --git a/src/Toplevel.zig b/src/Toplevel.zigindex 7624434..dbf9c90 100644--- a/src/Toplevel.zig+++ b/src/Toplevel.zig@@ -6,6 +6,7 @@ const explicit_sync = @import("explicit_sync.zig");const wl = @import("wayland").server.wl;const wlr = @import("wlroots");+const sn = @import("node.zig");const col = @import("color.zig");const Decoration = @import("Decoration.zig");@@ -50,7 +51,7 @@ pub const Placeholder = struct {pid: ?i32 = null,client_width: i32,client_height: i32,- body_rect: *wlr.SceneRect,+ body_rect: *sn.Rect,delay_timer: ?*wl.EventSource = null,timeout_timer: ?*wl.EventSource = null,child_source: ?*wl.EventSource = null,@@ -144,23 +145,25 @@ link: wl.list.Link = undefined,backend: Backend,// The frame tree owns compositor-drawn chrome and the client surface tree.// Keeping it separate lets the client remain entirely undecorated.-frame_tree: *wlr.SceneTree,-shadow_tree: *wlr.SceneTree,+frame_tree: *sn.Tree,+shadow_tree: *sn.Tree,// The analytic shadow's leaf: no buffer, only footprint, opacity and input.-shadow_node: *wlr.SceneBuffer,-resize_grab: *wlr.SceneBuffer,+shadow_node: *sn.Buffer,+resize_grab: *sn.Buffer,glass_effect: ?*glass.Effect = null,// Backdrop beneath the themed app body; opaque content masks it, leaving only// the sidebar frosted. The bufferless target owns geometry, never pixels/input.-sidebar_glass_target: ?*wlr.SceneBuffer = null,+sidebar_glass_target: ?*sn.Buffer = null,sidebar_glass_effect: ?*glass.Effect = null,-titlebar_buffer: *wlr.SceneBuffer,+titlebar_buffer: *sn.Buffer,// Body under the border ring beside and below the client (left, right, bottom).-frame_fills: [3]*wlr.SceneRect,+frame_fills: [3]*sn.Rect,// The outline of a window that draws its own decorations.-border_rects: [4]*wlr.SceneRect,-content_tree: *wlr.SceneTree,-scene_tree: *wlr.SceneTree,+border_rects: [4]*sn.Rect,+content_tree: *sn.Tree,+/// What the client draws into: the hosted surface tree of an xdg or X11 surface, or a+/// bare placeholder tree while there is none.+scene_tree: *sn.Node,decoration: ?*Decoration = null,kde_decoration: ?*@import("KdeDecoration.zig") = null,frame_data: scene_data.SceneData = undefined,@@ -250,7 +253,7 @@ size_wait: ConfigureWait = .none,// call; once a window's size has settled that call is pure per-commit waste.last_clip: ?wlr.Box = null,last_clip_valid: bool = false,-close_snapshot: ?*wlr.SceneTree = null,+close_snapshot: ?*sn.Tree = null,closing: bool = false,in_closing_list: bool = false,backend_gone: bool = false,@@ -332,15 +335,15 @@ reconnect_tile: ?tiling.Tile = null,pub const RestoreGeometry = @import("undo.zig").Geometry;const ChromeNodes = struct {- frame_tree: *wlr.SceneTree,- shadow_tree: *wlr.SceneTree,- shadow_node: *wlr.SceneBuffer,- resize_grab: *wlr.SceneBuffer,+ frame_tree: *sn.Tree,+ shadow_tree: *sn.Tree,+ shadow_node: *sn.Buffer,+ resize_grab: *sn.Buffer,glass_effect: ?*glass.Effect,- titlebar_buffer: *wlr.SceneBuffer,- frame_fills: [3]*wlr.SceneRect,- border_rects: [4]*wlr.SceneRect,- content_tree: *wlr.SceneTree,+ titlebar_buffer: *sn.Buffer,+ frame_fills: [3]*sn.Rect,+ border_rects: [4]*sn.Rect,+ content_tree: *sn.Tree,};fn createChromeNodes(server: *Server) !ChromeNodes {@@ -374,12 +377,12 @@ fn createChromeNodes(server: *Server) !ChromeNodes {// The titlebar backs the ring at the top with its fill. Carry that same// chrome under the ring beside and below the client.- var frame_fills: [3]*wlr.SceneRect = undefined;+ var frame_fills: [3]*sn.Rect = undefined;for (&frame_fills) |*rect| {rect.* = try col.createRect(frame_tree, 1, 1, chrome.fillColor());}const border_color = chrome.borderColor(0);- var border_rects: [4]*wlr.SceneRect = undefined;+ var border_rects: [4]*sn.Rect = undefined;for (&border_rects) |*rect| {rect.* = try col.createRect(frame_tree, 1, 1, border_color);}@@ -398,7 +401,7 @@ fn createChromeNodes(server: *Server) !ChromeNodes {};}-fn finishCreate(toplevel: *Toplevel, nodes: ChromeNodes, scene_tree: *wlr.SceneTree) void {+fn finishCreate(toplevel: *Toplevel, nodes: ChromeNodes, scene_tree: *sn.Node) void {toplevel.frame_tree = nodes.frame_tree;toplevel.shadow_tree = nodes.shadow_tree;toplevel.shadow_node = nodes.shadow_node;@@ -421,7 +424,8 @@ pub fn create(server: *Server, xdg_toplevel: *wlr.XdgToplevel) !void {const nodes = try createChromeNodes(server);errdefer nodes.frame_tree.node.destroy();- const scene_tree = try nodes.content_tree.createSceneXdgSurface(xdg_surface);+ const hosted = try nodes.content_tree.createSceneXdgSurface(xdg_surface);+ const scene_tree = &hosted.node;toplevel.* = .{.server = server,@@ -443,7 +447,7 @@ pub fn create(server: *Server, xdg_toplevel: *wlr.XdgToplevel) !void {};server.next_toplevel_id += 1;finishCreate(toplevel, nodes, scene_tree);- scene_data.setXdgSceneTree(xdg_surface, scene_tree);+ scene_data.setXdgSceneTree(xdg_surface, hosted.tree());server.shell.kde_decorations.attach(toplevel);switch (toplevel.backend) {.xdg => |*adapter| adapter.listen(),@@ -461,7 +465,8 @@ pub fn createXwayland(server: *Server, xsurface: *wlr.XwaylandSurface) !void {if (scale_n > 1) {_ = @import("projection.zig").setTreeScale(&nodes.content_tree.node, 1.0 / scale_n);}- const scene_tree = try nodes.content_tree.createSceneTree();+ const placeholder = try nodes.content_tree.createSceneTree();+ const scene_tree = &placeholder.node;toplevel.* = .{.server = server,@@ -547,7 +552,8 @@ pub fn createPlaceholder(const nodes = try createChromeNodes(server);errdefer nodes.frame_tree.node.destroy();- const scene_tree = try nodes.content_tree.createSceneTree();+ const placeholder = try nodes.content_tree.createSceneTree();+ const scene_tree = &placeholder.node;var init_w: i32 = 640;var init_h: i32 = 480;@@ -703,7 +709,8 @@ pub fn createShell(server: *Server, cc: *ControlCenter, width: i32, height: i32)const nodes = try createChromeNodes(server);errdefer nodes.frame_tree.node.destroy();- const scene_tree = try nodes.content_tree.createSceneTree();+ const placeholder = try nodes.content_tree.createSceneTree();+ const scene_tree = &placeholder.node;toplevel.* = .{.server = server,@@ -765,20 +772,20 @@ pub fn findMatchingPlaceholder(toplevel: *Toplevel) ?*Toplevel {}pub fn attachXwaylandScene(toplevel: *Toplevel, client_surface: *wlr.Surface) !void {- const new_tree = try toplevel.content_tree.createSceneSubsurfaceTree(client_surface);- toplevel.scene_tree.node.destroy();- toplevel.scene_tree = new_tree;+ const hosted = try toplevel.content_tree.createSceneSubsurfaceTree(client_surface);+ toplevel.scene_tree.destroy();+ toplevel.scene_tree = &hosted.node;}pub fn detachXwaylandScene(toplevel: *Toplevel) void {const placeholder = toplevel.content_tree.createSceneTree() catch return;- toplevel.scene_tree.node.destroy();- toplevel.scene_tree = placeholder;+ toplevel.scene_tree.destroy();+ toplevel.scene_tree = &placeholder.node;}pub fn replaceDestroyedXwaylandScene(toplevel: *Toplevel) void {// The previous node is in its destroy signal and must not be touched.- toplevel.scene_tree = toplevel.content_tree.createSceneTree() catch return;+ toplevel.scene_tree = &(toplevel.content_tree.createSceneTree() catch return).node;}/// Window that owns `surface`, walking xdg popup parents and subsurface roots.@@ -1557,7 +1564,7 @@ fn chromeSizeForClient(toplevel: *const Toplevel, client_w: i32, client_h: i32)};}-fn ignoreCloseInput(_: *wlr.SceneBuffer, _: *f64, _: *f64) callconv(.c) bool {+fn ignoreCloseInput(_: *sn.Buffer, _: *f64, _: *f64) callconv(.c) bool {return false;}@@ -1822,7 +1829,7 @@ pub fn finishClose(toplevel: *Toplevel) void {toplevel.closing = false;toplevel.clearChromeCache();toplevel.frame_tree.node.setEnabled(false);- toplevel.scene_tree.node.setEnabled(true);+ toplevel.scene_tree.setEnabled(true);}/// Idempotent: re-applying the clip a window already has is a no-op, so the@@ -1840,9 +1847,9 @@ fn setSizeClip(toplevel: *Toplevel, clip: ?wlr.Box) void {toplevel.last_clip_valid = true;if (clip) |box| {var copy = box;- wlr.SceneNode.subsurfaceTreeSetClip(&toplevel.scene_tree.node, ©);+ if (toplevel.scene_tree.foreign()) |hosted| hosted.subsurfaceTreeSetClip(©);} else {- wlr.SceneNode.subsurfaceTreeSetClip(&toplevel.scene_tree.node, null);+ if (toplevel.scene_tree.foreign()) |hosted| hosted.subsurfaceTreeSetClip(null);}}@@ -1919,7 +1926,7 @@ fn beginCloseAnimation(toplevel: *Toplevel) bool {snap.node.destroy();toplevel.close_snapshot = null;}- toplevel.scene_tree.node.setEnabled(true);+ toplevel.scene_tree.setEnabled(true);return false;}toplevel.closing = true;@@ -1932,7 +1939,7 @@ fn beginCloseAnimation(toplevel: *Toplevel) bool {}const CloseSnapshot = struct {- tree: *wlr.SceneTree,+ tree: *sn.Tree,count: u32 = 0,ok: bool = true,};@@ -1960,12 +1967,12 @@ fn copyCloseBuffer(buffer: *wlr.SceneBuffer, sx: c_int, sy: c_int, ctx: *CloseSnfn snapshotClient(toplevel: *Toplevel) bool {const snap = toplevel.content_tree.createSceneTree() catch return false;var ctx: CloseSnapshot = .{ .tree = snap };- toplevel.scene_tree.node.forEachBuffer(*CloseSnapshot, copyCloseBuffer, &ctx);+ toplevel.scene_tree.forEachSurfaceBuffer(*CloseSnapshot, copyCloseBuffer, &ctx);if (!ctx.ok or ctx.count == 0) {snap.node.destroy();return false;}- toplevel.scene_tree.node.setEnabled(false);+ toplevel.scene_tree.setEnabled(false);toplevel.close_snapshot = snap;return true;}@@ -1982,7 +1989,7 @@ fn cancelClose(toplevel: *Toplevel) void {toplevel.closing = false;toplevel.map_motion.cancel(1);toplevel.map_opacity.cancel(1);- toplevel.scene_tree.node.setEnabled(true);+ toplevel.scene_tree.setEnabled(true);}/// Only committed negotiation may change the frame, so the client and@@ -2675,7 +2682,7 @@ pub fn isGeometrySettled(toplevel: *Toplevel, now_ms: i64) bool {(toplevel.launch_origin == null or toplevel.map_motion.settled(now_ms));}-pub fn chromeAcceptsInput(buffer: *wlr.SceneBuffer, sx: *f64, sy: *f64) callconv(.c) bool {+pub fn chromeAcceptsInput(buffer: *sn.Buffer, sx: *f64, sy: *f64) callconv(.c) bool {const data = scene_data.SceneData.fromNode(&buffer.node) orelse return false;if (data.role == .chrome and data.role.chrome.closing) return false;const toplevel = switch (data.role) {@@ -2892,11 +2899,11 @@ fn syncSidebarGlass(toplevel: *Toplevel, width: i32, height: i32) void {if (enabled and toplevel.sidebar_glass_target == null) {const target = toplevel.content_tree.createSceneBuffer(null) catch return;target.point_accepts_input = struct {- fn accepts(_: *wlr.SceneBuffer, _: *f64, _: *f64) callconv(.c) bool {+ fn accepts(_: *sn.Buffer, _: *f64, _: *f64) callconv(.c) bool {return false;}}.accepts;- target.node.placeBelow(&toplevel.scene_tree.node);+ target.node.placeBelow(toplevel.scene_tree);const effect = glass.Engine.attach(toplevel.server.glass_engine, target, &target.node, .sidebar) orelse {target.node.destroy();return;@@ -3116,6 +3123,11 @@ pub fn dimAnimating(toplevel: *const Toplevel, now_ms: i64) bool {pub fn applyOpacity(toplevel: *Toplevel, now_ms: i64) void {var opacity = std.math.clamp(toplevel.effectiveOpacity(now_ms) * toplevel.map_opacity.value(now_ms) * toplevel.switch_fade.value(now_ms), 0, 1);toplevel.frame_tree.node.forEachBuffer(*f32, struct {+ fn iter(buffer: *sn.Buffer, _: c_int, _: c_int, value: *f32) void {+ buffer.setOpacity(value.*);+ }+ }.iter, &opacity);+ toplevel.frame_tree.node.forEachSurfaceBuffer(*f32, struct {fn iter(buffer: *wlr.SceneBuffer, _: c_int, _: c_int, value: *f32) void {buffer.setOpacity(value.*);}diff --git a/src/World.zig b/src/World.zigindex eb47fb0..10aa066 100644--- a/src/World.zig+++ b/src/World.zig@@ -14,11 +14,12 @@ pub const camera_mod = @import("camera.zig");const World = @This();const Projection = @import("projection.zig").Projection;+const sn = @import("node.zig");const glass = @import("glass.zig");const anim = @import("ui").anim;server: *Server,-tree: *wlr.SceneTree,+tree: *sn.Tree,projection: *Projection,/// Mapped windows, front of the list is the focused/top of the stack.toplevels: wl.list.Head(Toplevel, .link) = undefined,@@ -53,11 +54,11 @@ vel_z: anim.VelocityTracker = .{},/// Last chip selected during the current Super hold; IDs survive window teardown safely.peek_window_id: ?u64 = null,-pub fn init(world: *World, server: *Server, tree: *wlr.SceneTree) !void {+pub fn init(world: *World, server: *Server, tree: *sn.Tree) !void {world.* = .{.server = server,.tree = tree,- .projection = Projection.create(tree, server.scene) orelse return error.SceneCreateFailed,+ .projection = Projection.create(server.nodes, tree, server.scene) orelse return error.SceneCreateFailed,};world.toplevels.init();world.closing.init();diff --git a/src/battery_popup.zig b/src/battery_popup.zigindex 3313da5..04ea85a 100644--- a/src/battery_popup.zig+++ b/src/battery_popup.zig@@ -3,6 +3,7 @@ const std = @import("std");const popup_style = @import("popup_style.zig");const glass = @import("glass.zig");const wlr = @import("wlroots");+const sn = @import("node.zig");const Output = @import("Output.zig");const gpa = @import("main.zig").gpa;const scene = @import("scene_data.zig");@@ -18,7 +19,7 @@ const slide_distance: f32 = 20;pub const Popup = struct {output: *Output,- buffer_node: *wlr.SceneBuffer,+ buffer_node: *sn.Buffer,node_data: scene.SceneData = undefined,glass_effect: ?*glass.Effect = null,factor: f32 = 1,diff --git a/src/calendar.zig b/src/calendar.zigindex 2a3bfaa..fe50076 100644--- a/src/calendar.zig+++ b/src/calendar.zig@@ -2,6 +2,7 @@// output geometry changes, or the taskbar's existing minute tick.const std = @import("std");const wlr = @import("wlroots");+const sn = @import("node.zig");const c = @cImport({@cInclude("time.h");});@@ -20,7 +21,7 @@ const slide_distance: f32 = 20;pub const Calendar = struct {output: *Output,- buffer_node: *wlr.SceneBuffer,+ buffer_node: *sn.Buffer,glass_effect: ?*glass.Effect = null,node_data: scene.SceneData = undefined,year: i32,diff --git a/src/capture/window_source.zig b/src/capture/window_source.zigindex e30b08b..8e21b91 100644--- a/src/capture/window_source.zig+++ b/src/capture/window_source.zig@@ -24,6 +24,7 @@const std = @import("std");const wl = @import("wayland").server.wl;const wlr = @import("wlroots");+const sn = @import("../node.zig");const col = @import("../color.zig");const pixman = @import("pixman");const explicit_sync = @import("../explicit_sync.zig");@@ -67,7 +68,7 @@ pub const WindowCaptureSource = struct {/// `frame_tree`/`shadow_tree`: docs/screen-sharing.md's "Separate/// monitor and window semantics" excludes server decorations, shadows,/// and backdrop glass, which can sample unrelated windows.- content_node: *wlr.SceneNode,+ content_node: *sn.Node,node_destroy: wl.Listener(void) = .init(handleNodeDestroy),swapchain: ?*wlr.Swapchain = null,@@ -251,7 +252,9 @@ pub const WindowCaptureSource = struct {.off_y = geom.y,.shape = self.frameShape(geom.x, geom.y),};- self.content_node.forEachBuffer(*RenderCtx, renderNodeBuffer, &ctx);+ // The compositor's own buffers (a shell window's), then the clients' surfaces.+ self.content_node.forEachBuffer(*RenderCtx, renderOwnBuffer, &ctx);+ self.content_node.forEachSurfaceBuffer(*RenderCtx, renderNodeBuffer, &ctx);const submitted = pass.submit();explicit_sync.ReadFence.end(server.read_fence, submitted);@@ -277,6 +280,10 @@ pub const WindowCaptureSource = struct {/// Only enabled/visible buffers are visited, matching how the compositor/// already relies on `setEnabled(false)` to hide nodes from real output/// rendering elsewhere (e.g. `screenshot/capture.zig`'s isolation mode).+ fn renderOwnBuffer(buffer: *sn.Buffer, sx: c_int, sy: c_int, ctx: *RenderCtx) void {+ renderNodeBuffer(buffer.carrier, sx, sy, ctx);+ }+fn renderNodeBuffer(scene_buffer: *wlr.SceneBuffer, sx: c_int, sy: c_int, ctx: *RenderCtx) void {const buf = scene_buffer.buffer orelse return;const texture = wlr.Texture.fromBuffer(ctx.renderer, buf) orelse return;diff --git a/src/caret_overlay.zig b/src/caret_overlay.zigindex f511133..d4e16f1 100644--- a/src/caret_overlay.zig+++ b/src/caret_overlay.zig@@ -10,6 +10,7 @@//! each paint (`update`); its output's frame handler calls `frame`.const std = @import("std");const wlr = @import("wlroots");+const sn = @import("node.zig");const anim = @import("ui").anim;const PanelBuffer = @import("panel_buffer.zig").PanelBuffer;@@ -17,7 +18,7 @@ const ui = @import("ui");const CaretPlace = ui.widgets.secret_input.Input.CaretPlace;pub const CaretOverlay = struct {- node: *wlr.SceneBuffer,+ node: *sn.Buffer,caret: ui.input.Caret = .{},placed: ?Placed = null,/// What the node's buffer shows, so a frame that lands on the same device@@ -55,7 +56,7 @@ pub const CaretOverlay = struct {/// Above everything already in `parent`: create it after the buffer/// holding the field.- pub fn create(parent: *wlr.SceneTree) !CaretOverlay {+ pub fn create(parent: *sn.Tree) !CaretOverlay {const node = try parent.createSceneBuffer(null);node.node.setEnabled(false);return .{ .node = node };@@ -168,9 +169,9 @@ test "the overlay caret appears, glides, blinks, goes solid and hides on a realconst saved = ui.input.caret_config;defer ui.input.caret_config = saved;ui.input.caret_config = .{ .blink_ms = 1000, .blink_timeout_s = 10, .motion_ms = 80 };- const scene = try wlr.Scene.create();- defer scene.tree.node.destroy();- var overlay = try CaretOverlay.create(&scene.tree);+ var fixture = try sn.TestScene.create();+ defer fixture.destroy();+ var overlay = try CaretOverlay.create(&fixture.nodes.tree);defer overlay.destroy();const place = CaretOverlay.Placed{@@ -184,7 +185,7 @@ test "the overlay caret appears, glides, blinks, goes solid and hides on a realconst node = &overlay.node.node;overlay.update(1000, place, 1000);try std.testing.expect(overlay.frame(1000));- try std.testing.expect(node.enabled and overlay.node.buffer != null);+ try std.testing.expect(node.enabled and overlay.node.getBuffer() != null);try std.testing.expectEqual(@as(c_int, 130), node.x);try std.testing.expectEqual(@as(c_int, 55), node.y);diff --git a/src/color.zig b/src/color.zigindex c72fe09..0a57073 100644--- a/src/color.zig+++ b/src/color.zig@@ -8,6 +8,7 @@//! `Straight.premultiply`.const std = @import("std");const wlr = @import("wlroots");+const sn = @import("node.zig");pub const Straight = struct {r: f32,@@ -76,11 +77,11 @@ pub const Premul = struct {}};-pub fn createRect(tree: *wlr.SceneTree, width: c_int, height: c_int, c: Premul) !*wlr.SceneRect {+pub fn createRect(tree: *sn.Tree, width: c_int, height: c_int, c: Premul) !*sn.Rect {return tree.createSceneRect(width, height, &c.rgba);}-pub fn setRect(rect: *wlr.SceneRect, c: Premul) void {+pub fn setRect(rect: *sn.Rect, c: Premul) void {rect.setColor(&c.rgba);}diff --git a/src/control_center/panel.zig b/src/control_center/panel.zigindex c634e29..af6638b 100644--- a/src/control_center/panel.zig+++ b/src/control_center/panel.zig@@ -6,6 +6,7 @@// Device and appearance actions reuse the existing sections.const std = @import("std");const wlr = @import("wlroots");+const sn = @import("../node.zig");const pixman = @import("pixman");const gpa = @import("../main.zig").gpa;@@ -141,7 +142,7 @@ pub const ControlCenter = struct {toplevel: *Toplevel,selected_output_name: [128]u8 = undefined,selected_output_name_len: usize = 0,- buffer_node: *wlr.SceneBuffer,+ buffer_node: *sn.Buffer,node_data: scene_data.SceneData = undefined,dirty: bool = true,@@ -265,7 +266,7 @@ pub const ControlCenter = struct {toplevel.backend.shell.control_center = null;toplevel.destroy();}- const buffer_node = try toplevel.scene_tree.createSceneBuffer(null);+ const buffer_node = try toplevel.scene_tree.tree().?.createSceneBuffer(null);// Window zoom and fractional scales change the destination rounding;// interpolate glyph coverage instead of dropping rows/columns.buffer_node.setFilterMode(.bilinear);diff --git a/src/desktop/embedded.zig b/src/desktop/embedded.zigindex abfdc90..bb9a856 100644--- a/src/desktop/embedded.zig+++ b/src/desktop/embedded.zig@@ -13,6 +13,7 @@const std = @import("std");const wl = @import("wayland").server.wl;const wlr = @import("wlroots");+const sn = @import("../node.zig");const pixman = @import("pixman");const c = @import("c.zig").api;@@ -39,8 +40,8 @@ pub const Desktop = struct {server: *Server,worker: *Worker,app: app_mod.App,- tree: *wlr.SceneTree,- overlay: *wlr.SceneBuffer,+ tree: *sn.Tree,+ overlay: *sn.Buffer,overlay_rect: ?grid.Rect = null,output: ?*Output = null,/// Layout box and scale the canvas and tiles were built for.@@ -74,7 +75,7 @@ pub const Desktop = struct {const Secondary = struct {output: *Output,- node: *wlr.SceneBuffer,+ node: *sn.Buffer,box: wlr.Box,scale: f32,/// The App wallpaper revision this view shows; null repaints it.@@ -82,7 +83,7 @@ pub const Desktop = struct {};const Tile = struct {- node: *wlr.SceneBuffer,+ node: *sn.Buffer,/// Device-pixel rectangle within the canvas.x: i32,y: i32,@@ -244,7 +245,7 @@ pub const Desktop = struct {const image = self.app.wallpaper orelse {// No desktop wallpaper: the compositor's own shows through.view.node.setBuffer(null);- projection.damageBuffer(&view.node.node, null);+ projection.damageBuffer(view.node, null);continue;};const width = geometry.devicePixels(view.box.width, view.scale);@@ -429,7 +430,7 @@ pub const Desktop = struct {self.overlay.node.setEnabled(true);}- fn overlayAcceptsInput(node: *wlr.SceneBuffer, sx: *f64, sy: *f64) callconv(.c) bool {+ fn overlayAcceptsInput(node: *sn.Buffer, sx: *f64, sy: *f64) callconv(.c) bool {const data = SceneData.fromNode(&node.node) orelse return false;const self = data.role.desktop;const rect = self.overlay_rect orelse return false;diff --git a/src/dock_drag.zig b/src/dock_drag.zigindex 7bfc092..4f35adb 100644--- a/src/dock_drag.zig+++ b/src/dock_drag.zig@@ -12,6 +12,7 @@//! drag.const std = @import("std");const wlr = @import("wlroots");+const sn = @import("node.zig");const ui = @import("ui");const Input = @import("Input.zig");const Output = @import("Output.zig");@@ -39,9 +40,9 @@ origin_y: f64 = 0,/// A press on an application is held, and may still turn out to be a click.armed: bool = false,dragging: bool = false,-node: ?*wlr.SceneBuffer = null,+node: ?*sn.Buffer = null,-fn ignoreInput(_: *wlr.SceneBuffer, _: *f64, _: *f64) callconv(.c) bool {+fn ignoreInput(_: *sn.Buffer, _: *f64, _: *f64) callconv(.c) bool {return false;}diff --git a/src/glass.c b/src/glass.cindex 7d39c38..517e073 100644--- a/src/glass.c+++ b/src/glass.c@@ -9,6 +9,7 @@#include <wlr/types/wlr_scene.h>#include <wlr/util/addon.h>#include "glass.h"+#include "node.h"enum glass_kind { GLASS_TITLEBAR, GLASS_TASKBAR, GLASS_PANEL, GLASS_SIDEBAR };struct glass_effect;@@ -23,9 +24,9 @@ struct glass_engine {struct glass_effect {struct glass_engine *engine;struct wl_list link;- struct wlr_scene_buffer *node, *target;+ struct rediwm_buffer *node, *target;struct wl_listener destroy, target_destroy;- struct wlr_addon addon; // on `node`, for rediwm_glass_effect_info+ struct wlr_addon addon; // on the node's carrier, for rediwm_glass_effect_infoenum glass_kind kind;uint64_t serial;float radius, opacity;@@ -55,7 +56,7 @@ static void handle_target_destroy(struct wl_listener *listener, void *data){(void)data;struct glass_effect *effect = wl_container_of(listener, effect, target_destroy);- wlr_scene_node_destroy(&effect->node->node);+ rediwm_node_destroy(&effect->node->node);}static void addon_destroy(struct wlr_addon *addon) { wlr_addon_finish(addon); }static const struct wlr_addon_interface effect_addon = {.name = "rediwm glass effect",@@ -87,7 +88,7 @@ bool rediwm_glass_is_effect_node(struct wlr_scene_node *node){return node->type == WLR_SCENE_NODE_BUFFER && effect_of(node);}-static bool accepts_input(struct wlr_scene_buffer *buffer, double *x, double *y)+static bool accepts_input(struct rediwm_buffer *buffer, double *x, double *y){(void)buffer;(void)x;@@ -95,15 +96,15 @@ static bool accepts_input(struct wlr_scene_buffer *buffer, double *x, double *y)return false;}struct glass_effect *rediwm_glass_attach(struct glass_engine *engine,- struct wlr_scene_buffer *target,- struct wlr_scene_node *before, enum glass_kind kind)+ struct rediwm_buffer *target,+ struct rediwm_node *before, enum glass_kind kind){if (!engine)return NULL;struct glass_effect *effect = calloc(1, sizeof(*effect));if (!effect)return NULL;- effect->node = wlr_scene_buffer_create(target->node.parent, NULL);+ effect->node = rediwm_buffer_create(target->node.parent, NULL);if (!effect->node) {free(effect);return NULL;@@ -114,8 +115,8 @@ struct glass_effect *rediwm_glass_attach(struct glass_engine *engine,effect->opacity = 1;effect->serial = ++engine->next_serial;effect->node->point_accepts_input = accepts_input;- wlr_addon_init(&effect->addon, &effect->node->node.addons, NULL, &effect_addon);- wlr_scene_node_place_below(&effect->node->node, before);+ wlr_addon_init(&effect->addon, &effect->node->carrier->node.addons, NULL, &effect_addon);+ rediwm_node_place_below(&effect->node->node, before);effect->destroy.notify = handle_destroy;wl_signal_add(&effect->node->node.events.destroy, &effect->destroy);effect->target_destroy.notify = handle_target_destroy;@@ -143,7 +144,7 @@ void rediwm_glass_configure(struct glass_effect *effect, float radius, float opavoid rediwm_glass_detach(struct glass_effect *effect){if (effect)- wlr_scene_node_destroy(&effect->node->node);+ rediwm_node_destroy(&effect->node->node);}void rediwm_glass_destroy(struct glass_engine *engine){@@ -151,6 +152,6 @@ void rediwm_glass_destroy(struct glass_engine *engine)return;struct glass_effect *effect, *tmp;wl_list_for_each_safe(effect, tmp, &engine->effects, link)- wlr_scene_node_destroy(&effect->node->node);+ rediwm_node_destroy(&effect->node->node);free(engine);}diff --git a/src/glass.h b/src/glass.hindex d1e5c56..2595335 100644--- a/src/glass.h+++ b/src/glass.h@@ -4,10 +4,10 @@#include <stdbool.h>#include <stdint.h>struct wlr_scene_node;-struct wlr_scene_buffer;+struct rediwm_buffer;struct rediwm_glass_info {// The surface the effect backs: drawn over it, same parent, same box.- struct wlr_scene_buffer *target;+ struct rediwm_buffer *target;float sigma; // Gaussian sigma, logical px, before any zoomfloat saturation; // 1 leaves colours unchangedfloat opacity;@@ -17,6 +17,6 @@ struct rediwm_glass_info {// Keep the last blur while the effect moves (a dragged opaque titlebar, camera motion).bool held;};-// False when `node` is not a glass effect node.+// False when `node` (the carrier of an effect's buffer node) is not a glass effect.bool rediwm_glass_effect_info(struct wlr_scene_node *node, struct rediwm_glass_info *out);bool rediwm_glass_is_effect_node(struct wlr_scene_node *node);diff --git a/src/glass.zig b/src/glass.zigindex 2d510f2..127bd3f 100644--- a/src/glass.zig+++ b/src/glass.zig@@ -1,6 +1,7 @@// Glass effects are registered here and drawn by the owned output pass// (scene_output.c); see glass.c.const wlr = @import("wlroots");+const sn = @import("node.zig");pub const Kind = enum(c_int) { titlebar, taskbar, panel, sidebar };pub const Effect = opaque {@@ -14,7 +15,7 @@ pub const Engine = opaque {pub const create = rediwm_glass_create;extern fn rediwm_glass_destroy(engine: ?*Engine) void;pub const destroy = rediwm_glass_destroy;- extern fn rediwm_glass_attach(engine: ?*Engine, target: *wlr.SceneBuffer, before: *wlr.SceneNode, kind: Kind) ?*Effect;+ extern fn rediwm_glass_attach(engine: ?*Engine, target: *sn.Buffer, before: *sn.Node, kind: Kind) ?*Effect;pub const attach = rediwm_glass_attach;extern fn rediwm_glass_hold(engine: ?*Engine, effect: ?*Effect) void;pub const hold = rediwm_glass_hold;diff --git a/src/glass_test.c b/src/glass_test.cindex 9a54001..6d5dddb 100644--- a/src/glass_test.c+++ b/src/glass_test.c@@ -44,39 +44,43 @@ static void registry_checks(void){struct wlr_scene *scene = wlr_scene_create();assert(scene);+ struct wlr_scene_tree *host = wlr_scene_tree_create(&scene->tree);+ wlr_scene_node_set_enabled(&host->node, false);+ struct rediwm_scene *own = rediwm_scene_create(host, NULL, NULL);+ assert(own);struct glass_engine *engine = rediwm_glass_create();assert(engine);- struct wlr_scene_buffer *target = wlr_scene_buffer_create(&scene->tree, NULL);- wlr_scene_buffer_set_dest_size(target, 200, 60);+ struct rediwm_buffer *target = rediwm_buffer_create(&own->tree, NULL);+ rediwm_buffer_set_dest_size(target, 200, 60);struct glass_effect *effect = rediwm_glass_attach(engine, target, &target->node, GLASS_TITLEBAR);- assert(effect && rediwm_glass_is_effect_node(&effect->node->node));- assert(!rediwm_glass_is_effect_node(&target->node));+ assert(effect && rediwm_glass_is_effect_node(&effect->node->carrier->node));+ assert(!rediwm_glass_is_effect_node(&target->carrier->node));// Below its target, so the blur reads what lies under the surface.assert(effect->node->node.link.next == &target->node.link);struct rediwm_glass_info info;- assert(!rediwm_glass_effect_info(&target->node, &info));- assert(rediwm_glass_effect_info(&effect->node->node, &info));+ assert(!rediwm_glass_effect_info(&target->carrier->node, &info));+ assert(rediwm_glass_effect_info(&effect->node->carrier->node, &info));assert(info.target == target && info.sigma == 22 && info.saturation == 1.5f && info.opacity == 1);assert(!info.held && info.serial);rediwm_glass_configure(effect, 10, .5f);- assert(rediwm_glass_effect_info(&effect->node->node, &info) && info.radius == 10 && info.opacity == .5f);+ assert(rediwm_glass_effect_info(&effect->node->carrier->node, &info) && info.radius == 10 && info.opacity == .5f);// A node address may be reused; the serial is not.- struct wlr_scene_buffer *panel = wlr_scene_buffer_create(&scene->tree, NULL);+ struct rediwm_buffer *panel = rediwm_buffer_create(&own->tree, NULL);struct glass_effect *other = rediwm_glass_attach(engine, panel, &panel->node, GLASS_PANEL);struct rediwm_glass_info other_info;- assert(rediwm_glass_effect_info(&other->node->node, &other_info));+ assert(rediwm_glass_effect_info(&other->node->carrier->node, &other_info));assert(other_info.serial != info.serial && other_info.sigma == 26 && other_info.saturation == 1.6f);// Holds: one dragged effect, or every effect during camera motion.rediwm_glass_hold(engine, effect);- assert(rediwm_glass_effect_info(&effect->node->node, &info) && info.held);- assert(rediwm_glass_effect_info(&other->node->node, &other_info) && !other_info.held);+ assert(rediwm_glass_effect_info(&effect->node->carrier->node, &info) && info.held);+ assert(rediwm_glass_effect_info(&other->node->carrier->node, &other_info) && !other_info.held);rediwm_glass_hold(engine, NULL);rediwm_glass_hold_all(engine, true);- assert(rediwm_glass_effect_info(&other->node->node, &other_info) && other_info.held);+ assert(rediwm_glass_effect_info(&other->node->carrier->node, &other_info) && other_info.held);rediwm_glass_hold_all(engine, false);rediwm_glass_hold(engine, effect);// Removing the target removes its effect, and a held one is released.- wlr_scene_node_destroy(&target->node);+ rediwm_node_destroy(&target->node);assert(engine->held == NULL);assert(engine->effects.next == &other->link && other->link.next == &engine->effects);// Allocation failure leaves nothing behind.@@ -86,17 +90,17 @@ static void registry_checks(void)rediwm_glass_hold(engine, other);rediwm_glass_detach(other);assert(engine->held == NULL && wl_list_empty(&engine->effects));- assert(wl_list_length(&scene->tree.children) == 1);+ assert(wl_list_length(&own->tree.children) == 1);other = rediwm_glass_attach(engine, panel, &panel->node, GLASS_SIDEBAR);- assert(other && rediwm_glass_effect_info(&other->node->node, &info));+ assert(other && rediwm_glass_effect_info(&other->node->carrier->node, &info));assert(info.serial != other_info.serial);assert(info.sigma == 8 && info.saturation == 1.6f);rediwm_glass_destroy(engine);- assert(wl_list_length(&scene->tree.children) == 1); // the panel; its effect went+ assert(wl_list_length(&own->tree.children) == 1); // the panel; its effect wentwlr_scene_node_destroy(&scene->tree.node);fputs("PASS: glass registry: info, serials, holds, target lifetime, allocation failure\n", stderr);}-static bool projection_input(struct wlr_scene_buffer *buffer, double *x, double *y) {+static bool projection_input(struct rediwm_buffer *buffer, double *x, double *y) {(void)buffer;// Model a cropped surface's input callback, including a source-local offset.if (*x < 10) return false;@@ -114,17 +118,20 @@ static bool find_items(const struct rediwm_item *item, struct wlr_scene_node *trreturn true;}static void projection_checks(struct wlr_scene *scene, struct glass_engine *engine) {- struct wlr_scene_tree *source = wlr_scene_tree_create(&scene->tree);- struct rediwm_projection *p = rediwm_projection_create(source, scene);- assert(p);- struct wlr_scene_tree *frame = wlr_scene_tree_create(source);- wlr_scene_node_set_position(&frame->node, 101, 51);+ struct wlr_scene_tree *host = wlr_scene_tree_create(&scene->tree);+ wlr_scene_node_set_enabled(&host->node, false);+ struct rediwm_scene *own = rediwm_scene_create(host, NULL, NULL);+ struct rediwm_tree *source = rediwm_tree_create(&own->tree);+ struct rediwm_projection *p = rediwm_projection_create(own, source, scene);+ assert(own && source && p);+ struct rediwm_tree *frame = rediwm_tree_create(source);+ rediwm_node_set_position(&frame->node, 101, 51);struct test_buffer *image = buffer_create(400, 260);- struct wlr_scene_buffer *client = wlr_scene_buffer_create(frame, &image->base);- client_node = &client->node;+ struct rediwm_buffer *client = rediwm_buffer_create(frame, &image->base);+ client_node = &client->carrier->node;wlr_buffer_drop(&image->base);- wlr_scene_buffer_set_source_box(client, &(struct wlr_fbox){10, 10, 380, 240});- wlr_scene_buffer_set_dest_size(client, 400, 260);+ rediwm_buffer_set_source_box(client, &(struct wlr_fbox){10, 10, 380, 240});+ rediwm_buffer_set_dest_size(client, 400, 260);client->point_accepts_input = projection_input;const double levels[] = {1, .85, .70, .55, 1};for (size_t j = 0; j < sizeof(levels)/sizeof(levels[0]); j++) {@@ -144,19 +151,18 @@ static void projection_checks(struct wlr_scene *scene, struct glass_engine *engiassert(shown->content.src_box.x == 10 && shown->content.src_box.width == 380);assert(frame->node.x == 101 && frame->node.y == 51);assert(client->dst_width == 400 && client->dst_height == 260);- double x, y;- struct wlr_scene_node *hit = rediwm_projection_node_at(p,- snap.x + snap.width * .5, snap.y + snap.height * .5, &x, &y);- assert(hit == &client->node);- assert(fabs(x - 207) < .0001 && fabs(y - 139) < .0001);- assert(!rediwm_projection_node_at(p, snap.x + 1, snap.y + 1, &x, &y));+ struct rediwm_hit hit;+ assert(rediwm_projection_node_at(p, snap.x + snap.width * .5, snap.y + snap.height * .5, &hit));+ assert(hit.own == &client->node);+ assert(fabs(hit.x - 207) < .0001 && fabs(hit.y - 139) < .0001);+ assert(!rediwm_projection_node_at(p, snap.x + 1, snap.y + 1, &hit));}}// An effect has its target's box at every zoom, and is shown only with it.assert(rediwm_projection_set_tree_zoom(&frame->node, .70));- struct wlr_scene_buffer *target = wlr_scene_buffer_create(frame, NULL);- wlr_scene_node_set_position(&target->node, 0, 0);- wlr_scene_buffer_set_dest_size(target, 200, 60);+ struct rediwm_buffer *target = rediwm_buffer_create(frame, NULL);+ rediwm_node_set_position(&target->node, 0, 0);+ rediwm_buffer_set_dest_size(target, 200, 60);struct glass_effect *effect = rediwm_glass_attach(engine, target, &target->node, GLASS_TITLEBAR);assert(effect);for (size_t i = 0; i < sizeof(levels)/sizeof(levels[0]); i++) {@@ -168,18 +174,19 @@ static void projection_checks(struct wlr_scene *scene, struct glass_engine *engiassert(found.effect.width == 200 && found.effect.height == 60);assert(fabs(found.effect.scale - .70 * levels[i]) < .0001);}- wlr_scene_node_set_enabled(&target->node, false);+ rediwm_node_set_enabled(&target->node, false);rediwm_projection_sync(p, .55, 0, 0, 0, 0);struct items hidden = {0};rediwm_projection_for_each_item(p, false, find_items, &hidden);assert(hidden.effect.kind != REDIWM_ITEM_EFFECT);// Source destruction tears down the graph's items, including effects.- wlr_scene_node_destroy(&frame->node);+ rediwm_node_destroy(&frame->node);struct items gone = {0};rediwm_projection_for_each_item(p, false, find_items, &gone);assert(gone.client.width == 0 && gone.effect.kind != REDIWM_ITEM_EFFECT);rediwm_projection_destroy(p);- wlr_scene_node_destroy(&source->node);+ rediwm_scene_destroy(own);+ wlr_scene_node_destroy(&host->node);fputs("PASS: projection geometry, input, glass geometry and destruction\n", stderr);}int main(void)diff --git a/src/input/text_input.zig b/src/input/text_input.zigindex 4f23e1b..4604bf3 100644--- a/src/input/text_input.zig+++ b/src/input/text_input.zig@@ -3,6 +3,7 @@const std = @import("std");const wl = @import("wayland").server.wl;const wlr = @import("wlroots");+const sn = @import("../node.zig");const Server = @import("../Server.zig");const Keyboard = @import("../Keyboard.zig");const Toplevel = @import("../Toplevel.zig");@@ -294,7 +295,7 @@ fn methodDestroy(listener: *wl.Listener(void)) void {const Popup = struct {relay: *Self,popup: *wlr.InputPopupSurfaceV2,- tree: *wlr.SceneTree,+ tree: *sn.Tree,link: wl.list.Link = undefined,commit: wl.Listener(*wlr.Surface) = .init(committed),destroyed: wl.Listener(void) = .init(onDestroy),@@ -341,11 +342,11 @@ fn newPopup(listener: *wl.Listener(*wlr.InputPopupSurfaceV2), popup: *wlr.InputPself.updatePopups();}-fn surfaceNode(tree: *wlr.SceneTree, surface: *wlr.Surface) ?*wlr.SceneNode {+fn wlrSurfaceNode(tree: *wlr.SceneTree, surface: *wlr.Surface) ?*wlr.SceneNode {var it = tree.children.iterator(.forward);while (it.next()) |node| {if (node.type == .tree) {- if (surfaceNode(@fieldParentPtr("node", node), surface)) |found| return found;+ if (wlrSurfaceNode(wlr.SceneTree.fromNode(node), surface)) |found| return found;} else if (node.type == .buffer) {if (wlr.SceneSurface.tryFromBuffer(wlr.SceneBuffer.fromNode(node))) |scene_surface| {if (scene_surface.surface == surface) return node;@@ -355,6 +356,22 @@ fn surfaceNode(tree: *wlr.SceneTree, surface: *wlr.Surface) ?*wlr.SceneNode {return null;}+/// The node showing `surface` under `tree`: a client's surfaces are wlr_scene nodes+/// inside the foreign nodes that host them.+fn surfaceNode(tree: *sn.Tree, surface: *wlr.Surface) ?*wlr.SceneNode {+ var it = tree.children.iterator(.forward);+ while (it.next()) |node| {+ switch (node.type) {+ .tree => if (surfaceNode(@fieldParentPtr("node", node), surface)) |found| return found,+ .foreign => if (node.foreign().?.wlr != null) {+ if (wlrSurfaceNode(node.foreign().?.tree(), surface)) |found| return found;+ },+ else => {},+ }+ }+ return null;+}+pub fn updatePopups(self: *Self) void {var it = self.popups.iterator(.forward);while (it.next()) |popup| {@@ -366,10 +383,10 @@ pub fn updatePopups(self: *Self) void {const input = (self.active orelse break :visible false).input;const surface = input.focused_surface orelse break :visible false;if (!surface.mapped or !popup.popup.surface.mapped) break :visible false;- const node = surfaceNode(&self.server.scene.tree, surface) orelse break :visible false;+ const node = surfaceNode(&self.server.nodes.tree, surface) orelse break :visible false;var sx: i32 = 0;var sy: i32 = 0;- _ = node.coords(&sx, &sy);+ _ = sn.wlrCoords(node, &sx, &sy);var scale: f64 = 1;var x: f64 = @floatFromInt(sx);var y: f64 = @floatFromInt(sy);@@ -430,7 +447,7 @@ pub fn popupPoint(self: *Self, surface: *wlr.Surface, x: f64, y: f64) ?@import("const node = surfaceNode(self.server.ime_tree, surface) orelse return null;var sx: i32 = 0;var sy: i32 = 0;- _ = node.coords(&sx, &sy);+ _ = sn.wlrCoords(node, &sx, &sy);return .{ .x = x - @as(f64, @floatFromInt(sx)), .y = y - @as(f64, @floatFromInt(sy)) };}diff --git a/src/ipc/handlers.zig b/src/ipc/handlers.zigindex 0b3bf50..0c11002 100644--- a/src/ipc/handlers.zig+++ b/src/ipc/handlers.zig@@ -1,6 +1,7 @@const std = @import("std");const wl = @import("wayland").server.wl;const wlr = @import("wlroots");+const sn = @import("../node.zig");const Server = @import("../Server.zig");const Output = @import("../Output.zig");@@ -509,7 +510,7 @@ pub fn handleRequest(var nodes = std.ArrayList(protocol.SceneNodeData).empty;var total: usize = 0;const max_depth = p.max_depth orelse 16;- try walkSceneTree(&server.scene.tree.node, &nodes, allocator, 0, max_depth, &total);+ try walkSceneTree(&server.nodes.tree.node, &nodes, allocator, 0, max_depth, &total);return .{ .ok = .{ .scene_tree = .{.nodes = try nodes.toOwnedSlice(allocator),.total_nodes = total,@@ -1184,20 +1185,20 @@ fn handleAction(const toplevel = findToplevelById(server, win_id) orelse return .{ .err = "UnknownWindow" };if (!toplevel.hasServerDecorations()) return .{ .err = "WindowHasNoServerDecorations" };scale = toplevel.render_scale;- target_buf = toplevel.titlebar_buffer.buffer;+ target_buf = toplevel.titlebar_buffer.getBuffer();},// Each tag names the Output field holding that panel..control_center => {const cc = server.input.open_control_center orelse return .{ .err = comptime DumpTarget.control_center.missingError() };scale = cc.painted_scale;- target_buf = cc.buffer_node.buffer;+ target_buf = cc.buffer_node.getBuffer();},inline .taskbar, .start_menu, .power_menu => |tag| {const out = if (p.output) |name| findOutputByName(server, name) else server.getDefaultOutput();const target_out = out orelse return .{ .err = "NoOutput" };scale = target_out.wlr_output.scale;const panel = @field(target_out, @tagName(tag)) orelse return .{ .err = comptime tag.missingError() };- target_buf = panel.buffer_node.buffer;+ target_buf = panel.buffer_node.getBuffer();},}@@ -1789,7 +1790,7 @@ fn matchWindowRules(server: *Server, params: protocol.MatchWindowRulesParams, al}fn walkSceneTree(- node: *wlr.SceneNode,+ node: *sn.Node,list: *std.ArrayList(protocol.SceneNodeData),allocator: std.mem.Allocator,current_depth: u32,@@ -1801,7 +1802,7 @@ fn walkSceneTree(var children_count: usize = 0;if (node.type == .tree) {- const tree = wlr.SceneTree.fromNode(node);+ const tree = sn.Tree.fromNode(node);var it = tree.children.iterator(.forward);while (it.next()) |_| {children_count += 1;@@ -1815,11 +1816,11 @@ fn walkSceneTree(var box: ?protocol.RectData = null;if (node.type == .rect) {- const r = wlr.SceneRect.fromNode(node);+ const r = sn.Rect.fromNode(node);box = .{ .x = node.x, .y = node.y, .width = r.width, .height = r.height };} else if (node.type == .buffer) {- const b = wlr.SceneBuffer.fromNode(node);- if (b.buffer) |buf| {+ const b = sn.Buffer.fromNode(node);+ if (b.getBuffer()) |buf| {box = .{ .x = node.x, .y = node.y, .width = buf.width, .height = buf.height };} else {box = .{ .x = node.x, .y = node.y, .width = b.dst_width, .height = b.dst_height };@@ -1838,7 +1839,7 @@ fn walkSceneTree(});if (node.type == .tree) {- const tree = wlr.SceneTree.fromNode(node);+ const tree = sn.Tree.fromNode(node);var it = tree.children.iterator(.forward);while (it.next()) |child| {try walkSceneTree(child, list, allocator, current_depth + 1, max_depth, total_nodes);diff --git a/src/mini_map.zig b/src/mini_map.zigindex 78ede9d..8e01e65 100644--- a/src/mini_map.zig+++ b/src/mini_map.zig@@ -3,6 +3,7 @@const std = @import("std");const wl = @import("wayland").server.wl;const wlr = @import("wlroots");+const sn = @import("node.zig");const Server = @import("Server.zig");const Output = @import("Output.zig");const ui = @import("ui");@@ -16,11 +17,11 @@ const gpa = @import("main.zig").gpa;server: ?*Server = null,output: ?*Output = null,-tree: ?*wlr.SceneTree = null,-background: ?*wlr.SceneBuffer = null,-window_tree: ?*wlr.SceneTree = null,+tree: ?*sn.Tree = null,+background: ?*sn.Buffer = null,+window_tree: ?*sn.Tree = null,outlines: std.ArrayList(Outline) = .empty,-marker: ?*wlr.SceneBuffer = null,+marker: ?*sn.Buffer = null,marker_cache: ?MarkerCache = null,scene_data: SceneData = undefined,timer: ?*wl.EventSource = null,@@ -35,8 +36,8 @@ anchor: @import("camera.zig").Vec = .{ .x = 0, .y = 0 },cache: ?Cache = null,last_camera: ?@import("camera.zig").Camera = null,const Outline = struct {- tree: *wlr.SceneTree,- edges: [4]*wlr.SceneRect,+ tree: *sn.Tree,+ edges: [4]*sn.Rect,color: ?col.Premul = null,};const Cache = struct { map: geo.Map, bounds: @import("camera.zig").Bounds, columns: u32, rows: u32, scale: f32, bg: [4]f32, fg: [4]f32, bg_opacity: f32 = 0.91, grid_alpha: f32 = 0.065, border_alpha: f32 = 0.12, radius: f32 = 4 };@@ -239,11 +240,9 @@ pub fn tick(self: *Self, output: *Output, now: i64) bool {// A map can appear beneath a stationary pointer. Resolve actual scene// ownership so a covering toast does not hold the map open underneath it.if (!self.dragging) {- var sx: f64 = 0;- var sy: f64 = 0;- const picked = server.world.projection.nodeAt(server.input.cursor.x, server.input.cursor.y, &sx, &sy);+ const picked = server.world.projection.nodeAt(server.input.cursor.x, server.input.cursor.y);self.hovered = server.input.cursor_mode == .passthrough and server.input.active_buttons == 0 and- picked != null and SceneData.fromNode(picked.?) == &self.scene_data;+ picked != null and picked.?.own != null and SceneData.fromNode(picked.?.own.?) == &self.scene_data;}const changed = self.last_camera == null or !std.meta.eql(self.last_camera.?, world.camera);self.last_camera = world.camera;@@ -319,7 +318,7 @@ fn syncWindows(self: *Self, foreground: [4]f32, opacity: f32) !void {if (count == self.outlines.items.len) {const tree = try self.window_tree.?.createSceneTree();errdefer tree.node.destroy();- var edges: [4]*wlr.SceneRect = undefined;+ var edges: [4]*sn.Rect = undefined;for (&edges) |*edge| {edge.* = try col.createRect(tree, 1, 1, .transparent);self.scene_data.attach(&edge.*.node);diff --git a/src/network/popup.zig b/src/network/popup.zigindex 48b36bc..ca36bb2 100644--- a/src/network/popup.zig+++ b/src/network/popup.zig@@ -2,6 +2,7 @@ const std = @import("std");const popup_style = @import("../popup_style.zig");const glass = @import("../glass.zig");const wlr = @import("wlroots");+const sn = @import("../node.zig");const xkb = @import("xkbcommon");const Output = @import("../Output.zig");const scene = @import("../scene_data.zig");@@ -47,8 +48,8 @@ const expand_curve: anim.Curve = .{ .duration = .{ .ms = 220, .ease = .out_cubicpub const Popup = struct {output: *Output,- buffer_node: *wlr.SceneBuffer,- sonar_node: *wlr.SceneBuffer,+ buffer_node: *sn.Buffer,+ sonar_node: *sn.Buffer,sonar_step: i64 = -1,sonar_shown: bool = false,sonar_fade_start: i64 = -1,diff --git a/src/node.c b/src/node.cindex ab96a16..c91ad97 100644--- a/src/node.c+++ b/src/node.c@@ -4,12 +4,18 @@#include <stdlib.h>#include <string.h>#include <wlr/types/wlr_buffer.h>+#include <wlr/types/wlr_scene.h>static void changed(struct rediwm_node *node) {struct rediwm_scene *scene = node->scene;if (scene && scene->changed) scene->changed(scene->changed_data);}+static void buffer_damaged(struct rediwm_buffer *b, const pixman_region32_t *damage) {+ struct rediwm_scene *scene = b->node.scene;+ if (scene && scene->buffer_damaged) scene->buffer_damaged(scene->changed_data, b, damage);+}+static void node_init(struct rediwm_node *node, enum rediwm_node_type type, struct rediwm_tree *parent) {node->type = type;node->parent = parent;@@ -27,9 +33,11 @@ static void node_init(struct rediwm_node *node, enum rediwm_node_type type, stru}}-struct rediwm_scene *rediwm_scene_create(void (*notify)(void *), void *data) {+struct rediwm_scene *rediwm_scene_create(struct wlr_scene_tree *host, void (*notify)(void *),+ void *data) {struct rediwm_scene *scene = calloc(1, sizeof(*scene));if (!scene) return NULL;+ scene->host = host;node_init(&scene->tree.node, REDIWM_NODE_TREE, NULL);wl_list_init(&scene->tree.children);scene->tree.node.scene = scene;@@ -58,6 +66,11 @@ struct rediwm_rect *rediwm_rect_create(struct rediwm_tree *parent, int width, inconst float color[4]) {struct rediwm_rect *rect = calloc(1, sizeof(*rect));if (!rect) return NULL;+ rect->carrier = wlr_scene_rect_create(parent->node.scene->host, width, height, color);+ if (!rect->carrier) {+ free(rect);+ return NULL;+ }node_init(&rect->node, REDIWM_NODE_RECT, parent);rect->width = width;rect->height = height;@@ -69,12 +82,12 @@ struct rediwm_rect *rediwm_rect_create(struct rediwm_tree *parent, int width, instruct rediwm_buffer *rediwm_buffer_create(struct rediwm_tree *parent, struct wlr_buffer *buffer) {struct rediwm_buffer *b = calloc(1, sizeof(*b));if (!b) return NULL;+ b->carrier = wlr_scene_buffer_create(parent->node.scene->host, NULL);+ if (!b->carrier) {+ free(b);+ return NULL;+ }node_init(&b->node, REDIWM_NODE_BUFFER, parent);- wl_signal_init(&b->events.outputs_update);- wl_signal_init(&b->events.output_enter);- wl_signal_init(&b->events.output_leave);- wl_signal_init(&b->events.output_sample);- wl_signal_init(&b->events.frame_done);b->opacity = 1;b->filter_mode = WLR_SCALE_FILTER_BILINEAR;b->transform = WL_OUTPUT_TRANSFORM_NORMAL;@@ -84,15 +97,29 @@ struct rediwm_buffer *rediwm_buffer_create(struct rediwm_tree *parent, struct wlreturn b;}+static void foreign_wlr_destroyed(struct wl_listener *listener, void *data) {+ (void)data;+ struct rediwm_foreign *f = wl_container_of(listener, f, wlr_destroy);+ wl_list_remove(&f->wlr_destroy.link);+ f->wlr = NULL;+ rediwm_node_destroy(&f->node);+}+struct rediwm_foreign *rediwm_foreign_create(struct rediwm_tree *parent, struct wlr_scene_node *wlr) {struct rediwm_foreign *f = calloc(1, sizeof(*f));if (!f) return NULL;node_init(&f->node, REDIWM_NODE_FOREIGN, parent);f->wlr = wlr;+ f->wlr_destroy.notify = foreign_wlr_destroyed;+ wl_signal_add(&wlr->events.destroy, &f->wlr_destroy);changed(&f->node);return f;}+struct wlr_scene_tree *rediwm_tree_host(const struct rediwm_tree *tree) {+ return tree->node.scene->host;+}+void rediwm_node_destroy(struct rediwm_node *node) {if (!node) return;wl_signal_emit_mutable(&node->events.destroy, NULL);@@ -100,9 +127,19 @@ void rediwm_node_destroy(struct rediwm_node *node) {struct rediwm_tree *tree = (struct rediwm_tree *)node;struct rediwm_node *child, *tmp;wl_list_for_each_safe(child, tmp, &tree->children, link) rediwm_node_destroy(child);+ } else if (node->type == REDIWM_NODE_FOREIGN) {+ struct rediwm_foreign *f = (struct rediwm_foreign *)node;+ if (f->wlr) {+ wl_list_remove(&f->wlr_destroy.link);+ struct wlr_scene_node *wlr = f->wlr;+ f->wlr = NULL;+ wlr_scene_node_destroy(wlr);+ }+ } else if (node->type == REDIWM_NODE_RECT) {+ wlr_scene_node_destroy(&((struct rediwm_rect *)node)->carrier->node);} else if (node->type == REDIWM_NODE_BUFFER) {struct rediwm_buffer *b = (struct rediwm_buffer *)node;- rediwm_buffer_set_buffer(b, NULL);+ wlr_scene_node_destroy(&b->carrier->node);pixman_region32_fini(&b->opaque_region);}// Report before the node and its scene are gone; a root has no parent to tell.@@ -185,7 +222,6 @@ bool rediwm_node_coords(struct rediwm_node *node, int *lx, int *ly) {y += n->y;enabled = enabled && n->enabled;}- if (!enabled) x = y = 0;if (lx) *lx = x;if (ly) *ly = y;return enabled;@@ -201,34 +237,45 @@ void rediwm_rect_set_size(struct rediwm_rect *rect, int width, int height) {if (rect->width == width && rect->height == height) return;rect->width = width;rect->height = height;+ wlr_scene_rect_set_size(rect->carrier, width, height);changed(&rect->node);}void rediwm_rect_set_color(struct rediwm_rect *rect, const float color[4]) {if (!memcmp(rect->color, color, sizeof(rect->color))) return;memcpy(rect->color, color, sizeof(rect->color));+ wlr_scene_rect_set_color(rect->carrier, color);changed(&rect->node);}void rediwm_buffer_set_buffer(struct rediwm_buffer *b, struct wlr_buffer *buffer) {// A buffer set again is new content even if the pointer matches: a compositor-owned// buffer is redrawn in place, and the projection is told its damage separately.- struct wlr_buffer *old = b->buffer;- b->buffer = buffer ? wlr_buffer_lock(buffer) : NULL;- if (buffer) {- b->buffer_width = buffer->width;- b->buffer_height = buffer->height;- } else {- b->buffer_width = b->buffer_height = 0;- }- if (old) wlr_buffer_unlock(old);+ wlr_scene_buffer_set_buffer(b->carrier, buffer);+ b->buffer_width = buffer ? buffer->width : 0;+ b->buffer_height = buffer ? buffer->height : 0;+ buffer_damaged(b, NULL);changed(&b->node);}+void rediwm_buffer_set_buffer_with_damage(struct rediwm_buffer *b, struct wlr_buffer *buffer,+ const pixman_region32_t *damage) {+ wlr_scene_buffer_set_buffer_with_damage(b->carrier, buffer, damage);+ b->buffer_width = buffer ? buffer->width : 0;+ b->buffer_height = buffer ? buffer->height : 0;+ buffer_damaged(b, damage);+ changed(&b->node);+}++struct wlr_buffer *rediwm_buffer_get_buffer(const struct rediwm_buffer *b) {+ return b->carrier->buffer;+}+void rediwm_buffer_set_dest_size(struct rediwm_buffer *b, int width, int height) {if (b->dst_width == width && b->dst_height == height) return;b->dst_width = width;b->dst_height = height;+ wlr_scene_buffer_set_dest_size(b->carrier, width, height);changed(&b->node);}@@ -237,24 +284,28 @@ void rediwm_buffer_set_source_box(struct rediwm_buffer *b, const struct wlr_fboxconst struct wlr_fbox *next = box ? box : &none;if (!memcmp(&b->src_box, next, sizeof(*next))) return;b->src_box = *next;+ wlr_scene_buffer_set_source_box(b->carrier, box);changed(&b->node);}void rediwm_buffer_set_opacity(struct rediwm_buffer *b, float opacity) {if (b->opacity == opacity) return;b->opacity = opacity;+ wlr_scene_buffer_set_opacity(b->carrier, opacity);changed(&b->node);}void rediwm_buffer_set_filter_mode(struct rediwm_buffer *b, enum wlr_scale_filter_mode mode) {if (b->filter_mode == mode) return;b->filter_mode = mode;+ wlr_scene_buffer_set_filter_mode(b->carrier, mode);changed(&b->node);}void rediwm_buffer_set_transform(struct rediwm_buffer *b, enum wl_output_transform transform) {if (b->transform == transform) return;b->transform = transform;+ wlr_scene_buffer_set_transform(b->carrier, transform);changed(&b->node);}@@ -266,6 +317,7 @@ void rediwm_buffer_set_opaque_region(struct rediwm_buffer *b, const pixman_regioif (pixman_region32_equal((pixman_region32_t *)region, &b->opaque_region)) return;pixman_region32_copy(&b->opaque_region, region);}+ wlr_scene_buffer_set_opaque_region(b->carrier, &b->opaque_region);changed(&b->node);}@@ -343,3 +395,38 @@ void rediwm_node_for_each_buffer(struct rediwm_node *node, rediwm_buffer_iteratofn((struct rediwm_buffer *)node, 0, 0, data);}}++struct wlr_iteration {+ rediwm_wlr_buffer_iterator fn;+ void *data;+ int x, y;+};+static void wlr_buffer_shifted(struct wlr_scene_buffer *b, int sx, int sy, void *data) {+ struct wlr_iteration *it = data;+ it->fn(b, it->x + sx, it->y + sy, it->data);+}+static void for_each_wlr_buffer(struct rediwm_node *node, int x, int y, rediwm_wlr_buffer_iterator fn, void *data) {+ if (!node->enabled) return;+ x += node->x;+ y += node->y;+ if (node->type == REDIWM_NODE_TREE) {+ struct rediwm_node *child;+ wl_list_for_each(child, &((struct rediwm_tree *)node)->children, link)+ for_each_wlr_buffer(child, x, y, fn, data);+ } else if (node->type == REDIWM_NODE_FOREIGN) {+ struct rediwm_foreign *f = (struct rediwm_foreign *)node;+ struct wlr_iteration it = {.fn = fn, .data = data, .x = x, .y = y};+ if (f->wlr) wlr_scene_node_for_each_buffer(f->wlr, wlr_buffer_shifted, &it);+ }+}++void rediwm_node_for_each_wlr_buffer(struct rediwm_node *node, rediwm_wlr_buffer_iterator fn, void *data) {+ if (!node->enabled) return;+ if (node->type == REDIWM_NODE_TREE) {+ struct rediwm_node *child;+ wl_list_for_each(child, &((struct rediwm_tree *)node)->children, link)+ for_each_wlr_buffer(child, 0, 0, fn, data);+ } else if (node->type == REDIWM_NODE_FOREIGN) {+ for_each_wlr_buffer(node, -node->x, -node->y, fn, data);+ }+}diff --git a/src/node.h b/src/node.hindex ebd19c7..75cc883 100644--- a/src/node.h+++ b/src/node.h@@ -24,6 +24,9 @@#include <wlr/util/box.h>struct wlr_buffer;+struct wlr_scene_buffer;+struct wlr_scene_rect;+struct wlr_scene_tree;struct rediwm_scene;struct rediwm_tree;@@ -59,17 +62,20 @@ struct rediwm_rect {struct rediwm_node node;int width, height;float color[4]; // premultiplied, as wlr_scene_rect+ // The hidden wlr_scene rect the output pass reads the colour from, kept in step.+ struct wlr_scene_rect *carrier;};struct rediwm_buffer;typedef bool (*rediwm_buffer_point_accepts_input)(struct rediwm_buffer *, double *x, double *y);+// Geometry and content state live here; the pixels themselves (the locked buffer,+// its texture, wait points, single-pixel colour) are carried by a hidden wlr_scene+// buffer the output pass already knows how to read. Every setter keeps the two in+// step. Stage 7c replaces the carrier with the pass's own texture cache.struct rediwm_buffer {struct rediwm_node node;- struct wlr_buffer *buffer; // locked while set; may be NULL- struct {- struct wl_signal outputs_update, output_enter, output_leave, output_sample, frame_done;- } events;+ struct wlr_scene_buffer *carrier;rediwm_buffer_point_accepts_input point_accepts_input; // may be NULLfloat opacity;enum wlr_scale_filter_mode filter_mode;@@ -77,7 +83,7 @@ struct rediwm_buffer {int dst_width, dst_height;enum wl_output_transform transform;pixman_region32_t opaque_region;- // The size of `buffer` as last set, kept for when the renderer releases it.+ // The size of the buffer as last set, kept for when the renderer releases it.int buffer_width, buffer_height;};@@ -85,13 +91,21 @@ struct rediwm_buffer {// own position stays (0, 0) and the foreign node carries the position.struct rediwm_foreign {struct rediwm_node node;- struct wlr_scene_node *wlr;+ struct wlr_scene_node *wlr; // NULL once wlroots has destroyed it+ struct wl_listener wlr_destroy;};struct rediwm_scene {struct rediwm_tree tree;+ // A hidden, disabled wlr_scene tree that hosts every buffer's carrier and the+ // foreign subtrees, so wlroots computes nothing for them.+ struct wlr_scene_tree *host;// Something the tree shows may have changed: the owner schedules a frame.void (*changed)(void *data);+ // A buffer node was given a buffer (set_buffer, set_buffer_with_damage): the+ // buffer-local `damage` of what differs, or NULL for all of it. The projection turns+ // this into screen damage, as wlroots did for the nodes it tracked.+ void (*buffer_damaged)(void *data, struct rediwm_buffer *, const pixman_region32_t *damage);void *changed_data;};@@ -108,8 +122,10 @@ static inline struct rediwm_foreign *rediwm_foreign_from_node(struct rediwm_nodereturn node->type == REDIWM_NODE_FOREIGN ? (struct rediwm_foreign *)node : NULL;}-// A scene is its root tree. `changed` may be NULL.-struct rediwm_scene *rediwm_scene_create(void (*changed)(void *), void *data);+// A scene is its root tree. `host` is where carriers and foreign subtrees live (the+// caller disables it); `changed` may be NULL.+struct rediwm_scene *rediwm_scene_create(struct wlr_scene_tree *host, void (*changed)(void *),+ void *data);void rediwm_scene_destroy(struct rediwm_scene *);// Children are created enabled, at (0, 0), on top of their siblings. NULL on@@ -118,7 +134,11 @@ struct rediwm_tree *rediwm_tree_create(struct rediwm_tree *parent);struct rediwm_rect *rediwm_rect_create(struct rediwm_tree *parent, int width, int height,const float color[4]);struct rediwm_buffer *rediwm_buffer_create(struct rediwm_tree *parent, struct wlr_buffer *);+// Takes over `wlr`, a node of a wlr_scene tree under the scene's host. It goes when+// the foreign node does, and the foreign node goes when wlroots destroys it first.struct rediwm_foreign *rediwm_foreign_create(struct rediwm_tree *parent, struct wlr_scene_node *wlr);+// Where the scene's carriers and foreign subtrees are made.+struct wlr_scene_tree *rediwm_tree_host(const struct rediwm_tree *);// Destroys the node and everything under it; each node emits events.destroy first.void rediwm_node_destroy(struct rediwm_node *);@@ -131,8 +151,8 @@ void rediwm_node_place_above(struct rediwm_node *, struct rediwm_node *sibling);void rediwm_node_place_below(struct rediwm_node *, struct rediwm_node *sibling);// Moves the node to the top of `parent`, which must not be inside the node.void rediwm_node_reparent(struct rediwm_node *, struct rediwm_tree *parent);-// The node's origin in the scene's root; false (and 0, 0) if some ancestor is-// disabled, as wlr_scene_node_coords.+// The node's origin in the scene's root, and whether it and every ancestor are+// enabled, as wlr_scene_node_coords.bool rediwm_node_coords(struct rediwm_node *, int *lx, int *ly);// Whether the node and every ancestor are enabled.bool rediwm_node_visible(const struct rediwm_node *);@@ -140,9 +160,15 @@ bool rediwm_node_visible(const struct rediwm_node *);void rediwm_rect_set_size(struct rediwm_rect *, int width, int height);void rediwm_rect_set_color(struct rediwm_rect *, const float color[4]);-// Takes a lock on `buffer` (NULL clears). Nothing is damaged here: the caller of a-// compositor-owned buffer reports its damage to the projection.+// Takes a lock on `buffer` (NULL clears), as wlr_scene_buffer_set_buffer. Nothing is+// damaged here: the caller of a compositor-owned buffer reports its damage to the+// projection.void rediwm_buffer_set_buffer(struct rediwm_buffer *, struct wlr_buffer *);+// As wlr_scene_buffer_set_buffer_with_damage: `damage` is buffer-local.+void rediwm_buffer_set_buffer_with_damage(struct rediwm_buffer *, struct wlr_buffer *,+ const pixman_region32_t *damage);+// The buffer the carrier holds; NULL once the renderer released it after upload.+struct wlr_buffer *rediwm_buffer_get_buffer(const struct rediwm_buffer *);void rediwm_buffer_set_dest_size(struct rediwm_buffer *, int width, int height);void rediwm_buffer_set_source_box(struct rediwm_buffer *, const struct wlr_fbox *);void rediwm_buffer_set_opacity(struct rediwm_buffer *, float opacity);@@ -160,6 +186,10 @@ void rediwm_buffer_size(const struct rediwm_buffer *, int *width, int *height);// caller's pick of them is the projection's.struct rediwm_node *rediwm_node_at(struct rediwm_node *, double x, double y, double *nx, double *ny);typedef void (*rediwm_buffer_iterator)(struct rediwm_buffer *, int sx, int sy, void *data);+typedef void (*rediwm_wlr_buffer_iterator)(struct wlr_scene_buffer *, int sx, int sy, void *data);+// The same for the wlr_scene buffers of the foreign subtrees under the node (the+// surfaces of clients), with their positions relative to the node passed in.+void rediwm_node_for_each_wlr_buffer(struct rediwm_node *, rediwm_wlr_buffer_iterator, void *data);// Every buffer of the subtree, bottom to top, with its position relative to the// node passed in (as wlr_scene_node_for_each_buffer; disabled nodes are skipped).void rediwm_node_for_each_buffer(struct rediwm_node *, rediwm_buffer_iterator, void *data);diff --git a/src/node.zig b/src/node.zignew file mode 100644index 0000000..25cded7--- /dev/null+++ b/src/node.zig@@ -0,0 +1,312 @@+//! The compositor's own scene nodes (node.h): what wlr.Scene* was as a data model.+//! Method names are wlr_scene's, so a call site changes its type and little else.+//!+//! A client's surfaces are still wlr_scene trees (stage 7b replaces that): they live+//! under the scene's hidden host and an own `Foreign` node places them.+const std = @import("std");+const wayland = @import("wayland");+const wl = wayland.server.wl;+const pixman = @import("pixman");+const wlr = @import("wlroots");++pub const Node = extern struct {+ pub const Type = enum(c_int) { tree, rect, buffer, foreign };++ type: Type,+ parent: ?*Tree,+ link: wl.list.Link,+ enabled: bool,+ x: c_int,+ y: c_int,+ data: ?*anyopaque,+ events: extern struct {+ destroy: wl.Signal(void),+ },+ addons: wlr.AddonSet,+ scene: *Scene,++ extern fn rediwm_node_destroy(node: *Node) void;+ pub const destroy = rediwm_node_destroy;+ extern fn rediwm_node_set_enabled(node: *Node, enabled: bool) void;+ pub const setEnabled = rediwm_node_set_enabled;+ extern fn rediwm_node_set_position(node: *Node, x: c_int, y: c_int) void;+ pub const setPosition = rediwm_node_set_position;+ extern fn rediwm_node_raise_to_top(node: *Node) void;+ pub const raiseToTop = rediwm_node_raise_to_top;+ extern fn rediwm_node_lower_to_bottom(node: *Node) void;+ pub const lowerToBottom = rediwm_node_lower_to_bottom;+ extern fn rediwm_node_place_above(node: *Node, sibling: *Node) void;+ pub const placeAbove = rediwm_node_place_above;+ extern fn rediwm_node_place_below(node: *Node, sibling: *Node) void;+ pub const placeBelow = rediwm_node_place_below;+ extern fn rediwm_node_reparent(node: *Node, parent: *Tree) void;+ pub const reparent = rediwm_node_reparent;+ extern fn rediwm_node_coords(node: *Node, lx: *c_int, ly: *c_int) bool;+ pub const coords = rediwm_node_coords;+ extern fn rediwm_node_visible(node: *const Node) bool;+ /// Whether the node and every ancestor are enabled.+ pub const visible = rediwm_node_visible;++ extern fn rediwm_node_for_each_buffer(+ node: *Node,+ iterator: *const fn (buffer: *Buffer, sx: c_int, sy: c_int, data: ?*anyopaque) callconv(.c) void,+ user_data: ?*anyopaque,+ ) void;+ /// The own buffers of the subtree, positions relative to this node.+ pub inline fn forEachBuffer(+ node: *Node,+ comptime T: type,+ comptime iterator: fn (buffer: *Buffer, sx: c_int, sy: c_int, data: T) void,+ data: T,+ ) void {+ rediwm_node_for_each_buffer(+ node,+ struct {+ fn wrapper(b: *Buffer, sx: c_int, sy: c_int, d: ?*anyopaque) callconv(.c) void {+ iterator(b, sx, sy, @ptrCast(@alignCast(d)));+ }+ }.wrapper,+ data,+ );+ }++ extern fn rediwm_node_for_each_wlr_buffer(+ node: *Node,+ iterator: *const fn (buffer: *wlr.SceneBuffer, sx: c_int, sy: c_int, data: ?*anyopaque) callconv(.c) void,+ user_data: ?*anyopaque,+ ) void;+ /// The wlr_scene buffers of the clients' surfaces under this node, positions+ /// relative to it.+ pub inline fn forEachSurfaceBuffer(+ node: *Node,+ comptime T: type,+ comptime iterator: fn (buffer: *wlr.SceneBuffer, sx: c_int, sy: c_int, data: T) void,+ data: T,+ ) void {+ rediwm_node_for_each_wlr_buffer(+ node,+ struct {+ fn wrapper(b: *wlr.SceneBuffer, sx: c_int, sy: c_int, d: ?*anyopaque) callconv(.c) void {+ iterator(b, sx, sy, @ptrCast(@alignCast(d)));+ }+ }.wrapper,+ data,+ );+ }++ /// The foreign node this is, if it is one.+ pub fn foreign(node: *Node) ?*Foreign {+ return if (node.type == .foreign) @fieldParentPtr("node", node) else null;+ }+ pub fn tree(node: *Node) ?*Tree {+ return if (node.type == .tree) @fieldParentPtr("node", node) else null;+ }+};++pub const Tree = extern struct {+ node: Node,+ children: wl.list.Head(Node, .link),++ extern fn rediwm_tree_create(parent: *Tree) ?*Tree;+ pub fn createSceneTree(parent: *Tree) !*Tree {+ return rediwm_tree_create(parent) orelse error.OutOfMemory;+ }++ extern fn rediwm_rect_create(parent: *Tree, width: c_int, height: c_int, color: *const [4]f32) ?*Rect;+ pub fn createSceneRect(parent: *Tree, width: c_int, height: c_int, color: *const [4]f32) !*Rect {+ return rediwm_rect_create(parent, width, height, color) orelse error.OutOfMemory;+ }++ extern fn rediwm_buffer_create(parent: *Tree, buffer: ?*wlr.Buffer) ?*Buffer;+ pub fn createSceneBuffer(parent: *Tree, buffer: ?*wlr.Buffer) !*Buffer {+ return rediwm_buffer_create(parent, buffer) orelse error.OutOfMemory;+ }++ extern fn rediwm_foreign_create(parent: *Tree, wlr_node: *wlr.SceneNode) ?*Foreign;+ extern fn rediwm_tree_host(tree: *const Tree) *wlr.SceneTree;+ /// The hidden wlr_scene tree that holds the clients' surface trees.+ pub const host = rediwm_tree_host;++ /// A hosted subtree's root keeps its foreign node in its `data`, so a hit inside+ /// it finds its way back to the own tree.+ fn adopt(parent: *Tree, tree: *wlr.SceneTree) !*Foreign {+ const foreign = rediwm_foreign_create(parent, &tree.node) orelse {+ tree.node.destroy();+ return error.OutOfMemory;+ };+ tree.node.data = foreign;+ return foreign;+ }++ pub fn createSceneXdgSurface(parent: *Tree, xdg_surface: *wlr.XdgSurface) !*Foreign {+ return adopt(parent, try rediwm_tree_host(parent).createSceneXdgSurface(xdg_surface));+ }++ pub fn createSceneSubsurfaceTree(parent: *Tree, surface: *wlr.Surface) !*Foreign {+ return adopt(parent, try rediwm_tree_host(parent).createSceneSubsurfaceTree(surface));+ }++ pub fn createSceneDragIcon(parent: *Tree, drag_icon: *wlr.Drag.Icon) !*Foreign {+ return adopt(parent, try rediwm_tree_host(parent).createSceneDragIcon(drag_icon));+ }++ /// The layer surface's wlr_scene tree is hosted like any client's; the foreign+ /// node places it, and the wlr tree's own position is the layer shell's.+ pub fn createSceneLayerSurfaceV1(parent: *Tree, layer_surface: *wlr.LayerSurfaceV1) !struct { scene: *wlr.SceneLayerSurfaceV1, foreign: *Foreign } {+ const scene = try rediwm_tree_host(parent).createSceneLayerSurfaceV1(layer_surface);+ return .{ .scene = scene, .foreign = try adopt(parent, scene.tree) };+ }++ pub fn fromNode(node: *Node) *Tree {+ return @fieldParentPtr("node", node);+ }+};++pub const Rect = extern struct {+ node: Node,+ width: c_int,+ height: c_int,+ color: [4]f32,+ carrier: *wlr.SceneRect,++ extern fn rediwm_rect_set_color(rect: *Rect, color: *const [4]f32) void;+ pub const setColor = rediwm_rect_set_color;+ extern fn rediwm_rect_set_size(rect: *Rect, width: c_int, height: c_int) void;+ pub const setSize = rediwm_rect_set_size;++ pub fn fromNode(node: *Node) *Rect {+ return @fieldParentPtr("node", node);+ }+};++pub const Buffer = extern struct {+ node: Node,+ /// The hidden wlr_scene buffer that carries the pixels (see node.h).+ carrier: *wlr.SceneBuffer,+ point_accepts_input: ?*const fn (buffer: *Buffer, sx: *f64, sy: *f64) callconv(.c) bool,+ opacity: f32,+ filter_mode: wlr.RenderPass.ScaleFilterMode,+ src_box: wlr.FBox,+ dst_width: c_int,+ dst_height: c_int,+ transform: wl.Output.Transform,+ opaque_region: pixman.Region32,+ buffer_width: c_int,+ buffer_height: c_int,++ extern fn rediwm_buffer_set_buffer(buffer: *Buffer, wlr_buffer: ?*wlr.Buffer) void;+ pub const setBuffer = rediwm_buffer_set_buffer;+ extern fn rediwm_buffer_get_buffer(buffer: *const Buffer) ?*wlr.Buffer;+ /// The buffer the carrier holds; null once the renderer released it after upload.+ pub const getBuffer = rediwm_buffer_get_buffer;+ extern fn rediwm_buffer_set_buffer_with_damage(buffer: *Buffer, wlr_buffer: ?*wlr.Buffer, damage: *const pixman.Region32) void;+ pub const setBufferWithDamage = rediwm_buffer_set_buffer_with_damage;+ extern fn rediwm_buffer_set_dest_size(buffer: *Buffer, width: c_int, height: c_int) void;+ pub const setDestSize = rediwm_buffer_set_dest_size;+ extern fn rediwm_buffer_set_source_box(buffer: *Buffer, box: ?*const wlr.FBox) void;+ pub const setSourceBox = rediwm_buffer_set_source_box;+ extern fn rediwm_buffer_set_opacity(buffer: *Buffer, opacity: f32) void;+ pub const setOpacity = rediwm_buffer_set_opacity;+ extern fn rediwm_buffer_set_filter_mode(buffer: *Buffer, mode: wlr.RenderPass.ScaleFilterMode) void;+ pub const setFilterMode = rediwm_buffer_set_filter_mode;+ extern fn rediwm_buffer_set_transform(buffer: *Buffer, transform: wl.Output.Transform) void;+ pub const setTransform = rediwm_buffer_set_transform;+ extern fn rediwm_buffer_set_opaque_region(buffer: *Buffer, region: ?*const pixman.Region32) void;+ pub const setOpaqueRegion = rediwm_buffer_set_opaque_region;++ pub fn fromNode(node: *Node) *Buffer {+ return @fieldParentPtr("node", node);+ }+};++/// A wlr_scene subtree hosted under an own tree.+pub const Foreign = extern struct {+ node: Node,+ /// Null once wlroots has destroyed the subtree (this node goes with it).+ wlr: ?*wlr.SceneNode,+ wlr_destroy: wl.Listener(void),++ pub fn tree(foreign: *Foreign) *wlr.SceneTree {+ return wlr.SceneTree.fromNode(foreign.wlr.?);+ }++ /// The foreign node whose subtree holds this wlr node (a root's `data`).+ pub fn of(wlr_node: *wlr.SceneNode) ?*Foreign {+ var current: *wlr.SceneNode = wlr_node;+ while (true) {+ if (current.data) |data| return @ptrCast(@alignCast(data));+ current = if (current.parent) |parent| &parent.node else return null;+ }+ }++ /// Clips the hosted surface tree, as wlr_scene_subsurface_tree_set_clip.+ pub fn subsurfaceTreeSetClip(foreign: *Foreign, clip: ?*const wlr.Box) void {+ wlr.SceneNode.subsurfaceTreeSetClip(foreign.wlr.?, clip);+ }++ pub fn fromNode(node: *Node) *Foreign {+ return @fieldParentPtr("node", node);+ }+};++/// The own scene: its root tree's children are the layers, bottom to top.+pub const Scene = extern struct {+ tree: Tree,+ host: *wlr.SceneTree,+ changed: ?*const fn (data: ?*anyopaque) callconv(.c) void,+ changed_data: ?*anyopaque,++ extern fn rediwm_scene_create(host: *wlr.SceneTree, changed: ?*const fn (?*anyopaque) callconv(.c) void, data: ?*anyopaque) ?*Scene;+ /// `host` is a hidden, disabled wlr_scene tree for the carriers and the+ /// clients' subtrees.+ pub fn create(host: *wlr.SceneTree) !*Scene {+ return rediwm_scene_create(host, null, null) orelse error.OutOfMemory;+ }+ extern fn rediwm_scene_destroy(scene: ?*Scene) void;+ pub const destroy = rediwm_scene_destroy;+};++/// Where a node inside a client's subtree is in the scene's root, and whether the+/// own nodes above it are enabled: the hosting node's place plus the wlr_scene offsets+/// down to it.+pub fn wlrCoords(wlr_node: *wlr.SceneNode, lx: *c_int, ly: *c_int) bool {+ var x: c_int = 0;+ var y: c_int = 0;+ var current: *wlr.SceneNode = wlr_node;+ while (true) {+ x += current.x;+ y += current.y;+ if (current.data != null) break;+ current = if (current.parent) |parent| &parent.node else {+ lx.* = x;+ ly.* = y;+ return false;+ };+ }+ const foreign: *Foreign = @ptrCast(@alignCast(current.data.?));+ var ox: c_int = 0;+ var oy: c_int = 0;+ const enabled = foreign.node.coords(&ox, &oy);+ lx.* = ox + x;+ ly.* = oy + y;+ return enabled;+}++/// A scene for unit tests: a wlroots scene with the own scene's hidden host in it.+pub const TestScene = struct {+ wlr_scene: *wlr.Scene,+ nodes: *Scene,++ pub fn create() !TestScene {+ const wlr_scene = try wlr.Scene.create();+ errdefer wlr_scene.tree.node.destroy();+ const host = try wlr_scene.tree.createSceneTree();+ host.node.setEnabled(false);+ return .{ .wlr_scene = wlr_scene, .nodes = try Scene.create(host) };+ }++ pub fn destroy(fixture: TestScene) void {+ fixture.nodes.destroy();+ fixture.wlr_scene.tree.node.destroy();+ }+};diff --git a/src/node_test.c b/src/node_test.cindex 94bf08e..8fd99df 100644--- a/src/node_test.c+++ b/src/node_test.c@@ -7,6 +7,7 @@#include <stdlib.h>#include <wlr/interfaces/wlr_buffer.h>#include <wlr/types/wlr_buffer.h>+#include <wlr/types/wlr_scene.h>static int changes;static void on_change(void *data) {@@ -52,7 +53,11 @@ static void collect(struct rediwm_buffer *b, int sx, int sy, void *data) {}int main(void) {- struct rediwm_scene *scene = rediwm_scene_create(on_change, NULL);+ struct wlr_scene *wlr_scene = wlr_scene_create();+ assert(wlr_scene);+ struct wlr_scene_tree *host = wlr_scene_tree_create(&wlr_scene->tree);+ wlr_scene_node_set_enabled(&host->node, false);+ struct rediwm_scene *scene = rediwm_scene_create(host, on_change, NULL);assert(scene && scene->tree.node.enabled && !scene->tree.node.parent);// Creation reports, a no-op mutation does not.@@ -75,7 +80,7 @@ int main(void) {int lx, ly;assert(rediwm_node_coords(&inner->node, &lx, &ly) && lx == 15 && ly == 27);rediwm_node_set_enabled(&a->node, false);- assert(!rediwm_node_coords(&inner->node, &lx, &ly) && lx == 0 && ly == 0);+ assert(!rediwm_node_coords(&inner->node, &lx, &ly) && lx == 15 && ly == 27);assert(!rediwm_node_visible(&inner->node));rediwm_node_set_enabled(&a->node, true);assert(rediwm_node_visible(&inner->node));@@ -116,7 +121,7 @@ int main(void) {struct wlr_buffer *raw = buffer_create(200, 100);struct rediwm_buffer *buf = rediwm_buffer_create(&scene->tree, raw);wlr_buffer_drop(raw); // the node keeps its own lock- assert(buf->buffer == raw && buf->buffer_width == 200 && buf->buffer_height == 100);+ assert(rediwm_buffer_get_buffer(buf) == raw && buf->buffer_width == 200 && buf->buffer_height == 100);int w, h;rediwm_buffer_size(buf, &w, &h);assert(w == 200 && h == 100);@@ -173,6 +178,7 @@ int main(void) {rediwm_node_destroy(&buf->node);rediwm_scene_destroy(scene);+ wlr_scene_node_destroy(&wlr_scene->tree.node);puts("node tests passed");return 0;}diff --git a/src/notifications/toast.zig b/src/notifications/toast.zigindex 9378d38..3b6667f 100644--- a/src/notifications/toast.zig+++ b/src/notifications/toast.zig@@ -2,6 +2,7 @@//! Rendered using the ui/ widget engine into a PanelBuffer scene node.const std = @import("std");const wlr = @import("wlroots");+const sn = @import("../node.zig");const anim = @import("ui").anim;const panel_buffer = @import("../panel_buffer.zig");@@ -45,7 +46,7 @@ pub const Toast = struct {icon_id: ?u64 = null,icon_entry: ?icon_service_mod.Entry = null,- buffer_node: *wlr.SceneBuffer,+ buffer_node: *sn.Buffer,glass_effect: ?*glass.Effect = null,node_data: scene_data.SceneData = undefined,panel_box: wlr.Box = .{ .x = 0, .y = 0, .width = 0, .height = 0 },@@ -73,7 +74,7 @@ pub const Toast = struct {pub fn create(allocator: std.mem.Allocator,- parent_tree: *wlr.SceneTree,+ parent_tree: *sn.Tree,manager_ptr: *anyopaque,id: u32,app_name: []const u8,diff --git a/src/notifications_tests.zig b/src/notifications_tests.zigindex 972176d..c2b5ae5 100644--- a/src/notifications_tests.zig+++ b/src/notifications_tests.zig@@ -2,6 +2,7 @@const std = @import("std");const wl = @import("wayland").server.wl;const wlr = @import("wlroots");+const sn = @import("node.zig");const anim = @import("ui").anim;const notif = @import("notifications/mod.zig");@@ -16,8 +17,9 @@ test "notifications unit: replaces_id, urgency, DND, lock suppression" {defer display.destroy();const backend = try wlr.Backend.createHeadless(display.getEventLoop());defer backend.destroy();- const scene = try wlr.Scene.create();- defer scene.tree.node.destroy();+ var fixture = try sn.TestScene.create();+ defer fixture.destroy();+ const scene = fixture.wlr_scene;const output_layout = try wlr.OutputLayout.create(display);defer output_layout.destroy();var dummy_cursor: wlr.Cursor = std.mem.zeroes(wlr.Cursor);@@ -25,7 +27,7 @@ test "notifications unit: replaces_id, urgency, DND, lock suppression" {var server: Server = undefined;server.wl_server = display;server.scene = scene;- server.overlay_tree = try scene.tree.createSceneTree();+ server.overlay_tree = try fixture.nodes.tree.createSceneTree();server.locker = null;server.environ = std.process.Environ.empty;server.config = undefined;diff --git a/src/osd.zig b/src/osd.zigindex 7406f15..98e1f21 100644--- a/src/osd.zig+++ b/src/osd.zig@@ -1,6 +1,7 @@const std = @import("std");const wl = @import("wayland").server.wl;const wlr = @import("wlroots");+const sn = @import("node.zig");const Output = @import("Output.zig");const Server = @import("Server.zig");const painter = @import("osd_paint.zig");@@ -9,7 +10,7 @@ const anim = @import("ui").anim;const ui_input = @import("ui").input;pub const State = painter.State;-node: ?*wlr.SceneBuffer = null,+node: ?*sn.Buffer = null,timer: ?*wl.EventSource = null,state: ?State = null,painted_state: ?State = null,@@ -72,7 +73,7 @@ fn present(self: *Osd, output: *Output, state: State, restart: bool) !void {// Keep normal overlays inside the shell tree so isolated-window captures// exclude them. While locked, only this noninteractive buffer goes above// the opaque lock covers; the rest of the desktop remains covered.- const parent = if (output.server.locker != null) &output.server.scene.tree else output.server.overlay_tree;+ const parent = if (output.server.locker != null) output.server.lock_tree else output.server.overlay_tree;if (self.node.?.node.parent != parent) self.node.?.node.reparent(parent);const is_wide = painter.hasLevel(state.kind);@@ -141,7 +142,7 @@ fn position(self: *Osd, output: *Output) void {pub fn tick(self: *Osd, output: *Output, now: i64) bool {const state = self.state orelse return false;- const parent = if (output.server.locker != null) &output.server.scene.tree else output.server.overlay_tree;+ const parent = if (output.server.locker != null) output.server.lock_tree else output.server.overlay_tree;if (self.node) |node| {if (node.node.parent != parent) node.node.reparent(parent);}@@ -204,7 +205,7 @@ pub fn refreshAudio(server: *Server) void {}}-fn ignoreInput(_: *wlr.SceneBuffer, _: *f64, _: *f64) callconv(.c) bool {+fn ignoreInput(_: *sn.Buffer, _: *f64, _: *f64) callconv(.c) bool {return false;}@@ -215,15 +216,16 @@ test "OSD is noninteractive, stays above lock covers, rescales and releases itsdefer backend.destroy();const layout = try wlr.OutputLayout.create(display);defer layout.destroy();- const scene = try wlr.Scene.create();- defer scene.tree.node.destroy();+ var fixture = try sn.TestScene.create();+ defer fixture.destroy();+ const scene = fixture.wlr_scene;defer PanelBuffer.drainPool();var server: Server = undefined;server.wl_server = display;server.scene = scene;server.output_layout = layout;- server.overlay_tree = try scene.tree.createSceneTree();- server.lock_tree = try scene.tree.createSceneTree();+ server.overlay_tree = try fixture.nodes.tree.createSceneTree();+ server.lock_tree = try fixture.nodes.tree.createSceneTree();server.locker = null;const output = try backend.headlessAddOutput(1280, 720);var mode = wlr.Output.State.init();@@ -244,12 +246,12 @@ test "OSD is noninteractive, stays above lock covers, rescales and releases itsvar lock: @import("session/lock.zig").Lock = undefined;server.locker = &lock;try out.osd.present(&out, .{ .kind = .microphone, .active = true }, true);- try std.testing.expect(node.node.parent == &scene.tree);+ try std.testing.expect(node.node.parent == server.lock_tree);try std.testing.expectEqual(@as(i32, 76), node.dst_width);mode.setScale(1.5);try std.testing.expect(output.commitState(&mode));try out.osd.present(&out, .{ .kind = .caps_lock, .active = true }, true);- try std.testing.expectEqual(@as(i32, 114), node.buffer.?.width);+ try std.testing.expectEqual(@as(i32, 114), node.getBuffer().?.width);server.locker = null;_ = out.osd.tick(&out, 0);try std.testing.expect(node.node.parent == server.overlay_tree);@@ -270,15 +272,16 @@ test "OSD sound and brightness glides smoothly between levels" {defer backend.destroy();const layout = try wlr.OutputLayout.create(display);defer layout.destroy();- const scene = try wlr.Scene.create();- defer scene.tree.node.destroy();+ var fixture = try sn.TestScene.create();+ defer fixture.destroy();+ const scene = fixture.wlr_scene;defer PanelBuffer.drainPool();var server: Server = undefined;server.wl_server = display;server.scene = scene;server.output_layout = layout;- server.overlay_tree = try scene.tree.createSceneTree();- server.lock_tree = try scene.tree.createSceneTree();+ server.overlay_tree = try fixture.nodes.tree.createSceneTree();+ server.lock_tree = try fixture.nodes.tree.createSceneTree();server.locker = null;const output = try backend.headlessAddOutput(1280, 720);var mode = wlr.Output.State.init();diff --git a/src/panel_buffer.zig b/src/panel_buffer.zigindex 2f422d8..915d411 100644--- a/src/panel_buffer.zig+++ b/src/panel_buffer.zig@@ -6,6 +6,7 @@// only ever sees a buffer after wlroots has dropped it.const std = @import("std");const wlr = @import("wlroots");+const sn = @import("node.zig");const gpa = @import("main.zig").gpa;const geometry = @import("geometry.zig");@@ -131,7 +132,7 @@ pub const PanelBuffer = struct {return buf;}- pub fn publish(buf: *PanelBuffer, node: *wlr.SceneBuffer, scale: f32, damage: ?@import("ui").paint.ClipRect) void {+ pub fn publish(buf: *PanelBuffer, node: *sn.Buffer, scale: f32, damage: ?@import("ui").paint.ClipRect) void {if (damage) |box| {const pixman = @import("pixman");// Scene damage is buffer-local: use the actual raster scale,diff --git a/src/panel_present.zig b/src/panel_present.zigindex a7ad889..311a15c 100644--- a/src/panel_present.zig+++ b/src/panel_present.zig@@ -4,6 +4,7 @@// elsewhere; this file only moves and fades an already-installed buffer.const std = @import("std");const wlr = @import("wlroots");+const sn = @import("node.zig");pub const Stats = struct {paints: u64 = 0,@@ -66,7 +67,7 @@ pub fn slideOffset(t: f32, slide_distance: f32) i32 {/// so animation frames do not have to repaint pixels. No-ops when the node/// already has this position and opacity, so settled panels are not damaged/// on unrelated output frames.-pub fn applySlide(buffer_node: *wlr.SceneBuffer, box: wlr.Box, t: f32, slide_distance: f32) void {+pub fn applySlide(buffer_node: *sn.Buffer, box: wlr.Box, t: f32, slide_distance: f32) void {const clamped = std.math.clamp(t, 0, 1);const x = box.x;const y = box.y + slideOffset(clamped, slide_distance);diff --git a/src/polkit/dialog.zig b/src/polkit/dialog.zigindex b29272c..f361e3f 100644--- a/src/polkit/dialog.zig+++ b/src/polkit/dialog.zig@@ -2,6 +2,7 @@//! generic widget tree, clipboard, text cache or IPC inspection payloads.const std = @import("std");const wlr = @import("wlroots");+const sn = @import("../node.zig");const col = @import("../color.zig");const xkb = @import("xkbcommon");const Server = @import("../Server.zig");@@ -22,8 +23,8 @@ const unlock_box: ui.widgets.field.Rect = .{ .x = 288, .y = 408, .w = 244, .h =pub const Dialog = struct {server: *Server,output: *wlr.Output,- scrim: *wlr.SceneRect,- node: *wlr.SceneBuffer,+ scrim: *sn.Rect,+ node: *sn.Buffer,/// The response field's caret, above `node`.caret: CaretOverlay,/// Last key into the dialog: restarts the caret's blink phase.diff --git a/src/popup_style.zig b/src/popup_style.zigindex 19a41bf..50a08b6 100644--- a/src/popup_style.zig+++ b/src/popup_style.zig@@ -1,11 +1,12 @@//! Shared taskbar popup surfaces; controls still use the shared widgets.const std = @import("std");const wlr = @import("wlroots");+const sn = @import("node.zig");const ui = @import("ui");const glass = @import("glass.zig");const PanelBuffer = @import("panel_buffer.zig").PanelBuffer;-pub fn configureGlass(effect: *?*glass.Effect, engine: ?*glass.Engine, node: *wlr.SceneBuffer, factor: f32) void {+pub fn configureGlass(effect: *?*glass.Effect, engine: ?*glass.Engine, node: *sn.Buffer, factor: f32) void {const t = ui.theme.global;if (!t.popup_blur) {glass.Effect.detach(effect.*);diff --git a/src/power_menu.zig b/src/power_menu.zigindex 7804b57..f54d252 100644--- a/src/power_menu.zig+++ b/src/power_menu.zig@@ -3,6 +3,7 @@ const std = @import("std");const glass = @import("glass.zig");const wl = @import("wayland").server.wl;const wlr = @import("wlroots");+const sn = @import("node.zig");const col = @import("color.zig");const gpa = @import("main.zig").gpa;@@ -77,8 +78,8 @@ pub const PowerMenu = struct {// modal rather than just another floating panel. Purely decorative —// outside-click dismissal is driven by cursor-vs-panel_box math in// Input.zig, not by hit-testing this node.- scrim: *wlr.SceneRect,- buffer_node: *wlr.SceneBuffer,+ scrim: *sn.Rect,+ buffer_node: *sn.Buffer,glass_effect: ?*glass.Effect = null,node_data: scene_data.SceneData = undefined,diff --git a/src/projection.c b/src/projection.cindex ba6162f..b43e30a 100644--- a/src/projection.c+++ b/src/projection.c@@ -3,6 +3,7 @@#define WLR_USE_UNSTABLE#define WLR_PRIVATE private#include "projection.h"+#include "node.h"#include "scene_graph.h"#include "scene_damage.h"#include <math.h>@@ -29,7 +30,11 @@// told so and must treat everything as changed.enum { DAMAGE_EVENTS = 4096 };struct rediwm_projection {- struct wlr_scene_tree *source;+ // The compositor's scene. The children of its root are layers, bottom to top:+ // `world` follows the camera, every other layer is laid out as is. The wlroots+ // scene is kept for its outputs.+ struct rediwm_scene *own;+ struct rediwm_tree *world;struct wlr_scene *scene;// Every adapter, in creation order; `paint` holds the groups resolve() last// reached, bottom to top.@@ -66,7 +71,7 @@ struct group {struct wl_list items;bool enabled;struct rediwm_projection *projection;- struct wlr_scene_node *source;+ struct rediwm_node *source;struct wl_listener destroy;struct wlr_addon source_lookup;bool seen;@@ -81,7 +86,13 @@ struct leaf {// In its group's `items` when the last resolve() reached it, else alone.struct wl_list paint;struct rediwm_projection *projection;+ // The wlr_scene node the pass reads the pixels from (`transport`): a buffer's or a+ // rect's carrier, or a client surface's own node.struct wlr_scene_node *source;+ // The own node that places it, or NULL for a node inside a foreign subtree, whose+ // `foreign` is the own node hosting that subtree.+ struct rediwm_node *own;+ struct rediwm_foreign *foreign;struct wl_listener destroy, commit;struct wlr_addon source_lookup;struct wlr_scene_surface *surface;@@ -167,39 +178,39 @@ static void destroy_tree_props(struct wlr_addon *addon) {}static const struct wlr_addon_interface tree_props_impl = {.name = "rediwm tree presentation", .destroy = destroy_tree_props};-static struct tree_props *tree_props_find(struct wlr_scene_node *node) {- struct wlr_addon *addon = wlr_addon_find(&node->addons, NULL, &tree_props_impl);+static struct tree_props *tree_props_find(struct wlr_addon_set *set) {+ struct wlr_addon *addon = wlr_addon_find(set, NULL, &tree_props_impl);struct tree_props *props;return addon ? (props = wl_container_of(addon, props, addon)) : NULL;}-static struct tree_props *tree_props_get(struct wlr_scene_node *node) {- struct tree_props *props = tree_props_find(node);+static struct tree_props *tree_props_get(struct wlr_addon_set *set) {+ struct tree_props *props = tree_props_find(set);if (props) return props;props = calloc(1, sizeof(*props));if (!props) return NULL;- wlr_addon_init(&props->addon, &node->addons, NULL, &tree_props_impl);+ wlr_addon_init(&props->addon, set, NULL, &tree_props_impl);return props;}-bool rediwm_projection_set_tree_zoom(struct wlr_scene_node *node, double scale) {- struct tree_props *props = tree_props_get(node);+static bool set_tree_zoom(struct wlr_addon_set *set, double scale) {+ struct tree_props *props = tree_props_get(set);if (!props) return false;props->zoom = scale;props->has_zoom = true;return true;}-bool rediwm_projection_set_tree_scale(struct wlr_scene_node *node, double factor) {+static bool set_tree_scale(struct wlr_addon_set *set, double factor) {if (factor <= 0) return false;- struct tree_props *props = tree_props_get(node);+ struct tree_props *props = tree_props_get(set);if (!props) return false;props->scale = factor;props->has_scale = true;return true;}static bool finite_at_least_zero(double value) { return isfinite(value) && value >= 0; }-bool rediwm_projection_set_tree_clip(struct wlr_scene_node *node,+static bool set_tree_clip(struct wlr_addon_set *set,const struct rediwm_clip_spec *spec) {if (!spec) {- struct tree_props *props = tree_props_find(node);+ struct tree_props *props = tree_props_find(set);if (props) props->has_clip = false;return true;}@@ -211,16 +222,16 @@ bool rediwm_projection_set_tree_clip(struct wlr_scene_node *node,if (!isfinite(spec->glow_x) || !isfinite(spec->glow_y) || !finite_at_least_zero(spec->glow_radius) ||!finite_at_least_zero(spec->glow_depth))return false;- struct tree_props *props = tree_props_get(node);+ struct tree_props *props = tree_props_get(set);if (!props) return false;props->clip = *spec;props->has_clip = true;return true;}-bool rediwm_projection_set_tree_shadow(struct wlr_scene_node *node,+static bool set_tree_shadow(struct wlr_addon_set *set,const struct rediwm_shadow_spec *spec) {if (!spec) {- struct tree_props *props = tree_props_find(node);+ struct tree_props *props = tree_props_find(set);if (props) props->has_shadow = false;return true;}@@ -229,40 +240,55 @@ bool rediwm_projection_set_tree_shadow(struct wlr_scene_node *node,return false;for (int i = 0; i < 4; i++)if (!finite_at_least_zero(spec->radii[i]) || !isfinite(spec->color[i])) return false;- struct tree_props *props = tree_props_get(node);+ struct tree_props *props = tree_props_get(set);if (!props) return false;props->shadow = *spec;props->has_shadow = true;return true;}-bool rediwm_projection_set_tree_dim(struct wlr_scene_node *node, float brightness, float saturation) {+static bool set_tree_dim(struct wlr_addon_set *set, float brightness, float saturation) {if (!isfinite(brightness) || !isfinite(saturation) || brightness < 0 || brightness > 1 ||saturation < 0 || saturation > 1)return false;if (brightness == 0 && saturation == 0) {// Nothing taken away is no dim; a tree that has none gets no addon for it.- struct tree_props *props = tree_props_find(node);+ struct tree_props *props = tree_props_find(set);if (props) props->has_dim = false;return true;}- struct tree_props *props = tree_props_get(node);+ struct tree_props *props = tree_props_get(set);if (!props) return false;props->dim = (struct dim){brightness, saturation};props->has_dim = true;return true;}-bool rediwm_projection_set_tree_unclipped(struct wlr_scene_node *node, bool unclipped) {- struct tree_props *props = unclipped ? tree_props_get(node) : tree_props_find(node);+static bool set_tree_unclipped(struct wlr_addon_set *set, bool unclipped) {+ struct tree_props *props = unclipped ? tree_props_get(set) : tree_props_find(set);if (unclipped && !props) return false;if (props) props->unclipped = unclipped;return true;}-bool rediwm_projection_set_tree_inert(struct wlr_scene_node *node, bool inert) {- struct tree_props *props = inert ? tree_props_get(node) : tree_props_find(node);+static bool set_tree_inert(struct wlr_addon_set *set, bool inert) {+ struct tree_props *props = inert ? tree_props_get(set) : tree_props_find(set);if (inert && !props) return false;if (props) props->inert = inert;return true;}++bool rediwm_projection_set_tree_zoom(struct rediwm_node *node, double scale) { return set_tree_zoom(&node->addons, scale); }+bool rediwm_projection_set_wlr_tree_zoom(struct wlr_scene_node *node, double scale) { return set_tree_zoom(&node->addons, scale); }+bool rediwm_projection_set_tree_scale(struct rediwm_node *node, double factor) { return set_tree_scale(&node->addons, factor); }+bool rediwm_projection_set_wlr_tree_scale(struct wlr_scene_node *node, double factor) { return set_tree_scale(&node->addons, factor); }+bool rediwm_projection_set_tree_clip(struct rediwm_node *node, const struct rediwm_clip_spec *spec) { return set_tree_clip(&node->addons, spec); }+bool rediwm_projection_set_wlr_tree_clip(struct wlr_scene_node *node, const struct rediwm_clip_spec *spec) { return set_tree_clip(&node->addons, spec); }+bool rediwm_projection_set_tree_shadow(struct rediwm_node *node, const struct rediwm_shadow_spec *spec) { return set_tree_shadow(&node->addons, spec); }+bool rediwm_projection_set_wlr_tree_shadow(struct wlr_scene_node *node, const struct rediwm_shadow_spec *spec) { return set_tree_shadow(&node->addons, spec); }+bool rediwm_projection_set_tree_dim(struct rediwm_node *node, float brightness, float saturation) { return set_tree_dim(&node->addons, brightness, saturation); }+bool rediwm_projection_set_wlr_tree_dim(struct wlr_scene_node *node, float brightness, float saturation) { return set_tree_dim(&node->addons, brightness, saturation); }+bool rediwm_projection_set_tree_unclipped(struct rediwm_node *node, bool unclipped) { return set_tree_unclipped(&node->addons, unclipped); }+bool rediwm_projection_set_wlr_tree_unclipped(struct wlr_scene_node *node, bool unclipped) { return set_tree_unclipped(&node->addons, unclipped); }+bool rediwm_projection_set_tree_inert(struct rediwm_node *node, bool inert) { return set_tree_inert(&node->addons, inert); }+bool rediwm_projection_set_wlr_tree_inert(struct wlr_scene_node *node, bool inert) { return set_tree_inert(&node->addons, inert); }static const struct wlr_addon_interface source_lookup_impl, group_source_impl;struct watched_surface {struct rediwm_projection *projection;@@ -308,7 +334,7 @@ static void group_source_addon_destroy(struct wlr_addon *addon) {static const struct wlr_addon_interface group_source_impl = {.name = "rediwm projection group source", .destroy = group_source_addon_destroy};static struct group *get_group(struct rediwm_projection *p,- struct wlr_scene_node *source) {+ struct rediwm_node *source) {struct wlr_addon *addon = wlr_addon_find(&source->addons, p, &group_source_impl);struct group *g;if (addon)@@ -458,8 +484,8 @@ static void committed(struct wl_listener *listener, void *data) {l->dirty = true;schedule(l->projection);}-static struct leaf *get_leaf(struct rediwm_projection *p,- struct wlr_scene_node *source) {+static struct leaf *get_leaf(struct rediwm_projection *p, struct wlr_scene_node *source,+ struct rediwm_node *own, struct rediwm_foreign *foreign) {struct wlr_addon *addon =wlr_addon_find(&source->addons, p, &source_lookup_impl);struct leaf *l;@@ -469,6 +495,8 @@ static struct leaf *get_leaf(struct rediwm_projection *p,if (!l)return NULL;l->source = source;+ l->own = own;+ l->foreign = foreign;l->projection = p;l->item.id = ++p->next_leaf_id;l->dirty = true;@@ -501,16 +529,14 @@ static struct leaf *get_leaf(struct rediwm_projection *p,#include "glass.h"// A glass effect covers its target exactly: the box is the target's (same// parent), and it is shown only with it. The pass draws the blur (stage 5c).-static void effect_geometry(struct wlr_scene_node *node, int *x, int *y, int *width,- int *height, bool *enabled) {- struct rediwm_glass_info info;- if (!rediwm_glass_effect_info(node, &info)) return;- struct wlr_scene_buffer *t = info.target;- *x += t->node.x - node->x;- *y += t->node.y - node->y;+static void effect_geometry(const struct rediwm_node *own, const struct rediwm_glass_info *info,+ int *x, int *y, int *width, int *height, bool *enabled) {+ const struct rediwm_buffer *t = info->target;+ *x += t->node.x - own->x;+ *y += t->node.y - own->y;*enabled = *enabled && t->node.enabled;- *width = t->dst_width ? t->dst_width : t->private.buffer_width;- *height = t->dst_height ? t->dst_height : t->private.buffer_height;+ *width = t->dst_width ? t->dst_width : t->buffer_width;+ *height = t->dst_height ? t->dst_height : t->buffer_height;}// A clip's size, radii, border or colour changed: its views did not move, so@@ -581,68 +607,74 @@ static void damage_clip_change(struct rediwm_projection *p, const struct rediwm_// resolve(): source tree -> graph. Writes items, group origins, `seen` flags and// the paint-order lists; creates adapters for nodes it meets the first time, but// moves and shows nothing.-static void resolve_node(struct rediwm_projection *p, struct group *g,- struct wlr_scene_node *node, double x, double y,- bool enabled, bool inert, struct rediwm_xform t,- const struct rediwm_clip *clip, const struct dim *dim,- const struct rediwm_shadow *shadow) {- x += node->x;- y += node->y;- enabled = enabled && node->enabled;- if (node->type == WLR_SCENE_NODE_TREE) {- struct rediwm_clip here;- struct rediwm_shadow cast;- struct tree_props *props = tree_props_find(node);- if (props) {- // Window zoom composes with the camera, around the frame origin.- if (props->has_zoom) t = rediwm_xform_scale_about(t, props->zoom, x, y);- if (props->has_scale) t = rediwm_xform_scale_about(t, props->scale, x, y);- if (props->unclipped) {- clip = NULL;- dim = NULL;- }- if (props->inert) inert = true;- if (props->has_dim) dim = &props->dim;- if (props->has_clip) {- here = rediwm_clip_resolve(t, x, y, &props->clip);- clip = &here;- // A hidden window damages nothing; showing it will.- if (enabled && (!props->has_applied || !clip_same_shape(&props->applied, &here) ||- !clip_same_glow(&props->applied, &here)))- damage_clip_change(p, props->has_applied ? &props->applied : NULL, &here);- props->applied = here;- props->has_applied = true;- } else if (props->has_applied) {- if (enabled) damage_clip_change(p, &props->applied, NULL);- props->has_applied = false;- }- if (props->has_shadow) {- cast = rediwm_shadow_resolve(t, x, y, &props->shadow);- shadow = &cast;- }- }- struct wlr_scene_node *child;- wl_list_for_each(child, &wlr_scene_tree_from_node(node)->children, link)- resolve_node(p, g, child, x, y, enabled, inert, t, clip, dim, shadow);- return;+// What the walk carries down the tree: where the subtree is, whether it shows and+// takes input, and how it is presented. A tree's own properties are folded in as it+// is entered.+struct walk {+ double x, y;+ bool enabled, inert;+ struct rediwm_xform t;+ const struct rediwm_clip *clip;+ const struct dim *dim;+ const struct rediwm_shadow *shadow;+ struct rediwm_foreign *foreign;+};+// `here` and `cast` hold the tree's clip and shadow for as long as the walk is below+// it.+static void apply_tree(struct rediwm_projection *p, struct tree_props *props, struct walk *w,+ struct rediwm_clip *here, struct rediwm_shadow *cast) {+ if (!props) return;+ // Window zoom composes with the camera, around the frame origin.+ if (props->has_zoom) w->t = rediwm_xform_scale_about(w->t, props->zoom, w->x, w->y);+ if (props->has_scale) w->t = rediwm_xform_scale_about(w->t, props->scale, w->x, w->y);+ if (props->unclipped) {+ w->clip = NULL;+ w->dim = NULL;+ }+ if (props->inert) w->inert = true;+ if (props->has_dim) w->dim = &props->dim;+ if (props->has_clip) {+ *here = rediwm_clip_resolve(w->t, w->x, w->y, &props->clip);+ w->clip = here;+ // A hidden window damages nothing; showing it will.+ if (w->enabled && (!props->has_applied || !clip_same_shape(&props->applied, here) ||+ !clip_same_glow(&props->applied, here)))+ damage_clip_change(p, props->has_applied ? &props->applied : NULL, here);+ props->applied = *here;+ props->has_applied = true;+ } else if (props->has_applied) {+ if (w->enabled) damage_clip_change(p, &props->applied, NULL);+ props->has_applied = false;}- struct leaf *l = get_leaf(p, node);+ if (props->has_shadow) {+ *cast = rediwm_shadow_resolve(w->t, w->x, w->y, &props->shadow);+ w->shadow = cast;+ }+}+// One leaf into the graph. `node` is the wlr_scene node the pass reads pixels from;+// (x, y) and `enabled` are the leaf's own, from whichever tree placed it.+static void resolve_leaf(struct rediwm_projection *p, struct group *g, struct wlr_scene_node *node,+ struct rediwm_node *own, const struct walk *w, double x, double y,+ bool enabled) {+ struct leaf *l = get_leaf(p, node, own, w->foreign);if (!l) {wlr_log(WLR_ERROR, "zoom: cannot allocate presentation node");return;}l->seen = true;- if (l->inert != inert) l->inert = inert;+ if (l->inert != w->inert) l->inert = w->inert;+ if (l->own != own) l->own = own;+ if (l->foreign != w->foreign) l->foreign = w->foreign;// Flattened leaves within each group retain the source's paint order.wl_list_insert(g->items.prev, &l->paint);struct rediwm_item *item = &l->item;item->enabled = enabled;- item->scale = t.scale;+ item->scale = w->t.scale;item->content = (struct rediwm_content){0};// Only write what changes: rewriting a NULL over a NULL on every leaf of every// window dirties the line for nothing (measured at about 1 ns per leaf).- if (clip) {- l->clip = *clip;+ if (w->clip) {+ l->clip = *w->clip;item->clip = &l->clip;} else if (item->clip) {item->clip = NULL;@@ -661,8 +693,10 @@ static void resolve_node(struct rediwm_projection *p, struct group *g,item->width = b->dst_width;item->height = b->dst_height;if (item->kind == REDIWM_ITEM_EFFECT) {+ struct rediwm_glass_info info;int ex = 0, ey = 0;- effect_geometry(node, &ex, &ey, &item->width, &item->height, &item->enabled);+ if (own && rediwm_glass_effect_info(node, &info))+ effect_geometry(own, &info, &ex, &ey, &item->width, &item->height, &item->enabled);x += ex;y += ey;} else if (!item->width || !item->height) {@@ -678,24 +712,81 @@ static void resolve_node(struct rediwm_projection *p, struct group *g,content->src_box = b->src_box;content->transform = b->transform;content->opacity = b->opacity;- content->filter_mode = rediwm_filter_at_scale(t.scale, b->filter_mode);+ content->filter_mode = rediwm_filter_at_scale(w->t.scale, b->filter_mode);content->transfer_function = b->transfer_function;content->primaries = b->primaries;content->color_encoding = b->color_encoding;content->color_range = b->color_range;}- if (dim) {- item->content.dim_brightness = dim->brightness;- item->content.dim_saturation = dim->saturation;+ if (w->dim) {+ item->content.dim_brightness = w->dim->brightness;+ item->content.dim_saturation = w->dim->saturation;}- if (shadow && node->type == WLR_SCENE_NODE_BUFFER) {+ if (w->shadow && node->type == WLR_SCENE_NODE_BUFFER) {item->kind = REDIWM_ITEM_SHADOW;- l->shadow = *shadow;+ l->shadow = *w->shadow;item->shadow = &l->shadow;} else if (item->shadow) {item->shadow = NULL;}- item->edges = rediwm_xform_rect(t, x, y, item->width, item->height);+ item->edges = rediwm_xform_rect(w->t, x, y, item->width, item->height);+}+// A wlroots subtree (the surfaces of a client): its nodes are the pixel sources+// themselves.+static void resolve_wlr(struct rediwm_projection *p, struct group *g, struct wlr_scene_node *node,+ const struct walk *parent) {+ const double x = parent->x + node->x, y = parent->y + node->y;+ const bool enabled = parent->enabled && node->enabled;+ if (node->type != WLR_SCENE_NODE_TREE) {+ resolve_leaf(p, g, node, NULL, parent, x, y, enabled);+ return;+ }+ struct walk w = *parent;+ w.x = x;+ w.y = y;+ w.enabled = enabled;+ struct rediwm_clip here;+ struct rediwm_shadow cast;+ apply_tree(p, tree_props_find(&node->addons), &w, &here, &cast);+ struct wlr_scene_node *child;+ wl_list_for_each(child, &wlr_scene_tree_from_node(node)->children, link)+ resolve_wlr(p, g, child, &w);+}+static void resolve_own(struct rediwm_projection *p, struct group *g, struct rediwm_node *node,+ const struct walk *parent) {+ const double x = parent->x + node->x, y = parent->y + node->y;+ const bool enabled = parent->enabled && node->enabled;+ switch (node->type) {+ case REDIWM_NODE_RECT:+ resolve_leaf(p, g, &((struct rediwm_rect *)node)->carrier->node, node, parent, x, y, enabled);+ return;+ case REDIWM_NODE_BUFFER:+ resolve_leaf(p, g, &((struct rediwm_buffer *)node)->carrier->node, node, parent, x, y, enabled);+ return;+ case REDIWM_NODE_TREE: {+ struct walk w = *parent;+ w.x = x;+ w.y = y;+ w.enabled = enabled;+ struct rediwm_clip here;+ struct rediwm_shadow cast;+ apply_tree(p, tree_props_find(&node->addons), &w, &here, &cast);+ struct rediwm_node *child;+ wl_list_for_each(child, &((struct rediwm_tree *)node)->children, link)+ resolve_own(p, g, child, &w);+ return;+ }+ case REDIWM_NODE_FOREIGN: {+ // The hosted subtree's root stays at its own origin; this node carries the place.+ struct walk w = *parent;+ w.x = x;+ w.y = y;+ w.enabled = enabled;+ w.foreign = (struct rediwm_foreign *)node;+ resolve_wlr(p, g, ((struct rediwm_foreign *)node)->wlr, &w);+ return;+ }+ }}// What a shadow draws changed, or it appeared or went: damage the footprint it@@ -1041,12 +1132,17 @@ void rediwm_projection_send_frame_done(struct rediwm_projection *p, struct wlr_swl_signal_emit_mutable(&wlr_scene_buffer_from_node(f->leaf->source)->events.frame_done, &event);}}-struct rediwm_projection *-rediwm_projection_create(struct wlr_scene_tree *source, struct wlr_scene *scene) {+static void schedule_changed(void *data) { schedule(data); }+static void buffer_given(void *data, struct rediwm_buffer *b, const pixman_region32_t *damage) {+ rediwm_projection_damage_buffer(data, &b->carrier->node, damage);+}+struct rediwm_projection *rediwm_projection_create(struct rediwm_scene *own, struct rediwm_tree *world,+ struct wlr_scene *scene) {struct rediwm_projection *p = calloc(1, sizeof(*p));if (!p)return NULL;- p->source = source;+ p->own = own;+ p->world = world;p->scene = scene;wl_list_init(&p->leaves);wl_list_init(&p->groups);@@ -1055,15 +1151,16 @@ rediwm_projection_create(struct wlr_scene_tree *source, struct wlr_scene *scene)wl_list_init(&p->feedback);wl_list_init(&p->new_surface.link);pixman_region32_init(&p->pending);- // wlroots ignores a disabled tree: it computes no outputs, frame callbacks or- // damage for the source nodes; the graph does all three.- wlr_scene_node_set_enabled(&source->node, false);+ // Every change to the tree asks for a frame; the next sync finds what moved.+ own->changed = schedule_changed;+ own->buffer_damaged = buffer_given;+ own->changed_data = p;return p;}// Source tree -> graph. Every adapter is detached from the paint lists first, so// the lists hold exactly what this pass reaches, in source paint order.static void resolve(struct rediwm_projection *p, double z, double cx, double cy,- double ox, double oy, struct wlr_scene_tree *fixed) {+ double ox, double oy, struct rediwm_tree *fixed) {struct leaf *l;wl_list_for_each(l, &p->leaves, link) {l->seen = false;@@ -1076,19 +1173,29 @@ static void resolve(struct rediwm_projection *p, double z, double cx, double cy,}const struct rediwm_xform camera = rediwm_xform_camera(z, cx, cy, ox, oy);const struct rediwm_xform identity = {1, 0, 0};- struct wlr_scene_node *node;- wl_list_for_each(node, &p->source->children, link) {- g = get_group(p, node);- if (!g) {- wlr_log(WLR_ERROR, "zoom: cannot allocate presentation group");- continue;+ struct rediwm_node *layer;+ wl_list_for_each(layer, &p->own->tree.children, link) {+ if (layer->type != REDIWM_NODE_TREE) continue;+ const bool world = layer == &p->world->node;+ // The world is resolved from its children, ignoring its own place and state; any+ // other layer is a tree like the rest and hides what it holds when disabled.+ const struct walk base = {.x = world ? 0 : layer->x, .y = world ? 0 : layer->y,+ .enabled = world || layer->enabled, .t = world ? camera : identity};+ struct rediwm_node *node;+ wl_list_for_each(node, &((struct rediwm_tree *)layer)->children, link) {+ g = get_group(p, node);+ if (!g) {+ wlr_log(WLR_ERROR, "zoom: cannot allocate presentation group");+ continue;+ }+ struct walk w = base;+ // The fixed subtree is laid out as is; everything else follows the camera.+ if (world && fixed && node == &fixed->node) w.t = identity;+ g->seen = true;+ g->enabled = base.enabled && node->enabled;+ wl_list_insert(p->paint.prev, &g->paint);+ resolve_own(p, g, node, &w);}- // The fixed subtree is laid out as is; everything else follows the camera.- const struct rediwm_xform t = fixed && node == &fixed->node ? identity : camera;- g->seen = true;- g->enabled = node->enabled;- wl_list_insert(p->paint.prev, &g->paint);- resolve_node(p, g, node, 0, 0, true, false, t, NULL, NULL, NULL);}}static void damage_restacked(struct rediwm_projection *p);@@ -1177,7 +1284,7 @@ static void apply_damage(struct rediwm_projection *p) {}void rediwm_projection_sync_fixed(struct rediwm_projection *p, double z, double cx,double cy, double ox, double oy,- struct wlr_scene_tree *fixed) {+ struct rediwm_tree *fixed) {if (!p)return;resolve(p, z, cx, cy, ox, oy, fixed);@@ -1188,70 +1295,18 @@ void rediwm_projection_sync(struct rediwm_projection *p, double z, double cx,double cy, double ox, double oy) {rediwm_projection_sync_fixed(p, z, cx, cy, ox, oy, NULL);}-// Shell/layer/lock nodes have identity layout transforms. Resolve them into the-// same item type at the output boundary.-static struct rediwm_item layout_item(struct wlr_scene_node *node, int x, int y) {- struct rediwm_item item = {.enabled = node->enabled, .scale = 1};- if (node->type == WLR_SCENE_NODE_RECT) {- struct wlr_scene_rect *r = wlr_scene_rect_from_node(node);- item.kind = REDIWM_ITEM_RECT;- item.width = r->width;- item.height = r->height;- memcpy(item.content.color, r->color, sizeof(item.content.color));- } else {- struct wlr_scene_buffer *b = wlr_scene_buffer_from_node(node);- item.kind = rediwm_glass_is_effect_node(node) ? REDIWM_ITEM_EFFECT :- wlr_scene_surface_try_from_buffer(b) ? REDIWM_ITEM_SURFACE : REDIWM_ITEM_BUFFER;- item.width = b->dst_width;- item.height = b->dst_height;- if (item.kind == REDIWM_ITEM_EFFECT) {- effect_geometry(node, &x, &y, &item.width, &item.height, &item.enabled);- } else if (!item.width || !item.height) {- item.width = b->private.buffer_width;- item.height = b->private.buffer_height;- if (b->transform & 1) { int tmp = item.width; item.width = item.height; item.height = tmp; }- }- item.content = (struct rediwm_content){- .opacity = b->opacity, .src_box = b->src_box, .transform = b->transform,- .filter_mode = b->filter_mode, .transfer_function = b->transfer_function,- .primaries = b->primaries, .color_encoding = b->color_encoding, .color_range = b->color_range,- };- }- item.edges = rediwm_xform_rect((struct rediwm_xform){1, 0, 0}, x, y, item.width, item.height);- return item;-}-static bool visit_items(struct rediwm_projection *p, struct wlr_scene_node *node,- int x, int y, bool reverse, rediwm_item_iterator iterator, void *data) {- if (!node->enabled && node != &p->source->node) return true;- if (node == &p->source->node) {- for (struct wl_list *link = reverse ? p->paint.prev : p->paint.next;- link != &p->paint; link = reverse ? link->prev : link->next) {- struct group *g = wl_container_of(link, g, paint);- if (!g->enabled) continue;- for (struct wl_list *leaf_link = reverse ? g->items.prev : g->items.next;- leaf_link != &g->items; leaf_link = reverse ? leaf_link->prev : leaf_link->next) {- struct leaf *l = wl_container_of(leaf_link, l, paint);- if (l->item.enabled && !iterator(&l->item, l->source, data)) return false;- }- }- return true;- }- x += node->x;- y += node->y;- if (node->type == WLR_SCENE_NODE_TREE) {- struct wl_list *children = &wlr_scene_tree_from_node(node)->children;- for (struct wl_list *link = reverse ? children->prev : children->next;- link != children; link = reverse ? link->prev : link->next) {- struct wlr_scene_node *child = wl_container_of(link, child, link);- if (!visit_items(p, child, x, y, reverse, iterator, data)) return false;+bool rediwm_projection_for_each_item(struct rediwm_projection *p, bool reverse, rediwm_item_iterator iterator, void *data) {+ for (struct wl_list *link = reverse ? p->paint.prev : p->paint.next;+ link != &p->paint; link = reverse ? link->prev : link->next) {+ struct group *g = wl_container_of(link, g, paint);+ if (!g->enabled) continue;+ for (struct wl_list *leaf_link = reverse ? g->items.prev : g->items.next;+ leaf_link != &g->items; leaf_link = reverse ? leaf_link->prev : leaf_link->next) {+ struct leaf *l = wl_container_of(leaf_link, l, paint);+ if (l->item.enabled && !iterator(&l->item, l->source, data)) return false;}- return true;}- struct rediwm_item item = layout_item(node, x, y);- return iterator(&item, node, data);-}-bool rediwm_projection_for_each_item(struct rediwm_projection *p, bool reverse, rediwm_item_iterator iterator, void *data) {- return visit_items(p, &p->scene->tree.node, 0, 0, reverse, iterator, data);+ return true;}// A node's opaque region (in its own units) as it lands on screen, never larger// than the real one.@@ -1284,16 +1339,16 @@ void rediwm_mirror_opaque(pixman_region32_t *out, const pixman_region32_t *sourcpixman_region32_intersect_rect(out, out, 0, 0, width, height);}// ---- Hit testing (stage 6 of docs/plans/scene-graph.md) ---------------------------// What wlr_scene_node_at gave on the world's view tree, from the graph: the items-// from the top of the paint order down, each tested at the pixels it covers once-// rounded, then against the window's shape and the source buffer's own input-// region. The layout trees are still wlroots' to pick (D1).-static struct wlr_scene_node *pick_world(struct rediwm_projection *p, double lx, double ly,- double *nx, double *ny) {+// The topmost node at a layout point, from the graph: the items from the top of the+// paint order down, each tested at the pixels it covers once rounded, then against+// the window's shape and the node's own input rule.+// `only` restricts the pick to the leaves of one top-level subtree.+static bool pick_leaf(struct rediwm_projection *p, const struct group *only, double lx, double ly,+ struct rediwm_hit *hit) {const double px = floor(lx), py = floor(ly);for (struct wl_list *gl = p->paint.prev; gl != &p->paint; gl = gl->prev) {struct group *g = wl_container_of(gl, g, paint);- if (!g->enabled) continue;+ if (!g->enabled || (only && g != only)) continue;for (struct wl_list *ll = g->items.prev; ll != &g->items; ll = ll->prev) {struct leaf *l = wl_container_of(ll, l, paint);const struct rediwm_item *item = &l->item;@@ -1316,37 +1371,33 @@ static struct wlr_scene_node *pick_world(struct rediwm_projection *p, double lx,const double cy = e->y1 + y * (e->y2 - e->y1) / item->height;if (rediwm_clip_distance(item->clip, cx, cy) > 0) continue;}- struct wlr_scene_buffer *source = wlr_scene_buffer_from_node(l->source);- if (source->point_accepts_input && !source->point_accepts_input(source, &x, &y)) continue;+ if (l->own) {+ struct rediwm_buffer *own = rediwm_buffer_from_node(l->own);+ if (own->point_accepts_input && !own->point_accepts_input(own, &x, &y)) continue;+ } else {+ struct wlr_scene_buffer *source = wlr_scene_buffer_from_node(l->source);+ if (source->point_accepts_input && !source->point_accepts_input(source, &x, &y)) continue;+ }}- *nx = x;- *ny = y;- return l->source;+ *hit = (struct rediwm_hit){.own = l->own, .wlr = l->source, .foreign = l->foreign, .x = x, .y = y};+ return true;}}- return NULL;-}-static struct wlr_scene_node *pick_layout(struct wlr_scene_node *node, double lx, double ly,- double *nx, double *ny) {- return wlr_scene_node_at(node, lx, ly, nx, ny);-}-// The topmost node at a layout point and the point in its own coordinates, or NULL.-// A hit in the world is the source node.-struct wlr_scene_node *rediwm_projection_node_at(struct rediwm_projection *p, double lx, double ly,- double *nx, double *ny) {- struct wlr_scene_node *hit = NULL;- double x = 0, y = 0;- struct wl_list *children = &p->scene->tree.children;- for (struct wl_list *link = children->prev; link != children && !hit; link = link->prev) {- struct wlr_scene_node *child = wl_container_of(link, child, link);- if (child == &p->source->node) hit = pick_world(p, lx, ly, &x, &y);- else hit = pick_layout(child, lx, ly, &x, &y);- }- if (hit) {- if (nx) *nx = x;- if (ny) *ny = y;- }- return hit;+ return false;+}+bool rediwm_projection_node_at(struct rediwm_projection *p, double lx, double ly,+ struct rediwm_hit *hit) {+ return pick_leaf(p, NULL, lx, ly, hit);+}+// The topmost leaf of one top-level subtree of a layer (a window's frame tree) at a+// point, whatever lies above it.+bool rediwm_projection_node_at_in(struct rediwm_projection *p, struct rediwm_node *subtree,+ double lx, double ly, struct rediwm_hit *hit) {+ struct wlr_addon *addon = wlr_addon_find(&subtree->addons, p, &group_source_impl);+ struct group *g;+ if (!addon) return false;+ g = wl_container_of(addon, g, source_lookup);+ return pick_leaf(p, g, lx, ly, hit);}static void watched_commit(struct wl_listener *listener, void *data) {(void)data;@@ -1391,6 +1442,11 @@ void rediwm_projection_destroy(struct rediwm_projection *p) {struct group *g, *next_group;wl_list_for_each_safe(g, next_group, &p->groups, link) destroy_group(g);wl_list_remove(&p->new_surface.link);+ if (p->own->changed_data == p) {+ p->own->changed = NULL;+ p->own->buffer_damaged = NULL;+ p->own->changed_data = NULL;+ }pixman_region32_fini(&p->pending);struct watched_surface *watch, *next;wl_list_for_each_safe(watch, next, &p->surfaces, link)diff --git a/src/projection.h b/src/projection.hindex bcfe4a2..62a6f44 100644--- a/src/projection.h+++ b/src/projection.h@@ -4,6 +4,10 @@struct wlr_scene_node;struct wlr_scene_tree;struct wlr_scene;+struct rediwm_node;+struct rediwm_tree;+struct rediwm_foreign;+struct rediwm_scene;struct wlr_scene_buffer;struct wlr_surface_state;struct rediwm_projection;@@ -20,9 +24,13 @@ bool rediwm_projection_for_each_item(struct rediwm_projection *, bool reverse, r// Whether a commit changed how buffer pixels map onto the surface, so damage// from before it cannot be combined with damage after it.bool rediwm_surface_state_remapped(const struct wlr_surface_state *);-// `source` is the world's tree, disabled so that wlroots ignores it; the-// projection resolves it into the graph the output pass draws.-struct rediwm_projection *rediwm_projection_create(struct wlr_scene_tree *source,+// `own` is the compositor's scene: the children of its root are layers, bottom to+// top, and `world` (one of them) follows the camera while the others are laid out as+// they are. The projection resolves all of it into the graph the output pass draws,+// and asks for a frame whenever the scene changes. `scene` is wlroots' scene, kept+// for its outputs.+struct rediwm_projection *rediwm_projection_create(struct rediwm_scene *own,+ struct rediwm_tree *world,struct wlr_scene *);void rediwm_projection_destroy(struct rediwm_projection *);void rediwm_projection_sync(struct rediwm_projection *, double, double, double,@@ -40,37 +48,59 @@ typedef void (*rediwm_damage_event_iterator)(const struct rediwm_damage_event *,bool rediwm_projection_damage_events(struct rediwm_projection *, uint64_t *cursor,rediwm_damage_event_iterator, void *);uint64_t rediwm_projection_damage_cursor(struct rediwm_projection *);-// Optional root subtree presented in layout coordinates, independent of the camera.+// Optional child of the world presented in layout coordinates, independent of the+// camera.void rediwm_projection_sync_fixed(struct rediwm_projection *, double, double, double,- double, double, struct wlr_scene_tree *);-// The topmost node at a layout point, with the point in the node's own coordinates-// (source units for a client surface), or NULL. Hits in the world are source nodes.-struct wlr_scene_node *rediwm_projection_node_at(struct rediwm_projection *, double lx, double ly,- double *nx, double *ny);+ double, double, struct rediwm_tree *);+// What a point lands on. An own node has `own`; a node inside a client's subtree has+// only `wlr`, and `foreign` is the own node that hosts that subtree. (`wlr` is+// always the pixel source.) (x, y) is the point in the node's own coordinates+// (source units for a client surface).+struct rediwm_hit {+ struct rediwm_node *own;+ struct wlr_scene_node *wlr;+ struct rediwm_foreign *foreign;+ double x, y;+};+bool rediwm_projection_node_at(struct rediwm_projection *, double lx, double ly,+ struct rediwm_hit *);+// The same, among the leaves of one top-level subtree of a layer (a window's frame+// tree), whatever lies above it.+bool rediwm_projection_node_at_in(struct rediwm_projection *, struct rediwm_node *subtree,+ double lx, double ly, struct rediwm_hit *);// Window scale relative to its parent camera, around the frame origin.-bool rediwm_projection_set_tree_zoom(struct wlr_scene_node *, double);+bool rediwm_projection_set_tree_zoom(struct rediwm_node *, double);// Relative presentation scale. Composes with parent camera and window zoom.-bool rediwm_projection_set_tree_scale(struct wlr_scene_node *, double);+bool rediwm_projection_set_tree_scale(struct rediwm_node *, double);// One rounded-rectangle shape for every leaf under the tree, in the tree's own// units and anchored at its origin; NULL removes it. Returns false for a size// that is not positive or a radius or border that is negative or not finite.-bool rediwm_projection_set_tree_clip(struct wlr_scene_node *, const struct rediwm_clip_spec *);+bool rediwm_projection_set_tree_clip(struct rediwm_node *, const struct rediwm_clip_spec *);// Every leaf under the tree draws the analytic shadow of this shape (see// rediwm_shadow_spec in scene_graph.h); its node supplies only the footprint,// opacity and input. NULL removes it. False for a size that is not positive, or a// radius or softness that is negative or not finite.struct rediwm_shadow_spec;-bool rediwm_projection_set_tree_shadow(struct wlr_scene_node *, const struct rediwm_shadow_spec *);+bool rediwm_projection_set_tree_shadow(struct rediwm_node *, const struct rediwm_shadow_spec *);// Every leaf under the tree is drawn with this fraction of its brightness and of// its colour taken away (both 0 to 1; 0 and 0 removes the dim): a window that is not// the focus. It is part of what the leaf shows, so a change damages the leaves// under the tree; a shadow is not drawn dimmed. False for a value outside 0 to 1.-bool rediwm_projection_set_tree_dim(struct wlr_scene_node *, float brightness, float saturation);+bool rediwm_projection_set_tree_dim(struct rediwm_node *, float brightness, float saturation);// Ends the clip and the dim inherited from an ancestor for this subtree (an xdg// popup lives under its parent's tree but is no part of the window's frame).-bool rediwm_projection_set_tree_unclipped(struct wlr_scene_node *, bool);+bool rediwm_projection_set_tree_unclipped(struct rediwm_node *, bool);// Shows the subtree but lets the pick pass through it to what is below.-bool rediwm_projection_set_tree_inert(struct wlr_scene_node *, bool);+bool rediwm_projection_set_tree_inert(struct rediwm_node *, bool);+// The same for a node inside a wlroots subtree (a client's popup).+bool rediwm_projection_set_wlr_tree_zoom(struct wlr_scene_node *, double);+bool rediwm_projection_set_wlr_tree_scale(struct wlr_scene_node *, double);+bool rediwm_projection_set_wlr_tree_clip(struct wlr_scene_node *, const struct rediwm_clip_spec *);+struct rediwm_shadow_spec;+bool rediwm_projection_set_wlr_tree_shadow(struct wlr_scene_node *, const struct rediwm_shadow_spec *);+bool rediwm_projection_set_wlr_tree_dim(struct wlr_scene_node *, float brightness, float saturation);+bool rediwm_projection_set_wlr_tree_unclipped(struct wlr_scene_node *, bool);+bool rediwm_projection_set_wlr_tree_inert(struct wlr_scene_node *, bool);// Buffer-local damage for the next buffer set on a compositor-owned source// buffer node; NULL damages all of it. Surface leaves track their own.struct pixman_region32;diff --git a/src/projection.zig b/src/projection.zigindex 729b5aa..fd76621 100644--- a/src/projection.zig+++ b/src/projection.zig@@ -1,7 +1,11 @@const std = @import("std");const wlr = @import("wlroots");+const node = @import("node.zig");pub const Projection = opaque {- extern fn rediwm_projection_create(source: *wlr.SceneTree, scene: *wlr.Scene) ?*Projection;+ extern fn rediwm_projection_create(own: *node.Scene, world: *node.Tree, scene: *wlr.Scene) ?*Projection;+ /// `own` is the compositor's scene (its root's children are layers, bottom to+ /// top) and `world` the layer that follows the camera. The projection asks for a+ /// frame whenever the scene changes.pub const create = rediwm_projection_create;extern fn rediwm_projection_watch(projection: *Projection, compositor: *wlr.Compositor) void;pub const watch = rediwm_projection_watch;@@ -9,29 +13,52 @@ pub const Projection = opaque {pub const destroy = rediwm_projection_destroy;extern fn rediwm_projection_sync(projection: ?*Projection, zoom: f64, cx: f64, cy: f64, ox: f64, oy: f64) void;pub const sync = rediwm_projection_sync;- extern fn rediwm_projection_sync_fixed(projection: ?*Projection, zoom: f64, cx: f64, cy: f64, ox: f64, oy: f64, fixed: ?*wlr.SceneTree) void;+ extern fn rediwm_projection_sync_fixed(projection: ?*Projection, zoom: f64, cx: f64, cy: f64, ox: f64, oy: f64, fixed: ?*node.Tree) void;pub const syncFixed = rediwm_projection_sync_fixed;extern fn rediwm_projection_damage_buffer(projection: *Projection, source: *wlr.SceneNode, damage: ?*const @import("pixman").Region32) void;/// Buffer-local damage for the buffer just set on a compositor-owned- /// source node; null damages all of it.- pub const damageBuffer = rediwm_projection_damage_buffer;+ /// buffer node; null damages all of it.+ pub fn damageBuffer(projection: *Projection, buffer: *node.Buffer, damage: ?*const @import("pixman").Region32) void {+ rediwm_projection_damage_buffer(projection, &buffer.carrier.node, damage);+ }extern fn rediwm_projection_present_owned(projection: *Projection, source: *wlr.SceneBuffer, renderer: *wlr.Renderer, buffer: *wlr.Buffer, damage: ?*const @import("pixman").Region32) bool;- /// Sets `buffer` on a compositor-owned source node, updating the texture+ /// Sets `buffer` on a compositor-owned buffer node, updating the texture/// in place with `damage` when the renderer allows; null replaces all./// The caller may drop `buffer` afterwards. True when updated in place.- pub const presentOwned = rediwm_projection_present_owned;- extern fn rediwm_projection_node_at(projection: *Projection, lx: f64, ly: f64, nx: ?*f64, ny: ?*f64) ?*wlr.SceneNode;- /// The topmost node at a layout point (a source node for the world), and- /// the point in the node's own coordinates.- pub const nodeAt = rediwm_projection_node_at;+ pub fn presentOwned(projection: *Projection, target: *node.Buffer, renderer: *wlr.Renderer, buffer: *wlr.Buffer, damage: ?*const @import("pixman").Region32) bool {+ return rediwm_projection_present_owned(projection, target.carrier, renderer, buffer, damage);+ }+ pub const Hit = extern struct {+ /// The own node that was hit; null inside a client's surface tree.+ own: ?*node.Node,+ /// The node the pixels come from (an own node's carrier).+ wlr: *wlr.SceneNode,+ /// The own node that hosts the surface tree a client hit lies in.+ foreign: ?*node.Foreign,+ x: f64,+ y: f64,+ };+ extern fn rediwm_projection_node_at(projection: *Projection, lx: f64, ly: f64, hit: *Hit) bool;+ extern fn rediwm_projection_node_at_in(projection: *Projection, subtree: *node.Node, lx: f64, ly: f64, hit: *Hit) bool;+ /// The topmost leaf of one top-level subtree of a layer at a point, whatever lies+ /// above it.+ pub fn nodeAtIn(projection: *Projection, subtree: *node.Node, lx: f64, ly: f64) ?Hit {+ var hit: Hit = undefined;+ return if (rediwm_projection_node_at_in(projection, subtree, lx, ly, &hit)) hit else null;+ }+ /// What is topmost at a layout point, and the point in its own coordinates.+ pub fn nodeAt(projection: *Projection, lx: f64, ly: f64) ?Hit {+ var hit: Hit = undefined;+ return if (rediwm_projection_node_at(projection, lx, ly, &hit)) hit else null;+ }extern fn rediwm_projection_send_frame_done(projection: *Projection, output: *wlr.SceneOutput, now: *std.posix.timespec) void;/// Frame callbacks of the world's client surfaces for one output, beside/// `wlr.SceneOutput.sendFrameDone`, which reaches the layout trees only.pub const sendFrameDone = rediwm_projection_send_frame_done;};-extern fn rediwm_projection_set_tree_zoom(node: *wlr.SceneNode, scale: f64) bool;+extern fn rediwm_projection_set_tree_zoom(target: *node.Node, scale: f64) bool;pub const setTreeZoom = rediwm_projection_set_tree_zoom;-extern fn rediwm_projection_set_tree_scale(node: *wlr.SceneNode, factor: f64) bool;+extern fn rediwm_projection_set_tree_scale(target: *node.Node, factor: f64) bool;pub const setTreeScale = rediwm_projection_set_tree_scale;/// One rounded-rectangle shape for every leaf under a tree (see scene_graph.h):@@ -52,12 +79,12 @@ pub const ClipSpec = extern struct {glow_depth: f64 = 0,glow_color: [4]f32 = .{ 0, 0, 0, 0 },};-extern fn rediwm_projection_set_tree_clip(node: *wlr.SceneNode, spec: ?*const ClipSpec) bool;+extern fn rediwm_projection_set_tree_clip(target: *node.Node, spec: ?*const ClipSpec) bool;/// A null spec removes the clip. False for a size that is not positive or a/// radius, border or colour that is negative or not finite.-pub fn setTreeClip(node: *wlr.SceneNode, spec: ?ClipSpec) bool {- if (spec) |value| return rediwm_projection_set_tree_clip(node, &value);- return rediwm_projection_set_tree_clip(node, null);+pub fn setTreeClip(target: *node.Node, spec: ?ClipSpec) bool {+ if (spec) |value| return rediwm_projection_set_tree_clip(target, &value);+ return rediwm_projection_set_tree_clip(target, null);}/// The analytic drop shadow of a window's shape (see scene_graph.h): every leaf/// under the tree draws it in the owned pass. `width`, `height` and `radii` are@@ -72,24 +99,28 @@ pub const ShadowSpec = extern struct {softness: f64,color: [4]f32,};-extern fn rediwm_projection_set_tree_shadow(node: *wlr.SceneNode, spec: ?*const ShadowSpec) bool;+extern fn rediwm_projection_set_tree_shadow(target: *node.Node, spec: ?*const ShadowSpec) bool;/// A null spec removes the shadow. False for a size that is not positive or a/// radius or softness that is negative or not finite.-pub fn setTreeShadow(node: *wlr.SceneNode, spec: ?ShadowSpec) bool {- if (spec) |value| return rediwm_projection_set_tree_shadow(node, &value);- return rediwm_projection_set_tree_shadow(node, null);+pub fn setTreeShadow(target: *node.Node, spec: ?ShadowSpec) bool {+ if (spec) |value| return rediwm_projection_set_tree_shadow(target, &value);+ return rediwm_projection_set_tree_shadow(target, null);}/// Every leaf under the tree loses this fraction of its brightness and of its/// colour in the output pass (see `rediwm_projection_set_tree_dim`); both zero/// removes it. False for a fraction outside 0 to 1.-extern fn rediwm_projection_set_tree_dim(node: *wlr.SceneNode, brightness: f32, saturation: f32) bool;+extern fn rediwm_projection_set_tree_dim(target: *node.Node, brightness: f32, saturation: f32) bool;pub const setTreeDim = rediwm_projection_set_tree_dim;/// Ends the clip and the dim inherited from an ancestor for this subtree: an xdg/// popup or a window's shadow hangs under the window's tree but is no part of its/// frame.-extern fn rediwm_projection_set_tree_unclipped(node: *wlr.SceneNode, unclipped: bool) bool;+extern fn rediwm_projection_set_tree_unclipped(target: *node.Node, unclipped: bool) bool;pub const setTreeUnclipped = rediwm_projection_set_tree_unclipped;/// Shows the subtree but lets the pick pass through it to what is below: a/// window sliding off the workspace it has left.-extern fn rediwm_projection_set_tree_inert(node: *wlr.SceneNode, inert: bool) bool;+extern fn rediwm_projection_set_tree_inert(target: *node.Node, inert: bool) bool;pub const setTreeInert = rediwm_projection_set_tree_inert;++/// The same for a tree inside a client's wlr_scene subtree (a popup's).+extern fn rediwm_projection_set_wlr_tree_unclipped(target: *wlr.SceneNode, unclipped: bool) bool;+pub const setWlrTreeUnclipped = rediwm_projection_set_wlr_tree_unclipped;diff --git a/src/projection_test.c b/src/projection_test.cindex 7d5881b..0ae318e 100644--- a/src/projection_test.c+++ b/src/projection_test.c@@ -1,12 +1,59 @@// Synthetic surface commits into the real projection and wlroots scene damage// path. No renderer, GPU, socket or host desktop is needed.#include "projection.c"+#include "node.h"#include <assert.h>#include <stdio.h>#include <wlr/backend.h>#include <wlr/backend/headless.h>#include <wlr/interfaces/wlr_buffer.h>++// One own scene with its hidden wlr_scene host and a world layer, per test.+struct rig {+ struct rediwm_scene *own, *parking; // `parking` holds what the pass no longer reaches+ struct rediwm_tree *world;+ struct wlr_scene_tree *host;+};+static struct rig rig_create(struct wlr_scene *scene) {+ struct rig rig = {0};+ rig.host = wlr_scene_tree_create(&scene->tree);+ assert(rig.host);+ wlr_scene_node_set_enabled(&rig.host->node, false);+ rig.own = rediwm_scene_create(rig.host, NULL, NULL);+ rig.parking = rediwm_scene_create(rig.host, NULL, NULL);+ assert(rig.own && rig.parking);+ rig.world = rediwm_tree_create(&rig.own->tree);+ assert(rig.world);+ return rig;+}+static void rig_destroy(struct rig *rig) {+ rediwm_scene_destroy(rig->own);+ rediwm_scene_destroy(rig->parking);+ wlr_scene_node_destroy(&rig->host->node);+}+// The leaf of an own node: leaves hang on the node the pass reads, its carrier.+static struct wlr_scene_node *carrier_of(struct rediwm_node *node) {+ if (node->type == REDIWM_NODE_BUFFER) return &((struct rediwm_buffer *)node)->carrier->node;+ if (node->type == REDIWM_NODE_RECT) return &((struct rediwm_rect *)node)->carrier->node;+ return NULL;+}+static struct leaf *leaf_of(struct rediwm_projection *p, struct rediwm_node *node) {+ struct wlr_scene_node *carrier = carrier_of(node);+ assert(carrier);+ struct wlr_addon *addon = wlr_addon_find(&carrier->addons, p, &source_lookup_impl);+ struct leaf *l;+ return addon ? (l = wl_container_of(addon, l, source_lookup)) : NULL;+}++static struct rediwm_node *pick(struct rediwm_projection *p, double x, double y, double *nx, double *ny) {+ struct rediwm_hit hit;+ if (!rediwm_projection_node_at(p, x, y, &hit)) return NULL;+ if (nx) *nx = hit.x;+ if (ny) *ny = hit.y;+ return hit.own;+}+static struct wlr_scene_node *effect_node;bool rediwm_glass_is_effect_node(struct wlr_scene_node *node) {return node == effect_node;@@ -39,15 +86,10 @@ static void clear_damage(struct wlr_scene_output *out) {pixman_region32_clear(&out->damage_ring.current);pixman_region32_clear(&out->private.pending_commit_damage);}-static struct leaf *find_leaf(struct rediwm_projection *p, struct wlr_scene_node *source) {- struct wlr_addon *addon = wlr_addon_find(&source->addons, p, &source_lookup_impl);- struct leaf *l;- return addon ? (l = wl_container_of(addon, l, source_lookup)) : NULL;-}// Where the graph puts a leaf once rounded in layout space.static void assert_position(struct rediwm_projection *p,- struct wlr_scene_node *source, int x, int y) {- struct leaf *l = find_leaf(p, source);+ struct rediwm_node *source, int x, int y) {+ struct leaf *l = leaf_of(p, source);assert(l);const struct rediwm_snap s = rediwm_edges_snap(l->item.edges);assert(s.x == x && s.y == y);@@ -123,34 +165,35 @@ static bool probe_item(const struct rediwm_item *item, struct wlr_scene_node *trreturn true;}static void test_graph(struct wlr_scene *scene) {- struct wlr_scene_tree *source = wlr_scene_tree_create(&scene->tree);- struct rediwm_projection *p = rediwm_projection_create(source, scene);+ struct rig rig = rig_create(scene);+ struct rediwm_tree *source = rig.world;+ struct rediwm_projection *p = rediwm_projection_create(rig.own, source, scene);assert(p);- struct wlr_scene_tree *frame = wlr_scene_tree_create(source);- struct wlr_scene_tree *nested = wlr_scene_tree_create(frame);- struct wlr_scene_tree *other = wlr_scene_tree_create(source);+ struct rediwm_tree *frame = rediwm_tree_create(source);+ struct rediwm_tree *nested = rediwm_tree_create(frame);+ struct rediwm_tree *other = rediwm_tree_create(source);float color[4] = {.2, .3, .1, 1};- struct wlr_scene_rect *border = wlr_scene_rect_create(frame, 17, 9, color);+ struct rediwm_rect *border = rediwm_rect_create(frame, 17, 9, color);struct wlr_buffer *buffer = buffer_create(), *glass_buffer = buffer_create();- struct wlr_scene_buffer *client = wlr_scene_buffer_create(nested, buffer);- struct wlr_scene_buffer *glass = wlr_scene_buffer_create(frame, glass_buffer);- struct wlr_scene_rect *overlay = wlr_scene_rect_create(other, 20, 20, color);+ struct rediwm_buffer *client = rediwm_buffer_create(nested, buffer);+ struct rediwm_buffer *glass = rediwm_buffer_create(frame, glass_buffer);+ struct rediwm_rect *overlay = rediwm_rect_create(other, 20, 20, color);assert(frame && nested && other && border && client && glass && overlay);- wlr_scene_node_set_position(&frame->node, 37, 29);- wlr_scene_node_set_position(&nested->node, -12, 5);- wlr_scene_node_set_position(&client->node, 4, 3);- wlr_scene_node_set_position(&border->node, -2, -3);- wlr_scene_node_set_position(&other->node, 90, 60);- effect_node = &glass->node;- wlr_scene_buffer_set_dest_size(client, 100, 60);- wlr_scene_buffer_set_dest_size(glass, 50, 20);+ rediwm_node_set_position(&frame->node, 37, 29);+ rediwm_node_set_position(&nested->node, -12, 5);+ rediwm_node_set_position(&client->node, 4, 3);+ rediwm_node_set_position(&border->node, -2, -3);+ rediwm_node_set_position(&other->node, 90, 60);+ effect_node = carrier_of(&glass->node);+ rediwm_buffer_set_dest_size(client, 100, 60);+ rediwm_buffer_set_dest_size(glass, 50, 20);assert(rediwm_projection_set_tree_zoom(&frame->node, .85));rediwm_projection_sync(p, 1, 0, 0, 0, 0);assert_presented(p);struct group *g = get_group(p, &frame->node), *h = get_group(p, &other->node);- struct leaf *border_leaf = get_leaf(p, &border->node), *client_leaf = get_leaf(p, &client->node),- *glass_leaf = get_leaf(p, &glass->node), *overlay_leaf = get_leaf(p, &overlay->node);+ struct leaf *border_leaf = leaf_of(p, &border->node), *client_leaf = leaf_of(p, &client->node),+ *glass_leaf = leaf_of(p, &glass->node), *overlay_leaf = leaf_of(p, &overlay->node);struct leaf *order[8];assert(p->paint.next == &g->paint && g->paint.next == &h->paint && h->paint.next == &p->paint);@@ -201,7 +244,7 @@ static void test_graph(struct wlr_scene *scene) {const struct rediwm_snap s = rediwm_edges_snap(e);assert(s.width == lround(e.x2) - lround(e.x1) && s.x == lround(e.x1));// Scaled content is filtered bilinearly whatever the client asked for.- wlr_scene_buffer_set_filter_mode(client, WLR_SCALE_FILTER_NEAREST);+ rediwm_buffer_set_filter_mode(client, WLR_SCALE_FILTER_NEAREST);resolve(p, z, cx, cy, ox, oy, NULL);assert(client_leaf->item.content.filter_mode == WLR_SCALE_FILTER_BILINEAR);resolve(p, 1, 0, 0, 0, 0, NULL);@@ -209,7 +252,7 @@ static void test_graph(struct wlr_scene *scene) {resolve(p, 1, 0, 0, 0, 0, NULL);assert(client_leaf->item.content.filter_mode == WLR_SCALE_FILTER_NEAREST);assert(rediwm_projection_set_tree_zoom(&frame->node, .85));- wlr_scene_buffer_set_filter_mode(client, WLR_SCALE_FILTER_BILINEAR);+ rediwm_buffer_set_filter_mode(client, WLR_SCALE_FILTER_BILINEAR);// Presenting shows exactly that graph, and only that graph.present(p);@@ -222,37 +265,37 @@ static void test_graph(struct wlr_scene *scene) {const double zooms[] = {.25, .5, .85, 1, 1.25};for (size_t i = 0; i < sizeof(zooms) / sizeof(zooms[0]); ++i)for (int x = -9; x <= 9; x += 3) {- wlr_scene_node_set_position(&frame->node, x * 7, -x * 5);+ rediwm_node_set_position(&frame->node, x * 7, -x * 5);rediwm_projection_sync_fixed(p, zooms[i], x * .5, -x * .25, ox, oy, other);assert_presented(p);// Fixed: no camera.assert(near(overlay_leaf->item.edges.x1, other->node.x) && near(overlay_leaf->item.edges.y1, other->node.y));}- wlr_scene_node_set_position(&frame->node, 37, 29);+ rediwm_node_set_position(&frame->node, 37, 29);// Order follows the source: raising a node reorders its list, a reparent// moves the leaf between lists, and a disabled branch is still resolved.- wlr_scene_node_raise_to_top(&border->node);+ rediwm_node_raise_to_top(&border->node);rediwm_projection_sync(p, 1, 0, 0, 0, 0);assert(items_of(g, order, 8) == 3 && order[0] == client_leaf && order[1] == glass_leaf &&order[2] == border_leaf);- wlr_scene_node_reparent(&client->node, other);- wlr_scene_node_set_enabled(&other->node, false);+ rediwm_node_reparent(&client->node, other);+ rediwm_node_set_enabled(&other->node, false);rediwm_projection_sync(p, 1, 0, 0, 0, 0);assert(items_of(g, order, 8) == 2 && order[0] == glass_leaf && order[1] == border_leaf);assert(items_of(h, order, 8) == 2 && order[0] == overlay_leaf && order[1] == client_leaf);assert(!h->enabled && !client_leaf->item.enabled && !overlay_leaf->item.enabled);assert(border_leaf->item.enabled);assert_presented(p);- wlr_scene_node_set_enabled(&other->node, true);+ rediwm_node_set_enabled(&other->node, true);// A subtree the pass no longer reaches leaves the graph and is hidden.- wlr_scene_node_reparent(&other->node, &scene->tree);+ rediwm_node_reparent(&other->node, &rig.parking->tree);rediwm_projection_sync(p, 1, 0, 0, 0, 0);assert(wl_list_length(&p->paint) == 1 && wl_list_empty(&h->items));assert(!h->seen && !client_leaf->seen && !client_leaf->has_shown);assert(client_leaf->paint.next == &client_leaf->paint);- wlr_scene_node_reparent(&other->node, source);+ rediwm_node_reparent(&other->node, source);rediwm_projection_sync(p, 1, 0, 0, 0, 0);assert(wl_list_length(&p->paint) == 2 && wl_list_length(&h->items) == 2);assert_presented(p);@@ -260,19 +303,19 @@ static void test_graph(struct wlr_scene *scene) {// Destruction with the lists linked: a leaf leaves its list with its source,// a group takes the leaves it still lists with it, and neither order of// teardown touches freed list heads.- wlr_scene_node_destroy(&overlay->node);+ rediwm_node_destroy(&overlay->node);assert(wl_list_length(&h->items) == 1 && wl_list_length(&p->leaves) == 3);- wlr_scene_node_destroy(&other->node);+ rediwm_node_destroy(&other->node);assert(wl_list_length(&p->paint) == 1 && wl_list_length(&p->groups) == 1);assert(wl_list_length(&g->items) == 2);effect_node = NULL;int checks = 0;probe_group(g, &checks);- wlr_scene_node_destroy(&frame->node); // The group goes first, then its leaves.+ rediwm_node_destroy(&frame->node); // The group goes first, then its leaves.assert(checks == 2); // Both leaves were checked after the group was freed.assert(wl_list_empty(&p->groups) && wl_list_empty(&p->leaves) && wl_list_empty(&p->paint));rediwm_projection_destroy(p);- wlr_scene_node_destroy(&source->node);+ rig_destroy(&rig);wlr_buffer_drop(buffer);wlr_buffer_drop(glass_buffer);}@@ -395,34 +438,35 @@ static void test_clip_opaque(void) {assert(one[0].x == 5 + 42 && one[0].y == 7 && one[0].width == 120 - 84 && one[0].height == 80);}static void test_clip_projection(struct wlr_scene *scene) {- struct wlr_scene_tree *source = wlr_scene_tree_create(&scene->tree);- struct rediwm_projection *p = rediwm_projection_create(source, scene);+ struct rig rig = rig_create(scene);+ struct rediwm_tree *source = rig.world;+ struct rediwm_projection *p = rediwm_projection_create(rig.own, source, scene);assert(p);- struct wlr_scene_tree *frame = wlr_scene_tree_create(source);- struct wlr_scene_tree *nested = wlr_scene_tree_create(frame);- struct wlr_scene_tree *other = wlr_scene_tree_create(source);+ struct rediwm_tree *frame = rediwm_tree_create(source);+ struct rediwm_tree *nested = rediwm_tree_create(frame);+ struct rediwm_tree *other = rediwm_tree_create(source);float color[4] = {.2, .3, .1, 1};- struct wlr_scene_rect *border = wlr_scene_rect_create(frame, 17, 9, color);+ struct rediwm_rect *border = rediwm_rect_create(frame, 17, 9, color);struct wlr_buffer *buffer = buffer_create(), *glass_buffer = buffer_create(), *title_buffer = buffer_create();- struct wlr_scene_buffer *client = wlr_scene_buffer_create(nested, buffer);- struct wlr_scene_buffer *title = wlr_scene_buffer_create(frame, title_buffer);- struct wlr_scene_buffer *glass = wlr_scene_buffer_create(frame, glass_buffer);- struct wlr_scene_rect *overlay = wlr_scene_rect_create(other, 20, 20, color);+ struct rediwm_buffer *client = rediwm_buffer_create(nested, buffer);+ struct rediwm_buffer *title = rediwm_buffer_create(frame, title_buffer);+ struct rediwm_buffer *glass = rediwm_buffer_create(frame, glass_buffer);+ struct rediwm_rect *overlay = rediwm_rect_create(other, 20, 20, color);assert(frame && nested && other && border && client && title && glass && overlay);- wlr_scene_node_set_position(&frame->node, 37, 29);- wlr_scene_node_set_position(&nested->node, 2, 12);- wlr_scene_buffer_set_dest_size(client, 100, 60);- wlr_scene_buffer_set_dest_size(title, 100, 12);- wlr_scene_buffer_set_dest_size(glass, 100, 12);- effect_node = &glass->node;+ rediwm_node_set_position(&frame->node, 37, 29);+ rediwm_node_set_position(&nested->node, 2, 12);+ rediwm_buffer_set_dest_size(client, 100, 60);+ rediwm_buffer_set_dest_size(title, 100, 12);+ rediwm_buffer_set_dest_size(glass, 100, 12);+ effect_node = carrier_of(&glass->node);assert(rediwm_projection_set_tree_zoom(&frame->node, .85));assert(rediwm_projection_set_tree_scale(&nested->node, .5));// Nothing is clipped until a tree asks.rediwm_projection_sync(p, 1, 0, 0, 0, 0);- struct leaf *border_leaf = get_leaf(p, &border->node), *client_leaf = get_leaf(p, &client->node),- *title_leaf = get_leaf(p, &title->node), *glass_leaf = get_leaf(p, &glass->node),- *overlay_leaf = get_leaf(p, &overlay->node);+ struct leaf *border_leaf = leaf_of(p, &border->node), *client_leaf = leaf_of(p, &client->node),+ *title_leaf = leaf_of(p, &title->node), *glass_leaf = leaf_of(p, &glass->node),+ *overlay_leaf = leaf_of(p, &overlay->node);assert(!border_leaf->item.clip && !client_leaf->item.clip && !overlay_leaf->item.clip);// Every leaf under the tree carries the one shape: the frame's rectangle after@@ -453,17 +497,17 @@ static void test_clip_projection(struct wlr_scene *scene) {// A popup lives under its parent's tree but is no part of the window's shape;// its siblings, such as subsurfaces, still are. The barrier can be lifted.- struct wlr_scene_tree *subsurface = wlr_scene_tree_create(nested);- struct wlr_scene_tree *popup = wlr_scene_tree_create(nested);+ struct rediwm_tree *subsurface = rediwm_tree_create(nested);+ struct rediwm_tree *popup = rediwm_tree_create(nested);struct wlr_buffer *popup_buffer = buffer_create(), *sub_buffer = buffer_create();- struct wlr_scene_buffer *popup_content = wlr_scene_buffer_create(popup, popup_buffer);- struct wlr_scene_buffer *sub_content = wlr_scene_buffer_create(subsurface, sub_buffer);+ struct rediwm_buffer *popup_content = rediwm_buffer_create(popup, popup_buffer);+ struct rediwm_buffer *sub_content = rediwm_buffer_create(subsurface, sub_buffer);assert(popup_content && sub_content);- wlr_scene_node_set_position(&popup->node, 90, 70); // Hanging outside the 120x80 frame.+ rediwm_node_set_position(&popup->node, 90, 70); // Hanging outside the 120x80 frame.assert(rediwm_projection_set_tree_unclipped(&popup->node, true));assert(rediwm_projection_set_tree_unclipped(&popup->node, true)); // Idempotent.resolve(p, 1, 0, 0, 0, 0, NULL);- struct leaf *popup_leaf = get_leaf(p, &popup_content->node), *sub_leaf = get_leaf(p, &sub_content->node);+ struct leaf *popup_leaf = leaf_of(p, &popup_content->node), *sub_leaf = leaf_of(p, &sub_content->node);assert(!popup_leaf->item.clip && sub_leaf->item.clip && client_leaf->item.clip);assert(rediwm_projection_set_tree_unclipped(&popup->node, false));assert(rediwm_projection_set_tree_unclipped(&popup->node, false)); // Nothing to lift is fine.@@ -512,10 +556,10 @@ static void test_clip_projection(struct wlr_scene *scene) {assert_presented(p);// Destroying the clipped tree frees its addon with it.effect_node = NULL;- wlr_scene_node_destroy(&frame->node);+ rediwm_node_destroy(&frame->node);rediwm_projection_sync(p, 1, 0, 0, 0, 0);rediwm_projection_destroy(p);- wlr_scene_node_destroy(&source->node);+ rig_destroy(&rig);wlr_buffer_drop(buffer);wlr_buffer_drop(glass_buffer);wlr_buffer_drop(title_buffer);@@ -531,47 +575,48 @@ static bool layout_damaged(struct wlr_scene_output *out, double x, double y) {return damaged(out, (int)(x * out->output->scale), (int)(y * out->output->scale));}static void test_clip_output(struct wlr_scene *scene, struct wlr_scene_output *out) {- struct wlr_scene_tree *source = wlr_scene_tree_create(&scene->tree);- struct rediwm_projection *p = rediwm_projection_create(source, scene);+ struct rig rig = rig_create(scene);+ struct rediwm_tree *source = rig.world;+ struct rediwm_projection *p = rediwm_projection_create(rig.own, source, scene);assert(p);- struct wlr_scene_tree *under_tree = wlr_scene_tree_create(source);- struct wlr_scene_tree *frame = wlr_scene_tree_create(source);+ struct rediwm_tree *under_tree = rediwm_tree_create(source);+ struct rediwm_tree *frame = rediwm_tree_create(source);struct wlr_buffer *under_buffer = buffer_create(), *client_buffer = buffer_create();- struct wlr_scene_buffer *under = wlr_scene_buffer_create(under_tree, under_buffer);- struct wlr_scene_buffer *client = wlr_scene_buffer_create(frame, client_buffer);+ struct rediwm_buffer *under = rediwm_buffer_create(under_tree, under_buffer);+ struct rediwm_buffer *client = rediwm_buffer_create(frame, client_buffer);assert(under_tree && frame && under && client);- wlr_scene_node_set_position(&under_tree->node, 300, 200);- wlr_scene_node_set_position(&frame->node, 300, 200);- wlr_scene_buffer_set_dest_size(under, 120, 80);- wlr_scene_buffer_set_dest_size(client, 120, 80);+ rediwm_node_set_position(&under_tree->node, 300, 200);+ rediwm_node_set_position(&frame->node, 300, 200);+ rediwm_buffer_set_dest_size(under, 120, 80);+ rediwm_buffer_set_dest_size(client, 120, 80);struct rediwm_clip_spec spec = {.width = 120, .height = 80, .radii = {10, 10, 10, 10}, .border = 1,.border_color = {.1f, .1f, .1f, .1f}};assert(rediwm_projection_set_tree_clip(&frame->node, &spec));rediwm_projection_sync(p, 1, 0, 0, 0, 0);- struct leaf *client_leaf = get_leaf(p, &client->node), *under_leaf = get_leaf(p, &under->node);+ struct leaf *client_leaf = leaf_of(p, &client->node), *under_leaf = leaf_of(p, &under->node);// Points inside the window reach it; the corner pixel, which the arc cuts away,// goes to the window below, and so does the one just outside the box.double nx, ny;- struct wlr_scene_node *hit = rediwm_projection_node_at(p, 360, 240, &nx, &ny);- assert(hit == client_leaf->source);- hit = rediwm_projection_node_at(p, 300.5, 200.5, &nx, &ny);- assert(hit == under_leaf->source);- hit = rediwm_projection_node_at(p, 419.5, 279.5, &nx, &ny); // bottom-right corner- assert(hit == under_leaf->source);- hit = rediwm_projection_node_at(p, 310.5, 200.5, &nx, &ny); // on the straight edge- assert(hit == client_leaf->source);+ struct rediwm_node *hit = pick(p, 360, 240, &nx, &ny);+ assert(hit == client_leaf->own);+ hit = pick(p, 300.5, 200.5, &nx, &ny);+ assert(hit == under_leaf->own);+ hit = pick(p, 419.5, 279.5, &nx, &ny); // bottom-right corner+ assert(hit == under_leaf->own);+ hit = pick(p, 310.5, 200.5, &nx, &ny); // on the straight edge+ assert(hit == client_leaf->own);// An inert window is still drawn, but the pointer reaches what is below it.assert(rediwm_projection_set_tree_inert(&frame->node, true));rediwm_projection_sync(p, 1, 0, 0, 0, 0);- assert(client_leaf->item.enabled && rediwm_projection_node_at(p, 360, 240, &nx, &ny) == under_leaf->source);+ assert(client_leaf->item.enabled && pick(p, 360, 240, &nx, &ny) == under_leaf->own);assert(rediwm_projection_set_tree_inert(&frame->node, false));rediwm_projection_sync(p, 1, 0, 0, 0, 0);- assert(rediwm_projection_node_at(p, 360, 240, &nx, &ny) == client_leaf->source);+ assert(pick(p, 360, 240, &nx, &ny) == client_leaf->own);// Without a shape the corner is the window's again.assert(rediwm_projection_set_tree_clip(&frame->node, NULL));rediwm_projection_sync(p, 1, 0, 0, 0, 0);- assert(rediwm_projection_node_at(p, 300.5, 200.5, &nx, &ny) == client_leaf->source);+ assert(pick(p, 300.5, 200.5, &nx, &ny) == client_leaf->own);clear_damage(out);// A shape appearing, a different border colour, and the shape going away each@@ -603,15 +648,15 @@ static void test_clip_output(struct wlr_scene *scene, struct wlr_scene_output *oassert(rediwm_projection_set_tree_clip(&frame->node, &spec));rediwm_projection_sync(p, 1, 0, 0, 0, 0);clear_damage(out);- wlr_scene_node_set_position(&frame->node, 310, 200);+ rediwm_node_set_position(&frame->node, 310, 200);rediwm_projection_sync(p, 1, 0, 0, 0, 0);assert(layout_damaged(out, 370, 240)); // the views of the window moved- wlr_scene_node_set_position(&frame->node, 300, 200);+ rediwm_node_set_position(&frame->node, 300, 200);rediwm_projection_sync(p, 1, 0, 0, 0, 0);assert(rediwm_projection_set_tree_clip(&frame->node, NULL));rediwm_projection_sync(p, 1, 0, 0, 0, 0);// A hidden window damages nothing for a shape change.- wlr_scene_node_set_enabled(&frame->node, false);+ rediwm_node_set_enabled(&frame->node, false);rediwm_projection_sync(p, 1, 0, 0, 0, 0);clear_damage(out);assert(rediwm_projection_set_tree_clip(&frame->node, &spec));@@ -623,7 +668,7 @@ static void test_clip_output(struct wlr_scene *scene, struct wlr_scene_output *oassert(!pixman_region32_not_empty(&out->damage_ring.current));rediwm_projection_destroy(p);- wlr_scene_node_destroy(&source->node);+ rig_destroy(&rig);wlr_buffer_drop(under_buffer);wlr_buffer_drop(client_buffer);}@@ -631,20 +676,21 @@ static void test_clip_output(struct wlr_scene *scene, struct wlr_scene_output *o// projection damages the footprint itself: when it appears, moves, changes, is// hidden with its window, or goes away, and never when nothing changed.static void test_shadow_output(struct wlr_scene *scene, struct wlr_scene_output *out) {- struct wlr_scene_tree *source = wlr_scene_tree_create(&scene->tree);- struct rediwm_projection *p = rediwm_projection_create(source, scene);+ struct rig rig = rig_create(scene);+ struct rediwm_tree *source = rig.world;+ struct rediwm_projection *p = rediwm_projection_create(rig.own, source, scene);assert(p);- struct wlr_scene_tree *frame = wlr_scene_tree_create(source);- struct wlr_scene_tree *shadow_tree = wlr_scene_tree_create(frame);- struct wlr_scene_buffer *footprint = wlr_scene_buffer_create(shadow_tree, NULL);+ struct rediwm_tree *frame = rediwm_tree_create(source);+ struct rediwm_tree *shadow_tree = rediwm_tree_create(frame);+ struct rediwm_buffer *footprint = rediwm_buffer_create(shadow_tree, NULL);assert(frame && shadow_tree && footprint);- wlr_scene_node_set_position(&frame->node, 100, 100);- wlr_scene_node_set_position(&footprint->node, -16, -8);- wlr_scene_buffer_set_dest_size(footprint, 152, 112);+ rediwm_node_set_position(&frame->node, 100, 100);+ rediwm_node_set_position(&footprint->node, -16, -8);+ rediwm_buffer_set_dest_size(footprint, 152, 112);struct rediwm_shadow_spec spec = {.width = 120, .height = 80, .radii = {10, 10, 10, 10},.offset_y = 8, .softness = 16, .color = {0, 0, 0, .4f}};rediwm_projection_sync(p, 1, 0, 0, 0, 0);- struct leaf *l = get_leaf(p, &footprint->node);+ struct leaf *l = leaf_of(p, &footprint->node);assert(l->item.kind == REDIWM_ITEM_BUFFER && !l->item.shadow);clear_damage(out);@@ -659,7 +705,7 @@ static void test_shadow_output(struct wlr_scene *scene, struct wlr_scene_outputrediwm_projection_sync(p, 1, 0, 0, 0, 0); // Nothing changed.assert(!pixman_region32_not_empty(&out->damage_ring.current));// A moved window damages where its shadow was and where it is.- wlr_scene_node_set_position(&frame->node, 140, 100);+ rediwm_node_set_position(&frame->node, 140, 100);rediwm_projection_sync(p, 1, 0, 0, 0, 0);assert(layout_damaged(out, 85, 140) && layout_damaged(out, 270, 140));clear_damage(out);@@ -670,20 +716,20 @@ static void test_shadow_output(struct wlr_scene *scene, struct wlr_scene_outputassert(layout_damaged(out, 130, 140) && !layout_damaged(out, 100, 140));clear_damage(out);// Hidden with its window, shown again, and destroyed.- wlr_scene_node_set_enabled(&frame->node, false);+ rediwm_node_set_enabled(&frame->node, false);rediwm_projection_sync(p, 1, 0, 0, 0, 0);assert(layout_damaged(out, 130, 140));clear_damage(out);- wlr_scene_node_set_enabled(&frame->node, true);+ rediwm_node_set_enabled(&frame->node, true);rediwm_projection_sync(p, 1, 0, 0, 0, 0);assert(layout_damaged(out, 130, 140));clear_damage(out);- wlr_scene_node_destroy(&footprint->node);+ rediwm_node_destroy(&footprint->node);assert(layout_damaged(out, 130, 140));rediwm_projection_sync(p, 1, 0, 0, 0, 0);rediwm_projection_destroy(p);- wlr_scene_node_destroy(&source->node);+ rig_destroy(&rig);}// Stage 5a: damage events name the leaf and the layout box its pixels changed in,// for consumers that must tell what lies below a backdrop effect from what lies@@ -704,20 +750,21 @@ static bool event_is(const struct rediwm_damage_event *e, uint64_t leaf, int x,return e->leaf == leaf && e->box.x == x && e->box.y == y && e->box.width == w && e->box.height == h;}static void test_damage_events(struct wlr_scene *scene) {- struct wlr_scene_tree *source = wlr_scene_tree_create(&scene->tree);- struct rediwm_projection *p = rediwm_projection_create(source, scene);+ struct rig rig = rig_create(scene);+ struct rediwm_tree *source = rig.world;+ struct rediwm_projection *p = rediwm_projection_create(rig.own, source, scene);assert(p);uint64_t cursor = rediwm_projection_damage_cursor(p), other = cursor;- struct wlr_scene_tree *window = wlr_scene_tree_create(source);+ struct rediwm_tree *window = rediwm_tree_create(source);struct wlr_buffer *buffer = buffer_create(); // 200x120- struct wlr_scene_buffer *a = wlr_scene_buffer_create(window, buffer);- struct wlr_scene_buffer *b = wlr_scene_buffer_create(window, buffer);- wlr_scene_node_set_position(&window->node, 40, 30);- wlr_scene_buffer_set_dest_size(a, 100, 60); // half size: one buffer px = 0.5- wlr_scene_node_set_position(&b->node, 0, 100);- wlr_scene_buffer_set_dest_size(b, 20, 20);- rediwm_projection_sync(p, 1, 0, 0, 0, 0);- struct leaf *la = get_leaf(p, &a->node), *lb = get_leaf(p, &b->node);+ struct rediwm_buffer *a = rediwm_buffer_create(window, buffer);+ struct rediwm_buffer *b = rediwm_buffer_create(window, buffer);+ rediwm_node_set_position(&window->node, 40, 30);+ rediwm_buffer_set_dest_size(a, 100, 60); // half size: one buffer px = 0.5+ rediwm_node_set_position(&b->node, 0, 100);+ rediwm_buffer_set_dest_size(b, 20, 20);+ rediwm_projection_sync(p, 1, 0, 0, 0, 0);+ struct leaf *la = leaf_of(p, &a->node), *lb = leaf_of(p, &b->node);assert(la->item.id && lb->item.id && la->item.id != lb->item.id);// Appearing: each leaf's whole box.@@ -731,50 +778,50 @@ static void test_damage_events(struct wlr_scene *scene) {// Reported buffer damage maps through the scale, a pixel wider for filtering.pixman_region32_t damage;pixman_region32_init_rect(&damage, 20, 40, 10, 10);- rediwm_projection_damage_buffer(p, &a->node, &damage);+ rediwm_projection_damage_buffer(p, carrier_of(&a->node), &damage);rediwm_projection_sync(p, 1, 0, 0, 0, 0);seen = events_since(p, &cursor, NULL);assert(seen.count == 1 && event_is(&seen.last[0], la->item.id, 49, 49, 7, 7));// Unreported damage is the whole box.- rediwm_projection_damage_buffer(p, &a->node, NULL);+ rediwm_projection_damage_buffer(p, carrier_of(&a->node), NULL);rediwm_projection_sync(p, 1, 0, 0, 0, 0);seen = events_since(p, &cursor, NULL);assert(seen.count == 1 && event_is(&seen.last[0], la->item.id, 40, 30, 100, 60));// A move changes the old and the new box; a hidden leaf its last one.- wlr_scene_node_set_position(&b->node, 10, 100);+ rediwm_node_set_position(&b->node, 10, 100);rediwm_projection_sync(p, 1, 0, 0, 0, 0);seen = events_since(p, &cursor, NULL);assert(seen.count == 2);assert(event_is(&seen.last[0], lb->item.id, 40, 130, 20, 20));assert(event_is(&seen.last[1], lb->item.id, 50, 130, 20, 20));- wlr_scene_node_set_enabled(&b->node, false);+ rediwm_node_set_enabled(&b->node, false);rediwm_projection_sync(p, 1, 0, 0, 0, 0);seen = events_since(p, &cursor, NULL);assert(seen.count == 1 && event_is(&seen.last[0], lb->item.id, 50, 130, 20, 20));- wlr_scene_node_set_enabled(&b->node, true);+ rediwm_node_set_enabled(&b->node, true);rediwm_projection_sync(p, 1, 0, 0, 0, 0);seen = events_since(p, &cursor, NULL);assert(seen.count == 1 && event_is(&seen.last[0], lb->item.id, 50, 130, 20, 20));// A changed opacity is a restyle of the whole box.- wlr_scene_buffer_set_opacity(a, .5f);+ rediwm_buffer_set_opacity(a, .5f);rediwm_projection_sync(p, 1, 0, 0, 0, 0);seen = events_since(p, &cursor, NULL);assert(seen.count == 2 && event_is(&seen.last[1], la->item.id, 40, 30, 100, 60));// A destroyed leaf reports its last box at once.const uint64_t gone = lb->item.id;- wlr_scene_node_destroy(&b->node);+ rediwm_node_destroy(&b->node);seen = events_since(p, &cursor, NULL);assert(seen.count == 1 && event_is(&seen.last[0], gone, 50, 130, 20, 20));// A leaf that draws nothing (an input-only node such as a resize grab) has no// events, however it moves: glass would otherwise take it for a change below.- struct wlr_scene_buffer *grab = wlr_scene_buffer_create(window, NULL);- wlr_scene_buffer_set_dest_size(grab, 300, 300);+ struct rediwm_buffer *grab = rediwm_buffer_create(window, NULL);+ rediwm_buffer_set_dest_size(grab, 300, 300);rediwm_projection_sync(p, 1, 0, 0, 0, 0);- wlr_scene_node_set_position(&grab->node, 5, 5);+ rediwm_node_set_position(&grab->node, 5, 5);rediwm_projection_sync(p, 1, 0, 0, 0, 0);- wlr_scene_node_destroy(&grab->node);+ rediwm_node_destroy(&grab->node);assert(events_since(p, &cursor, NULL).count == 0);// A second consumer read nothing yet and sees everything since its cursor.@@ -784,7 +831,7 @@ static void test_damage_events(struct wlr_scene *scene) {// One that falls behind the ring is told so.uint64_t stale = rediwm_projection_damage_cursor(p);for (int i = 0; i < 2100; i++) {- wlr_scene_node_set_position(&window->node, 40 + i % 2, 30);+ rediwm_node_set_position(&window->node, 40 + i % 2, 30);rediwm_projection_sync(p, 1, 0, 0, 0, 0);}events_since(p, &stale, &complete);@@ -793,39 +840,40 @@ static void test_damage_events(struct wlr_scene *scene) {pixman_region32_fini(&damage);rediwm_projection_destroy(p);- wlr_scene_node_destroy(&source->node);+ rig_destroy(&rig);wlr_buffer_drop(buffer);}// A window's dim is a field of what its leaves show: inherited down the tree like// its shape, ended where a popup hangs under it, and a change of it restyles (so// damages) every leaf under the tree and no other.static void test_dim(struct wlr_scene *scene) {- struct wlr_scene_tree *source = wlr_scene_tree_create(&scene->tree);- struct rediwm_projection *p = rediwm_projection_create(source, scene);+ struct rig rig = rig_create(scene);+ struct rediwm_tree *source = rig.world;+ struct rediwm_projection *p = rediwm_projection_create(rig.own, source, scene);assert(p);uint64_t cursor = rediwm_projection_damage_cursor(p);- struct wlr_scene_tree *window = wlr_scene_tree_create(source);- struct wlr_scene_tree *content = wlr_scene_tree_create(window);- struct wlr_scene_tree *popup = wlr_scene_tree_create(content);- struct wlr_scene_tree *sibling = wlr_scene_tree_create(source);+ struct rediwm_tree *window = rediwm_tree_create(source);+ struct rediwm_tree *content = rediwm_tree_create(window);+ struct rediwm_tree *popup = rediwm_tree_create(content);+ struct rediwm_tree *sibling = rediwm_tree_create(source);float color[4] = {.2, .3, .1, 1};struct wlr_buffer *buffer = buffer_create();- struct wlr_scene_rect *ring = wlr_scene_rect_create(window, 10, 10, color);- struct wlr_scene_buffer *client = wlr_scene_buffer_create(content, buffer);- struct wlr_scene_buffer *menu = wlr_scene_buffer_create(popup, buffer);- struct wlr_scene_buffer *other = wlr_scene_buffer_create(sibling, buffer);+ struct rediwm_rect *ring = rediwm_rect_create(window, 10, 10, color);+ struct rediwm_buffer *client = rediwm_buffer_create(content, buffer);+ struct rediwm_buffer *menu = rediwm_buffer_create(popup, buffer);+ struct rediwm_buffer *other = rediwm_buffer_create(sibling, buffer);assert(ring && client && menu && other);- wlr_scene_node_set_position(&window->node, 40, 30);- wlr_scene_node_set_position(&client->node, 0, 10);- wlr_scene_buffer_set_dest_size(client, 100, 60);- wlr_scene_node_set_position(&popup->node, 50, 20);- wlr_scene_buffer_set_dest_size(menu, 30, 30);- wlr_scene_node_set_position(&sibling->node, 300, 200);- wlr_scene_buffer_set_dest_size(other, 20, 20);+ rediwm_node_set_position(&window->node, 40, 30);+ rediwm_node_set_position(&client->node, 0, 10);+ rediwm_buffer_set_dest_size(client, 100, 60);+ rediwm_node_set_position(&popup->node, 50, 20);+ rediwm_buffer_set_dest_size(menu, 30, 30);+ rediwm_node_set_position(&sibling->node, 300, 200);+ rediwm_buffer_set_dest_size(other, 20, 20);assert(rediwm_projection_set_tree_unclipped(&popup->node, true));rediwm_projection_sync(p, 1, 0, 0, 0, 0);- struct leaf *lring = get_leaf(p, &ring->node), *lclient = get_leaf(p, &client->node),- *lmenu = get_leaf(p, &menu->node), *lother = get_leaf(p, &other->node);+ struct leaf *lring = leaf_of(p, &ring->node), *lclient = leaf_of(p, &client->node),+ *lmenu = leaf_of(p, &menu->node), *lother = leaf_of(p, &other->node);assert(events_since(p, &cursor, NULL).count == 4); // Appearing.// Nothing is dimmed until a tree asks, and taking nothing away makes no addon.@@ -881,7 +929,7 @@ static void test_dim(struct wlr_scene *scene) {assert(events_since(p, &cursor, NULL).count == 4);rediwm_projection_destroy(p);- wlr_scene_node_destroy(&source->node);+ rig_destroy(&rig);wlr_buffer_drop(buffer);}// The output pass hides what a client's opaque region covers, from the region as@@ -935,34 +983,35 @@ static bool in_group(struct group *g, struct leaf *l) {}static int snap_width(struct leaf *l) { return rediwm_edges_snap(l->item.edges).width; }static void test_groups(struct wlr_scene *scene, struct wlr_scene_output *out) {- struct wlr_scene_tree *source = wlr_scene_tree_create(&scene->tree);- struct rediwm_projection *p = rediwm_projection_create(source, scene);+ struct rig rig = rig_create(scene);+ struct rediwm_tree *source = rig.world;+ struct rediwm_projection *p = rediwm_projection_create(rig.own, source, scene);assert(p);- struct wlr_scene_tree *frame = wlr_scene_tree_create(source);- struct wlr_scene_tree *nested = wlr_scene_tree_create(frame);- struct wlr_scene_tree *other = wlr_scene_tree_create(source);+ struct rediwm_tree *frame = rediwm_tree_create(source);+ struct rediwm_tree *nested = rediwm_tree_create(frame);+ struct rediwm_tree *other = rediwm_tree_create(source);float color[4] = {.2, .3, .1, 1};- struct wlr_scene_rect *border = wlr_scene_rect_create(frame, 17, 9, color);+ struct rediwm_rect *border = rediwm_rect_create(frame, 17, 9, color);struct wlr_buffer *buffer = buffer_create();- struct wlr_scene_buffer *client = wlr_scene_buffer_create(nested, buffer);- struct wlr_scene_rect *overlay = wlr_scene_rect_create(other, 20, 20, color);+ struct rediwm_buffer *client = rediwm_buffer_create(nested, buffer);+ struct rediwm_rect *overlay = rediwm_rect_create(other, 20, 20, color);assert(frame && nested && other && border && client && overlay);- wlr_scene_node_set_position(&frame->node, 37, 29);- wlr_scene_node_set_position(&nested->node, -12, 5);- wlr_scene_node_set_position(&client->node, 4, 3);- wlr_scene_node_set_position(&border->node, -2, -3);- wlr_scene_node_set_position(&other->node, 90, 60);+ rediwm_node_set_position(&frame->node, 37, 29);+ rediwm_node_set_position(&nested->node, -12, 5);+ rediwm_node_set_position(&client->node, 4, 3);+ rediwm_node_set_position(&border->node, -2, -3);+ rediwm_node_set_position(&other->node, 90, 60);rediwm_projection_sync(p, 1, 0, 0, 0, 0);struct group *g = get_group(p, &frame->node);struct group *h = get_group(p, &other->node);- struct leaf *l = get_leaf(p, &client->node);- struct leaf *border_leaf = get_leaf(p, &border->node);- assert(in_group(g, l) && in_group(g, border_leaf) && in_group(h, get_leaf(p, &overlay->node)));+ struct leaf *l = leaf_of(p, &client->node);+ struct leaf *border_leaf = leaf_of(p, &border->node);+ assert(in_group(g, l) && in_group(g, border_leaf) && in_group(h, leaf_of(p, &overlay->node)));assert(wl_list_length(&p->paint) == 2);assert_position(p, &client->node, 29, 37);assert_position(p, &border->node, 35, 26);clear_damage(out);- wlr_scene_node_set_position(&frame->node, 83, 71);+ rediwm_node_set_position(&frame->node, 83, 71);rediwm_projection_sync(p, 1, 0, 0, 0, 0);// Ordinary movement moves every leaf of the group.assert_position(p, &client->node, 75, 79);@@ -987,7 +1036,7 @@ static void test_groups(struct wlr_scene *scene, struct wlr_scene_output *out) {double z = zooms[i], cx = 6.5, cy = -2.5, ox = -17, oy = 31;double tx = ox * (1 - z) - z * cx, ty = oy * (1 - z) - z * cy;for (int x = -13; x <= 13; ++x) {- wlr_scene_node_set_position(&frame->node, x, -x);+ rediwm_node_set_position(&frame->node, x, -x);rediwm_projection_sync(p, z, cx, cy, ox, oy);assert_position(p, &client->node, lround(z * (x - 8) + tx),lround(z * (-x + 8) + ty));@@ -1000,7 +1049,7 @@ static void test_groups(struct wlr_scene *scene, struct wlr_scene_output *out) {// Window zoom multiplies the camera scale while preserving its world origin.// Nested geometry keeps the same per-leaf projected scale.assert(rediwm_projection_set_tree_zoom(&frame->node, .85));- wlr_scene_node_set_position(&frame->node, -17, 23);+ rediwm_node_set_position(&frame->node, -17, 23);rediwm_projection_sync(p, .5, 3, -7, 0, 0);assert_position(p, &client->node, lround(.5 * -17 - 1.5 + (.85 * .5) * -8),lround(.5 * 23 + 3.5 + (.85 * .5) * 8));@@ -1018,41 +1067,41 @@ static void test_groups(struct wlr_scene *scene, struct wlr_scene_output *out) {assert(rediwm_projection_set_tree_zoom(&frame->node, 1.0));// Reorder a whole window and a leaf within it, retaining source paint order.- wlr_scene_node_raise_to_top(&frame->node);- wlr_scene_node_raise_to_top(&nested->node);+ rediwm_node_raise_to_top(&frame->node);+ rediwm_node_raise_to_top(&nested->node);rediwm_projection_sync(p, 1, 0, 0, 0, 0);struct leaf *order[8];assert(p->paint.next == &h->paint && h->paint.next == &g->paint && g->paint.next == &p->paint);assert(items_of(g, order, 8) == 2 && order[0] == border_leaf && order[1] == l);// The source node and its input stay attached to the leaf when a subsurface// changes source root, rather than retaining a stale group.- wlr_scene_node_reparent(&client->node, other);+ rediwm_node_reparent(&client->node, other);rediwm_projection_sync(p, 1, 0, 0, 0, 0);assert(in_group(h, l) && !in_group(g, l));assert_position(p, &client->node, 94, 63);double input_x, input_y;- assert(rediwm_projection_node_at(p, 94 + 40, 63 + 24, &input_x, &input_y) == &client->node);+ assert(pick(p, 94 + 40, 63 + 24, &input_x, &input_y) == &client->node);assert(input_x == 40 && input_y == 24);- wlr_scene_node_set_enabled(&other->node, false);+ rediwm_node_set_enabled(&other->node, false);rediwm_projection_sync(p, 1, 0, 0, 0, 0);- assert(!l->item.enabled && !rediwm_projection_node_at(p, 94 + 40, 63 + 24, &input_x, &input_y));- wlr_scene_node_set_enabled(&other->node, true);+ assert(!l->item.enabled && !pick(p, 94 + 40, 63 + 24, &input_x, &input_y));+ rediwm_node_set_enabled(&other->node, true);rediwm_projection_sync(p, 1, 0, 0, 0, 0);assert_position(p, &client->node, 94, 63);// A former source root can become nested, leave the projected tree, and// return. Its unused group is not reached while its leaves change group, and// neither its former position nor window zoom may leak into other leaves.- wlr_scene_node_reparent(&frame->node, other);+ rediwm_node_reparent(&frame->node, other);rediwm_projection_sync(p, 1, 0, 0, 0, 0);assert(!g->seen);assert(in_group(h, border_leaf));assert_position(p, &border->node, 71, 80);assert_position(p, &client->node, 94, 63);- wlr_scene_node_reparent(&frame->node, &scene->tree);+ rediwm_node_reparent(&frame->node, &rig.parking->tree);rediwm_projection_sync(p, 1, 0, 0, 0, 0);assert(!border_leaf->seen);- wlr_scene_node_reparent(&frame->node, source);+ rediwm_node_reparent(&frame->node, source);rediwm_projection_sync(p, 1, 0, 0, 0, 0);assert(g->seen);assert(in_group(g, border_leaf));@@ -1060,58 +1109,59 @@ static void test_groups(struct wlr_scene *scene, struct wlr_scene_output *out) {// A leaf moved out of a window's tree before the tree is destroyed keeps its// leaf: the surviving source node needs nothing recreated.- struct wlr_scene_tree *temporary = wlr_scene_tree_create(source);- struct wlr_scene_rect *survivor = wlr_scene_rect_create(temporary, 12, 12, color);+ struct rediwm_tree *temporary = rediwm_tree_create(source);+ struct rediwm_rect *survivor = rediwm_rect_create(temporary, 12, 12, color);assert(temporary && survivor);rediwm_projection_sync(p, 1, 0, 0, 0, 0);- wlr_scene_node_reparent(&survivor->node, other);- wlr_scene_node_destroy(&temporary->node);- assert(find_leaf(p, &survivor->node));+ rediwm_node_reparent(&survivor->node, other);+ rediwm_node_destroy(&temporary->node);+ assert(leaf_of(p, &survivor->node));rediwm_projection_sync(p, 1, 0, 0, 0, 0);assert_position(p, &survivor->node, 90, 60);- wlr_scene_node_destroy(&survivor->node);+ rediwm_node_destroy(&survivor->node);// A direct leaf can itself be a former group root. After it becomes nested,// destroying the source runs both leaf and group cleanup on the same node.- struct wlr_scene_rect *direct = wlr_scene_rect_create(source, 12, 12, color);+ struct rediwm_rect *direct = rediwm_rect_create(source, 12, 12, color);assert(direct);rediwm_projection_sync(p, 1, 0, 0, 0, 0);- wlr_scene_node_reparent(&direct->node, other);+ rediwm_node_reparent(&direct->node, other);rediwm_projection_sync(p, 1, 0, 0, 0, 0);- assert(in_group(h, get_leaf(p, &direct->node)));- wlr_scene_node_destroy(&direct->node);+ assert(in_group(h, leaf_of(p, &direct->node)));+ rediwm_node_destroy(&direct->node);assert(wl_list_length(&p->groups) == 2 && wl_list_length(&p->leaves) == 3);// Source-first teardown destroys its group without dangling leaf listeners.- wlr_scene_node_destroy(&frame->node);+ rediwm_node_destroy(&frame->node);assert(wl_list_length(&p->groups) == 1 && wl_list_length(&p->leaves) == 2);rediwm_projection_sync(p, 1, 0, 0, 0, 0);- wlr_scene_node_destroy(&other->node);+ rediwm_node_destroy(&other->node);assert(wl_list_empty(&p->groups) && wl_list_empty(&p->leaves));rediwm_projection_destroy(p);- wlr_scene_node_destroy(&source->node);+ rig_destroy(&rig);wlr_buffer_drop(buffer);}// Stage 6b: the screen's damage comes from the graph. A restack damages what// changed order, a change of what a leaf itself shows is cut to what was visible// of it at the last build, and a window going away is damaged at once.static void test_graph_damage(struct wlr_scene *scene, struct wlr_scene_output *out) {- struct wlr_scene_tree *source = wlr_scene_tree_create(&scene->tree);- struct rediwm_projection *p = rediwm_projection_create(source, scene);+ struct rig rig = rig_create(scene);+ struct rediwm_tree *source = rig.world;+ struct rediwm_projection *p = rediwm_projection_create(rig.own, source, scene);assert(p);struct wlr_buffer *buffer = buffer_create(); // 200x120- struct wlr_scene_tree *frame_a = wlr_scene_tree_create(source);- struct wlr_scene_tree *frame_b = wlr_scene_tree_create(source);- struct wlr_scene_buffer *a = wlr_scene_buffer_create(frame_a, buffer);- struct wlr_scene_buffer *b = wlr_scene_buffer_create(frame_b, buffer);- wlr_scene_node_set_position(&frame_a->node, 20, 20);- wlr_scene_node_set_position(&frame_b->node, 60, 40);+ struct rediwm_tree *frame_a = rediwm_tree_create(source);+ struct rediwm_tree *frame_b = rediwm_tree_create(source);+ struct rediwm_buffer *a = rediwm_buffer_create(frame_a, buffer);+ struct rediwm_buffer *b = rediwm_buffer_create(frame_b, buffer);+ rediwm_node_set_position(&frame_a->node, 20, 20);+ rediwm_node_set_position(&frame_b->node, 60, 40);rediwm_projection_sync(p, 1, 0, 0, 0, 0);clear_damage(out);// Raising the window below changes the pixels where the two overlap, and says// nothing about the rest of the screen.- wlr_scene_node_raise_to_top(&frame_a->node);+ rediwm_node_raise_to_top(&frame_a->node);rediwm_projection_sync(p, 1, 0, 0, 0, 0);assert(layout_damaged(out, 100, 60) && layout_damaged(out, 210, 130));assert(!layout_damaged(out, 350, 300) && !layout_damaged(out, 5, 5));@@ -1121,30 +1171,30 @@ static void test_graph_damage(struct wlr_scene *scene, struct wlr_scene_output *// What changes only what a leaf shows is cut to what of it was visible at the// last build: the right part of `a` was hidden, so its change is not damaged.- struct leaf *la = get_leaf(p, &a->node), *lb = get_leaf(p, &b->node);+ struct leaf *la = leaf_of(p, &a->node), *lb = leaf_of(p, &b->node);pixman_region32_t visible;pixman_region32_init_rect(&visible, 20, 20, 50, 120);- rediwm_projection_note_visible(p, &a->node, &visible);- rediwm_projection_damage_buffer(p, &a->node, NULL);+ rediwm_projection_note_visible(p, carrier_of(&a->node), &visible);+ rediwm_projection_damage_buffer(p, carrier_of(&a->node), NULL);rediwm_projection_sync(p, 1, 0, 0, 0, 0);assert(layout_damaged(out, 30, 60) && !layout_damaged(out, 150, 60));clear_damage(out);// Nothing visible, nothing to damage; a leaf the pass never saw is damaged whole.pixman_region32_clear(&visible);- rediwm_projection_note_visible(p, &a->node, &visible);- rediwm_projection_damage_buffer(p, &a->node, NULL);+ rediwm_projection_note_visible(p, carrier_of(&a->node), &visible);+ rediwm_projection_damage_buffer(p, carrier_of(&a->node), NULL);rediwm_projection_sync(p, 1, 0, 0, 0, 0);assert(!pixman_region32_not_empty(&out->damage_ring.current));assert(!lb->has_visible);- rediwm_projection_damage_buffer(p, &b->node, NULL);+ rediwm_projection_damage_buffer(p, carrier_of(&b->node), NULL);rediwm_projection_sync(p, 1, 0, 0, 0, 0);assert(layout_damaged(out, 70, 50) && layout_damaged(out, 250, 150));clear_damage(out);// A leaf that is moved damages where it was only where it was visible, and// where it is whatever the last build saw.pixman_region32_init_rect(&visible, 60, 40, 40, 120);- rediwm_projection_note_visible(p, &b->node, &visible);- wlr_scene_node_set_position(&frame_b->node, 200, 150);+ rediwm_projection_note_visible(p, carrier_of(&b->node), &visible);+ rediwm_node_set_position(&frame_b->node, 200, 150);rediwm_projection_sync(p, 1, 0, 0, 0, 0);assert(layout_damaged(out, 70, 60) && !layout_damaged(out, 150, 60)); // old box, cutassert(layout_damaged(out, 250, 200)); // new box, whole@@ -1153,12 +1203,12 @@ static void test_graph_damage(struct wlr_scene *scene, struct wlr_scene_output *// A window going away damages what it showed without waiting for a sync: a// capture can build a frame before the next one.- rediwm_projection_note_visible(p, &a->node, &(pixman_region32_t){.extents = {20, 20, 220, 140}, .data = NULL});- wlr_scene_node_destroy(&frame_a->node);+ rediwm_projection_note_visible(p, carrier_of(&a->node), &(pixman_region32_t){.extents = {20, 20, 220, 140}, .data = NULL});+ rediwm_node_destroy(&frame_a->node);assert(layout_damaged(out, 30, 30) && layout_damaged(out, 210, 130));pixman_region32_fini(&visible);rediwm_projection_destroy(p);- wlr_scene_node_destroy(&source->node);+ rig_destroy(&rig);wlr_buffer_drop(buffer);}// Stage 6a: what the output pass reports of a surface becomes the signals wlroots@@ -1201,58 +1251,59 @@ static void test_feedback(struct wlr_scene *scene, struct wlr_backend *backend,wlr_output_effective_resolution(left_output, &seam, &unused);wlr_scene_output_set_position(right, seam, 0);- struct wlr_scene_tree *source = wlr_scene_tree_create(&scene->tree);- struct rediwm_projection *p = rediwm_projection_create(source, scene);+ struct rig rig = rig_create(scene);+ struct rediwm_tree *source = rig.world;+ struct rediwm_projection *p = rediwm_projection_create(rig.own, source, scene);assert(p);struct wlr_buffer *buffer = buffer_create();- struct wlr_scene_buffer *node = wlr_scene_buffer_create(source, buffer);- wlr_scene_node_set_position(&node->node, seam - 26, 50);+ struct rediwm_buffer *node = rediwm_buffer_create(source, buffer);+ rediwm_node_set_position(&node->node, seam - 26, 50);rediwm_projection_sync(p, 1, 0, 0, 0, 0);- struct leaf *l = get_leaf(p, &node->node);+ struct leaf *l = leaf_of(p, &node->node);l->feedback = calloc(1, sizeof(*l->feedback));assert(l->feedback);l->feedback->leaf = l;wl_list_insert(&p->feedback, &l->feedback->link);struct wl_listener updated = {.notify = on_outputs_update}, done = {.notify = on_frame_done};- wl_signal_add(&node->events.outputs_update, &updated);- wl_signal_add(&node->events.frame_done, &done);+ wl_signal_add(&node->carrier->events.outputs_update, &updated);+ wl_signal_add(&node->carrier->events.frame_done, &done);struct timespec now = {0};// Over the seam: both outputs show more than a tenth, the one with most is primary.- report(p, &node->node, seam - 26, 50, 200, 100); // 26 columns left, 174 right+ report(p, carrier_of(&node->node), seam - 26, 50, 200, 100); // 26 columns left, 174 rightassert(outputs_updates == 1 && update_size == 2 && l->feedback->primary == right);assert(l->feedback->active == (1ull << left->private.index | 1ull << right->private.index));- report(p, &node->node, seam - 26, 50, 200, 100);+ report(p, carrier_of(&node->node), seam - 26, 50, 200, 100);assert(outputs_updates == 1); // Unchanged: no signal.// A sliver on the other side is ignored (10 % rule): 2 of 28 columns.- report(p, &node->node, seam - 26, 50, 28, 100);+ report(p, carrier_of(&node->node), seam - 26, 50, 28, 100);assert(outputs_updates == 2 && update_size == 1 && update_active[0] == left && l->feedback->primary == left);// Frames are sent for what is shown, and for no output it is not.rediwm_projection_send_frame_done(p, left, &now);assert(frame_dones == 1);// A hidden leaf hears none, whatever it was told last.- wlr_scene_node_set_enabled(&node->node, false);+ rediwm_node_set_enabled(&node->node, false);rediwm_projection_sync(p, 1, 0, 0, 0, 0);rediwm_projection_send_frame_done(p, left, &now);assert(frame_dones == 1);- wlr_scene_node_set_enabled(&node->node, true);+ rediwm_node_set_enabled(&node->node, true);rediwm_projection_sync(p, 1, 0, 0, 0, 0);- report(p, &node->node, 0, 0, 0, 0); // hidden+ report(p, carrier_of(&node->node), 0, 0, 0, 0); // hiddenassert(outputs_updates == 3 && update_size == 0 && !l->feedback->active && !l->feedback->primary);rediwm_projection_send_frame_done(p, left, &now);assert(frame_dones == 1); // nothing shown, nothing sent// An active output whose scale changed hears again, whatever else is the same.- report(p, &node->node, seam - 26, 50, 26, 100);+ report(p, carrier_of(&node->node), seam - 26, 50, 26, 100);assert(outputs_updates == 4 && update_size == 1);- report(p, &node->node, seam - 26, 50, 26, 100);+ report(p, carrier_of(&node->node), seam - 26, 50, 26, 100);assert(outputs_updates == 4);wlr_output_state_init(&state);wlr_output_state_set_scale(&state, 1.25f);assert(wlr_output_commit_state(left_output, &state));wlr_output_state_finish(&state);- report(p, &node->node, seam - 26, 50, 26, 100);+ report(p, carrier_of(&node->node), seam - 26, 50, 26, 100);assert(outputs_updates == 5);- report(p, &node->node, seam - 26, 50, 26, 100);+ report(p, carrier_of(&node->node), seam - 26, 50, 26, 100);assert(outputs_updates == 5);wlr_output_state_init(&state);wlr_output_state_set_scale(&state, 1.f);@@ -1262,7 +1313,7 @@ static void test_feedback(struct wlr_scene *scene, struct wlr_backend *backend,wl_list_remove(&updated.link);wl_list_remove(&done.link);rediwm_projection_destroy(p);- wlr_scene_node_destroy(&source->node);+ rig_destroy(&rig);wlr_buffer_drop(buffer);wlr_scene_output_destroy(right);wlr_output_destroy(right_output);@@ -1283,17 +1334,18 @@ int main(void) {assert(scene);struct wlr_scene_output *out = wlr_scene_output_create(scene, output);assert(out);- struct wlr_scene_tree *source = wlr_scene_tree_create(&scene->tree);- struct rediwm_projection *p = rediwm_projection_create(source, scene);+ struct rig rig = rig_create(scene);+ struct rediwm_tree *source = rig.world;+ struct rediwm_projection *p = rediwm_projection_create(rig.own, source, scene);assert(p);struct wlr_buffer *a = buffer_create(), *b = buffer_create();- struct wlr_scene_buffer *node = wlr_scene_buffer_create(source, a);+ struct rediwm_buffer *node = rediwm_buffer_create(source, a);assert(node);rediwm_projection_sync(p, 1, 0, 0, 0, 0);assert(damaged(out, 100, 60)); // First presentation is fully damaged.clear_damage(out);- struct leaf *l = get_leaf(p, &node->node);+ struct leaf *l = leaf_of(p, &node->node);struct wlr_surface surface = {.current = {.buffer_width = 200, .buffer_height = 120}};pixman_region32_init(&surface.buffer_damage);struct wlr_scene_surface scene_surface = {.surface = &surface};@@ -1313,11 +1365,11 @@ int main(void) {// Rotation with empty damage is not a repaint; rotation with partial damage// must retain only that region. The source tree itself is disabled.- wlr_scene_buffer_set_buffer(node, b);+ rediwm_buffer_set_buffer(node, b);commit_damage(l, 0, 0, 0, 0);rediwm_projection_sync(p, 1, 0, 0, 0, 0);assert(!pixman_region32_not_empty(&out->damage_ring.current));- wlr_scene_buffer_set_buffer(node, a);+ rediwm_buffer_set_buffer(node, a);commit_damage(l, 20, 20, 4, 4);rediwm_projection_sync(p, 1, 0, 0, 0, 0);assert(damaged(out, 21, 21) && !damaged(out, 100, 60));@@ -1349,8 +1401,8 @@ int main(void) {// Cropping and fractional zoom use wlroots' buffer-to-output damage mapping,// including filtering expansion, rather than treating buffer pixels as scene// coordinates.- wlr_scene_buffer_set_source_box(node, &(struct wlr_fbox){20, 20, 100, 60});- wlr_scene_buffer_set_dest_size(node, 100, 60);+ rediwm_buffer_set_source_box(node, &(struct wlr_fbox){20, 20, 100, 60});+ rediwm_buffer_set_dest_size(node, 100, 60);rediwm_projection_sync(p, .5, 0, 0, 0, 0);clear_damage(out);commit_damage(l, 40, 40, 4, 4);@@ -1373,28 +1425,28 @@ int main(void) {// Geometry changes still damage both the old and new location, independently// of client buffer damage. Re-enabling a hidden node must repaint it too.- wlr_scene_node_set_position(&node->node, 200, 0);+ rediwm_node_set_position(&node->node, 200, 0);rediwm_projection_sync(p, .5, 0, 0, 0, 0);assert(damaged(out, 20, 20) && damaged(out, 170, 20));clear_damage(out);- wlr_scene_node_set_enabled(&node->node, false);+ rediwm_node_set_enabled(&node->node, false);rediwm_projection_sync(p, .5, 0, 0, 0, 0);clear_damage(out);commit_damage(l, 0, 0, 0, 0);rediwm_projection_sync(p, .5, 0, 0, 0, 0);- wlr_scene_node_set_enabled(&node->node, true);+ rediwm_node_set_enabled(&node->node, true);rediwm_projection_sync(p, .5, 0, 0, 0, 0);assert(damaged(out, 170, 20));- wlr_scene_node_set_position(&node->node, 0, 0);+ rediwm_node_set_position(&node->node, 0, 0);rediwm_projection_sync(p, .5, 0, 0, 0, 0);clear_damage(out);// Unmap/remap must repaint even when the remapping commit has empty damage.- wlr_scene_buffer_set_buffer(node, NULL);+ rediwm_buffer_set_buffer(node, NULL);commit_damage(l, 0, 0, 0, 0);rediwm_projection_sync(p, .5, 0, 0, 0, 0);clear_damage(out);- wlr_scene_buffer_set_buffer(node, a);+ rediwm_buffer_set_buffer(node, a);commit_damage(l, 0, 0, 0, 0);rediwm_projection_sync(p, .5, 0, 0, 0, 0);assert(damaged(out, 25, 15));diff --git a/src/scene_data.zig b/src/scene_data.zigindex 72acc30..abe0fa5 100644--- a/src/scene_data.zig+++ b/src/scene_data.zig@@ -5,6 +5,7 @@// `*SceneData`. Hit-testing must go through `fromNode` / `hitTest` rather than// casting the opaque pointer to a window or widget type.const wlr = @import("wlroots");+const sn = @import("node.zig");const ControlCenter = @import("control_center/panel.zig").ControlCenter;const StartMenu = @import("start_menu/panel.zig").StartMenu;@@ -43,17 +44,17 @@ pub const SceneData = struct {desktop: *@import("desktop/embedded.zig").Desktop,};- pub fn attach(data: *SceneData, node: *wlr.SceneNode) void {+ pub fn attach(data: *SceneData, node: *sn.Node) void {node.data = data;}- pub fn fromNode(node: *wlr.SceneNode) ?*SceneData {+ pub fn fromNode(node: *sn.Node) ?*SceneData {const ptr = node.data orelse return null;return @ptrCast(@alignCast(ptr));}- pub fn fromNodeOrParents(node: *wlr.SceneNode) ?*SceneData {- var current: ?*wlr.SceneNode = node;+ pub fn fromNodeOrParents(node: *sn.Node) ?*SceneData {+ var current: ?*sn.Node = node;while (current) |n| {if (fromNode(n)) |data| return data;current = if (n.parent) |tree| &tree.node else null;@@ -62,6 +63,13 @@ pub const SceneData = struct {}};+/// The role of a node inside a client's surface tree: up to the root of the hosted+/// subtree, then on through the own tree that places it.+pub fn fromWlrNode(node: *wlr.SceneNode) ?*SceneData {+ const hosted = sn.Foreign.of(node) orelse return null;+ return SceneData.fromNodeOrParents(&hosted.node);+}+pub const Hit = union(enum) {none,input_popup: struct { surface: *wlr.Surface, sx: f64, sy: f64 },@@ -135,46 +143,16 @@ pub const Hit = union(enum) {/// Layout point relative to an output-local shell node. Window frames use/// Toplevel.frameLocal, and projected client buffers map through projection.c.-pub fn toNodeLocal(node: *wlr.SceneNode, lx: f64, ly: f64) geometry.Vec2 {+pub fn toNodeLocal(node: *sn.Node, lx: f64, ly: f64) geometry.Vec2 {var ox: i32 = 0;var oy: i32 = 0;_ = node.coords(&ox, &oy);return geometry.toLocal(lx, ly, ox, oy);}-pub fn hitTest(server: *@import("Server.zig"), lx: f64, ly: f64) Hit {- server.world.syncPresentation();- var nx: f64 = undefined;- var ny: f64 = undefined;- var node = server.world.projection.nodeAt(lx, ly, &nx, &ny) orelse return .none;-- // Let the latched preview receive input through other dimmed windows.- // Shell UI and layers keep their normal priority, as do points outside- // the selected window's input region. Reuse scene picking so subsurfaces,- // popups, chrome and client input regions retain their normal semantics.- if (server.world.peekTarget()) |selected| {- if (SceneData.fromNodeOrParents(node)) |data| {- const owner: ?*Toplevel = switch (data.role) {- .toplevel => |t| t,- .chrome => |t| t,- else => null,- };- if (owner != null and owner != selected) {- const local = selected.frameLocal(lx, ly);- const frame = &selected.frame_tree.node;- var sx: f64 = undefined;- var sy: f64 = undefined;- if (frame.at(local.x + @as(f64, @floatFromInt(frame.x)), local.y + @as(f64, @floatFromInt(frame.y)), &sx, &sy)) |picked| {- node = picked;- nx = sx;- ny = sy;- }- }- }- }-- if (SceneData.fromNode(node)) |data| {- return switch (data.role) {+/// What an own node of the shell is, from its role.+fn shellHit(data: *SceneData, lx: f64, ly: f64) Hit {+ return switch (data.role) {.wifi_popup => |popup| blk: {const local = toNodeLocal(&popup.buffer_node.node, lx, ly);break :blk .{ .wifi_popup = .{ .popup = popup, .sx = local.x, .sy = local.y } };@@ -224,15 +202,48 @@ pub fn hitTest(server: *@import("Server.zig"), lx: f64, ly: f64) Hit {},// The frame tree itself is not a pickable leaf..toplevel, .layer, .xwayland_unmanaged => .none,- };+ };+}++pub fn hitTest(server: *@import("Server.zig"), lx: f64, ly: f64) Hit {+ server.world.syncPresentation();+ const projection = server.world.projection;+ var hit = projection.nodeAt(lx, ly) orelse return .none;++ // Let the latched preview receive input through other dimmed windows.+ // Shell UI and layers keep their normal priority, as do points outside+ // the selected window's input region. Pick among the selected window's own+ // leaves, so subsurfaces, popups, chrome and client input regions retain their+ // normal semantics.+ if (server.world.peekTarget()) |selected| {+ if (SceneData.fromNodeOrParents(hitNode(hit))) |data| {+ const owner: ?*Toplevel = switch (data.role) {+ .toplevel => |t| t,+ .chrome => |t| t,+ else => null,+ };+ if (owner != null and owner != selected) {+ if (projection.nodeAtIn(&selected.frame_tree.node, lx, ly)) |picked| hit = picked;+ }+ }+ }+ const nx = hit.x;+ const ny = hit.y;++ // An own node of the shell: its role says what it is.+ if (hit.own) |own| {+ const data = SceneData.fromNode(own) orelse return .none;+ return shellHit(data, lx, ly);}- if (node.type != .buffer) return .none;- const scene_surface = wlr.SceneSurface.tryFromBuffer(wlr.SceneBuffer.fromNode(node)) orelse return .none;+ // A client's surface: found through the subtree that hosts it.+ if (hit.wlr.type != .buffer) return .none;+ const scene_surface = wlr.SceneSurface.tryFromBuffer(wlr.SceneBuffer.fromNode(hit.wlr)) orelse return .none;if (wlr.InputPopupSurfaceV2.tryFromWlrSurface(scene_surface.surface.getRootSurface()) != null) {return .{ .input_popup = .{ .surface = scene_surface.surface, .sx = nx, .sy = ny } };}- const data = SceneData.fromNodeOrParents(node) orelse return .none;+ const hosted = hit.foreign orelse return .none;+ const data = SceneData.fromNodeOrParents(&hosted.node) orelse return .none;return switch (data.role) {.toplevel => |toplevel| .{ .surface = .{.toplevel = toplevel,@@ -261,3 +272,9 @@ pub fn xdgSceneTree(xdg_surface: *wlr.XdgSurface) ?*wlr.SceneTree {const ptr = xdg_surface.data orelse return null;return @ptrCast(@alignCast(ptr));}++/// The own node a hit belongs to: the node itself, or the one that hosts the client+/// surface it lies in.+fn hitNode(hit: @import("projection.zig").Projection.Hit) *sn.Node {+ return hit.own orelse &hit.foreign.?.node;+}diff --git a/src/scene_output.c b/src/scene_output.cindex 8172c73..fe1425e 100644--- a/src/scene_output.c+++ b/src/scene_output.c@@ -8,6 +8,7 @@#include "scene_graph.h"#include "projection.h"#include "glass.h"+#include "node.h"#include <math.h>#include <stdlib.h>#include <string.h>@@ -330,7 +331,7 @@ static bool collect(const struct rediwm_item *item, struct wlr_scene_node *transe->padded = (struct wlr_box){box.x - pad, box.y - pad, box.width + 2 * pad, box.height + 2 * pad};pixman_region32_union_rect(&collector->reads, &collector->reads,e->padded.x, e->padded.y, e->padded.width, e->padded.height);- e->front = &glass.target->node;+ e->front = &glass.target->carrier->node;return true;}bool full = item->kind == REDIWM_ITEM_RECT && item->content.color[3] == 1;diff --git a/src/screenshot/capture.zig b/src/screenshot/capture.zigindex 21c6ee1..4a48157 100644--- a/src/screenshot/capture.zig+++ b/src/screenshot/capture.zig@@ -2,6 +2,7 @@ const std = @import("std");const posix = std.posix;const wl = @import("wayland").server.wl;const wlr = @import("wlroots");+const sn = @import("../node.zig");const Server = @import("../Server.zig");const Output = @import("../Output.zig");@@ -293,7 +294,7 @@ pub const Manager = struct {return;};- var disabled_nodes = std.ArrayList(*wlr.SceneNode).empty;+ var disabled_nodes = std.ArrayList(*sn.Node).empty;defer disabled_nodes.deinit(mgr.allocator);const is_isolated = std.mem.eql(u8, job.capture_mode, "isolated-window");diff --git a/src/screenshot/selector.zig b/src/screenshot/selector.zigindex bd9c233..b8f42f8 100644--- a/src/screenshot/selector.zig+++ b/src/screenshot/selector.zig@@ -1,6 +1,7 @@//! Native, modal region picker. All geometry is output-local logical pixels.const std = @import("std");const wlr = @import("wlroots");+const sn = @import("../node.zig");const col = @import("../color.zig");const Server = @import("../Server.zig");const Output = @import("../Output.zig");@@ -10,14 +11,14 @@ const Self = @This();const stats = @import("../ipc/stats.zig");output: ?*Output = null,-tree: ?*wlr.SceneTree = null,-shades: [4]?*wlr.SceneRect = @splat(null),-borders: [4]?*wlr.SceneBuffer = @splat(null),+tree: ?*sn.Tree = null,+shades: [4]?*sn.Rect = @splat(null),+borders: [4]?*sn.Buffer = @splat(null),// GLES can release SceneBuffer.buffer after uploading its pixels. Keep the// immutable strip dimensions here; geometry must not borrow that buffer later.strip_sizes: [2]struct { width: f64 = 0, height: f64 = 0 } = @splat(.{}),-corners: [8]?*wlr.SceneRect = @splat(null),-label: ?*wlr.SceneBuffer = null,+corners: [8]?*sn.Rect = @splat(null),+label: ?*sn.Buffer = null,label_width: i32 = -1,label_height: i32 = -1,dirty: bool = false,@@ -63,7 +64,7 @@ pub fn open(self: *Self, server: *Server) !void {self.flush(output);}-fn setRect(node: *wlr.SceneRect, x: i32, y: i32, width: i32, height: i32) void {+fn setRect(node: *sn.Rect, x: i32, y: i32, width: i32, height: i32) void {node.node.setEnabled(width > 0 and height > 0);if (width <= 0 or height <= 0) return;node.node.setPosition(x, y);diff --git a/src/session/client_lock.zig b/src/session/client_lock.zigindex 3ea26e5..a304a84 100644--- a/src/session/client_lock.zig+++ b/src/session/client_lock.zig@@ -14,6 +14,7 @@const std = @import("std");const wl = @import("wayland").server.wl;const wlr = @import("wlroots");+const sn = @import("../node.zig");const Server = @import("../Server.zig");const Output = @import("../Output.zig");@@ -262,7 +263,7 @@ const Surface = struct {lock_surface: *wlr.SessionLockSurfaceV1,/// Null once the output is gone; wlroots destroys the surface next.output: ?*Output,- tree: ?*wlr.SceneTree,+ tree: ?*sn.Foreign,width: i32 = 0,height: i32 = 0,link: wl.list.Link = undefined,diff --git a/src/session/lock.zig b/src/session/lock.zigindex 2ef2f34..d97ab4e 100644--- a/src/session/lock.zig+++ b/src/session/lock.zig@@ -7,6 +7,7 @@ const std = @import("std");const Child = @import("child.zig");const wl = @import("wayland").server.wl;const wlr = @import("wlroots");+const sn = @import("../node.zig");const col = @import("../color.zig");const xkb = @import("xkbcommon");const Server = @import("../Server.zig");@@ -792,23 +793,23 @@ const Geometry = struct {const field_options: text_field.Options = .{ .size = .lg, .secret_dots = .{ .diameter = 0.46, .pitch = 1.05 }, .trailing = .reveal };pub const View = struct {- tree: *wlr.SceneTree,- guard: *wlr.SceneRect,- wallpaper: *wlr.SceneBuffer,- ui_node: *wlr.SceneBuffer,+ tree: *sn.Tree,+ guard: *sn.Rect,+ wallpaper: *sn.Buffer,+ ui_node: *sn.Buffer,/// The password field's caret, above `ui_node`: it blinks and glides/// without re-rastering the whole screen.caret: CaretOverlay,/// The volume/brightness block: its own small raster (`Lock.controls`),/// so dragging a slider never re-rasters the screen under it.- controls_node: *wlr.SceneBuffer,+ controls_node: *sn.Buffer,controls_key: ?ControlsKey = null,revision: u64 = 0,width: i32 = 0,height: i32 = 0,scale: f32 = 0,- pub fn create(parent: *wlr.SceneTree) !View {+ pub fn create(parent: *sn.Tree) !View {const tree = try parent.createSceneTree();errdefer tree.node.destroy();const guard = try col.createRect(tree, 0, 0, col.Straight.fromRgba(lockBackground()).premultiply());@@ -1088,15 +1089,15 @@ test "lock IPC and client focus requests stop before touching desktop state" {}test "lock output guard is opaque independent of wallpaper and UI buffers" {- const scene = try wlr.Scene.create();- defer scene.tree.node.destroy();- var view = try View.create(&scene.tree);+ var fixture = try sn.TestScene.create();+ defer fixture.destroy();+ var view = try View.create(&fixture.nodes.tree);try std.testing.expect(!view.tree.node.enabled);try std.testing.expectEqual(@as(f32, 1), view.guard.color[3]);view.tree.node.setEnabled(true);view.guard.setSize(1920, 1080);try std.testing.expectEqual(@as(i32, 1920), view.guard.width);- try std.testing.expect(view.ui_node.buffer == null);+ try std.testing.expect(view.ui_node.getBuffer() == null);view.hide();try std.testing.expect(!view.tree.node.enabled);}@@ -1106,9 +1107,9 @@ test "lock raster scales to small outputs and renders a solid accent unlock butt@memcpy(lock.name[0..11], "Alex Morgan");@memcpy(lock.user[0..10], "alexmorgan");lock.controls = .{ .has_volume = true, .volume = 0.5, .has_brightness = true, .brightness = 0.25, .active = .volume };- const scene = try wlr.Scene.create();- defer scene.tree.node.destroy();- var view = try View.create(&scene.tree);+ var fixture = try sn.TestScene.create();+ defer fixture.destroy();+ var view = try View.create(&fixture.nodes.tree);for ([_][3]i32{ .{ 1672, 941, 1 }, .{ 640, 480, 1 }, .{ 1280, 720, 2 } }) |size| {const scale: f32 = if (size[2] == 2) 1.5 else 1;const buf = try Buffer.create(size[0], size[1], scale);@@ -1124,7 +1125,7 @@ test "lock raster scales to small outputs and renders a solid accent unlock buttview.syncControls(&lock, .{ .x = 0, .y = 0, .width = size[0], .height = size[1] }, scale);const placed = geo.controlsBox(lock.controls.height());const node = &view.controls_node.node;- try std.testing.expect(node.enabled and view.controls_node.buffer != null);+ try std.testing.expect(node.enabled and view.controls_node.getBuffer() != null);try std.testing.expectEqual(placed.x, node.x);try std.testing.expectEqual(placed.y, node.y);try std.testing.expect(node.y >= 0 and node.y + placed.h <= size[1]);@@ -1172,7 +1173,7 @@ test "lock raster scales to small outputs and renders a solid accent unlock butt// a sound server show nothing there.lock.controls = .{};view.syncControls(&lock, .{ .x = 0, .y = 0, .width = 1280, .height = 720 }, 1);- try std.testing.expect(!view.controls_node.node.enabled and view.controls_node.buffer == null);+ try std.testing.expect(!view.controls_node.node.enabled and view.controls_node.getBuffer() == null);Buffer.drainPool();}@@ -1246,11 +1247,11 @@ test "lock covers new outputs and follows layout and mode changes without UI" {defer backend.destroy();const output_layout = try wlr.OutputLayout.create(display);defer output_layout.destroy();- const scene = try wlr.Scene.create();- defer scene.tree.node.destroy();+ var fixture = try sn.TestScene.create();+ defer fixture.destroy();var server: Server = undefined;server.output_layout = output_layout;- server.lock_tree = try scene.tree.createSceneTree();+ server.lock_tree = try fixture.nodes.tree.createSceneTree();for (0..2) |i| {const output = try backend.headlessAddOutput(1280, 720);var state = wlr.Output.State.init();@@ -1266,7 +1267,7 @@ test "lock covers new outputs and follows layout and mode changes without UI" {try std.testing.expectEqual(@as(i32, 100), out.lock_view.tree.node.y);try std.testing.expectEqual(@as(i32, 1280), out.lock_view.guard.width);try std.testing.expectEqual(@as(i32, 720), out.lock_view.guard.height);- try std.testing.expect(out.lock_view.ui_node.buffer == null);+ try std.testing.expect(out.lock_view.ui_node.getBuffer() == null);state.setCustomMode(1920, 1080, 60000);try std.testing.expect(output.commitState(&state));_ = try output_layout.add(output, x, -50);diff --git a/src/snap.zig b/src/snap.zigindex 99b9f82..0a74fee 100644--- a/src/snap.zig+++ b/src/snap.zig@@ -6,6 +6,7 @@// Toplevel.setTiledOn converts them to world-space client geometry.const std = @import("std");const wlr = @import("wlroots");+const sn = @import("node.zig");const col = @import("color.zig");const theme = @import("ui").theme;@@ -197,13 +198,13 @@ pub fn step(layout: Layout, dir: Direction) Layout {/// The drop target shown while dragging: an accent-tinted fill with an/// outline, above windows so it stays visible over whatever it will cover.pub const Preview = struct {- tree: ?*wlr.SceneTree = null,- fill: ?*wlr.SceneRect = null,- outline: [4]?*wlr.SceneRect = .{ null, null, null, null },+ tree: ?*sn.Tree = null,+ fill: ?*sn.Rect = null,+ outline: [4]?*sn.Rect = .{ null, null, null, null },const outline_px = 2;- pub fn show(preview: *Preview, parent: *wlr.SceneTree, box: wlr.Box) void {+ pub fn show(preview: *Preview, parent: *sn.Tree, box: wlr.Box) void {const tree = preview.tree orelse preview.create(parent) catch return;tree.node.setPosition(box.x, box.y);preview.fill.?.setSize(box.width, box.height);@@ -226,12 +227,12 @@ pub const Preview = struct {if (preview.tree) |tree| tree.node.setEnabled(false);}- fn create(preview: *Preview, parent: *wlr.SceneTree) !*wlr.SceneTree {+ fn create(preview: *Preview, parent: *sn.Tree) !*sn.Tree {const tree = try parent.createSceneTree();errdefer tree.node.destroy();const accent = col.Straight.fromRgba(theme.shellPalette().accent).premultiply();const fill = try col.createRect(tree, 0, 0, accent.scale(0.16));- var outline: [4]?*wlr.SceneRect = undefined;+ var outline: [4]?*sn.Rect = undefined;for (&outline) |*rect| rect.* = try col.createRect(tree, 0, 0, accent.scale(0.55));preview.* = .{ .tree = tree, .fill = fill, .outline = outline };return tree;diff --git a/src/start_menu/panel.zig b/src/start_menu/panel.zigindex d46d385..2d66d4f 100644--- a/src/start_menu/panel.zig+++ b/src/start_menu/panel.zig@@ -6,6 +6,7 @@ const Allocator = std.mem.Allocator;const glass = @import("../glass.zig");const wl = @import("wayland").server.wl;const wlr = @import("wlroots");+const sn = @import("../node.zig");const xkb = @import("xkbcommon");const gpa = @import("../main.zig").gpa;@@ -56,7 +57,7 @@ pub const StartMenu = struct {card_selection: ?usize = null,server: *Server,wlr_output: *wlr.Output,- buffer_node: *wlr.SceneBuffer,+ buffer_node: *sn.Buffer,glass_effect: ?*glass.Effect = null,node_data: scene_data.SceneData = undefined,diff --git a/src/taskbar/window_menu.zig b/src/taskbar/window_menu.zigindex 7f259a1..a73ce49 100644--- a/src/taskbar/window_menu.zig+++ b/src/taskbar/window_menu.zig@@ -1,6 +1,7 @@//! The taskbar's window actions. Input owns one menu across all outputs.const std = @import("std");const wlr = @import("wlroots");+const sn = @import("../node.zig");const Taskbar = @import("../Taskbar.zig");const Toplevel = @import("../Toplevel.zig");const Output = @import("../Output.zig");@@ -19,7 +20,7 @@ pub const Menu = struct {pin_bytes: [512]u8 = undefined,pin_len: usize = 0,pinned: bool = false,- node: ?*wlr.SceneBuffer = null,+ node: ?*sn.Buffer = null,box: wlr.Box = .{ .x = 0, .y = 0, .width = 0, .height = 0 },selected: ?usize = null,diff --git a/src/tray.zig b/src/tray.zigindex 246ab3e..2a8473c 100644--- a/src/tray.zig+++ b/src/tray.zig@@ -3,6 +3,7 @@//! Protocol: https://specifications.freedesktop.org/status-notifier-item/latest-single/const std = @import("std");const wlr = @import("wlroots");+const sn = @import("node.zig");const col = @import("color.zig");const dbus = @import("dbus");const wire = dbus.wire;@@ -79,7 +80,7 @@ pub const Tray = struct {menu_parent: i32 = 0,parents: std.ArrayList(i32) = .empty,rows: std.ArrayList(Row) = .empty,- menu_node: ?*wlr.SceneBuffer = null,+ menu_node: ?*sn.Buffer = null,menu_box: wlr.Box = .{ .x = 0, .y = 0, .width = 0, .height = 0 },menu_bounds: wlr.Box = .{ .x = 0, .y = 0, .width = 0, .height = 0 },menu_scale: f32 = 1,diff --git a/src/xwayland_surface.zig b/src/xwayland_surface.zigindex df1a10f..fa4bb4b 100644--- a/src/xwayland_surface.zig+++ b/src/xwayland_surface.zig@@ -117,7 +117,7 @@ pub fn attachSurface(self: *Adapter) void {return;};self.scene_attached = true;- self.window.scene_tree.node.events.destroy.add(&self.scene_destroy);+ self.window.scene_tree.events.destroy.add(&self.scene_destroy);}if (surface.mapped and !self.window.in_world) self.window.handleMapped();}diff --git a/src/xwayland_unmanaged.zig b/src/xwayland_unmanaged.zigindex e4d40cd..7ed72c2 100644--- a/src/xwayland_unmanaged.zig+++ b/src/xwayland_unmanaged.zig@@ -6,6 +6,7 @@ const xscale = @import("xwayland_scale.zig");const wl = @import("wayland").server.wl;const wlr = @import("wlroots");+const sn = @import("node.zig");const Server = @import("Server.zig");const scene_data = @import("scene_data.zig");@@ -16,8 +17,8 @@ const log = std.log.scoped(.xwayland);server: *Server,xsurface: *wlr.XwaylandSurface,-tree: *wlr.SceneTree,-scene_tree: ?*wlr.SceneTree = null,+tree: *sn.Tree,+scene_tree: ?*sn.Foreign = null,node_data: scene_data.SceneData = undefined,destroy: wl.Listener(void) = .init(handleDestroy),