From 591aa73bed1ce4f84659cdd4ef2b3d0ab1b2b295 Mon Sep 17 00:00:00 2001 From: Squibid Date: Sun, 26 Oct 2025 12:53:44 -0400 Subject: [PATCH 1/3] we can now switch vts --- runtime/share/mezzaluna/init.lua | 6 ++++++ src/lua/api.zig | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/runtime/share/mezzaluna/init.lua b/runtime/share/mezzaluna/init.lua index 069e955..1839c12 100644 --- a/runtime/share/mezzaluna/init.lua +++ b/runtime/share/mezzaluna/init.lua @@ -35,6 +35,12 @@ mez.input.add_keymap("alt", "q", { end }) +for i = 1, 12 do + mez.input.add_keymap("ctrl|alt", "XF86Switch_VT_"..i, { + press = function() mez.api.chvt(i) end + }) +end + -- mez.input.add_keymap("alt", "a", { -- press = function() -- print("hello from my keymap") diff --git a/src/lua/api.zig b/src/lua/api.zig index 9e0e3f7..325e0de 100644 --- a/src/lua/api.zig +++ b/src/lua/api.zig @@ -1,5 +1,6 @@ const std = @import("std"); const zlua = @import("zlua"); +const wlr = @import("wlroots"); const gpa = std.heap.c_allocator; @@ -57,3 +58,19 @@ pub fn exit(L: *zlua.Lua) i32 { return 0; } + +pub fn chvt(L: *zlua.Lua) i32 { + L.checkType(1, .number); + const f = L.toNumber(-1) catch unreachable; + const n: u32 = @intFromFloat(f); + + if (server.session) |session| { + wlr.Session.changeVt(session, n) catch { + L.raiseErrorStr("Failed to switch vt", .{}); + }; + } else { + L.raiseErrorStr("Mez has not been initialized yet", .{}); + } + + return 0; +} From f710bae5f5615050cf92e3032c80e71c76c77d0c Mon Sep 17 00:00:00 2001 From: Squibid Date: Sun, 26 Oct 2025 12:58:18 -0400 Subject: [PATCH 2/3] terminate properly instead of just deiniting everthing --- src/lua/api.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lua/api.zig b/src/lua/api.zig index 325e0de..e61eea0 100644 --- a/src/lua/api.zig +++ b/src/lua/api.zig @@ -54,7 +54,7 @@ pub fn exit(L: *zlua.Lua) i32 { return 0; } - server.deinit(); + server.wl_server.terminate(); return 0; } From de54d9867d3f6e6daf7cc73d334a84de0a7f3683 Mon Sep 17 00:00:00 2001 From: Squibid Date: Sun, 26 Oct 2025 19:07:39 -0400 Subject: [PATCH 3/3] you can now delete keymaps via the api --- src/lua/input.zig | 67 ++++++++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 27 deletions(-) diff --git a/src/lua/input.zig b/src/lua/input.zig index 9ecc72d..e1633e0 100644 --- a/src/lua/input.zig +++ b/src/lua/input.zig @@ -10,32 +10,10 @@ const wlr = @import("wlroots"); const gpa = std.heap.c_allocator; const server = &@import("../main.zig").server; -pub fn add_keymap(L: *zlua.Lua) i32 { - const nargs: i32 = L.getTop(); - - if (nargs < 3) { - L.raiseErrorStr("Expected at least three arguments", .{}); - return 0; - } - - // ensure the first three agrs of the correct types - L.checkType(1, .string); - L.checkType(2, .string); - L.checkType(3, .table); - - var keymap: Keymap = undefined; - keymap.options = .{ - .repeat = true, - }; - - const mod = L.toString(1) catch { - L.raiseErrorStr("Lua error check your config", .{}); - return 0; - }; - var it = std.mem.splitScalar(u8, mod, '|'); +fn parse_modkeys(modStr: []const u8) wlr.Keyboard.ModifierMask { + var it = std.mem.splitScalar(u8, modStr, '|'); var modifiers = wlr.Keyboard.ModifierMask{}; while (it.next()) |m| { - // TODO: can we generate this at comptime? if (std.mem.eql(u8, m, "shift")) { modifiers.shift = true; } else if (std.mem.eql(u8, m, "caps")) { @@ -54,7 +32,26 @@ pub fn add_keymap(L: *zlua.Lua) i32 { modifiers.mod5 = true; } } - keymap.modifier = modifiers; + + return modifiers; +} + +pub fn add_keymap(L: *zlua.Lua) i32 { + // ensure the first three agrs of the correct types + L.checkType(1, .string); + L.checkType(2, .string); + L.checkType(3, .table); + + var keymap: Keymap = undefined; + keymap.options = .{ + .repeat = true, + }; + + const mod = L.toString(1) catch { + L.raiseErrorStr("Lua error check your config", .{}); + return 0; + }; + keymap.modifier = parse_modkeys(mod); const key = L.toString(2) catch { L.raiseErrorStr("Lua error check your config", .{}); @@ -93,7 +90,23 @@ pub fn add_keymap(L: *zlua.Lua) i32 { return 0; } -pub fn get_keybind(L: *zlua.Lua) i32 { - _ = L; +pub fn del_keymap(L: *zlua.Lua) i32 { + L.checkType(1, .string); + L.checkType(2, .string); + + var keymap: Keymap = undefined; + const mod = L.toString(1) catch { + L.raiseErrorStr("Lua error check your config", .{}); + return 0; + }; + keymap.modifier = parse_modkeys(mod); + + const key = L.toString(2) catch { + L.raiseErrorStr("Lua error check your config", .{}); + return 0; + }; + keymap.keycode = xkb.Keysym.fromName(key, .no_flags); + _ = server.keymaps.remove(Keymap.hash(keymap.modifier, keymap.keycode)); + return 0; }