diff options
author | Florian Pelz <pelzflorian@pelzflorian.de> | 2020-04-09 02:17:22 +0200 |
---|---|---|
committer | Florian Pelz <pelzflorian@pelzflorian.de> | 2020-04-09 02:42:54 +0000 |
commit | 91c231a2223440081426929828a23c7baa0214fd (patch) | |
tree | db6adbba3f79d4cdaa1db0ee33938ced07763a0f | |
parent | 543516ed0040df28eb15ea9b15ce905c038671c5 (diff) | |
download | guix-91c231a2223440081426929828a23c7baa0214fd.tar.gz |
installer: Allow Alt+Shift toggle from non-Latin keyboard layouts.
Fixes <https://bugs.gnu.org/40493>. * gnu/installer/newt/keymap.scm (%non-latin-layouts): New variable. (%non-latin-variants): New variable. (%latin-layout+variants): New variable. (toggleable-latin-layout): New procedure to compute combined layouts. (run-keymap-page): Use it. (keyboard-layout->configuration): Apply it in config.scm. (run-layout-page): Mention Alt+Shift. * gnu/installer/keymap.scm (kmscon-update-keymap): Pass on XKB options. * gnu/installer/record.scm (<installer>): Adjust code comments. * gnu/installer.scm (apply-keymap): Pass on XKB options. (installer-steps): Adjust code comments. * gnu/packages/patches/kmscon-runtime-keymap-switch.patch: Apply XKB options.
-rw-r--r-- | gnu/installer.scm | 14 | ||||
-rw-r--r-- | gnu/installer/keymap.scm | 10 | ||||
-rw-r--r-- | gnu/installer/newt/keymap.scm | 61 | ||||
-rw-r--r-- | gnu/installer/record.scm | 3 | ||||
-rw-r--r-- | gnu/packages/patches/kmscon-runtime-keymap-switch.patch | 27 |
5 files changed, 79 insertions, 36 deletions
diff --git a/gnu/installer.scm b/gnu/installer.scm index 6cd3995e51..d2b7fc327d 100644 --- a/gnu/installer.scm +++ b/gnu/installer.scm @@ -2,6 +2,7 @@ ;;; Copyright © 2018, 2020 Mathieu Othacehe <m.othacehe@gmail.com> ;;; Copyright © 2019, 2020 Ludovic Courtès <ludo@gnu.org> ;;; Copyright © 2019, 2020 Tobias Geerinckx-Rice <me@tobias.gr> +;;; Copyright © 2020 Florian Pelz <pelzflorian@pelzflorian.de> ;;; ;;; This file is part of GNU Guix. ;;; @@ -170,9 +171,9 @@ been performed at build time." (define apply-keymap ;; Apply the specified keymap. Use the default keyboard model. #~(match-lambda - ((layout variant) + ((layout variant options) (kmscon-update-keymap (default-keyboard-model) - layout variant)))) + layout variant options)))) (define* (compute-keymap-step context) "Return a gexp that runs the keymap-page of INSTALLER and install the @@ -235,12 +236,13 @@ selected keymap." ;; The installer runs in a kmscon virtual terminal where loadkeys ;; won't work. kmscon uses libxkbcommon as a backend for keyboard - ;; input. It is possible to update kmscon current keymap by sending it - ;; a keyboard model, layout and variant, in a somehow similar way as - ;; what is done with setxkbmap utility. + ;; input. It is possible to update kmscon current keymap by sending + ;; it a keyboard model, layout, variant and options, in a somehow + ;; similar way as what is done with setxkbmap utility. ;; ;; So ask for a keyboard model, layout and variant to update the - ;; current kmscon keymap. + ;; current kmscon keymap. For non-Latin layouts, we add an + ;; appropriate second layout and toggle via Alt+Shift. (installer-step (id 'keymap) (description (G_ "Keyboard mapping selection")) diff --git a/gnu/installer/keymap.scm b/gnu/installer/keymap.scm index df9fc5e441..c42b308009 100644 --- a/gnu/installer/keymap.scm +++ b/gnu/installer/keymap.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2018 Mathieu Othacehe <m.othacehe@gmail.com> +;;; Copyright © 2020 Florian Pelz <pelzflorian@pelzflorian.de> ;;; ;;; This file is part of GNU Guix. ;;; @@ -154,8 +155,8 @@ Configuration Database, describing possible XKB configurations." ((models layouts) (values models layouts))))) -(define (kmscon-update-keymap model layout variant) - "Update kmscon keymap with the provided MODEL, LAYOUT and VARIANT." +(define (kmscon-update-keymap model layout variant options) + "Update kmscon keymap with the provided MODEL, LAYOUT, VARIANT and OPTIONS." (and=> (getenv "KEYMAP_UPDATE") (lambda (keymap-file) @@ -174,5 +175,8 @@ Configuration Database, describing possible XKB configurations." (format port layout) (put-u8 port 0) - (format port variant) + (format port (or variant "")) + (put-u8 port 0) + + (format port (or options "")) (put-u8 port 0)))))) diff --git a/gnu/installer/newt/keymap.scm b/gnu/installer/newt/keymap.scm index 8625afaa03..a555a1ecc1 100644 --- a/gnu/installer/newt/keymap.scm +++ b/gnu/installer/newt/keymap.scm @@ -1,6 +1,7 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2018, 2020 Mathieu Othacehe <m.othacehe@gmail.com> ;;; Copyright © 2019 Ludovic Courtès <ludo@gnu.org> +;;; Copyright © 2020 Florian Pelz <pelzflorian@pelzflorian.de> ;;; ;;; This file is part of GNU Guix. ;;; @@ -40,10 +41,12 @@ #:info-text (case context ((param) (G_ "Please choose your keyboard layout. \ -It will only be used during the installation process.")) +It will only be used during the installation process. \ +Non-Latin layouts can be toggled with Alt+Shift.")) (else (G_ "Please choose your keyboard layout. \ It will be used during the install process, and for the installed system. \ -You can switch to different layout at any time from the parameters menu."))) +Non-Latin layouts can be toggled with Alt+Shift. You can switch to a \ +different layout at any time from the parameters menu."))) #:listbox-items layouts #:listbox-item->text layout->text #:sort-listbox-items? #f @@ -112,10 +115,48 @@ You can switch to different layout at any time from the parameters menu."))) variants)) (cut append <> <>))) +(define %non-latin-layouts + ;; List of keyboard layouts marked as $nonlatin in xkeyboard-config. + ;; See comments in xkeyboard-config file /share/X11/xkb/rules/base. + ;; We ignore layouts that support Latin input: "kr" + '("am" "ara" "ben" "bd" "bg" "bt" "by" "cs" "deva" "ge" "gh" + "gr" "guj" "guru" "il" "in" "ir" "iku" "jp" "kan" "kh" + "la" "lao" "lk" "mk" "mm" "mn" "mv" "mal" "olck" "ori" "pk" + "ru" "scc" "sy" "syr" "tel" "th" "tj" "tam" "ua" "uz" + ;; The list from xkeyboard-config is incomplete. Add more layouts when + ;; noticed: + "et" "kz")) + +(define %non-latin-variants + '("cyrillic")) + +(define %latin-layout+variants + ;; These layout+variant combinations are Latin after all. + '(("ir" "ku"))) + +(define (toggleable-latin-layout layout variant) + "If LAYOUT is a non-Latin layout, return a new combined layout, +a variant, and options that allow the user to switch between the +non-Latin and the Latin layout. Otherwise, return LAYOUT, VARIANT, +and #f." + (if (and (not (equal? variant "latin")) + (not (member (list layout variant) %latin-layout+variants)) + (or (member layout %non-latin-layouts) + (member variant %non-latin-variants))) + (let ((latin-layout (if (equal? variant "azerty") "fr" "us"))) + (list + (string-append layout "," latin-layout) + ;; Comma to use variant only for non-Latin: + (and variant (string-append variant ",")) + "grp:alt_shift_toggle")) + (list layout variant #f))) + (define* (run-keymap-page layouts #:key (context #f)) "Run a page asking the user to select a keyboard layout and variant. LAYOUTS -is a list of supported X11-KEYMAP-LAYOUT. Return a list of two elements, the -names of the selected keyboard layout and variant." +is a list of supported X11-KEYMAP-LAYOUT. For non-Latin keyboard layouts, a +second layout and toggle options will be added automatically. Return a list +of three elements, the names of the selected keyboard layout, variant and +options." (define keymap-steps (list (installer-step @@ -151,14 +192,20 @@ names of the selected keyboard layout and variant." (lambda (variant) (gettext (x11-keymap-variant-name variant) "xkeyboard-config"))))) - (list layout (or variant "")))) + (toggleable-latin-layout layout variant))) (format-result (run-installer-steps #:steps keymap-steps))) (define (keyboard-layout->configuration keymap) "Return the operating system configuration snippet to install KEYMAP." (match keymap - ((name "") + ((name #f "grp:alt_shift_toggle") + `((keyboard-layout (keyboard-layout ,name + #:options '("grp:alt_shift_toggle"))))) + ((name #f _) `((keyboard-layout (keyboard-layout ,name)))) - ((name variant) + ((name variant "grp:alt_shift_toggle") + `((keyboard-layout (keyboard-layout ,name ,variant + #:options '("grp:alt_shift_toggle"))))) + ((name variant _) `((keyboard-layout (keyboard-layout ,name ,variant)))))) diff --git a/gnu/installer/record.scm b/gnu/installer/record.scm index 7bc22e90e0..6ebd87f6a6 100644 --- a/gnu/installer/record.scm +++ b/gnu/installer/record.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2018, 2020 Mathieu Othacehe <m.othacehe@gmail.com> +;;; Copyright © 2020 Florian Pelz <pelzflorian@pelzflorian.de> ;;; ;;; This file is part of GNU Guix. ;;; @@ -63,7 +64,7 @@ (exit-error installer-exit-error) ;; procedure void -> void (final-page installer-final-page) - ;; procedure (layouts context) -> (list layout variant) + ;; procedure (layouts context) -> (list layout variant options) (keymap-page installer-keymap-page) ;; procedure: (#:key supported-locales iso639-languages iso3166-territories) ;; -> glibc-locale diff --git a/gnu/packages/patches/kmscon-runtime-keymap-switch.patch b/gnu/packages/patches/kmscon-runtime-keymap-switch.patch index 656c76fa40..deb5688daf 100644 --- a/gnu/packages/patches/kmscon-runtime-keymap-switch.patch +++ b/gnu/packages/patches/kmscon-runtime-keymap-switch.patch @@ -1,14 +1,5 @@ -From 360d44d67e7be46108bec982ff2e79b89f04a9a3 Mon Sep 17 00:00:00 2001 -From: Mathieu Othacehe <m.othacehe@gmail.com> -Date: Thu, 15 Nov 2018 14:34:40 +0900 -Subject: [PATCH] add runtime keymap switch support. - ---- - src/pty.c | 23 ++++++++++- - src/uterm_input.c | 2 + - src/uterm_input_internal.h | 5 +++ - src/uterm_input_uxkb.c | 83 ++++++++++++++++++++++++++++++++++++++ - 4 files changed, 111 insertions(+), 2 deletions(-) +By Mathieu Othacehe <m.othacehe@gmail.com>. +Modified by Florian Pelz <pelzflorian@pelzflorian.de>. diff --git a/src/pty.c b/src/pty.c index 1443f4a..f64cb5b 100644 @@ -124,7 +115,7 @@ index 04e6cc9..ec44459 100644 uint16_t key_state, uint16_t code); diff --git a/src/uterm_input_uxkb.c b/src/uterm_input_uxkb.c -index 925c755..4760972 100644 +index 925c755..5d5c22e 100644 --- a/src/uterm_input_uxkb.c +++ b/src/uterm_input_uxkb.c @@ -31,6 +31,9 @@ @@ -137,7 +128,7 @@ index 925c755..4760972 100644 #include <xkbcommon/xkbcommon.h> #include "shl_hook.h" #include "shl_llog.h" -@@ -178,6 +181,86 @@ static void timer_event(struct ev_timer *timer, uint64_t num, void *data) +@@ -178,6 +181,87 @@ static void timer_event(struct ev_timer *timer, uint64_t num, void *data) shl_hook_call(dev->input->hook, dev->input, &dev->repeat_event); } @@ -145,11 +136,11 @@ index 925c755..4760972 100644 +{ + struct uterm_input_dev *dev = data; + char in; -+ char keymap[3][255]; ++ char keymap[4][255]; + int pos = 0; + int curr_keymap = 0; + int ret; -+ char *model, *layout, *variant; ++ char *model, *layout, *variant, *options; + + if (!(mask & EV_READABLE)) + return; @@ -159,6 +150,7 @@ index 925c755..4760972 100644 + model = keymap[0]; + layout = keymap[1]; + variant = keymap[2]; ++ options = keymap[3]; + + do { + ret = read(dev->rupdate_fd, &in, sizeof(in)); @@ -175,7 +167,7 @@ index 925c755..4760972 100644 + + llog_info(dev->input, "HANDLER CALLED %s|%s|%s\n", + model, layout, variant); -+ uxkb_desc_init(dev->input, model, layout, variant, NULL, NULL); ++ uxkb_desc_init(dev->input, model, layout, variant, options, NULL); + + dev->state = xkb_state_new(dev->input->keymap); + if (!dev->state) { @@ -224,6 +216,3 @@ index 925c755..4760972 100644 int uxkb_dev_init(struct uterm_input_dev *dev) { int ret; --- -2.17.1 - |