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/keyboard.c | |
parent | Add missing description for focus_on_window_activation command in docs. (diff) | |
download | sway-eb770e88b7396e892898d6a71867d2a603e707ff.tar.gz sway-eb770e88b7396e892898d6a71867d2a603e707ff.tar.zst sway-eb770e88b7396e892898d6a71867d2a603e707ff.zip |
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/keyboard.c')
-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, | |||
534 | 534 | ||
535 | struct xkb_keymap *sway_keyboard_compile_keymap(struct input_config *ic, | 535 | struct xkb_keymap *sway_keyboard_compile_keymap(struct input_config *ic, |
536 | char **error) { | 536 | char **error) { |
537 | struct xkb_rule_names rules = {0}; | ||
538 | if (ic) { | ||
539 | input_config_fill_rule_names(ic, &rules); | ||
540 | } | ||
541 | |||
542 | struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); | 537 | struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); |
543 | if (!sway_assert(context, "cannot create XKB context")) { | 538 | if (!sway_assert(context, "cannot create XKB context")) { |
544 | return NULL; | 539 | return NULL; |
@@ -546,8 +541,46 @@ struct xkb_keymap *sway_keyboard_compile_keymap(struct input_config *ic, | |||
546 | xkb_context_set_user_data(context, error); | 541 | xkb_context_set_user_data(context, error); |
547 | xkb_context_set_log_fn(context, handle_xkb_context_log); | 542 | xkb_context_set_log_fn(context, handle_xkb_context_log); |
548 | 543 | ||
549 | struct xkb_keymap *keymap = | 544 | struct xkb_keymap *keymap = NULL; |
550 | xkb_keymap_new_from_names(context, &rules, XKB_KEYMAP_COMPILE_NO_FLAGS); | 545 | |
546 | if (ic && ic->xkb_file) { | ||
547 | FILE *keymap_file = fopen(ic->xkb_file, "r"); | ||
548 | if (!keymap_file) { | ||
549 | if (error) { | ||
550 | size_t len = snprintf(NULL, 0, "cannot read XKB file %s: %s", | ||
551 | ic->xkb_file, strerror(errno)) + 1; | ||
552 | *error = malloc(len); | ||
553 | if (*error) { | ||
554 | snprintf(*error, len, "cannot read XKB file %s: %s", | ||
555 | ic->xkb_file, strerror(errno)); | ||
556 | } else { | ||
557 | sway_log_errno(SWAY_ERROR, "cannot read XKB file %s: %s", | ||
558 | ic->xkb_file, strerror(errno)); | ||
559 | } | ||
560 | } else { | ||
561 | sway_log_errno(SWAY_ERROR, "cannot read XKB file %s: %s", | ||
562 | ic->xkb_file, strerror(errno)); | ||
563 | } | ||
564 | goto cleanup; | ||
565 | } | ||
566 | |||
567 | keymap = xkb_keymap_new_from_file(context, keymap_file, | ||
568 | XKB_KEYMAP_FORMAT_TEXT_V1, XKB_KEYMAP_COMPILE_NO_FLAGS); | ||
569 | |||
570 | if (!fclose(keymap_file)) { | ||
571 | sway_log_errno(SWAY_ERROR, "cannot close XKB file %s: %s", | ||
572 | ic->xkb_file, strerror(errno)); | ||
573 | } | ||
574 | } else { | ||
575 | struct xkb_rule_names rules = {0}; | ||
576 | if (ic) { | ||
577 | input_config_fill_rule_names(ic, &rules); | ||
578 | } | ||
579 | keymap = xkb_keymap_new_from_names(context, &rules, | ||
580 | XKB_KEYMAP_COMPILE_NO_FLAGS); | ||
581 | } | ||
582 | |||
583 | cleanup: | ||
551 | xkb_context_set_user_data(context, NULL); | 584 | xkb_context_set_user_data(context, NULL); |
552 | xkb_context_unref(context); | 585 | xkb_context_unref(context); |
553 | return keymap; | 586 | return keymap; |