diff --git a/runtime/share/mezzaluna/base_config.lua b/runtime/share/mezzaluna/base_config.lua index 30f845d..7c9b01d 100644 --- a/runtime/share/mezzaluna/base_config.lua +++ b/runtime/share/mezzaluna/base_config.lua @@ -282,4 +282,3 @@ function print_table(tbl, indent, seen) end end end - diff --git a/runtime/share/mezzaluna/init.lua b/runtime/share/mezzaluna/init.lua index 5487611..3168cc0 100644 --- a/runtime/share/mezzaluna/init.lua +++ b/runtime/share/mezzaluna/init.lua @@ -1,4 +1,5 @@ local env_conf = os.getenv("XDG_CONFIG_HOME") + if not env_conf then env_conf = os.getenv("HOME") if not env_conf then diff --git a/src/Cursor.zig b/src/Cursor.zig index e9386af..d193771 100644 --- a/src/Cursor.zig +++ b/src/Cursor.zig @@ -32,7 +32,7 @@ mode: enum { passthrough, move, resize } = .passthrough, drag: struct { start_x: c_int, start_y: c_int, - view: ?*View, + view: ?*View, view_offset_x: ?c_int, view_offset_y: ?c_int, }, diff --git a/src/Output.zig b/src/Output.zig index 43b9e42..6ea033a 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -92,7 +92,7 @@ pub fn init(wlr_output: *wlr.Output) ?*Output { server.root.scene_output_layout.addOutput(layout_output, self.scene_output); self.setFocused(); - wlr_output.data = self; + wlr_output.data = &self.scene_node_data; server.events.exec("OutputInitPost", .{self.id}); @@ -187,24 +187,44 @@ pub fn surfaceAt(self: *Output, lx: f64, ly: f64) ?SurfaceAtResult { }; 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; + const node = layer.node.at(lx, ly, &sx, &sy); + if(node == null) continue; - if (node.data == null) continue; - const scene_node_data: *SceneNodeData = @ptrCast(@alignCast(node.data.?)); - - switch (scene_node_data.*) { - .layer_surface, .view => { - return SurfaceAtResult{ - .scene_node_data = scene_node_data, - .surface = scene_surface.surface, - .sx = sx, - .sy = sy, - }; - }, - else => continue + const surface: ?*wlr.Surface = blk: { + if (node.?.type == .buffer) { + const scene_buffer = wlr.SceneBuffer.fromNode(node.?); + if (wlr.SceneSurface.tryFromBuffer(scene_buffer)) |scene_surface| { + break :blk scene_surface.surface; + } } + break :blk null; + }; + if(surface == null) continue; + + const scene_node_data: *SceneNodeData = blk: { + var n = node.?; + while (true) { + if (@as(?*SceneNodeData, @ptrCast(@alignCast(n.data)))) |snd| { + break :blk snd; + } + if (n.parent) |parent_tree| { + n = &parent_tree.node; + } else { + continue; + } + } + }; + + switch (scene_node_data.*) { + .layer_surface, .view => { + return SurfaceAtResult{ + .scene_node_data = scene_node_data, + .surface = surface.?, + .sx = sx, + .sy = sy, + }; + }, + else => continue } } diff --git a/src/Root.zig b/src/Root.zig index bca85ef..63af0e1 100644 --- a/src/Root.zig +++ b/src/Root.zig @@ -74,8 +74,8 @@ pub fn viewById(self: *Root, id: u64) ?*View { while(output_it.next()) |o| { if(o.output.data == null) continue; - const scene_node_data: *SceneNodeData = @ptrCast(@alignCast(o.output.data.?)); - const output: *Output = switch (scene_node_data.*) { + const output_snd: *SceneNodeData = @ptrCast(@alignCast(o.output.data.?)); + const output: *Output = switch (output_snd.*) { .output => |output_ptr| output_ptr, else => { std.log.err("Incorrect scene node type found", .{}); @@ -88,8 +88,14 @@ pub fn viewById(self: *Root, id: u64) ?*View { while(node_it.next()) |node| { if(node.data == null) continue; - const view: *View = @as(*View, @ptrCast(@alignCast(node.data.?))); - if(view.id == id) return view; + const view_snd: *SceneNodeData = @ptrCast(@alignCast(node.data.?)); + + // TODO: Should we assert that we want only views to be here + // -- Basically should we use switch statements for snd interactions + // -- Or if statements, for simplicity + if(view_snd.* == .view and view_snd.view.id == id) { + return view_snd.view; + } } } diff --git a/src/Server.zig b/src/Server.zig index 3360f9e..1c5b2bd 100644 --- a/src/Server.zig +++ b/src/Server.zig @@ -131,7 +131,7 @@ pub fn init(self: *Server) void { self.root.scene.setGammaControlManagerV1(try wlr.GammaControlManagerV1.create(self.wl_server)); // Add event listeners to events - // Backedn events + // Backend events self.backend.events.new_input.add(&self.new_input); self.backend.events.new_output.add(&self.new_output); @@ -211,12 +211,13 @@ fn handleNewXdgToplevelDecoration( decoration: *wlr.XdgToplevelDecorationV1 ) void { if(server.root.viewById(@intFromPtr(decoration.toplevel))) |view| { + std.log.debug("found view\n", .{}); view.xdg_toplevel_decoration = decoration; } } -fn handleNewXdgPopup(_: *wl.Listener(*wlr.XdgPopup), xdg_popup: *wlr.XdgPopup) void { - _ = xdg_popup; +fn handleNewXdgPopup(_: *wl.Listener(*wlr.XdgPopup), _: *wlr.XdgPopup) void { + std.log.debug("Unimplemented Server.handleNewXdgPopup\n", .{}); } fn handleNewLayerSurface( diff --git a/src/View.zig b/src/View.zig index 2787b2d..663ac5e 100644 --- a/src/View.zig +++ b/src/View.zig @@ -164,6 +164,7 @@ fn handleMap(listener: *wl.Listener(void)) void { &server.seat.keyboard_group.keyboard.modifiers ); + std.log.debug("setting view decoration mode to server side\n", .{}); if(view.xdg_toplevel_decoration) |decoration| { _ = decoration.setMode(wlr.XdgToplevelDecorationV1.Mode.server_side); }