cleanup the keymap stuff

This commit is contained in:
Squibid 2025-11-21 23:32:03 -05:00
parent b3322eeb90
commit 41cbe17262
Signed by: squibid
GPG key ID: BECE5684D3C4005D
4 changed files with 14 additions and 16 deletions

View file

@ -6,7 +6,7 @@ const Keyboard = @This();
const std = @import("std");
const gpa = std.heap.c_allocator;
const server = &@import("main.zig").server;
const Keymap = @import("keymap.zig");
const Keymap = @import("types/keymap.zig");
const Utils = @import("utils.zig");
const wl = @import("wayland").server.wl;
@ -80,10 +80,10 @@ fn handleKey(_: *wl.Listener(*wlr.Keyboard.event.Key), event: *wlr.Keyboard.even
if (server.seat.keyboard_group.keyboard.xkb_state) |xkb_state| {
for (xkb_state.keyGetSyms(keycode)) |sym| {
if (server.keymaps.get(Keymap.hash(modifiers, sym))) |map| {
if (event.state == .pressed and map.lua_press_ref_idx > 0) {
if (event.state == .pressed and map.options.lua_press_ref_idx > 0) {
map.callback(false);
handled = true;
} else if (event.state == .released and map.lua_release_ref_idx > 0) {
} else if (event.state == .released and map.options.lua_release_ref_idx > 0) {
map.callback(true);
handled = true;
}

View file

@ -1,7 +1,7 @@
const Api = @This();
const std = @import("std");
const Keymap = @import("../keymap.zig");
const Keymap = @import("../types/keymap.zig");
const zlua = @import("zlua");
const xkb = @import("xkbcommon");
@ -43,9 +43,7 @@ pub fn add_keymap(L: *zlua.Lua) i32 {
L.checkType(3, .table);
var keymap: Keymap = undefined;
keymap.options = .{
.repeat = true,
};
keymap.options.repeat = true;
const mod = L.toString(1) catch {
L.raiseErrorStr("Lua error check your config", .{});
@ -62,7 +60,7 @@ pub fn add_keymap(L: *zlua.Lua) i32 {
_ = L.pushString("press");
_ = L.getTable(3);
if (L.isFunction(-1)) {
keymap.lua_press_ref_idx = L.ref(zlua.registry_index) catch {
keymap.options.lua_press_ref_idx = L.ref(zlua.registry_index) catch {
L.raiseErrorStr("Lua error check your config", .{});
return 0;
};
@ -71,7 +69,7 @@ pub fn add_keymap(L: *zlua.Lua) i32 {
_ = L.pushString("release");
_ = L.getTable(3);
if (L.isFunction(-1)) {
keymap.lua_release_ref_idx = L.ref(zlua.registry_index) catch {
keymap.options.lua_release_ref_idx = L.ref(zlua.registry_index) catch {
L.raiseErrorStr("Lua error check your config", .{});
return 0;
};

View file

@ -11,7 +11,7 @@ const Keyboard = @import("keyboard.zig");
const Output = @import("output.zig");
const View = @import("view.zig");
const Utils = @import("utils.zig");
const Keymap = @import("keymap.zig");
const Keymap = @import("types/keymap.zig");
const Hook = @import("types/hook.zig");
const Events = @import("types/events.zig");

View file

@ -8,20 +8,20 @@ const xkb = @import("xkbcommon");
const wlr = @import("wlroots");
const zlua = @import("zlua");
const Lua = &@import("main.zig").lua;
const Lua = &@import("../main.zig").lua;
modifier: wlr.Keyboard.ModifierMask,
keycode: xkb.Keysym,
options: struct {
repeat: bool,
/// This is the location of the on press lua function in the lua registry
lua_press_ref_idx: i32,
/// This is the location of the on release lua function in the lua registry
lua_release_ref_idx: i32,
options: struct {
repeat: bool,
},
pub fn callback(self: *const Keymap, release: bool) void {
const lua_ref_idx = if(release) self.lua_release_ref_idx else self.lua_press_ref_idx;
const lua_ref_idx = if (release) self.options.lua_release_ref_idx else self.options.lua_press_ref_idx;
const t = Lua.state.rawGetIndex(zlua.registry_index, lua_ref_idx);
if (t != zlua.LuaType.function) {