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