Add keyboard:configure

This enables the user to set the keyboard with libxkbcommon.
This commit is contained in:
Hardy 2020-02-27 21:05:33 +01:00
parent 5f632b1a81
commit 1a1163f2a9
3 changed files with 33 additions and 5 deletions

View file

@ -127,11 +127,6 @@ keyboard_create(struct kiwmi_server *server, struct wlr_input_device *device)
keyboard->server = server; keyboard->server = server;
keyboard->device = device; keyboard->device = device;
struct xkb_rule_names rules = {0};
struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
struct xkb_keymap *keymap =
xkb_map_new_from_names(context, &rules, XKB_KEYMAP_COMPILE_NO_FLAGS);
keyboard->modifiers.notify = keyboard_modifiers_notify; keyboard->modifiers.notify = keyboard_modifiers_notify;
wl_signal_add(&device->keyboard->events.modifiers, &keyboard->modifiers); wl_signal_add(&device->keyboard->events.modifiers, &keyboard->modifiers);
@ -141,6 +136,10 @@ keyboard_create(struct kiwmi_server *server, struct wlr_input_device *device)
keyboard->device_destroy.notify = keyboard_destroy_notify; keyboard->device_destroy.notify = keyboard_destroy_notify;
wl_signal_add(&device->events.destroy, &keyboard->device_destroy); wl_signal_add(&device->events.destroy, &keyboard->device_destroy);
struct xkb_rule_names rules = {0};
struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
struct xkb_keymap *keymap =
xkb_map_new_from_names(context, &rules, XKB_KEYMAP_COMPILE_NO_FLAGS);
wlr_keyboard_set_keymap(device->keyboard, keymap); wlr_keyboard_set_keymap(device->keyboard, keymap);
xkb_keymap_unref(keymap); xkb_keymap_unref(keymap);
xkb_context_unref(context); xkb_context_unref(context);

View file

@ -16,6 +16,29 @@
#include "input/keyboard.h" #include "input/keyboard.h"
#include "luak/kiwmi_lua_callback.h" #include "luak/kiwmi_lua_callback.h"
static int
l_kiwmi_keyboard_configure(lua_State *L)
{
struct kiwmi_keyboard *keyboard =
*(struct kiwmi_keyboard **)luaL_checkudata(L, 1, "kiwmi_keyboard");
struct xkb_rule_names rules = {
.rules = luaL_checkstring(L, 2),
.model = luaL_checkstring(L, 3),
.layout = luaL_checkstring(L, 4),
.variant = luaL_checkstring(L, 5),
.options = luaL_checkstring(L, 6),
};
wlr_log(WLR_INFO, " %s ", lua_tostring(L, 2));
struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
struct xkb_keymap *keymap =
xkb_map_new_from_names(context, &rules, XKB_KEYMAP_COMPILE_NO_FLAGS);
wlr_keyboard_set_keymap(keyboard->device->keyboard, keymap);
xkb_keymap_unref(keymap);
xkb_context_unref(context);
return 0;
}
static int static int
l_kiwmi_keyboard_modifiers(lua_State *L) l_kiwmi_keyboard_modifiers(lua_State *L)
{ {
@ -61,6 +84,7 @@ l_kiwmi_keyboard_modifiers(lua_State *L)
static const luaL_Reg kiwmi_keyboard_methods[] = { static const luaL_Reg kiwmi_keyboard_methods[] = {
{"modifiers", l_kiwmi_keyboard_modifiers}, {"modifiers", l_kiwmi_keyboard_modifiers},
{"configure", l_kiwmi_keyboard_configure},
{"on", luaK_callback_register_dispatch}, {"on", luaK_callback_register_dispatch},
{NULL, NULL}, {NULL, NULL},
}; };

View file

@ -121,6 +121,11 @@ These are: `shift`, `caps`, `ctrl`, `alt`, `mod2`, `mod3`, `super`, and `mod5`.
Used to register event listeners. Used to register event listeners.
#### keyboard:configure(rules, model, layout, variant, options)
The parameters are all strings for more information see xkbcommon library.
<https://xkbcommon.org/doc/current/index.html>
### Events ### Events
#### destroy #### destroy