Add option to use a xkb file

This commit is contained in:
mateus-cezario-barreto 2024-06-08 08:50:32 -03:00
parent 21205f2f40
commit 50a7359218
No known key found for this signature in database
2 changed files with 32 additions and 4 deletions

View File

@ -57,6 +57,14 @@ static const struct xkb_rule_names xkb_rules = {
.options = NULL, .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_rate = 25;
static const int repeat_delay = 600; static const int repeat_delay = 600;

28
dwl.c
View File

@ -814,17 +814,37 @@ KeyboardGroup *
createkeyboardgroup(void) createkeyboardgroup(void)
{ {
KeyboardGroup *group = ecalloc(1, sizeof(*group)); KeyboardGroup *group = ecalloc(1, sizeof(*group));
struct xkb_context *context; struct xkb_context *context = NULL;
struct xkb_keymap *keymap; struct xkb_keymap *keymap = NULL;
group->wlr_group = wlr_keyboard_group_create(); group->wlr_group = wlr_keyboard_group_create();
group->wlr_group->data = group; group->wlr_group->data = group;
/* Prepare an XKB keymap and assign it to the keyboard group. */ /* Prepare an XKB keymap and assign it to the keyboard group. */
context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); 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"); die("failed to compile keymap");
}
wlr_keyboard_set_keymap(&group->wlr_group->keyboard, keymap); wlr_keyboard_set_keymap(&group->wlr_group->keyboard, keymap);
xkb_keymap_unref(keymap); xkb_keymap_unref(keymap);