diff --git a/kiwmi/luak/kiwmi_keyboard.c b/kiwmi/luak/kiwmi_keyboard.c index dd8416c..e8621d6 100644 --- a/kiwmi/luak/kiwmi_keyboard.c +++ b/kiwmi/luak/kiwmi_keyboard.c @@ -12,52 +12,59 @@ #include #include #include +#include #include "input/keyboard.h" #include "luak/kiwmi_lua_callback.h" static int -l_kiwmi_keyboard_set_keymap(lua_State *L) +l_kiwmi_keyboard_keymap(lua_State *L) { struct kiwmi_object *obj = *(struct kiwmi_object **)luaL_checkudata(L, 1, "kiwmi_keyboard"); + luaL_checktype(L, 2, LUA_TTABLE); + if (!obj->valid) { return luaL_error(L, "kiwmi_keyboard no longer valid"); } + struct kiwmi_keyboard *keyboard = obj->object; + struct xkb_rule_names settings = {0}; - if (!lua_istable(L, 2)) { - return luaL_error(L, "You have to pass a table as parameter."); - } - - struct xkb_rule_names settings = {0}; lua_getfield(L, 2, "rules"); if (lua_isstring(L, -1)) { settings.rules = luaL_checkstring(L, -1); } + lua_getfield(L, 2, "model"); if (lua_isstring(L, -1)) { settings.model = luaL_checkstring(L, -1); } + lua_getfield(L, 2, "layout"); if (lua_isstring(L, -1)) { settings.layout = luaL_checkstring(L, -1); } + lua_getfield(L, 2, "variant"); if (lua_isstring(L, -1)) { settings.variant = luaL_checkstring(L, -1); } + lua_getfield(L, 2, "options"); if (lua_isstring(L, -1)) { settings.options = luaL_checkstring(L, -1); } struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); - struct xkb_keymap *keymap = - xkb_keymap_new_from_names(context, &settings, XKB_KEYMAP_COMPILE_NO_FLAGS); + struct xkb_keymap *keymap = xkb_keymap_new_from_names( + context, &settings, XKB_KEYMAP_COMPILE_NO_FLAGS); + wlr_keyboard_set_keymap(keyboard->device->keyboard, keymap); + xkb_keymap_unref(keymap); xkb_context_unref(context); + return 0; } @@ -105,9 +112,9 @@ l_kiwmi_keyboard_modifiers(lua_State *L) } static const luaL_Reg kiwmi_keyboard_methods[] = { + {"keymap", l_kiwmi_keyboard_keymap}, {"modifiers", l_kiwmi_keyboard_modifiers}, {"on", luaK_callback_register_dispatch}, - {"set_keymap", l_kiwmi_keyboard_set_keymap}, {NULL, NULL}, }; diff --git a/lua_docs.md b/lua_docs.md index 6fddf2f..264d1a8 100644 --- a/lua_docs.md +++ b/lua_docs.md @@ -112,6 +112,14 @@ A handle to a keyboard. ### Methods +#### keyboard:keymap(keymap) + +The funtcion takes a table as parameter. +The possible table indexes are "rules, model, layout, variant, options". +All the table parameters are optional and set to the system default if not set. +For the values to set have a look at the xkbcommon library. + + #### keyboard:modifiers() Returns a table with the state of all modifiers. @@ -121,14 +129,6 @@ These are: `shift`, `caps`, `ctrl`, `alt`, `mod2`, `mod3`, `super`, and `mod5`. Used to register event listeners. -#### keyboard:set_keymap({}) - -The funtcion takes a table as parameter. -The possible table indexes are "rules, model, layout, variant, options". -All the table parameters are optional and set to the system default if not set. -For the values to set have a look at the xkbcommon library. - - ### Events #### destroy