still working on migrating to the new SceneNodeData

This commit is contained in:
Harrison DiAmbrosio 2025-12-13 00:30:42 -05:00
parent 7a619ab770
commit 1039e3a800
7 changed files with 148 additions and 123 deletions

View file

@ -86,8 +86,8 @@ pub fn processCursorMotion(self: *Cursor, time_msec: u32) void {
// Exit the switch if no focused output exists // Exit the switch if no focused output exists
if (output == null) return; if (output == null) return;
const viewAtResult = output.?.viewAt(self.wlr_cursor.x, self.wlr_cursor.y); const surfaceAtResult = output.?.surfaceAt(self.wlr_cursor.x, self.wlr_cursor.y);
if (viewAtResult == null) { if (surfaceAtResult == null) {
self.wlr_cursor.setXcursor(self.x_cursor_manager, "default"); self.wlr_cursor.setXcursor(self.x_cursor_manager, "default");
server.seat.wlr_seat.pointerClearFocus(); server.seat.wlr_seat.pointerClearFocus();
@ -98,10 +98,16 @@ pub fn processCursorMotion(self: *Cursor, time_msec: u32) void {
return; return;
} }
server.events.exec("ViewPointerMotion", .{viewAtResult.?.view.id, self.wlr_cursor.x, self.wlr_cursor.y}); switch (surfaceAtResult.?.scene_node_data.*) {
.view => {
server.events.exec("ViewPointerMotion", .{surfaceAtResult.?.scene_node_data.view.id, self.wlr_cursor.x, self.wlr_cursor.y});
},
.layer_surface => { },
else => unreachable
}
server.seat.wlr_seat.pointerNotifyEnter(viewAtResult.?.surface, viewAtResult.?.sx, viewAtResult.?.sy); server.seat.wlr_seat.pointerNotifyEnter(surfaceAtResult.?.surface, surfaceAtResult.?.sx, surfaceAtResult.?.sy);
server.seat.wlr_seat.pointerNotifyMotion(time_msec, viewAtResult.?.sx, viewAtResult.?.sy); server.seat.wlr_seat.pointerNotifyMotion(time_msec, surfaceAtResult.?.sx, surfaceAtResult.?.sy);
}, },
.move => { // TODO: Have these behave more like pointer motion .move => { // TODO: Have these behave more like pointer motion
if(self.drag.view) |view| { if(self.drag.view) |view| {

View file

@ -6,12 +6,13 @@ const wlr = @import("wlroots");
const Utils = @import("Utils.zig"); const Utils = @import("Utils.zig");
const Output = @import("Output.zig"); const Output = @import("Output.zig");
const SceneNodeData = @import("SceneNodeData.zig"); const SceneNodeData = @import("SceneNodeData.zig").SceneNodeData;
const gpa = std.heap.c_allocator; const gpa = std.heap.c_allocator;
const server = &@import("main.zig").server; const server = &@import("main.zig").server;
output: *Output, output: *Output,
scene_node_data: SceneNodeData,
wlr_layer_surface: *wlr.LayerSurfaceV1, wlr_layer_surface: *wlr.LayerSurfaceV1,
scene_layer_surface: *wlr.SceneLayerSurfaceV1, scene_layer_surface: *wlr.SceneLayerSurfaceV1,
@ -27,11 +28,26 @@ pub fn init(wlr_layer_surface: *wlr.LayerSurfaceV1) *LayerSurface {
const self = try gpa.create(LayerSurface); const self = try gpa.create(LayerSurface);
self.* = .{ self.* = .{
.output = @ptrCast(@alignCast(wlr_layer_surface.output.?.data)), .output = blk: {
// These block things are dangerous
// There was no need for this
// But I cannot be stopped
// - Powerhungry programmer
const data = wlr_layer_surface.output.?.data;
if(data == null) unreachable;
const scene_node_data: *SceneNodeData = @ptrCast(@alignCast(wlr_layer_surface.output.?.data.?));
break :blk switch(scene_node_data.*) {
.output => @fieldParentPtr("scene_node_data", scene_node_data),
else => unreachable
};
},
.wlr_layer_surface = wlr_layer_surface, .wlr_layer_surface = wlr_layer_surface,
.scene_layer_surface = undefined, .scene_layer_surface = undefined,
.scene_node_data = .{ .layer_surface = self }
}; };
self.wlr_layer_surface.surface.data = &self.scene_node_data;
if(server.seat.focused_output) |output| { if(server.seat.focused_output) |output| {
self.scene_layer_surface = switch (wlr_layer_surface.current.layer) { self.scene_layer_surface = switch (wlr_layer_surface.current.layer) {
.background => try output.layers.background.createSceneLayerSurfaceV1(wlr_layer_surface), .background => try output.layers.background.createSceneLayerSurfaceV1(wlr_layer_surface),
@ -45,11 +61,6 @@ pub fn init(wlr_layer_surface: *wlr.LayerSurfaceV1) *LayerSurface {
}; };
} }
try SceneNodeData.setData(
&self.scene_layer_surface.tree.node,
.{ .layer_surface = self },
);
self.wlr_layer_surface.surface.data = &self.scene_layer_surface.tree.node;
self.wlr_layer_surface.events.destroy.add(&self.destroy); self.wlr_layer_surface.events.destroy.add(&self.destroy);
self.wlr_layer_surface.surface.events.map.add(&self.map); self.wlr_layer_surface.surface.events.map.add(&self.map);

View file

@ -5,11 +5,13 @@ const zwlr = @import("wayland").server.zwlr;
const wlr = @import("wlroots"); const wlr = @import("wlroots");
const std = @import("std"); const std = @import("std");
const Server = @import("Server.zig");
const Utils = @import("Utils.zig"); const Utils = @import("Utils.zig");
const Server = @import("Server.zig");
const View = @import("View.zig"); const View = @import("View.zig");
const LayerSurface = @import("LayerSurface.zig"); const LayerSurface = @import("LayerSurface.zig");
const SceneNodeData = @import("SceneNodeData.zig");
const SceneNodeData = @import("SceneNodeData.zig").SceneNodeData;
const posix = std.posix; const posix = std.posix;
const gpa = std.heap.c_allocator; const gpa = std.heap.c_allocator;
@ -21,6 +23,7 @@ id: u64,
wlr_output: *wlr.Output, wlr_output: *wlr.Output,
state: wlr.Output.State, state: wlr.Output.State,
tree: *wlr.SceneTree, tree: *wlr.SceneTree,
scene_node_data: SceneNodeData,
scene_output: *wlr.SceneOutput, scene_output: *wlr.SceneOutput,
layers: struct { layers: struct {
@ -59,6 +62,7 @@ pub fn init(wlr_output: *wlr.Output) ?*Output {
.overlay = try self.tree.createSceneTree(), .overlay = try self.tree.createSceneTree(),
}, },
.scene_output = try server.root.scene.createSceneOutput(wlr_output), .scene_output = try server.root.scene.createSceneOutput(wlr_output),
.scene_node_data = SceneNodeData{ .output = self },
.state = wlr.Output.State.init() .state = wlr.Output.State.init()
}; };
@ -130,7 +134,6 @@ pub fn configureLayers(self: *Output) void {
self.wlr_output.effectiveResolution(&output_box.width, &output_box.height); self.wlr_output.effectiveResolution(&output_box.width, &output_box.height);
// Should calculate usable area here for LUA view positioning // Should calculate usable area here for LUA view positioning
for ([_]zwlr.LayerShellV1.Layer{ .background, .bottom, .top, .overlay }) |layer| { for ([_]zwlr.LayerShellV1.Layer{ .background, .bottom, .top, .overlay }) |layer| {
const tree = blk: { const tree = blk: {
const trees = [_]*wlr.SceneTree{ const trees = [_]*wlr.SceneTree{
@ -146,43 +149,65 @@ pub fn configureLayers(self: *Output) void {
while(it.next()) |node| { while(it.next()) |node| {
if(node.data == null) continue; if(node.data == null) continue;
const layer_surface: *wlr.LayerSurfaceV1 = @ptrCast(@alignCast(node.data.?)); const scene_node_data: *SceneNodeData = @ptrCast(@alignCast(node.data.?));
_ = layer_surface.configure(@intCast(output_box.width), @intCast(output_box.height)); switch (scene_node_data.*) {
.layer_surface => {
_ = scene_node_data.layer_surface.wlr_layer_surface.configured(
@intCast(output_box.width),
@intCast(output_box.height)
);
},
else => {
std.log.err("Something other than a layer surface found in layer surface scene trees", .{});
unreachable;
}
}
} }
} }
} }
const ViewAtResult = struct { const SurfaceAtResult = struct {
view: *View, scene_node_data: *SceneNodeData,
surface: *wlr.Surface, surface: *wlr.Surface,
sx: f64, sx: f64,
sy: f64, sy: f64,
}; };
pub fn viewAt(self: *Output, lx: f64, ly: f64) ?ViewAtResult { pub fn surfaceAt(self: *Output, lx: f64, ly: f64) ?SurfaceAtResult {
var sx: f64 = undefined; var sx: f64 = undefined;
var sy: f64 = undefined; var sy: f64 = undefined;
if(self.layers.content.node.at(lx, ly, &sx, &sy)) |node| { const layers = [_]*wlr.SceneTree{
if (node.type != .buffer) return null; self.layers.top,
const scene_buffer = wlr.SceneBuffer.fromNode(node); self.layers.overlay,
const scene_surface = wlr.SceneSurface.tryFromBuffer(scene_buffer) orelse return null; self.layers.fullscreen,
self.layers.content,
self.layers.bottom,
self.layers.background
};
var it: ?*wlr.SceneTree = node.parent; for(layers) |layer| {
if(layer.node.at(lx, ly, &sx, &sy)) |node| {
const scene_buffer = wlr.SceneBuffer.fromNode(node);
const scene_surface = wlr.SceneSurface.tryFromBuffer(scene_buffer) orelse continue;
while (it) |n| : (it = n.node.parent) { if (node.data == null) continue;
if (n.node.data == null) continue; const scene_node_data: *SceneNodeData = @ptrCast(@alignCast(node.data.?));
const view: *View = @ptrCast(@alignCast(n.node.data.?)); switch (scene_node_data.*) {
.layer_surface, .view => {
return ViewAtResult{ return SurfaceAtResult{
.view = view, .scene_node_data = scene_node_data,
.surface = scene_surface.surface, .surface = scene_surface.surface,
.sx = sx, .sx = sx,
.sy = sy, .sy = sy,
}; };
},
else => continue
}
} }
} }
return null; return null;
} }
@ -247,23 +272,27 @@ pub fn arrangeLayers(self: *Output) void {
const layer: *wlr.SceneTree = @field(self.layers, comptime_layer.name); const layer: *wlr.SceneTree = @field(self.layers, comptime_layer.name);
var it = layer.children.safeIterator(.forward); var it = layer.children.safeIterator(.forward);
while (it.next()) |node| { while (it.next()) |node| {
if (@as(?*SceneNodeData, @alignCast(@ptrCast(node.data)))) |node_data| { if(node.data == null) continue;
const layer_surface = node_data.data.layer_surface;
if (!layer_surface.wlr_layer_surface.initialized) continue; const scene_node_data: *SceneNodeData = @ptrCast(@alignCast(node.data.?));
const layer_surface: *LayerSurface = switch(scene_node_data.*) {
.layer_surface => @fieldParentPtr("scene_node_data", scene_node_data),
else => continue
};
// TEST: river seems to try and prevent clients from taking an if (!layer_surface.wlr_layer_surface.initialized) continue;
// exclusive size greater than half the screen by killing them. Do we
// need to? Clients can do quite a bit of nasty stuff and taking
// exclusive focus isn't even that bad.
layer_surface.scene_layer_surface.configure(&full_box, &full_box); // TEST: river seems to try and prevent clients from taking an
// exclusive size greater than half the screen by killing them. Do we
// need to? Clients can do quite a bit of nasty stuff and taking
// exclusive focus isn't even that bad.
// TEST: are these calls useless? layer_surface.scene_layer_surface.configure(&full_box, &full_box);
// const x = layer_surface.scene_layer_surface.tree.node.x;
// const y = layer_surface.scene_layer_surface.tree.node.y; // TEST: are these calls useless?
// layer_surface.scene_layer_surface.tree.node.setPosition(x, y); // const x = layer_surface.scene_layer_surface.tree.node.x;
} // const y = layer_surface.scene_layer_surface.tree.node.y;
// layer_surface.scene_layer_surface.tree.node.setPosition(x, y);
} }
} }
} }

View file

@ -1,22 +1,25 @@
/// The root of Mezzaluna is, you guessed it, the root of many of the systems mez needs: /// The root of Mezzaluna is, you guessed it, the root of many of the systems mez needs:
/// - Managing outputs
/// -
const Root = @This(); const Root = @This();
const std = @import("std"); const std = @import("std");
const wl = @import("wayland").server.wl; const wl = @import("wayland").server.wl;
const wlr = @import("wlroots"); const wlr = @import("wlroots");
const Output = @import("Output.zig");
const View = @import("View.zig");
const Utils = @import("Utils.zig");
const server = &@import("main.zig").server; const server = &@import("main.zig").server;
const gpa = std.heap.c_allocator; const gpa = std.heap.c_allocator;
const Output = @import("Output.zig");
const View = @import("View.zig");
const LayerSurface = @import("LayerSurface.zig");
const SceneNodeData = @import("SceneNodeData.zig").SceneNodeData;
const Utils = @import("Utils.zig");
xdg_toplevel_decoration_manager: *wlr.XdgDecorationManagerV1, xdg_toplevel_decoration_manager: *wlr.XdgDecorationManagerV1,
scene: *wlr.Scene, scene: *wlr.Scene,
waiting_room: *wlr.SceneTree, waiting_room: *wlr.SceneTree,
scene_output_layout: *wlr.SceneOutputLayout, scene_output_layout: *wlr.SceneOutputLayout,
@ -48,8 +51,16 @@ pub fn deinit(self: *Root) void {
while(it.next()) |node| { while(it.next()) |node| {
if(node.data == null) continue; if(node.data == null) continue;
const view: *View = @ptrCast(@alignCast(node.data.?)); const scene_node_data: *SceneNodeData = @ptrCast(@alignCast(node.data.?));
view.deinit(); switch(scene_node_data.*) {
.output => {
scene_node_data.output.deinit();
},
else => {
std.log.debug("The root has a child that is not an output", .{});
unreachable;
}
}
} }
self.output_layout.destroy(); self.output_layout.destroy();
@ -62,7 +73,16 @@ pub fn viewById(self: *Root, id: u64) ?*View {
while(output_it.next()) |o| { while(output_it.next()) |o| {
if(o.output.data == null) continue; if(o.output.data == null) continue;
const output: *Output = @ptrCast(@alignCast(o.output.data.?));
const scene_node_data: *SceneNodeData = @ptrCast(@alignCast(o.output.data.?));
const output: *Output = switch (scene_node_data.*) {
.output => |output_ptr| output_ptr,
else => {
std.log.err("Incorrect scene node type found", .{});
unreachable;
}
};
var node_it = output.layers.content.children.iterator(.forward); var node_it = output.layers.content.children.iterator(.forward);
while(node_it.next()) |node| { while(node_it.next()) |node| {

View file

@ -1,54 +1,10 @@
const SceneNodeData = @This();
const std = @import("std");
const wlr = @import("wlroots");
const wl = @import("wayland").server.wl;
const View = @import("View.zig"); const View = @import("View.zig");
const LayerSurface = @import("LayerSurface.zig"); const LayerSurface = @import("LayerSurface.zig");
const Output = @import("Output.zig");
const gpa = std.heap.c_allocator; const SceneNodeType = enum { view, layer_surface, output };
pub const SceneNodeData = union(SceneNodeType) {
pub const Data = union(enum) {
view: *View, view: *View,
layer_surface: *LayerSurface, layer_surface: *LayerSurface,
output: *Output
}; };
node: *wlr.SceneNode,
data: Data,
destroy: wl.Listener(void) = wl.Listener(void).init(handleDestroy),
pub fn setData(node: *wlr.SceneNode, data: Data) !void {
const scene_node_data = try gpa.create(SceneNodeData);
scene_node_data.* = .{
.node = node,
.data = data,
};
node.data = scene_node_data;
node.events.destroy.add(&scene_node_data.destroy);
}
fn handleDestroy(listener: *wl.Listener(void)) void {
const scene_node_data: *SceneNodeData = @fieldParentPtr("destroy", listener);
scene_node_data.destroy.link.remove();
scene_node_data.node.data = null;
gpa.destroy(scene_node_data);
}
pub fn getFromNode(node: *wlr.SceneNode) ?*SceneNodeData {
var n = node;
while (true) {
if (@as(?*SceneNodeData, @alignCast(@ptrCast(n.data)))) |scene_node_data| {
return scene_node_data;
}
if (n.parent) |parent_tree| {
n = &parent_tree.node;
} else {
return null;
}
}
}

View file

@ -4,19 +4,19 @@ const std = @import("std");
const wl = @import("wayland").server.wl; const wl = @import("wayland").server.wl;
const wlr = @import("wlroots"); const wlr = @import("wlroots");
const Root = @import("Root.zig"); const Root = @import("Root.zig");
const Seat = @import("Seat.zig"); const Seat = @import("Seat.zig");
const Cursor = @import("Cursor.zig"); const Cursor = @import("Cursor.zig");
const Keyboard = @import("Keyboard.zig"); const Keyboard = @import("Keyboard.zig");
const LayerSurface = @import("LayerSurface.zig"); const LayerSurface = @import("LayerSurface.zig");
const Output = @import("Output.zig"); const Output = @import("Output.zig");
const View = @import("View.zig"); const View = @import("View.zig");
const Utils = @import("Utils.zig"); const Utils = @import("Utils.zig");
const Keymap = @import("types/Keymap.zig"); const Keymap = @import("types/Keymap.zig");
const Hook = @import("types/Hook.zig"); const Hook = @import("types/Hook.zig");
const Events = @import("types/Events.zig"); const Events = @import("types/Events.zig");
const Popup = @import("Popup.zig"); const Popup = @import("Popup.zig");
const RemoteLua = @import("RemoteLua.zig"); const RemoteLua = @import("RemoteLua.zig");
const RemoteLuaManager = @import("RemoteLuaManager.zig"); const RemoteLuaManager = @import("RemoteLuaManager.zig");
const gpa = std.heap.c_allocator; const gpa = std.heap.c_allocator;
@ -35,15 +35,13 @@ xdg_shell: *wlr.XdgShell,
layer_shell: *wlr.LayerShellV1, layer_shell: *wlr.LayerShellV1,
xdg_toplevel_decoration_manager: *wlr.XdgDecorationManagerV1, xdg_toplevel_decoration_manager: *wlr.XdgDecorationManagerV1,
// Input
allocator: *wlr.Allocator, allocator: *wlr.Allocator,
root: Root, root: Root,
seat: Seat, seat: Seat,
cursor: Cursor, cursor: Cursor,
// lua data // Lua data
keymaps: std.AutoHashMap(u64, Keymap), keymaps: std.AutoHashMap(u64, Keymap),
hooks: std.ArrayList(*Hook), hooks: std.ArrayList(*Hook),
events: Events, events: Events,

View file

@ -6,6 +6,8 @@ const wlr = @import("wlroots");
const Popup = @import("Popup.zig"); const Popup = @import("Popup.zig");
const Output = @import("Output.zig"); const Output = @import("Output.zig");
const SceneNodeData = @import("SceneNodeData.zig").SceneNodeData;
const Utils = @import("Utils.zig"); const Utils = @import("Utils.zig");
const gpa = std.heap.c_allocator; const gpa = std.heap.c_allocator;
@ -20,6 +22,7 @@ output: ?*Output,
xdg_toplevel: *wlr.XdgToplevel, xdg_toplevel: *wlr.XdgToplevel,
xdg_toplevel_decoration: ?*wlr.XdgToplevelDecorationV1, xdg_toplevel_decoration: ?*wlr.XdgToplevelDecorationV1,
scene_tree: *wlr.SceneTree, scene_tree: *wlr.SceneTree,
scene_node_data: SceneNodeData,
// Surface Listeners // Surface Listeners
map: wl.Listener(void) = .init(handleMap), map: wl.Listener(void) = .init(handleMap),
@ -62,6 +65,8 @@ pub fn initFromTopLevel(xdg_toplevel: *wlr.XdgToplevel) *View {
.xdg_toplevel = xdg_toplevel, .xdg_toplevel = xdg_toplevel,
.scene_tree = undefined, .scene_tree = undefined,
.xdg_toplevel_decoration = null, .xdg_toplevel_decoration = null,
.scene_node_data = .{ .view = self }
}; };
self.xdg_toplevel.base.surface.events.unmap.add(&self.unmap); self.xdg_toplevel.base.surface.events.unmap.add(&self.unmap);
@ -76,8 +81,8 @@ pub fn initFromTopLevel(xdg_toplevel: *wlr.XdgToplevel) *View {
self.scene_tree = try server.root.waiting_room.createSceneXdgSurface(xdg_toplevel.base); self.scene_tree = try server.root.waiting_room.createSceneXdgSurface(xdg_toplevel.base);
} }
self.scene_tree.node.data = self; self.scene_tree.node.data = &self.scene_node_data;
self.xdg_toplevel.base.data = self.scene_tree; self.xdg_toplevel.base.data = &self.scene_node_data;
self.xdg_toplevel.events.destroy.add(&self.destroy); self.xdg_toplevel.events.destroy.add(&self.destroy);
self.xdg_toplevel.base.surface.events.map.add(&self.map); self.xdg_toplevel.base.surface.events.map.add(&self.map);