From 9fe54377dfc819548bd7427be7a16e2173811198 Mon Sep 17 00:00:00 2001 From: Harrison DiAmbrosio Date: Wed, 26 Nov 2025 18:08:23 -0500 Subject: [PATCH] changed details to individual values --- runtime/share/mezzaluna/init.lua | 9 ++- src/lua/output.zig | 129 +++++++++++++++++++++++-------- src/lua/view.zig | 39 ++++++---- 3 files changed, 126 insertions(+), 51 deletions(-) diff --git a/runtime/share/mezzaluna/init.lua b/runtime/share/mezzaluna/init.lua index a414489..f515c95 100644 --- a/runtime/share/mezzaluna/init.lua +++ b/runtime/share/mezzaluna/init.lua @@ -32,11 +32,12 @@ mez.input.add_keymap("alt", "q", { mez.input.add_keymap("alt", "v", { press = function () - local id = mez.view.get_focused_id() + local id = mez.output.get_focused_id() - local details = mez.view.get_details(id); - print(details.title); - print(details.app_id); + print(mez.output.get_name(id)) + print(mez.output.get_serial(id)) + print(mez.output.get_model(id)) + print(mez.output.get_make(id)) end }) diff --git a/src/lua/output.zig b/src/lua/output.zig index b1b55ce..a041a67 100644 --- a/src/lua/output.zig +++ b/src/lua/output.zig @@ -86,7 +86,8 @@ pub fn get_resolution(L: *zlua.Lua) i32 { return 0; } -pub fn get_details(L: *zlua.Lua) i32 { +// Return the serial of the output +pub fn get_serial(L: *zlua.Lua) i32 { const nargs: i32 = L.getTop(); if(nargs != 1) { @@ -95,41 +96,103 @@ pub fn get_details(L: *zlua.Lua) i32 { L.checkType(1, .number); - const output_id: u64 = @as(u64, @intCast(L.toInteger(1) catch { - L.raiseErrorStr("Arg is not convertable to an int", .{}); - })); + errdefer L.raiseErrorStr("Arg is not convertable to an int", .{}); + const output_id: u64 = @intCast(try L.toInteger(1)); if(server.root.outputById(output_id)) |output| { - L.newTable(); - - if(output.wlr_output.description) |detail| { - _ = L.pushString("description"); - _ = L.pushString(std.mem.span(detail)); - L.setTable(-3); - } - - if(output.wlr_output.model) |detail| { - _ = L.pushString("model"); - _ = L.pushString(std.mem.span(detail)); - L.setTable(-3); - } - - if(output.wlr_output.make) |detail| { - _ = L.pushString("make"); - _ = L.pushString(std.mem.span(detail)); - L.setTable(-3); - } - - _ = L.pushString("name"); - _ = L.pushString(std.mem.span(output.wlr_output.name)); - L.setTable(-3); - - if(output.wlr_output.serial) |detail| { - _ = L.pushString("serial"); - _ = L.pushString(std.mem.span(detail)); - L.setTable(-3); - } + if(output.wlr_output.serial == null) return 0; + _ = L.pushString(std.mem.span(output.wlr_output.serial.?)); + return 1; + } + + return 0; +} + +// Return the make of the output +pub fn get_make(L: *zlua.Lua) i32 { + const nargs: i32 = L.getTop(); + + if(nargs != 1) { + L.raiseErrorStr("Expected 1 argument, found", .{nargs}); + } + + L.checkType(1, .number); + + errdefer L.raiseErrorStr("Arg is not convertable to an int", .{}); + const output_id: u64 = @intCast(try L.toInteger(1)); + + if(server.root.outputById(output_id)) |output| { + if(output.wlr_output.make == null) return 0; + + _ = L.pushString(std.mem.span(output.wlr_output.make.?)); + return 1; + } + + return 0; +} + +// Return the model of the output +pub fn get_model(L: *zlua.Lua) i32 { + const nargs: i32 = L.getTop(); + + if(nargs != 1) { + L.raiseErrorStr("Expected 1 argument, found", .{nargs}); + } + + L.checkType(1, .number); + + errdefer L.raiseErrorStr("Arg is not convertable to an int", .{}); + const output_id: u64 = @intCast(try L.toInteger(1)); + + if(server.root.outputById(output_id)) |output| { + if(output.wlr_output.model == null) return 0; + + _ = L.pushString(std.mem.span(output.wlr_output.model.?)); + return 1; + } + + return 0; +} + +// Return the description of the output +pub fn get_description(L: *zlua.Lua) i32 { + const nargs: i32 = L.getTop(); + + if(nargs != 1) { + L.raiseErrorStr("Expected 1 argument, found", .{nargs}); + } + + L.checkType(1, .number); + + errdefer L.raiseErrorStr("Arg is not convertable to an int", .{}); + const output_id: u64 = @intCast(try L.toInteger(1)); + + if(server.root.outputById(output_id)) |output| { + if(output.wlr_output.description == null) return 0; + + _ = L.pushString(std.mem.span(output.wlr_output.description.?)); + return 1; + } + + return 0; +} + +// Return the name of the output +pub fn get_name(L: *zlua.Lua) i32 { + const nargs: i32 = L.getTop(); + + if(nargs != 1) { + L.raiseErrorStr("Expected 1 argument, found", .{nargs}); + } + + L.checkType(1, .number); + + errdefer L.raiseErrorStr("Arg is not convertable to an int", .{}); + const output_id: u64 = @intCast(try L.toInteger(1)); + + if(server.root.outputById(output_id)) |output| { + _ = L.pushString(std.mem.span(output.wlr_output.name)); return 1; } diff --git a/src/lua/view.zig b/src/lua/view.zig index 9d63586..c597ac2 100644 --- a/src/lua/view.zig +++ b/src/lua/view.zig @@ -113,7 +113,7 @@ pub fn set_focused(L: *zlua.Lua) i32 { return 0; } -pub fn get_details(L: *zlua.Lua) i32 { +pub fn get_title(L: *zlua.Lua) i32 { const nargs: i32 = L.getTop(); if(nargs != 1) { @@ -126,20 +126,31 @@ pub fn get_details(L: *zlua.Lua) i32 { const view_id: u64 = @as(u64, @intCast(L.toInteger(1) catch { L.raiseErrorStr("Arg is not convertable to an int", .{}); })); if(server.root.viewById(view_id)) |view| { - L.newTable(); - - if(view.xdg_toplevel.title) |detail| { - _ = L.pushString("title"); - _ = L.pushString(std.mem.span(detail)); - L.setTable(-3); - } - - if(view.xdg_toplevel.app_id) |detail| { - _ = L.pushString("app_id"); - _ = L.pushString(std.mem.span(detail)); - L.setTable(-3); - } + if(view.xdg_toplevel.title == null) return 0; + _ = L.pushString(std.mem.span(view.xdg_toplevel.title.?)); + return 1; + } + + return 0; +} + +pub fn get_app_id(L: *zlua.Lua) i32 { + const nargs: i32 = L.getTop(); + + if(nargs != 1) { + L.raiseErrorStr("Expected 1 arguments, found {d}", .{nargs}); + return 0; + } + + L.checkType(1, .number); + + const view_id: u64 = @as(u64, @intCast(L.toInteger(1) catch { L.raiseErrorStr("Arg is not convertable to an int", .{}); })); + + if(server.root.viewById(view_id)) |view| { + if(view.xdg_toplevel.app_id == null) return 0; + + _ = L.pushString(std.mem.span(view.xdg_toplevel.app_id.?)); return 1; }