diff options
author | Ed Younis <edyounis123@gmail.com> | 2019-07-12 19:04:29 -0700 |
---|---|---|
committer | Brian Ashworth <bosrsf04@gmail.com> | 2019-07-17 19:26:58 -0400 |
commit | eb770e88b7396e892898d6a71867d2a603e707ff (patch) | |
tree | b4f04a7316b1c25286daabee57025fb1e7307919 /sway/input | |
parent | 3716c53d358fce7503ed0f59fcb5622c5e1a5a8f (diff) | |
download | sway-eb770e88b7396e892898d6a71867d2a603e707ff.tar.xz |
Implement input_cmd_xkb_file (#3999)
Adds a new commend "xkb_file", which constructs the internal
xkb_keymap from a xkb file rather than an RMLVO configuration.
This allows greater flexibility when specifying xkb configurations.
An xkb file can be dumped with the xkbcomp program.
Diffstat (limited to 'sway/input')
-rw-r--r-- | sway/input/keyboard.c | 47 |
1 files changed, 40 insertions, 7 deletions
diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c index ef20a3cf..1f7ed849 100644 --- a/sway/input/keyboard.c +++ b/sway/input/keyboard.c @@ -534,11 +534,6 @@ static void handle_xkb_context_log(struct xkb_context *context, struct xkb_keymap *sway_keyboard_compile_keymap(struct input_config *ic, char **error) { - struct xkb_rule_names rules = {0}; - if (ic) { - input_config_fill_rule_names(ic, &rules); - } - struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); if (!sway_assert(context, "cannot create XKB context")) { return NULL; @@ -546,8 +541,46 @@ struct xkb_keymap *sway_keyboard_compile_keymap(struct input_config *ic, xkb_context_set_user_data(context, error); xkb_context_set_log_fn(context, handle_xkb_context_log); - struct xkb_keymap *keymap = - xkb_keymap_new_from_names(context, &rules, XKB_KEYMAP_COMPILE_NO_FLAGS); + struct xkb_keymap *keymap = NULL; + + if (ic && ic->xkb_file) { + FILE *keymap_file = fopen(ic->xkb_file, "r"); + if (!keymap_file) { + if (error) { + size_t len = snprintf(NULL, 0, "cannot read XKB file %s: %s", + ic->xkb_file, strerror(errno)) + 1; + *error = malloc(len); + if (*error) { + snprintf(*error, len, "cannot read XKB file %s: %s", + ic->xkb_file, strerror(errno)); + } else { + sway_log_errno(SWAY_ERROR, "cannot read XKB file %s: %s", + ic->xkb_file, strerror(errno)); + } + } else { + sway_log_errno(SWAY_ERROR, "cannot read XKB file %s: %s", + ic->xkb_file, strerror(errno)); + } + goto cleanup; + } + + keymap = xkb_keymap_new_from_file(context, keymap_file, + XKB_KEYMAP_FORMAT_TEXT_V1, XKB_KEYMAP_COMPILE_NO_FLAGS); + + if (!fclose(keymap_file)) { + sway_log_errno(SWAY_ERROR, "cannot close XKB file %s: %s", + ic->xkb_file, strerror(errno)); + } + } else { + struct xkb_rule_names rules = {0}; + if (ic) { + input_config_fill_rule_names(ic, &rules); + } + keymap = xkb_keymap_new_from_names(context, &rules, + XKB_KEYMAP_COMPILE_NO_FLAGS); + } + +cleanup: xkb_context_set_user_data(context, NULL); xkb_context_unref(context); return keymap; |