Rename set_keymap to keymap, fix style issues
This commit is contained in:
parent
abc3783401
commit
d1c36f82e5
2 changed files with 24 additions and 17 deletions
|
@ -12,52 +12,59 @@
|
|||
#include <wlr/types/wlr_input_device.h>
|
||||
#include <wlr/types/wlr_keyboard.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include <xkbcommon/xkbcommon.h>
|
||||
|
||||
#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},
|
||||
};
|
||||
|
||||
|
|
16
lua_docs.md
16
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.
|
||||
<https://xkbcommon.org/doc/current/structxkb__rule__names.html>
|
||||
|
||||
#### 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.
|
||||
<https://xkbcommon.org/doc/current/structxkb__rule__names.html>
|
||||
|
||||
### Events
|
||||
|
||||
#### destroy
|
||||
|
|
Loading…
Add table
Reference in a new issue