mirror of
https://github.com/MezzalunaWM/Mezzaluna.git
synced 2026-03-08 04:57:32 -04:00
lua position, size, focus and z-index (not really)
This commit is contained in:
parent
2c130539f6
commit
47bcce621d
14 changed files with 236 additions and 98 deletions
|
|
@ -59,7 +59,7 @@ pub fn exit(L: *zlua.Lua) i32 {
|
|||
return 0;
|
||||
}
|
||||
|
||||
pub fn chvt(L: *zlua.Lua) i32 {
|
||||
pub fn change_vt(L: *zlua.Lua) i32 {
|
||||
L.checkType(1, .number);
|
||||
const f = L.toNumber(-1) catch unreachable;
|
||||
const n: u32 = @intFromFloat(f);
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ 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 gpa = std.heap.c_allocator;
|
||||
|
||||
|
|
@ -75,6 +76,11 @@ pub fn init(self: *Lua) !void {
|
|||
self.state.newLib(api_funcs);
|
||||
self.state.setField(-2, "api");
|
||||
}
|
||||
{
|
||||
const view_funcs = zlua.fnRegsFromType(View);
|
||||
self.state.newLib(view_funcs);
|
||||
self.state.setField(-2, "view");
|
||||
}
|
||||
}
|
||||
|
||||
loadRuntimeDir(self) catch |err| {
|
||||
|
|
@ -82,6 +88,7 @@ pub fn init(self: *Lua) !void {
|
|||
std.log.warn("{s}", .{try self.state.toString(-1)});
|
||||
}
|
||||
};
|
||||
|
||||
loadConfigDir(self) catch |err| {
|
||||
if (err == error.LuaRuntime) {
|
||||
std.log.warn("{s}", .{try self.state.toString(-1)});
|
||||
|
|
|
|||
116
src/lua/view.zig
Normal file
116
src/lua/view.zig
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
const std = @import("std");
|
||||
const zlua = @import("zlua");
|
||||
const wlr = @import("wlroots");
|
||||
|
||||
const View = @import("../view.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.tree.children.iterator(.forward);
|
||||
var index: usize = 1;
|
||||
|
||||
L.newTable();
|
||||
|
||||
while(it.next()) |node| : (index += 1) {
|
||||
if(node.data == null) continue;
|
||||
|
||||
const view = @as(*View, @ptrCast(@alignCast(node.data.?)));
|
||||
|
||||
L.pushInteger(@intCast(index));
|
||||
L.pushInteger(@intCast(view.id));
|
||||
L.setTable(1);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
pub fn get_focused_id(L: *zlua.Lua) i32 {
|
||||
if(server.seat.focused_view) |view| {
|
||||
_ = L.pushNumber(@floatFromInt(view.id));
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
for (1..@intCast(nargs + 1)) |i| {
|
||||
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 = server.root.viewById(view_id);
|
||||
if(view == null) {
|
||||
L.raiseErrorStr("View with id {d} does not exist", .{view_id});
|
||||
return 0;
|
||||
}
|
||||
|
||||
view.?.setPosition(x, y);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
pub fn set_size(L: *zlua.Lua) i32 {
|
||||
const nargs: i32 = L.getTop();
|
||||
|
||||
if (nargs != 3) {
|
||||
L.raiseErrorStr("Expected 3 arguments, found {d}", .{nargs});
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (1..@intCast(nargs + 1)) |i| {
|
||||
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 = server.root.viewById(view_id);
|
||||
if(view == null) {
|
||||
L.raiseErrorStr("View with id {d} does not exist", .{view_id});
|
||||
return 0;
|
||||
}
|
||||
|
||||
view.?.setSize(width, height);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
pub fn raise_to_top(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 = @intCast(L.toInteger(1) catch unreachable);
|
||||
|
||||
const view = server.root.viewById(view_id);
|
||||
if(view == null) {
|
||||
L.raiseErrorStr("View with id {d} does not exist", .{view_id});
|
||||
return 0;
|
||||
}
|
||||
|
||||
view.?.raiseToTop();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue