basic data retrieval output api and some more view api

This commit is contained in:
Harrison DiAmbrosio 2025-11-25 23:31:23 -05:00
parent d4ab71fb35
commit d34db37589
11 changed files with 272 additions and 72 deletions

View file

@ -16,7 +16,6 @@ pub fn spawn(L: *zlua.Lua) i32 {
}
L.checkType(1, .string);
std.log.debug("GOT HERE", .{});
const cmd = L.toString(1) catch {
L.raiseErrorStr("Lua error check your config", .{});

View file

@ -10,6 +10,7 @@ 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;
@ -81,6 +82,11 @@ pub fn init(self: *Lua) !void {
self.state.newLib(view_funcs);
self.state.setField(-2, "view");
}
{
const output_funcs = zlua.fnRegsFromType(Output);
self.state.newLib(output_funcs);
self.state.setField(-2, "output");
}
}
loadRuntimeDir(self) catch |err| {

137
src/lua/output.zig Normal file
View file

@ -0,0 +1,137 @@
const std = @import("std");
const zlua = @import("zlua");
const wlr = @import("wlroots");
const Output = @import("../output.zig");
const gpa = std.heap.c_allocator;
const server = &@import("../main.zig").server;
pub fn get_all_ids(L: *zlua.Lua) i32 {
var it = server.root.scene.outputs.iterator(.forward);
var index: usize = 1;
L.newTable();
while(it.next()) |scene_output| : (index += 1) {
if(scene_output.output.data == null) continue;
const output = @as(*Output, @ptrCast(@alignCast(scene_output.output.data.?)));
L.pushInteger(@intCast(index));
L.pushInteger(@intCast(output.id));
L.setTable(-3);
}
return 1;
}
pub fn get_focused_id(L: *zlua.Lua) i32 {
if(server.seat.focused_output) |output| {
L.pushInteger(@intCast(output.id));
return 1;
}
return 0;
}
pub fn get_rate(L: *zlua.Lua) i32 {
const nargs: i32 = L.getTop();
if(nargs != 1) {
L.raiseErrorStr("Expected 1 argument, found", .{nargs});
}
L.checkType(1, .number);
const output_id: u64 = @as(u64, @intCast(L.toInteger(1) catch {
L.raiseErrorStr("Arg is not convertable to an int", .{});
}));
if(server.root.outputById(output_id)) |output| {
L.pushInteger(@intCast(output.wlr_output.refresh));
return 1;
}
return 0;
}
pub fn get_resolution(L: *zlua.Lua) i32 {
const nargs: i32 = L.getTop();
if(nargs != 1) {
L.raiseErrorStr("Expected 1 argument, found", .{nargs});
}
L.checkType(1, .number);
const output_id: u64 = @as(u64, @intCast(L.toInteger(1) catch {
L.raiseErrorStr("Arg is not convertable to an int", .{});
}));
if(server.root.outputById(output_id)) |output| {
L.newTable();
_ = L.pushString("width");
L.pushInteger(@intCast(output.wlr_output.width));
L.setTable(-3);
_ = L.pushString("height");
L.pushInteger(@intCast(output.wlr_output.height));
L.setTable(-3);
return 1;
}
return 0;
}
pub fn get_details(L: *zlua.Lua) i32 {
const nargs: i32 = L.getTop();
if(nargs != 1) {
L.raiseErrorStr("Expected 1 argument, found", .{nargs});
}
L.checkType(1, .number);
const output_id: u64 = @as(u64, @intCast(L.toInteger(1) catch {
L.raiseErrorStr("Arg is not convertable to an int", .{});
}));
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);
}
return 1;
}
return 0;
}

View file

@ -21,7 +21,7 @@ pub fn get_all_ids(L: *zlua.Lua) i32 {
L.pushInteger(@intCast(index));
L.pushInteger(@intCast(view.id));
L.setTable(1);
L.setTable(-3);
}
return 1;
@ -39,8 +39,6 @@ pub fn get_focused_id(L: *zlua.Lua) i32 {
pub fn set_position(L: *zlua.Lua) i32 {
const nargs: i32 = L.getTop();
std.log.debug("Starting view reposition", .{});
if (nargs != 3) {
L.raiseErrorStr("Expected 3 arguments, found {d}", .{nargs});
return 0;
@ -50,9 +48,9 @@ pub fn set_position(L: *zlua.Lua) i32 {
L.checkType(@intCast(i), .number);
}
const view_id: u64 = @as(u64, @intCast(L.toInteger(1) catch unreachable));
const x: i32 = @as(i32, @intCast(L.toInteger(2) catch unreachable));
const y: i32 = @as(i32, @intCast(L.toInteger(3) catch unreachable));
const view_id: u64 = @as(u64, @intCast(L.toInteger(1) catch { L.raiseErrorStr("Arg is not convertable to an int", .{}); }));
const x: i32 = @as(i32, @intFromFloat(L.toNumber(2) catch { L.raiseErrorStr("Arg is not convertable to an int", .{}); }));
const y: i32 = @as(i32, @intFromFloat(L.toNumber(3) catch { L.raiseErrorStr("Arg is not convertable to an int", .{}); }));
const view = server.root.viewById(view_id);
if(view == null) {
@ -77,9 +75,9 @@ pub fn set_size(L: *zlua.Lua) i32 {
L.checkType(@intCast(i), .number);
}
const view_id: u64 = @as(u64, @intCast(L.toInteger(1) catch unreachable));
const width: i32 = @as(i32, @intCast(L.toInteger(2) catch unreachable));
const height: i32 = @as(i32, @intCast(L.toInteger(3) catch unreachable));
const view_id: u64 = @as(u64, @intCast(L.toInteger(1) catch { L.raiseErrorStr("Arg is not convertable to an int", .{}); }));
const width: i32 = @as(i32, @intFromFloat(L.toNumber(2) catch { L.raiseErrorStr("Arg is not convertable to an int", .{}); }));
const height: i32 = @as(i32, @intFromFloat(L.toNumber(3) catch { L.raiseErrorStr("Arg is not convertable to an int", .{}); }));
const view = server.root.viewById(view_id);
if(view == null) {
@ -102,7 +100,7 @@ pub fn set_focused(L: *zlua.Lua) i32 {
L.checkType(1, .number);
const view_id: u64 = @intCast(L.toInteger(1) catch unreachable);
const view_id: u64 = @as(u64, @intCast(L.toInteger(1) catch { L.raiseErrorStr("Arg is not convertable to an int", .{}); }));
const view = server.root.viewById(view_id);
if(view == null) {
@ -114,3 +112,36 @@ pub fn set_focused(L: *zlua.Lua) i32 {
return 0;
}
pub fn get_details(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| {
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);
}
return 1;
}
return 0;
}