From f636efdfe9a187b1a9f97edfbe6c3f61a1943220 Mon Sep 17 00:00:00 2001 From: Squibid Date: Fri, 24 Oct 2025 23:53:56 -0400 Subject: [PATCH] fix merge breaking stuff --- runtime/share/mezzaluna/init.lua | 28 +++++++++++++++++----------- src/lua/api.zig | 30 ++++++++++++++++++++++++++++++ src/lua/input.zig | 27 +-------------------------- src/lua/lua.zig | 6 ++++++ 4 files changed, 54 insertions(+), 37 deletions(-) create mode 100644 src/lua/api.zig diff --git a/runtime/share/mezzaluna/init.lua b/runtime/share/mezzaluna/init.lua index 9bfd52d..4c58888 100644 --- a/runtime/share/mezzaluna/init.lua +++ b/runtime/share/mezzaluna/init.lua @@ -11,19 +11,25 @@ mez.path.config = mez.fs.joinpath(env_conf, "mez", "init.lua") package.path = package.path..";"..mez.fs.joinpath(env_conf, "mez", "lua", "?.lua") -- this is an example -mez.api.add_keymap("alt", "a", function() - print("hello from my keymap") -end) +mez.input.add_keymap("alt", "a", { + press = function() + print("hello from my keymap") + end +}) -mez.api.add_keymap("alt", "t", function() - print("spawning foot") - mez.api.spawn("foot") -end) +mez.input.add_keymap("alt", "Return", { + press = function() + print("spawning foot") + mez.api.spawn("foot") + end +}) -mez.api.add_keymap("alt", "p", function() - print("spawning foot") - mez.api.spawn("wmenu-run") -end) +mez.api.add_keymap("alt", "p", { + press = function() + print("spawning foot") + mez.api.spawn("wmenu-run") + end +}) -- mez.input.add_keymap("alt", "a", { -- press = function() diff --git a/src/lua/api.zig b/src/lua/api.zig new file mode 100644 index 0000000..bf64d93 --- /dev/null +++ b/src/lua/api.zig @@ -0,0 +1,30 @@ +const std = @import("std"); +const zlua = @import("zlua"); + +const gpa = std.heap.c_allocator; + +const env_map = &@import("../main.zig").env_map; + +pub fn spawn(L: *zlua.Lua) i32 { + const nargs: i32 = L.getTop(); + + if (nargs < 1) { + L.raiseErrorStr("Expected at least one arguments", .{}); + return 0; + } + + L.checkType(1, .string); + + const cmd = L.toString(1) catch { + L.raiseErrorStr("Lua error check your config", .{}); + return 0; + }; + + var child = std.process.Child.init(&[_][]const u8{ "/bin/sh", "-c", cmd }, gpa); + child.env_map = env_map; + child.spawn() catch { + std.log.err("Unable to spawn process \"{s}\"", .{cmd}); + }; + + return 0; +} diff --git a/src/lua/input.zig b/src/lua/input.zig index 1282a21..9ecc72d 100644 --- a/src/lua/input.zig +++ b/src/lua/input.zig @@ -9,7 +9,6 @@ const wlr = @import("wlroots"); const gpa = std.heap.c_allocator; const server = &@import("../main.zig").server; -const env_map = &@import("../main.zig").env_map; pub fn add_keymap(L: *zlua.Lua) i32 { const nargs: i32 = L.getTop(); @@ -26,7 +25,7 @@ pub fn add_keymap(L: *zlua.Lua) i32 { var keymap: Keymap = undefined; keymap.options = .{ - .on_release = false, + .repeat = true, }; const mod = L.toString(1) catch { @@ -98,27 +97,3 @@ pub fn get_keybind(L: *zlua.Lua) i32 { _ = L; return 0; } - -pub fn spawn(L: *zlua.Lua) i32 { - const nargs: i32 = L.getTop(); - - if (nargs < 1) { - L.raiseErrorStr("Expected at least one arguments", .{}); - return 0; - } - - L.checkType(1, .string); - - const cmd = L.toString(1) catch { - L.raiseErrorStr("Lua error check your config", .{}); - return 0; - }; - - var child = std.process.Child.init(&[_][]const u8{ "/bin/sh", "-c", cmd }, gpa); - child.env_map = env_map; - child.spawn() catch { - std.log.err("Unable to spawn process \"{s}\"", .{cmd}); - }; - - return 0; -} diff --git a/src/lua/lua.zig b/src/lua/lua.zig index 5e2db41..43d2255 100644 --- a/src/lua/lua.zig +++ b/src/lua/lua.zig @@ -7,6 +7,7 @@ const zlua = @import("zlua"); const Bridge = @import("bridge.zig"); const Fs = @import("fs.zig"); const Input = @import("input.zig"); +const Api = @import("api.zig"); const gpa = std.heap.c_allocator; @@ -63,6 +64,11 @@ pub fn init(self: *Lua) !void { self.state.newLib(input_funcs); self.state.setField(-2, "input"); } + { + const api_funcs = zlua.fnRegsFromType(Api); + self.state.newLib(api_funcs); + self.state.setField(-2, "api"); + } } loadRuntimeDir(self) catch |err| {