changed details to individual values

This commit is contained in:
Harrison DiAmbrosio 2025-11-26 18:08:23 -05:00
parent bc7a76cdd0
commit 9fe54377df
3 changed files with 126 additions and 51 deletions

View file

@ -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;
}

View file

@ -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;
}