From 41cbe1726217220ce28599e8bb81e46f7a305a8f Mon Sep 17 00:00:00 2001 From: Squibid Date: Fri, 21 Nov 2025 23:32:03 -0500 Subject: [PATCH] cleanup the keymap stuff --- src/keyboard.zig | 6 +++--- src/lua/input.zig | 10 ++++------ src/server.zig | 2 +- src/{ => types}/keymap.zig | 12 ++++++------ 4 files changed, 14 insertions(+), 16 deletions(-) rename src/{ => types}/keymap.zig (73%) diff --git a/src/keyboard.zig b/src/keyboard.zig index a360ce0..260ef75 100644 --- a/src/keyboard.zig +++ b/src/keyboard.zig @@ -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; } diff --git a/src/lua/input.zig b/src/lua/input.zig index e1633e0..5ecea31 100644 --- a/src/lua/input.zig +++ b/src/lua/input.zig @@ -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; }; diff --git a/src/server.zig b/src/server.zig index 12670eb..1aafa5a 100644 --- a/src/server.zig +++ b/src/server.zig @@ -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"); diff --git a/src/keymap.zig b/src/types/keymap.zig similarity index 73% rename from src/keymap.zig rename to src/types/keymap.zig index 93a74c8..1b43e27 100644 --- a/src/keymap.zig +++ b/src/types/keymap.zig @@ -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, -/// 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, + /// 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, }, 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) {