diff --git a/runtime/share/mezzaluna/master.lua b/runtime/share/mezzaluna/master.lua index 168d233..b3b6044 100644 --- a/runtime/share/mezzaluna/master.lua +++ b/runtime/share/mezzaluna/master.lua @@ -279,6 +279,7 @@ local master = function() mez.input.set_cursor_type("pointer") end, drag = function(pos, drag) + print("running this too!") if drag.view ~= nil then mez.view.set_position(drag.view.id, pos.x - drag.view.offset.x, pos.y - drag.view.offset.y) end @@ -288,6 +289,28 @@ local master = function() end, }, {}) + -- This is so impractical + -- I love it + mez.input.add_mousemap("alt|shift", "BTN_LEFT", { + press = function() + mez.input.set_cursor_type("cross") + move_all_drag = {} + for _, id in ipairs(mez.view.get_all_ids()) do + move_all_drag[id] = mez.view.get_position(id) + end + end, + drag = function(pos, drag) + print("Dragging") + for id, view_start in pairs(move_all_drag) do + mez.view.set_position(id, view_start.x + pos.x - drag.start.x, view_start.y + pos.y - drag.start.y) + end + end, + release = function() + move_all_drag = nil + mez.input.set_cursor_type("default") + end + }) + mez.input.add_mousemap("alt", "BTN_RIGHT", { press = function() mez.input.set_cursor_type("cross") @@ -306,6 +329,7 @@ local master = function() mez.input.set_cursor_type("default") end }) + end master() diff --git a/src/Cursor.zig b/src/Cursor.zig index ef5ba74..2285aa0 100644 --- a/src/Cursor.zig +++ b/src/Cursor.zig @@ -90,7 +90,6 @@ pub fn processCursorMotion(self: *Cursor, time_msec: u32) void { // Proceed if mousemap for current mouse and modifier state's exist if (server.mousemaps.get(Mousemap.hash(modifiers, @bitCast(self.drag.?.event_code)))) |map| { if(map.options.lua_drag_ref_idx > 0) { - std.debug.print("check\n", .{}); handled = map.callback(.drag, .{ .{ .x = @as(c_int, @intFromFloat(self.wlr_cursor.x)), diff --git a/src/LayerSurface.zig b/src/LayerSurface.zig index f31b6f5..258db07 100644 --- a/src/LayerSurface.zig +++ b/src/LayerSurface.zig @@ -28,24 +28,18 @@ pub fn init(wlr_layer_surface: *wlr.LayerSurfaceV1) *LayerSurface { const self = try gpa.create(LayerSurface); self.* = .{ - .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 - }; - }, + .output = undefined, .wlr_layer_surface = wlr_layer_surface, .scene_layer_surface = undefined, .scene_node_data = .{ .layer_surface = self } }; + if(wlr_layer_surface.output.?.data == null) { + std.log.err("Wlr_output arbitrary data not assigned", .{}); + unreachable; + } + self.output = @ptrCast(@alignCast(wlr_layer_surface.output.?.data)); + 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), diff --git a/src/Output.zig b/src/Output.zig index e032784..96bd5d2 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -54,11 +54,8 @@ destroy: wl.Listener(*wlr.Output) = .init(handleDestroy), pub fn init(wlr_output: *wlr.Output) ?*Output { errdefer Utils.oomPanic(); - server.events.exec("OutputInitPre", .{}); - const self = try gpa.create(Output); - self.* = .{ .focused = false, .id = @intFromPtr(wlr_output), @@ -108,11 +105,12 @@ pub fn init(wlr_output: *wlr.Output) ?*Output { return null; } + // TODO: Allow user to define output positions const layout_output = try server.root.output_layout.addAuto(self.wlr_output); server.root.scene_output_layout.addOutput(layout_output, self.scene_output); self.setFocused(); - self.wlr_output.data = &self.scene_node_data; + self.wlr_output.data = self; self.tree.node.data = &self.scene_node_data; self.layers.background.node.data = &self.layer_scene_node_data.background; diff --git a/src/Root.zig b/src/Root.zig index 6383a0e..65894cb 100644 --- a/src/Root.zig +++ b/src/Root.zig @@ -74,17 +74,12 @@ pub fn viewById(self: *Root, id: u64) ?*View { var output_it = self.output_layout.outputs.iterator(.forward); while(output_it.next()) |o| { - if(o.output.data == null) continue; - - 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", .{}); - unreachable; - } - }; + if(o.output.data == null) { + std.log.err("Wlr_output arbitrary data not assigned", .{}); + unreachable; + } + const output: *Output = @ptrCast(@alignCast(o.output.data.?)); var node_it = output.layers.content.children.iterator(.forward); while(node_it.next()) |node| { diff --git a/src/lua/View.zig b/src/lua/View.zig index 7ae7bc6..57303e5 100644 --- a/src/lua/View.zig +++ b/src/lua/View.zig @@ -20,18 +20,19 @@ fn view_id_err(L: *zlua.Lua) noreturn { // ---@return view_id[]? pub fn get_all_ids(L: *zlua.Lua) i32 { var output_it = server.root.output_layout.outputs.iterator(.forward); - var index: i32 = 1; + var index: i32 = 1; L.newTable(); while(output_it.next()) |o| { - if(o.output.data == null) continue; - const output: *Output = @ptrCast(@alignCast(o.output.data.?)); - if (!output.state.enabled) { - std.log.debug("ts not enabled", .{}); - continue; + if(o.output.data == null) { + std.log.err("Output arbitrary data not assigned", .{}); + unreachable; } + const output: *Output = @ptrCast(@alignCast(o.output.data.?)); + if (!output.state.enabled) continue; + const layers = [_]*wlr.SceneTree{ output.layers.content, output.layers.fullscreen, @@ -123,11 +124,11 @@ pub fn get_position(L: *zlua.Lua) i32 { L.newTable(); _ = L.pushString("x"); - L.pushInteger(@intCast(v.xdg_toplevel.base.geometry.x)); + L.pushInteger(@intCast(v.scene_tree.node.x)); L.setTable(-3); _ = L.pushString("y"); - L.pushInteger(@intCast(v.xdg_toplevel.base.geometry.y)); + L.pushInteger(@intCast(v.scene_tree.node.y)); L.setTable(-3); return 1; @@ -251,9 +252,9 @@ pub fn get_app_id(L: *zlua.Lua) i32 { return 1; } -// ---Get the app_id of the view +// ---Enable or disable a view // ---@param view_id view_id 0 maps to focused view -// ---@param enable boolean +// ---@param enabled boolean pub fn set_enabled(L: *zlua.Lua) i32 { const view_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch view_id_err(L); if (!L.isBoolean(2)) { @@ -270,7 +271,7 @@ pub fn set_enabled(L: *zlua.Lua) i32 { return 1; } -// ---Get the app_id of the view +// ---Check if a view is enabled // ---@param view_id view_id 0 maps to focused view // ---@return boolean? pub fn get_enabled(L: *zlua.Lua) i32 { @@ -285,6 +286,40 @@ pub fn get_enabled(L: *zlua.Lua) i32 { return 1; } +// ---Set a view you intend to resize +// ---@param view_id view_id 0 maps to focused view +// ---@param enable boolean +pub fn set_resizing(L: *zlua.Lua) i32 { + const view_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch view_id_err(L); + if (!L.isBoolean(2)) { + L.raiseErrorStr("argument 2 must be a boolean", .{}); + } + const resizing = L.toBoolean(2); + + if (LuaUtils.viewById(view_id)) |v| { + _ = v.xdg_toplevel.setResizing(resizing); + return 0; + } + + L.pushNil(); + return 1; +} + +// ---Check if a view is resizing +// ---@param view_id view_id 0 maps to focused view +// ---@return boolean? nil if view cannot be found +pub fn get_resizing(L: *zlua.Lua) i32 { + const view_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch view_id_err(L); + + if(LuaUtils.viewById(view_id)) |v| { + _ = L.pushBoolean(v.xdg_toplevel.current.resizing); + return 1; + } + + L.pushNil(); + return 1; +} + /// TODO: impl /// Setting the wm capabilities is for telling the client what they can request. /// This is important to letting the user define whatever type of layout they