it must be done
This commit is contained in:
Harrison DiAmbrosio 2025-10-26 21:17:32 -04:00
commit 13a91c15f0
3 changed files with 64 additions and 28 deletions

View file

@ -35,6 +35,12 @@ mez.input.add_keymap("alt", "q", {
end 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", { -- mez.input.add_keymap("alt", "a", {
-- press = function() -- press = function()
-- print("hello from my keymap") -- print("hello from my keymap")

View file

@ -1,5 +1,6 @@
const std = @import("std"); const std = @import("std");
const zlua = @import("zlua"); const zlua = @import("zlua");
const wlr = @import("wlroots");
const gpa = std.heap.c_allocator; const gpa = std.heap.c_allocator;
@ -53,7 +54,23 @@ pub fn exit(L: *zlua.Lua) i32 {
return 0; return 0;
} }
server.deinit(); server.wl_server.terminate();
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; return 0;
} }

View file

@ -10,32 +10,10 @@ const wlr = @import("wlroots");
const gpa = std.heap.c_allocator; const gpa = std.heap.c_allocator;
const server = &@import("../main.zig").server; const server = &@import("../main.zig").server;
pub fn add_keymap(L: *zlua.Lua) i32 { fn parse_modkeys(modStr: []const u8) wlr.Keyboard.ModifierMask {
const nargs: i32 = L.getTop(); var it = std.mem.splitScalar(u8, modStr, '|');
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, '|');
var modifiers = wlr.Keyboard.ModifierMask{}; var modifiers = wlr.Keyboard.ModifierMask{};
while (it.next()) |m| { while (it.next()) |m| {
// TODO: can we generate this at comptime?
if (std.mem.eql(u8, m, "shift")) { if (std.mem.eql(u8, m, "shift")) {
modifiers.shift = true; modifiers.shift = true;
} else if (std.mem.eql(u8, m, "caps")) { } else if (std.mem.eql(u8, m, "caps")) {
@ -54,7 +32,26 @@ pub fn add_keymap(L: *zlua.Lua) i32 {
modifiers.mod5 = true; 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 { const key = L.toString(2) catch {
L.raiseErrorStr("Lua error check your config", .{}); L.raiseErrorStr("Lua error check your config", .{});
@ -93,7 +90,23 @@ pub fn add_keymap(L: *zlua.Lua) i32 {
return 0; return 0;
} }
pub fn get_keybind(L: *zlua.Lua) i32 { pub fn del_keymap(L: *zlua.Lua) i32 {
_ = L; 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; return 0;
} }