From 9186aeecd3dea1c61922b07ba093bf955ee30cc2 Mon Sep 17 00:00:00 2001 From: Harrison DiAmbrosio Date: Thu, 4 Dec 2025 23:50:39 -0500 Subject: [PATCH] viewById works again, layer still ontop of other things --- runtime/share/mezzaluna/init.lua | 61 +++++++------ src/{c.zig => C.zig} | 0 src/{cursor.zig => Cursor.zig} | 85 +++++++++++------- src/{keyboard.zig => Keyboard.zig} | 4 +- src/{layer_surface.zig => LayerSurface.zig} | 24 +++++- src/{output.zig => Output.zig} | 95 ++++++++++++++++++++- src/{root.zig => Root.zig} | 59 ++++--------- src/{seat.zig => Seat.zig} | 6 +- src/{server.zig => Server.zig} | 22 ++--- src/{utils.zig => Utils.zig} | 0 src/{view.zig => View.zig} | 61 +++++-------- src/lua/{api.zig => Api.zig} | 0 src/lua/{bridge.zig => Bridge.zig} | 2 +- src/lua/{fs.zig => Fs.zig} | 2 +- src/lua/{hook.zig => Hook.zig} | 4 +- src/lua/{input.zig => Input.zig} | 4 +- src/lua/{lua.zig => Lua.zig} | 14 +-- src/lua/{output.zig => Output.zig} | 2 +- src/lua/{view.zig => View.zig} | 10 ++- src/main.zig | 4 +- src/types/{events.zig => Events.zig} | 2 +- src/types/{hook.zig => Hook.zig} | 2 +- src/types/{keymap.zig => Keymap.zig} | 0 23 files changed, 282 insertions(+), 181 deletions(-) rename src/{c.zig => C.zig} (100%) rename src/{cursor.zig => Cursor.zig} (71%) rename src/{keyboard.zig => Keyboard.zig} (97%) rename src/{layer_surface.zig => LayerSurface.zig} (67%) rename src/{output.zig => Output.zig} (58%) rename src/{root.zig => Root.zig} (59%) rename src/{seat.zig => Seat.zig} (95%) rename src/{server.zig => Server.zig} (92%) rename src/{utils.zig => Utils.zig} (100%) rename src/{view.zig => View.zig} (80%) rename src/lua/{api.zig => Api.zig} (100%) rename src/lua/{bridge.zig => Bridge.zig} (94%) rename src/lua/{fs.zig => Fs.zig} (96%) rename src/lua/{hook.zig => Hook.zig} (93%) rename src/lua/{input.zig => Input.zig} (95%) rename src/lua/{lua.zig => Lua.zig} (90%) rename src/lua/{output.zig => Output.zig} (99%) rename src/lua/{view.zig => View.zig} (95%) rename src/types/{events.zig => Events.zig} (97%) rename src/types/{hook.zig => Hook.zig} (96%) rename src/types/{keymap.zig => Keymap.zig} (100%) diff --git a/runtime/share/mezzaluna/init.lua b/runtime/share/mezzaluna/init.lua index dc21260..d9d12c8 100644 --- a/runtime/share/mezzaluna/init.lua +++ b/runtime/share/mezzaluna/init.lua @@ -10,31 +10,13 @@ end mez.path.config = mez.fs.joinpath(env_conf, "mez", "init.lua") package.path = package.path..";"..mez.fs.joinpath(env_conf, "mez", "lua", "?.lua") -function print_table(tbl, indent, seen) - indent = indent or 0 - seen = seen or {} - - -- Prevent infinite loops from circular references - if seen[tbl] then - print(string.rep(" ", indent) .. "...(circular reference)") - return - end - seen[tbl] = true - - for key, value in pairs(tbl) do - local formatting = string.rep(" ", indent) .. tostring(key) .. ": " - - if type(value) == "table" then - print(formatting .. "{") - print_table(value, indent + 1, seen) - print(string.rep(" ", indent) .. "}") - elseif type(value) == "string" then - print(formatting .. '"' .. value .. '"') - else - print(formatting .. tostring(value)) - end - end -end +mez.hook.add("ViewPointerMotion", { + callback = function (view_id, cursor_x, cursor_y) + print("cursor_x: " .. cursor_x) + print("cursor_y: " .. cursor_y) + print("view_name: ") + end +}) local master = function() local config = { @@ -48,8 +30,6 @@ local master = function() } local tile_onscreen = function(tag_id, res) - print("positioning tag " .. tag_id .. " ONscreen") - if ctx.tags[tag_id].master == nil then return end @@ -277,3 +257,30 @@ local master = function() end master() + +function print_table(tbl, indent, seen) + indent = indent or 0 + seen = seen or {} + + -- Prevent infinite loops from circular references + if seen[tbl] then + print(string.rep(" ", indent) .. "...(circular reference)") + return + end + seen[tbl] = true + + for key, value in pairs(tbl) do + local formatting = string.rep(" ", indent) .. tostring(key) .. ": " + + if type(value) == "table" then + print(formatting .. "{") + print_table(value, indent + 1, seen) + print(string.rep(" ", indent) .. "}") + elseif type(value) == "string" then + print(formatting .. '"' .. value .. '"') + else + print(formatting .. tostring(value)) + end + end +end + diff --git a/src/c.zig b/src/C.zig similarity index 100% rename from src/c.zig rename to src/C.zig diff --git a/src/cursor.zig b/src/Cursor.zig similarity index 71% rename from src/cursor.zig rename to src/Cursor.zig index 44c8bc9..557f668 100644 --- a/src/cursor.zig +++ b/src/Cursor.zig @@ -8,10 +8,9 @@ const wl = @import("wayland").server.wl; const wlr = @import("wlroots"); const xkb = @import("xkbcommon"); -const View = @import("view.zig"); -const Utils = @import("utils.zig"); - -const c = @import("c.zig").c; +const View = @import("View.zig"); +const Utils = @import("Utils.zig"); +const c = @import("C.zig").c; const server = &@import("main.zig").server; const linux = std.os.linux; @@ -30,12 +29,13 @@ hold_end: wl.Listener(*wlr.Pointer.event.HoldEnd) = .init(handleHoldEnd), mode: enum { passthrough, move, resize } = .passthrough, // Drag information -drag_start_x: c_int = 0, -drag_start_y: c_int = 0, -drag_view_offset_x: c_int = 0, -drag_view_offset_y: c_int = 0, -drag_view_width: c_int = 0, -drag_view_height: c_int = 0, +drag: struct { + start_x: c_int, + start_y: c_int, + view: ?*View, + view_offset_x: ?c_int, + view_offset_y: ?c_int, +}, pub fn init(self: *Cursor) void { errdefer Utils.oomPanic(); @@ -43,6 +43,13 @@ pub fn init(self: *Cursor) void { self.* = .{ .wlr_cursor = try wlr.Cursor.create(), .x_cursor_manager = try wlr.XcursorManager.create(null, 24), + .drag = .{ + .start_x = 0, + .start_y = 0, + .view = null, + .view_offset_x = null, + .view_offset_y = null, + } }; try self.x_cursor_manager.load(1); @@ -72,27 +79,37 @@ pub fn deinit(self: *Cursor) void { } pub fn processCursorMotion(self: *Cursor, time_msec: u32) void { + server.events.exec("PointerMotion", .{self.wlr_cursor.x, self.wlr_cursor.y}); switch (self.mode) { .passthrough => { - if (server.root.viewAt(self.wlr_cursor.x, self.wlr_cursor.y)) |res| { - res.view.setFocused(); + const output = server.seat.focused_output; + // Exit the switch if no focused output exists + if (output == null) return; - server.seat.wlr_seat.pointerNotifyEnter(res.surface, res.sx, res.sy); - server.seat.wlr_seat.pointerNotifyMotion(time_msec, res.sx, res.sy); - } else { + const viewAtResult = output.?.viewAt(self.wlr_cursor.x, self.wlr_cursor.y); + if (viewAtResult == null) { self.wlr_cursor.setXcursor(self.x_cursor_manager, "default"); server.seat.wlr_seat.pointerClearFocus(); - } - }, - .move => { - const focused_view = server.seat.focused_view; - if(focused_view) |view| { + // This is gonna be fun + // server.seat.wlr_seat.keyboardSendKey(time_msec: u32, key: u32, state: u32); + // server.seat.wlr_seat.pointerSendMotion(time_msec: u32, sx: f64, sy: f64) + // server.seat.wlr_seat.pointerSendButton(time_msec: u32, button: u32, state: ButtonState) + return; + } + + server.events.exec("ViewPointerMotion", .{viewAtResult.?.view.id, self.wlr_cursor.x, self.wlr_cursor.y}); + + server.seat.wlr_seat.pointerNotifyEnter(viewAtResult.?.surface, viewAtResult.?.sx, viewAtResult.?.sy); + server.seat.wlr_seat.pointerNotifyMotion(time_msec, viewAtResult.?.sx, viewAtResult.?.sy); + }, + .move => { // TODO: Have these behave more like pointer motion + if(self.drag.view) |view| { view.scene_tree.node.setPosition( // TODO: add a lua option to configure the behavior of this, by // default it will be the following: - @as(c_int, @intFromFloat(self.wlr_cursor.x)) - self.drag_view_offset_x, - @as(c_int, @intFromFloat(self.wlr_cursor.y)) - self.drag_view_offset_y + @as(c_int, @intFromFloat(self.wlr_cursor.x)) - self.drag.view_offset_x.?, + @as(c_int, @intFromFloat(self.wlr_cursor.y)) - self.drag.view_offset_y.? // and the user should be able to configure if it clamps or not ); } @@ -141,18 +158,24 @@ fn handleButton( view.setFocused(); } + // @hook PointerButtonPress // TODO Probably change this name + // @param button string // TODO Translate a button to a string or smth + // @param state string - "pressed" or "released" + // @param time_msecs number // TODO idk what the hell msecs is + const state = if (event.state == .pressed) "pressed" else "released"; + server.events.exec("PointerButtonPress", .{event.button, state, event.time_msec}); + switch (event.state) { .pressed => { if(server.seat.keyboard_group.keyboard.getModifiers().alt) { // Can be BTN_RIGHT, BTN_LEFT, or BTN_MIDDLE + cursor.drag.start_x = @as(c_int, @intFromFloat(cursor.wlr_cursor.x)); + cursor.drag.start_y = @as(c_int, @intFromFloat(cursor.wlr_cursor.y)); if(server.seat.focused_view) |view| { // Keep track of where the drag started - cursor.drag_start_x = @as(c_int, @intFromFloat(cursor.wlr_cursor.x)); - cursor.drag_start_y = @as(c_int, @intFromFloat(cursor.wlr_cursor.y)); - cursor.drag_view_offset_x = cursor.drag_start_x - view.scene_tree.node.x; - cursor.drag_view_offset_y = cursor.drag_start_y - view.scene_tree.node.y; - cursor.drag_view_width = view.xdg_toplevel.base.geometry.width; - cursor.drag_view_height = view.xdg_toplevel.base.geometry.height; + cursor.drag.view = view; + cursor.drag.view_offset_x = cursor.drag.start_x - view.scene_tree.node.x; + cursor.drag.view_offset_y = cursor.drag.start_y - view.scene_tree.node.y; // Maybe comptime this for later reference if(event.button == c.libevdev_event_code_from_name(c.EV_KEY, "BTN_LEFT")) { @@ -167,9 +190,13 @@ fn handleButton( .released => { cursor.mode = .passthrough; - if(server.seat.focused_view) |view| { + if(cursor.drag.view) |view| { _ = view.xdg_toplevel.setResizing(false); } + + cursor.drag.view = null; + cursor.drag.view_offset_x = null; + cursor.drag.view_offset_y = null; }, else => { std.log.err("Invalid/Unimplemented pointer button event type", .{}); diff --git a/src/keyboard.zig b/src/Keyboard.zig similarity index 97% rename from src/keyboard.zig rename to src/Keyboard.zig index 260ef75..546095e 100644 --- a/src/keyboard.zig +++ b/src/Keyboard.zig @@ -6,8 +6,8 @@ const Keyboard = @This(); const std = @import("std"); const gpa = std.heap.c_allocator; const server = &@import("main.zig").server; -const Keymap = @import("types/keymap.zig"); -const Utils = @import("utils.zig"); +const Keymap = @import("types/Keymap.zig"); +const Utils = @import("Utils.zig"); const wl = @import("wayland").server.wl; const wlr = @import("wlroots"); diff --git a/src/layer_surface.zig b/src/LayerSurface.zig similarity index 67% rename from src/layer_surface.zig rename to src/LayerSurface.zig index 433ad27..b248229 100644 --- a/src/layer_surface.zig +++ b/src/LayerSurface.zig @@ -4,8 +4,8 @@ const std = @import("std"); const wl = @import("wayland").server.wl; const wlr = @import("wlroots"); -const Utils = @import("utils.zig"); -const Output = @import("output.zig"); +const Utils = @import("Utils.zig"); +const Output = @import("Output.zig"); const gpa = std.heap.c_allocator; const server = &@import("main.zig").server; @@ -28,8 +28,21 @@ pub fn init(wlr_layer_surface: *wlr.LayerSurfaceV1) *LayerSurface { self.* = .{ .output = @ptrCast(@alignCast(wlr_layer_surface.output.?.data)), .wlr_layer_surface = wlr_layer_surface, - .scene_layer_surface = try server.root.scene.tree.createSceneLayerSurfaceV1(wlr_layer_surface) + .scene_layer_surface = undefined, }; +// try server.root.scene.tree.createSceneLayerSurfaceV1(wlr_layer_surface) + if(server.seat.focused_output) |output| { + self.scene_layer_surface = switch (wlr_layer_surface.current.layer) { + .background => try output.layers.background.createSceneLayerSurfaceV1(wlr_layer_surface), + .bottom => try output.layers.background.createSceneLayerSurfaceV1(wlr_layer_surface), + .top => try output.layers.background.createSceneLayerSurfaceV1(wlr_layer_surface), + .overlay => try output.layers.background.createSceneLayerSurfaceV1(wlr_layer_surface), + else => { + std.log.err("New layer surface of unidentified type", .{}); + unreachable; + } + }; + } self.wlr_layer_surface.surface.data = &self.scene_layer_surface.tree.node; @@ -78,5 +91,10 @@ fn handleCommit( ) void { const layer_surface: *LayerSurface = @fieldParentPtr("commit", listener); + var width: c_int = undefined; + var height: c_int = undefined; + layer_surface.output.wlr_output.effectiveResolution(&width, &height); + _ = layer_surface.wlr_layer_surface.configure(@intCast(width), @intCast(height)); + layer_surface.scene_layer_surface.tree.node.reparent(&layer_surface.output.scene_output.scene.tree); } diff --git a/src/output.zig b/src/Output.zig similarity index 58% rename from src/output.zig rename to src/Output.zig index e66148c..e0f0283 100644 --- a/src/output.zig +++ b/src/Output.zig @@ -1,10 +1,15 @@ const Output = @This(); const wl = @import("wayland").server.wl; +const zwlr = @import("wayland").server.zwlr; const wlr = @import("wlroots"); const std = @import("std"); -const Server = @import("server.zig"); -const Utils = @import("utils.zig"); + + + +const Server = @import("Server.zig"); +const Utils = @import("Utils.zig"); +const View = @import("View.zig"); const posix = std.posix; const gpa = std.heap.c_allocator; @@ -15,12 +20,23 @@ id: u64, wlr_output: *wlr.Output, state: wlr.Output.State, +tree: *wlr.SceneTree, scene_output: *wlr.SceneOutput, +layers: struct { + background: *wlr.SceneTree, + bottom: *wlr.SceneTree, + content: *wlr.SceneTree, + top: *wlr.SceneTree, + fullscreen: *wlr.SceneTree, + overlay: *wlr.SceneTree +}, + frame: wl.Listener(*wlr.Output) = .init(handleFrame), request_state: wl.Listener(*wlr.Output.event.RequestState) = .init(handleRequestState), destroy: wl.Listener(*wlr.Output) = .init(handleDestroy), + // The wlr.Output should be destroyed by the caller on failure to trigger cleanup. pub fn init(wlr_output: *wlr.Output) ?*Output { errdefer Utils.oomPanic(); @@ -31,6 +47,15 @@ pub fn init(wlr_output: *wlr.Output) ?*Output { .focused = false, .id = @intFromPtr(wlr_output), .wlr_output = wlr_output, + .tree = try server.root.scene.tree.createSceneTree(), + .layers = .{ + .background = try self.tree.createSceneTree(), + .bottom = try self.tree.createSceneTree(), + .content = try self.tree.createSceneTree(), + .top = try self.tree.createSceneTree(), + .fullscreen = try self.tree.createSceneTree(), + .overlay = try self.tree.createSceneTree(), + }, .scene_output = try server.root.scene.createSceneOutput(wlr_output), .state = wlr.Output.State.init() }; @@ -87,6 +112,72 @@ pub fn setFocused(self: *Output) void { self.focused = true; } +pub fn configureLayers(self: *Output) void { + var output_box: wlr.Box = .{ + .x = 0, + .y = 0, + .width = undefined, + .height = undefined, + }; + self.wlr_output.effectiveResolution(&output_box.width, &output_box.height); + + // Should calculate usable area here for LUA view positioning + + for ([_]zwlr.LayerShellV1.Layer{ .background, .bottom, .top, .overlay }) |layer| { + const tree = blk: { + const trees = [_]*wlr.SceneTree{ + self.layers.background, + self.layers.bottom, + self.layers.top, + self.layers.overlay, + }; + break :blk trees[@intCast(@intFromEnum(layer))]; + }; + + var it = tree.children.iterator(.forward); + while(it.next()) |node| { + if(node.data == null) continue; + + const layer_surface: *wlr.LayerSurfaceV1 = @ptrCast(@alignCast(node.data.?)); + _ = layer_surface.configure(@intCast(output_box.width), @intCast(output_box.height)); + } + } +} + +const ViewAtResult = struct { + view: *View, + surface: *wlr.Surface, + sx: f64, + sy: f64, +}; + +pub fn viewAt(self: *Output, lx: f64, ly: f64) ?ViewAtResult { + var sx: f64 = undefined; + var sy: f64 = undefined; + + if(self.layers.content.node.at(lx, ly, &sx, &sy)) |node| { + if (node.type != .buffer) return null; + const scene_buffer = wlr.SceneBuffer.fromNode(node); + const scene_surface = wlr.SceneSurface.tryFromBuffer(scene_buffer) orelse return null; + + var it: ?*wlr.SceneTree = node.parent; + + while (it) |n| : (it = n.node.parent) { + if (n.node.data == null) continue; + + const view: *View = @ptrCast(@alignCast(n.node.data.?)); + + return ViewAtResult{ + .view = view, + .surface = scene_surface.surface, + .sx = sx, + .sy = sy, + }; + } + } + return null; +} + // --------- WlrOutput Event Handlers --------- fn handleRequestState( listener: *wl.Listener(*wlr.Output.event.RequestState), diff --git a/src/root.zig b/src/Root.zig similarity index 59% rename from src/root.zig rename to src/Root.zig index 925dd9a..3614286 100644 --- a/src/root.zig +++ b/src/Root.zig @@ -7,9 +7,9 @@ const std = @import("std"); const wl = @import("wayland").server.wl; const wlr = @import("wlroots"); -const Output = @import("output.zig"); -const View = @import("view.zig"); -const Utils = @import("utils.zig"); +const Output = @import("Output.zig"); +const View = @import("View.zig"); +const Utils = @import("Utils.zig"); const server = &@import("main.zig").server; const gpa = std.heap.c_allocator; @@ -17,6 +17,7 @@ const gpa = std.heap.c_allocator; xdg_toplevel_decoration_manager: *wlr.XdgDecorationManagerV1, scene: *wlr.Scene, +waiting_room: *wlr.SceneTree, scene_output_layout: *wlr.SceneOutputLayout, output_layout: *wlr.OutputLayout, @@ -34,6 +35,7 @@ pub fn init(self: *Root) void { self.* = .{ .scene = scene, + .waiting_room = try scene.tree.createSceneTree(), .output_layout = output_layout, .xdg_toplevel_decoration_manager = try wlr.XdgDecorationManagerV1.create(server.wl_server), .scene_output_layout = try scene.attachOutputLayout(output_layout), @@ -54,14 +56,21 @@ pub fn deinit(self: *Root) void { self.scene.tree.node.destroy(); } +// Search output_layout's ouputs, and each outputs views pub fn viewById(self: *Root, id: u64) ?*View { - var it = self.scene.tree.children.iterator(.forward); + var output_it = self.output_layout.outputs.iterator(.forward); - while(it.next()) |node| { - if(node.data == null) continue; + while(output_it.next()) |o| { + if(o.output.data == null) continue; + const output: *Output = @ptrCast(@alignCast(o.output.data.?)); + var node_it = output.layers.content.children.iterator(.forward); - const view: *View = @as(*View, @ptrCast(@alignCast(node.data.?))); - if(view.id == id) return 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; + } } return null; @@ -79,37 +88,3 @@ pub fn outputById(self: *Root, id: u64) ?*Output { return null; } - -const ViewAtResult = struct { - view: *View, - surface: *wlr.Surface, - sx: f64, - sy: f64, -}; - -pub fn viewAt(self: *Root, lx: f64, ly: f64) ?ViewAtResult { - var sx: f64 = undefined; - var sy: f64 = undefined; - - if (self.scene.tree.node.at(lx, ly, &sx, &sy)) |node| { - if (node.type != .buffer) return null; - const scene_buffer = wlr.SceneBuffer.fromNode(node); - const scene_surface = wlr.SceneSurface.tryFromBuffer(scene_buffer) orelse return null; - - var it: ?*wlr.SceneTree = node.parent; - - while (it) |n| : (it = n.node.parent) { - if (n.node.data) |data_ptr| { - if (@as(?*View, @ptrCast(@alignCast(data_ptr)))) |view| { - return ViewAtResult{ - .view = view, - .surface = scene_surface.surface, - .sx = sx, - .sy = sy, - }; - } - } - } - } - return null; -} diff --git a/src/seat.zig b/src/Seat.zig similarity index 95% rename from src/seat.zig rename to src/Seat.zig index 9f47647..5617a26 100644 --- a/src/seat.zig +++ b/src/Seat.zig @@ -5,9 +5,9 @@ const wlr = @import("wlroots"); const wl = @import("wayland").server.wl; const xkb = @import("xkbcommon"); -const Utils = @import("utils.zig"); -const View = @import("view.zig"); -const Output = @import("output.zig"); +const Utils = @import("Utils.zig"); +const View = @import("View.zig"); +const Output = @import("Output.zig"); const server = &@import("main.zig").server; diff --git a/src/server.zig b/src/Server.zig similarity index 92% rename from src/server.zig rename to src/Server.zig index b824ea4..d6c61b0 100644 --- a/src/server.zig +++ b/src/Server.zig @@ -4,17 +4,17 @@ const std = @import("std"); const wl = @import("wayland").server.wl; const wlr = @import("wlroots"); -const Root = @import("root.zig"); -const Seat = @import("seat.zig"); -const Cursor = @import("cursor.zig"); -const Keyboard = @import("keyboard.zig"); -const LayerSurface = @import("layer_surface.zig"); -const Output = @import("output.zig"); -const View = @import("view.zig"); -const Utils = @import("utils.zig"); -const Keymap = @import("types/keymap.zig"); -const Hook = @import("types/hook.zig"); -const Events = @import("types/events.zig"); +const Root = @import("Root.zig"); +const Seat = @import("Seat.zig"); +const Cursor = @import("Cursor.zig"); +const Keyboard = @import("Keyboard.zig"); +const LayerSurface = @import("LayerSurface.zig"); +const Output = @import("Output.zig"); +const View = @import("View.zig"); +const Utils = @import("Utils.zig"); +const Keymap = @import("types/Keymap.zig"); +const Hook = @import("types/Hook.zig"); +const Events = @import("types/Events.zig"); const gpa = std.heap.c_allocator; const server = &@import("main.zig").server; diff --git a/src/utils.zig b/src/Utils.zig similarity index 100% rename from src/utils.zig rename to src/Utils.zig diff --git a/src/view.zig b/src/View.zig similarity index 80% rename from src/view.zig rename to src/View.zig index 843af51..2afd78c 100644 --- a/src/view.zig +++ b/src/View.zig @@ -4,7 +4,7 @@ const std = @import("std"); const wl = @import("wayland").server.wl; const wlr = @import("wlroots"); -const Utils = @import("utils.zig"); +const Utils = @import("Utils.zig"); const gpa = std.heap.c_allocator; const server = &@import("main.zig").server; @@ -64,7 +64,15 @@ pub fn initFromTopLevel(xdg_toplevel: *wlr.XdgToplevel) *View { // Add new Toplevel to root of the tree // Later add to spesified output - self.scene_tree = try server.root.scene.tree.createSceneXdgSurface(xdg_toplevel.base); + if(server.seat.focused_output) |output| { + std.log.debug("adding new view to content layer", .{}); + self.scene_tree = try output.layers.content.createSceneXdgSurface(xdg_toplevel.base); + // _ = output; + // self.scene_tree = try server.root.scene.tree.createSceneXdgSurface(xdg_toplevel.base); + } else { + self.scene_tree = try server.root.waiting_room.createSceneXdgSurface(xdg_toplevel.base); + std.log.err("No output to attach new view to", .{}); + } self.scene_tree.node.data = self; self.xdg_toplevel.base.data = self.scene_tree; @@ -153,8 +161,6 @@ fn handleMap(listener: *wl.Listener(void)) void { _ = decoration.setMode(wlr.XdgToplevelDecorationV1.Mode.server_side); } - // Here is where we should tile and set size - view.mapped = true; server.events.exec("ViewMapPost", .{view.id}); @@ -216,40 +222,19 @@ fn handleNewPopup(listener: *wl.Listener(*wlr.XdgPopup), popup: *wlr.XdgPopup) v } fn handleRequestMove( - _: *wl.Listener(*wlr.XdgToplevel.event.Move), + listener: *wl.Listener(*wlr.XdgToplevel.event.Move), _: *wlr.XdgToplevel.event.Move ) void { - // const view: *View = @fieldParentPtr("request_move", listener); - - // server.cursor.moveView(view); - // server.cursor.grabbed_view = view; - // server.cursor.mode = .move; - // server.cursor.grab_x = server.cursor.wlr_cursor.x - @as(f64, @floatFromInt(view.geometry.x)); - // server.cursor.grab_y = server.cursor.wlr_cursor.y - @as(f64, @floatFromInt(view.geometry.y)); + const view: *View = @fieldParentPtr("request_move", listener); + server.events.exec("ViewRequestMove", .{view.id}); } fn handleRequestResize( - _: *wl.Listener(*wlr.XdgToplevel.event.Resize), + listener: *wl.Listener(*wlr.XdgToplevel.event.Resize), _: *wlr.XdgToplevel.event.Resize ) void { - // const view: *View = @fieldParentPtr("request_resize", listener); - - std.log.debug("The clients should not be request moves", .{}); - - // server.cursor.grabbed_view = view; - // server.cursor.mode = .resize; - // server.cursor.resize_edges = event.edges; - // - // const box = view.xdg_toplevel.base.geometry; - // - // const border_x = view.geometry.x + box.x + if (event.edges.right) box.width else 0; - // const border_y = view.geometry.y + box.y + if (event.edges.bottom) box.height else 0; - // server.cursor.grab_x = server.cursor.wlr_cursor.x - @as(f64, @floatFromInt(border_x)); - // server.cursor.grab_y = server.cursor.wlr_cursor.y - @as(f64, @floatFromInt(border_y)); - // - // server.cursor.grab_box = box; - // server.cursor.grab_box.x += view.geometry.x; - // server.cursor.grab_box.y += view.geometry.y; + const view: *View = @fieldParentPtr("request_resize", listener); + server.events.exec("ViewRequestResize", .{view.id}); } fn handleAckConfigure( @@ -265,30 +250,26 @@ fn handleRequestFullscreen( listener: *wl.Listener(void) ) void { const view: *View = @fieldParentPtr("request_fullscreen", listener); - _ = view; - std.log.err("Unimplemented request fullscreen", .{}); + server.events.exec("ViewRequestFullscreen", .{view.id}); } fn handleRequestMinimize( listener: *wl.Listener(void) ) void { - const view: *View = @fieldParentPtr("request_fullscreen", listener); - _ = view; - std.log.err("Unimplemented request minimize", .{}); + const view: *View = @fieldParentPtr("request_minimize", listener); + server.events.exec("ViewRequestFullscreen", .{view.id}); } fn handleSetAppId( listener: *wl.Listener(void) ) void { const view: *View = @fieldParentPtr("set_app_id", listener); - _ = view; - std.log.err("Unimplemented set appid", .{}); + server.events.exec("ViewAppIdUpdate", .{view.id}); } fn handleSetTitle( listener: *wl.Listener(void) ) void { const view: *View = @fieldParentPtr("set_title", listener); - _ = view; - std.log.err("Unimplemented set title", .{}); + server.events.exec("ViewTitleUpdate", .{view.id}); } diff --git a/src/lua/api.zig b/src/lua/Api.zig similarity index 100% rename from src/lua/api.zig rename to src/lua/Api.zig diff --git a/src/lua/bridge.zig b/src/lua/Bridge.zig similarity index 94% rename from src/lua/bridge.zig rename to src/lua/Bridge.zig index 37868d3..f8d4153 100644 --- a/src/lua/bridge.zig +++ b/src/lua/Bridge.zig @@ -1,7 +1,7 @@ const Bridge = @This(); const std = @import("std"); -const Lua = @import("lua.zig"); +const Lua = @import("Lua.zig"); const gpa = std.heap.c_allocator; diff --git a/src/lua/fs.zig b/src/lua/Fs.zig similarity index 96% rename from src/lua/fs.zig rename to src/lua/Fs.zig index 3e5ea2c..df9616f 100644 --- a/src/lua/fs.zig +++ b/src/lua/Fs.zig @@ -3,7 +3,7 @@ const Fs = @This(); const std = @import("std"); const zlua = @import("zlua"); -const Lua = @import("lua.zig"); +const Lua = @import("Lua.zig"); const gpa = std.heap.c_allocator; diff --git a/src/lua/hook.zig b/src/lua/Hook.zig similarity index 93% rename from src/lua/hook.zig rename to src/lua/Hook.zig index 8bd0f37..8111954 100644 --- a/src/lua/hook.zig +++ b/src/lua/Hook.zig @@ -3,8 +3,8 @@ const Hook = @This(); const std = @import("std"); const zlua = @import("zlua"); -const THook = @import("../types/hook.zig"); -const Utils = @import("../utils.zig"); +const THook = @import("../types/Hook.zig"); +const Utils = @import("../Utils.zig"); const gpa = std.heap.c_allocator; const server = &@import("../main.zig").server; diff --git a/src/lua/input.zig b/src/lua/Input.zig similarity index 95% rename from src/lua/input.zig rename to src/lua/Input.zig index c43acd2..b5b75cd 100644 --- a/src/lua/input.zig +++ b/src/lua/Input.zig @@ -5,8 +5,8 @@ const zlua = @import("zlua"); const xkb = @import("xkbcommon"); const wlr = @import("wlroots"); -const Keymap = @import("../types/keymap.zig"); -const Utils = @import("../utils.zig"); +const Keymap = @import("../types/Keymap.zig"); +const Utils = @import("../Utils.zig"); const server = &@import("../main.zig").server; diff --git a/src/lua/lua.zig b/src/lua/Lua.zig similarity index 90% rename from src/lua/lua.zig rename to src/lua/Lua.zig index e94388e..89510dc 100644 --- a/src/lua/lua.zig +++ b/src/lua/Lua.zig @@ -4,13 +4,13 @@ const std = @import("std"); const config = @import("config"); const zlua = @import("zlua"); -const Bridge = @import("bridge.zig"); -const Fs = @import("fs.zig"); -const Input = @import("input.zig"); -const Api = @import("api.zig"); -const Hook = @import("hook.zig"); -const View = @import("view.zig"); -const Output = @import("output.zig"); +const Bridge = @import("Bridge.zig"); +const Fs = @import("Fs.zig"); +const Input = @import("Input.zig"); +const Api = @import("Api.zig"); +const Hook = @import("Hook.zig"); +const View = @import("View.zig"); +const Output = @import("Output.zig"); const gpa = std.heap.c_allocator; diff --git a/src/lua/output.zig b/src/lua/Output.zig similarity index 99% rename from src/lua/output.zig rename to src/lua/Output.zig index 2f9d149..932e5de 100644 --- a/src/lua/output.zig +++ b/src/lua/Output.zig @@ -1,7 +1,7 @@ const std = @import("std"); const zlua = @import("zlua"); -const Output = @import("../output.zig"); +const Output = @import("../Output.zig"); const server = &@import("../main.zig").server; diff --git a/src/lua/view.zig b/src/lua/View.zig similarity index 95% rename from src/lua/view.zig rename to src/lua/View.zig index b0e0363..bc76197 100644 --- a/src/lua/view.zig +++ b/src/lua/View.zig @@ -1,7 +1,7 @@ const std = @import("std"); const zlua = @import("zlua"); -const View = @import("../view.zig"); +const View = @import("../View.zig"); const server = &@import("../main.zig").server; @@ -104,9 +104,11 @@ pub fn set_size(L: *zlua.Lua) i32 { pub fn set_focused(L: *zlua.Lua) i32 { const view_id: ?c_longlong = L.optInteger(1); - if(view_id == null and server.seat.focused_view != null) { - server.seat.focused_view.?.focused = false; - server.seat.focused_view = null; + if(view_id == null) { + if(server.seat.focused_view != null) { + server.seat.focused_view.?.focused = false; + server.seat.focused_view = null; + } L.pushNil(); return 1; } diff --git a/src/main.zig b/src/main.zig index d28f93b..35721da 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,8 +1,8 @@ const std = @import("std"); const wlr = @import("wlroots"); -const Server = @import("server.zig"); -const Lua = @import("lua/lua.zig"); +const Server = @import("Server.zig"); +const Lua = @import("lua/Lua.zig"); const gpa = std.heap.c_allocator; diff --git a/src/types/events.zig b/src/types/Events.zig similarity index 97% rename from src/types/events.zig rename to src/types/Events.zig index 59f37e4..e8d4605 100644 --- a/src/types/events.zig +++ b/src/types/Events.zig @@ -2,7 +2,7 @@ pub const Events = @This(); const std = @import("std"); -const Hook = @import("hook.zig"); +const Hook = @import("Hook.zig"); const Node = struct { hook: *const Hook, diff --git a/src/types/hook.zig b/src/types/Hook.zig similarity index 96% rename from src/types/hook.zig rename to src/types/Hook.zig index 511e84a..3b3d63f 100644 --- a/src/types/hook.zig +++ b/src/types/Hook.zig @@ -7,7 +7,7 @@ const xkb = @import("xkbcommon"); const wlr = @import("wlroots"); const zlua = @import("zlua"); -const Event = @import("events.zig"); +const Event = @import("Events.zig"); const Lua = &@import("../main.zig").lua; events: std.ArrayList([]const u8), // a list of events diff --git a/src/types/keymap.zig b/src/types/Keymap.zig similarity index 100% rename from src/types/keymap.zig rename to src/types/Keymap.zig