mirror of
https://github.com/MezzalunaWM/Mezzaluna.git
synced 2026-03-07 19:49:53 -05:00
cleanup the keymap stuff
This commit is contained in:
parent
b3322eeb90
commit
41cbe17262
4 changed files with 14 additions and 16 deletions
|
|
@ -6,7 +6,7 @@ const Keyboard = @This();
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const gpa = std.heap.c_allocator;
|
const gpa = std.heap.c_allocator;
|
||||||
const server = &@import("main.zig").server;
|
const server = &@import("main.zig").server;
|
||||||
const Keymap = @import("keymap.zig");
|
const Keymap = @import("types/keymap.zig");
|
||||||
const Utils = @import("utils.zig");
|
const Utils = @import("utils.zig");
|
||||||
|
|
||||||
const wl = @import("wayland").server.wl;
|
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| {
|
if (server.seat.keyboard_group.keyboard.xkb_state) |xkb_state| {
|
||||||
for (xkb_state.keyGetSyms(keycode)) |sym| {
|
for (xkb_state.keyGetSyms(keycode)) |sym| {
|
||||||
if (server.keymaps.get(Keymap.hash(modifiers, sym))) |map| {
|
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);
|
map.callback(false);
|
||||||
handled = true;
|
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);
|
map.callback(true);
|
||||||
handled = true;
|
handled = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
const Api = @This();
|
const Api = @This();
|
||||||
|
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const Keymap = @import("../keymap.zig");
|
const Keymap = @import("../types/keymap.zig");
|
||||||
|
|
||||||
const zlua = @import("zlua");
|
const zlua = @import("zlua");
|
||||||
const xkb = @import("xkbcommon");
|
const xkb = @import("xkbcommon");
|
||||||
|
|
@ -43,9 +43,7 @@ pub fn add_keymap(L: *zlua.Lua) i32 {
|
||||||
L.checkType(3, .table);
|
L.checkType(3, .table);
|
||||||
|
|
||||||
var keymap: Keymap = undefined;
|
var keymap: Keymap = undefined;
|
||||||
keymap.options = .{
|
keymap.options.repeat = true;
|
||||||
.repeat = true,
|
|
||||||
};
|
|
||||||
|
|
||||||
const mod = L.toString(1) catch {
|
const mod = L.toString(1) catch {
|
||||||
L.raiseErrorStr("Lua error check your config", .{});
|
L.raiseErrorStr("Lua error check your config", .{});
|
||||||
|
|
@ -62,7 +60,7 @@ pub fn add_keymap(L: *zlua.Lua) i32 {
|
||||||
_ = L.pushString("press");
|
_ = L.pushString("press");
|
||||||
_ = L.getTable(3);
|
_ = L.getTable(3);
|
||||||
if (L.isFunction(-1)) {
|
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", .{});
|
L.raiseErrorStr("Lua error check your config", .{});
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
@ -71,7 +69,7 @@ pub fn add_keymap(L: *zlua.Lua) i32 {
|
||||||
_ = L.pushString("release");
|
_ = L.pushString("release");
|
||||||
_ = L.getTable(3);
|
_ = L.getTable(3);
|
||||||
if (L.isFunction(-1)) {
|
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", .{});
|
L.raiseErrorStr("Lua error check your config", .{});
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ const Keyboard = @import("keyboard.zig");
|
||||||
const Output = @import("output.zig");
|
const Output = @import("output.zig");
|
||||||
const View = @import("view.zig");
|
const View = @import("view.zig");
|
||||||
const Utils = @import("utils.zig");
|
const Utils = @import("utils.zig");
|
||||||
const Keymap = @import("keymap.zig");
|
const Keymap = @import("types/keymap.zig");
|
||||||
const Hook = @import("types/hook.zig");
|
const Hook = @import("types/hook.zig");
|
||||||
const Events = @import("types/events.zig");
|
const Events = @import("types/events.zig");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,20 +8,20 @@ const xkb = @import("xkbcommon");
|
||||||
const wlr = @import("wlroots");
|
const wlr = @import("wlroots");
|
||||||
const zlua = @import("zlua");
|
const zlua = @import("zlua");
|
||||||
|
|
||||||
const Lua = &@import("main.zig").lua;
|
const Lua = &@import("../main.zig").lua;
|
||||||
|
|
||||||
modifier: wlr.Keyboard.ModifierMask,
|
modifier: wlr.Keyboard.ModifierMask,
|
||||||
keycode: xkb.Keysym,
|
keycode: xkb.Keysym,
|
||||||
|
options: struct {
|
||||||
|
repeat: bool,
|
||||||
/// This is the location of the on press lua function in the lua registry
|
/// This is the location of the on press lua function in the lua registry
|
||||||
lua_press_ref_idx: i32,
|
lua_press_ref_idx: i32,
|
||||||
/// This is the location of the on release lua function in the lua registry
|
/// This is the location of the on release lua function in the lua registry
|
||||||
lua_release_ref_idx: i32,
|
lua_release_ref_idx: i32,
|
||||||
options: struct {
|
|
||||||
repeat: bool,
|
|
||||||
},
|
},
|
||||||
|
|
||||||
pub fn callback(self: *const Keymap, release: bool) void {
|
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);
|
const t = Lua.state.rawGetIndex(zlua.registry_index, lua_ref_idx);
|
||||||
if (t != zlua.LuaType.function) {
|
if (t != zlua.LuaType.function) {
|
||||||
Loading…
Add table
Add a link
Reference in a new issue