Add keyboard:configure (#18)
* Add keyboard:configure This enables the user to set the keyboard with libxkbcommon. * changed keyboard:configure to keyboard:set_keymap this now take a table as parameter * Rename set_keymap to keymap, fix style issues Co-authored-by: buffet <dev@buffet.sh>
This commit is contained in:
parent
28490350d5
commit
9fe0f03a44
3 changed files with 65 additions and 5 deletions
|
@ -127,11 +127,6 @@ keyboard_create(struct kiwmi_server *server, struct wlr_input_device *device)
|
|||
keyboard->server = server;
|
||||
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;
|
||||
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;
|
||||
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);
|
||||
xkb_keymap_unref(keymap);
|
||||
xkb_context_unref(context);
|
||||
|
|
|
@ -12,11 +12,63 @@
|
|||
#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"
|
||||
#include "luak/lua_compat.h"
|
||||
|
||||
static int
|
||||
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};
|
||||
|
||||
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);
|
||||
|
||||
wlr_keyboard_set_keymap(keyboard->device->keyboard, keymap);
|
||||
|
||||
xkb_keymap_unref(keymap);
|
||||
xkb_context_unref(context);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
l_kiwmi_keyboard_modifiers(lua_State *L)
|
||||
{
|
||||
|
@ -61,6 +113,7 @@ 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},
|
||||
{NULL, NULL},
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue