mirror of
https://codeberg.org/dwl/dwl.git
synced 2025-10-26 17:54:14 +00:00
Add option to use a xkb file
This commit is contained in:
parent
21205f2f40
commit
50a7359218
@ -57,6 +57,14 @@ static const struct xkb_rule_names xkb_rules = {
|
||||
.options = NULL,
|
||||
};
|
||||
|
||||
/* Wether to try to use an xkb file */
|
||||
static const int use_custom_xkb_file = 1;
|
||||
|
||||
/* Complete path to a xkb file */
|
||||
/* NOTE: if dwl fails to compile the file, the xkb_names will be used */
|
||||
/* instead */
|
||||
static const char* path_to_xkb_file = "/etc/xkb/custom-layout.xkb";
|
||||
|
||||
static const int repeat_rate = 25;
|
||||
static const int repeat_delay = 600;
|
||||
|
||||
|
||||
28
dwl.c
28
dwl.c
@ -814,17 +814,37 @@ KeyboardGroup *
|
||||
createkeyboardgroup(void)
|
||||
{
|
||||
KeyboardGroup *group = ecalloc(1, sizeof(*group));
|
||||
struct xkb_context *context;
|
||||
struct xkb_keymap *keymap;
|
||||
struct xkb_context *context = NULL;
|
||||
struct xkb_keymap *keymap = NULL;
|
||||
|
||||
group->wlr_group = wlr_keyboard_group_create();
|
||||
group->wlr_group->data = group;
|
||||
|
||||
/* Prepare an XKB keymap and assign it to the keyboard group. */
|
||||
context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
|
||||
if (!(keymap = xkb_keymap_new_from_names(context, &xkb_rules,
|
||||
XKB_KEYMAP_COMPILE_NO_FLAGS)))
|
||||
|
||||
FILE* xkb_file = NULL;
|
||||
|
||||
if (use_custom_xkb_file == 1) {
|
||||
xkb_file = fopen(path_to_xkb_file, "r");
|
||||
}
|
||||
|
||||
if (xkb_file != NULL) {
|
||||
keymap = xkb_keymap_new_from_file(context, xkb_file,
|
||||
XKB_KEYMAP_FORMAT_TEXT_V1,
|
||||
XKB_KEYMAP_COMPILE_NO_FLAGS);
|
||||
fclose(xkb_file);
|
||||
}
|
||||
|
||||
/* Compile keymap from names if it was not compiled from xkb_file */
|
||||
if (keymap == NULL) {
|
||||
keymap = xkb_keymap_new_from_names(context, &xkb_rules,
|
||||
XKB_KEYMAP_COMPILE_NO_FLAGS);
|
||||
}
|
||||
|
||||
if (keymap == NULL) {
|
||||
die("failed to compile keymap");
|
||||
}
|
||||
|
||||
wlr_keyboard_set_keymap(&group->wlr_group->keyboard, keymap);
|
||||
xkb_keymap_unref(keymap);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user