all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#40493: installer: Provide a way to select multiple keyboard layouts
@ 2020-04-07 17:12 Mathieu Othacehe
  2020-04-07 17:50 ` pelzflorian (Florian Pelz)
  0 siblings, 1 reply; 12+ messages in thread
From: Mathieu Othacehe @ 2020-04-07 17:12 UTC (permalink / raw)
  To: 40493


Hello,

The installer gained support for keyboard layout switching from every
step recently[1].

It is also possible with commit 2729cb406d9f3e9eb22cc660f887138134edb3a8
to specify comma-separated keyboard layouts, this way:

--8<---------------cut here---------------start------------->8---
(keyboard-layout "ar,us" #:options '("grp:alt_shift_toggle"))
--8<---------------cut here---------------end--------------->8---

Now it would be nice to support multiple keyboard layout selection from
the installer, so that a configuration like to one above is generated.

Thanks,

Mathieu

[1]: https://lists.gnu.org/archive/html/bug-guix/2020-03/msg00381.html 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#40493: installer: Provide a way to select multiple keyboard layouts
  2020-04-07 17:12 bug#40493: installer: Provide a way to select multiple keyboard layouts Mathieu Othacehe
@ 2020-04-07 17:50 ` pelzflorian (Florian Pelz)
  2020-04-07 20:38   ` Ludovic Courtès
  0 siblings, 1 reply; 12+ messages in thread
From: pelzflorian (Florian Pelz) @ 2020-04-07 17:50 UTC (permalink / raw)
  To: Mathieu Othacehe; +Cc: 40493

[-- Attachment #1: Type: text/plain, Size: 1938 bytes --]

On Tue, Apr 07, 2020 at 07:12:34PM +0200, Mathieu Othacehe wrote:
> Now it would be nice to support multiple keyboard layout selection from
> the installer, so that a configuration like to one above is generated.
> 
> Thanks,
> 
> Mathieu

Ludo responded to the other bug:

On Tue, Apr 07, 2020 at 11:49:09AM +0200, Ludovic Courtès wrote:
> Ideally we’d also offer a way to choose multiple layouts in the
> installer, so that one can end up with:
>
>   (keyboard-layout "ar,us" #:options '("grp:alt_shift_toggle"))
>

I believe the user should not have to manually select the other layout
(if the user wants they can select via F1 key).  Instead there should
be a sane default (typically U.S. layout).  But since I am used to
Latin script, I may not have good judgment.

IMHO two things should be done:

* Within the installer, a toggleable second keyboard layout should be
  available by default.

  Mathieu enabled changing the layout via the F1 help menu.  This is
  good and more flexible and discoverable, but a key combination is
  more convenient and people appear to be used to Alt+Shift toggling.

* In the config.scm created by the installer, the default
  keyboard-layout should include the second layout.

Both the config.scm default and the installer layout should be the
same, I think.

I attach a proposed solution for the first thing, though it does not
  yet update the toggle option correctly.  If you think the
approach is OK, then I will add more default alternative layouts to
the maybe-add-second-layout procedure.

> Although that’s mostly useful for the console as GDM and GNOME should be
> able to do the right thing.
> 
> Anyway, we can discuss it in a separate issue.
> 
> Ludo’.

The GNOME session after login will ask the user what keyboard layout
they want, but the (I believe changeable) default for GDM comes
from config.scm.

Regards,
Florian

[-- Attachment #2: 0001-installer-Allow-Alt-Shift-toggle-from-non-Latin-keyb.patch --]
[-- Type: text/plain, Size: 10221 bytes --]

From 0d3a1ecc214fe55d77f45f4b2e690a93978da9ec Mon Sep 17 00:00:00 2001
From: Florian Pelz <pelzflorian@pelzflorian.de>
Date: Tue, 7 Apr 2020 19:06:31 +0200
Subject: [PATCH] installer: Allow Alt+Shift toggle from non-Latin keyboard
 layouts.

See <https://bugs.gnu.org/40273>.

* gnu/installer/newt/keymap.scm (run-keymap-page): Maybe add second layout.
* gnu/installer/keymap.scm (kmscon-update-keymap): Pass on XKB options.
* gnu/installer/records.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.
---
 gnu/installer.scm                             | 14 +++++-----
 gnu/installer/keymap.scm                      |  8 ++++--
 gnu/installer/newt/keymap.scm                 | 19 ++++++++++---
 gnu/installer/record.scm                      |  3 ++-
 .../kmscon-runtime-keymap-switch.patch        | 27 ++++++-------------
 5 files changed, 40 insertions(+), 31 deletions(-)

diff --git a/gnu/installer.scm b/gnu/installer.scm
index 75c5a01570..72b7d195fd 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..d520b782fd 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)
@@ -175,4 +176,7 @@ Configuration Database, describing possible XKB configurations."
          (put-u8 port 0)
 
          (format port variant)
+         (put-u8 port 0)
+
+         (format port options)
          (put-u8 port 0))))))
diff --git a/gnu/installer/newt/keymap.scm b/gnu/installer/newt/keymap.scm
index 0147a0b9d5..ba02085a44 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.
 ;;;
@@ -114,8 +115,10 @@ You can switch to different layout at any time from the help menu.")))
 
 (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
+optionsxs."
   (define keymap-steps
     (list
      (installer-step
@@ -144,6 +147,15 @@ names of the selected keyboard layout and variant."
                    (gettext (x11-keymap-variant-description variant)
                             "xkeyboard-config"))))))))))
 
+  (define (maybe-add-second-layout first-layout)
+    "Return for a chosen keyboard layout either the same layout or possibly
+the layout plus a suitable second layout, and also variant and options."
+    (match first-layout
+      (("ar" "azerty") (list "ar,fr" "azerty," "grp:alt_shift_toggle"))
+      (("ar" variant) (list "ar,us" variant "grp:alt_shift_toggle"))
+      (("ja" variant) (list "ja,us" variant "grp:alt_shift_toggle"))
+      ((layout variant) (list layout variant ""))))
+
   (define (format-result result)
     (let ((layout (x11-keymap-layout-name
                    (result-step result 'layout)))
@@ -151,7 +163,8 @@ names of the selected keyboard layout and variant."
                           (lambda (variant)
                             (gettext (x11-keymap-variant-name variant)
                                      "xkeyboard-config")))))
-      (list layout (or variant ""))))
+      (maybe-add-second-layout
+       (list layout (or variant "")))))
   (format-result
    (run-installer-steps #:steps keymap-steps)))
 
diff --git a/gnu/installer/record.scm b/gnu/installer/record.scm
index 78acf50c63..13acd33fc6 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
-
-- 
2.26.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* bug#40493: installer: Provide a way to select multiple keyboard layouts
  2020-04-07 17:50 ` pelzflorian (Florian Pelz)
@ 2020-04-07 20:38   ` Ludovic Courtès
  2020-04-07 21:56     ` pelzflorian (Florian Pelz)
  2020-04-08  9:58     ` pelzflorian (Florian Pelz)
  0 siblings, 2 replies; 12+ messages in thread
From: Ludovic Courtès @ 2020-04-07 20:38 UTC (permalink / raw)
  To: pelzflorian (Florian Pelz); +Cc: 40493

Good evening comrades!

"pelzflorian (Florian Pelz)" <pelzflorian@pelzflorian.de> skribis:

> IMHO two things should be done:
>
> * Within the installer, a toggleable second keyboard layout should be
>   available by default.
>
>   Mathieu enabled changing the layout via the F1 help menu.  This is
>   good and more flexible and discoverable, but a key combination is
>   more convenient and people appear to be used to Alt+Shift toggling.

Agreed!

> * In the config.scm created by the installer, the default
>   keyboard-layout should include the second layout.

Yes.

> I attach a proposed solution for the first thing, though it does not
>   yet update the toggle option correctly.  If you think the
> approach is OK, then I will add more default alternative layouts to
> the maybe-add-second-layout procedure.

I think the approach is OK, even as-is.  We can then improve it by
(hopefully) replacing the hard-coded list of non-Latin layouts (ar, jp,
etc.) with code that determines whether the main layout is Latin or not.

> From 0d3a1ecc214fe55d77f45f4b2e690a93978da9ec Mon Sep 17 00:00:00 2001
> From: Florian Pelz <pelzflorian@pelzflorian.de>
> Date: Tue, 7 Apr 2020 19:06:31 +0200
> Subject: [PATCH] installer: Allow Alt+Shift toggle from non-Latin keyboard
>  layouts.
>
> See <https://bugs.gnu.org/40273>.
>
> * gnu/installer/newt/keymap.scm (run-keymap-page): Maybe add second layout.
> * gnu/installer/keymap.scm (kmscon-update-keymap): Pass on XKB options.
> * gnu/installer/records.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.

Overall LGTM!  Minor suggestion below:

>  (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
> +optionsxs."
          ^
You forgot to hold the “Control” key.  :-)

> +  (define (maybe-add-second-layout first-layout)
> +    "Return for a chosen keyboard layout either the same layout or possibly
> +the layout plus a suitable second layout, and also variant and options."

To leave room for improvement, how about making it a top-level procedure
along these lines:

  (define (switchable-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 (member layout '("ar" …))
        …))

?

Eventually we can replace ‘member’ or ‘match’ with something more fancy,
assuming the xkeyboard-config databases contain the relevant info
(‘base.xml’ doesn’t say what’s Latin and what’s not apparently.)

> +    (match first-layout
> +      (("ar" "azerty") (list "ar,fr" "azerty," "grp:alt_shift_toggle"))
                                               ^
Remove comma?

Thank you!

Ludo’.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#40493: installer: Provide a way to select multiple keyboard layouts
  2020-04-07 20:38   ` Ludovic Courtès
@ 2020-04-07 21:56     ` pelzflorian (Florian Pelz)
  2020-04-08  9:58     ` pelzflorian (Florian Pelz)
  1 sibling, 0 replies; 12+ messages in thread
From: pelzflorian (Florian Pelz) @ 2020-04-07 21:56 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 40493

On Tue, Apr 07, 2020 at 10:38:16PM +0200, Ludovic Courtès wrote:
> Overall LGTM!  Minor suggestion below:

I will make a new patch tonight and follow your suggestions.  Thank you!

The layout toggling worked fine btw, except Arabic layout is called
"ara" and not "ar" in base.xml …

Regards,
Florian

^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#40493: installer: Provide a way to select multiple keyboard layouts
  2020-04-07 20:38   ` Ludovic Courtès
  2020-04-07 21:56     ` pelzflorian (Florian Pelz)
@ 2020-04-08  9:58     ` pelzflorian (Florian Pelz)
  2020-04-08 13:22       ` Ludovic Courtès
  1 sibling, 1 reply; 12+ messages in thread
From: pelzflorian (Florian Pelz) @ 2020-04-08  9:58 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 40493

[-- Attachment #1: Type: text/plain, Size: 725 bytes --]

On Tue, Apr 07, 2020 at 10:38:16PM +0200, Ludovic Courtès wrote:
> I think the approach is OK, even as-is.  We can then improve it by
> (hopefully) replacing the hard-coded list of non-Latin layouts (ar, jp,
> etc.) with code that determines whether the main layout is Latin or not.
>

I am still doing final testing, but I believe I can push the attached
patch.


> > +    (match first-layout
> > +      (("ar" "azerty") (list "ar,fr" "azerty," "grp:alt_shift_toggle"))
>                                                ^
> Remove comma?

The comma is needed, for example the Japanese Kana ("jp" "kana")
layout breaks otherwise.  I believe the reason is that the "kana"
variant gets applied to "us" layout.

Regards,
Florian

[-- Attachment #2: 0001-installer-Allow-Alt-Shift-toggle-from-non-Latin-keyb.patch --]
[-- Type: text/plain, Size: 12075 bytes --]

From 68fc18d2816e3997f38d0a3c69566d85b26c8719 Mon Sep 17 00:00:00 2001
From: Florian Pelz <pelzflorian@pelzflorian.de>
Date: Wed, 8 Apr 2020 11:46:16 +0200
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Subject: [PATCH] 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.
(toggleable-latin-layout): New procedure to compute combined layouts.
(run-keymap-page): Use it.
(keyboard-layout->configuration): Apply it in config.scm.
* gnu/installer/newt/help.scm (run-help-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.
---
 gnu/installer.scm                             | 14 ++++---
 gnu/installer/keymap.scm                      |  8 +++-
 gnu/installer/newt/help.scm                   |  5 ++-
 gnu/installer/newt/keymap.scm                 | 40 ++++++++++++++++---
 gnu/installer/record.scm                      |  3 +-
 .../kmscon-runtime-keymap-switch.patch        | 27 ++++---------
 6 files changed, 63 insertions(+), 34 deletions(-)

diff --git a/gnu/installer.scm b/gnu/installer.scm
index 75c5a01570..72b7d195fd 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..d520b782fd 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)
@@ -175,4 +176,7 @@ Configuration Database, describing possible XKB configurations."
          (put-u8 port 0)
 
          (format port variant)
+         (put-u8 port 0)
+
+         (format port options)
          (put-u8 port 0))))))
diff --git a/gnu/installer/newt/help.scm b/gnu/installer/newt/help.scm
index a488f5fa2a..3ccfaf2e54 100644
--- a/gnu/installer/newt/help.scm
+++ b/gnu/installer/newt/help.scm
@@ -1,5 +1,6 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2020 Mathieu Othacehe <m.othacehe@gmail.com>
+;;; Copyright © 2020 Florian Pelz <pelzflorian@pelzflorian.de>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -31,7 +32,9 @@
            (cons (G_ "Change keyboard layout") keyboard-layout-selection)))
          (result
           (run-listbox-selection-page
-           #:info-text (G_ "This is the help menu, please choose an action.")
+           #:info-text (G_ "This is the help menu.  Here you can change your
+keyboard layout.  Non-Latin layouts can also be toggled with Alt+Shift.
+Please choose an action.")
            #:title (G_ "Installation help")
            #:listbox-items items
            #:listbox-item->text car
diff --git a/gnu/installer/newt/keymap.scm b/gnu/installer/newt/keymap.scm
index 0147a0b9d5..475ffc2261 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.
 ;;;
@@ -112,10 +113,35 @@ You can switch to different layout at any time from the help menu.")))
          variants))
     (cut append <> <>)))
 
+(define %non-latin-layouts
+  ;; List of keyboard layouts marked as $nonlatin in xkeyboard-config.
+  '("am" "ara" "ben" "bd" "bg" "bt" "by" "cs" "deva" "ge" "gh"
+    "gr" "guj" "guru" "il" "in" "ir" "iku" "jp" "kan" "kh" "kr"
+    "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"))
+
+(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 the empty string."
+  (if (member layout %non-latin-layouts)
+      (let ((latin-layout (if (string=? variant "azerty") "fr" "us")))
+        (list
+         (string-append layout "," latin-layout)
+         (string-append variant ",") ;comma to use variant only for non-Latin
+         "grp:alt_shift_toggle"))
+      (list layout variant "")))
+
 (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 +177,18 @@ names of the selected keyboard layout and variant."
                           (lambda (variant)
                             (gettext (x11-keymap-variant-name variant)
                                      "xkeyboard-config")))))
-      (list layout (or variant ""))))
+      (apply toggleable-latin-layout
+             (list layout (or 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 "" "")
      `((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 78acf50c63..13acd33fc6 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
-
-- 
2.26.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* bug#40493: installer: Provide a way to select multiple keyboard layouts
  2020-04-08  9:58     ` pelzflorian (Florian Pelz)
@ 2020-04-08 13:22       ` Ludovic Courtès
  2020-04-09  4:14         ` pelzflorian (Florian Pelz)
  0 siblings, 1 reply; 12+ messages in thread
From: Ludovic Courtès @ 2020-04-08 13:22 UTC (permalink / raw)
  To: pelzflorian (Florian Pelz); +Cc: 40493

Hi,

"pelzflorian (Florian Pelz)" <pelzflorian@pelzflorian.de> skribis:

> The comma is needed, for example the Japanese Kana ("jp" "kana")
> layout breaks otherwise.  I believe the reason is that the "kana"
> variant gets applied to "us" layout.

I see.

> From 68fc18d2816e3997f38d0a3c69566d85b26c8719 Mon Sep 17 00:00:00 2001
> From: Florian Pelz <pelzflorian@pelzflorian.de>
> Date: Wed, 8 Apr 2020 11:46:16 +0200
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: 8bit
> Subject: [PATCH] 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.
> (toggleable-latin-layout): New procedure to compute combined layouts.
> (run-keymap-page): Use it.
> (keyboard-layout->configuration): Apply it in config.scm.
> * gnu/installer/newt/help.scm (run-help-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.

[...]

> +(define %non-latin-layouts
> +  ;; List of keyboard layouts marked as $nonlatin in xkeyboard-config.

Out of curiosity, where did you find that info?  Perhaps add the name of
the relevant file or XML tag here.

> +      (apply toggleable-latin-layout
> +             (list layout (or variant "")))))

Simply:

  (toggleable-latin-layout layout (or variant ""))

This allows the compiler to detect a wrong number of arguments.

Go for it, thank you!

Ludo’.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#40493: installer: Provide a way to select multiple keyboard layouts
  2020-04-08 13:22       ` Ludovic Courtès
@ 2020-04-09  4:14         ` pelzflorian (Florian Pelz)
  2020-04-09  4:21           ` pelzflorian (Florian Pelz)
                             ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: pelzflorian (Florian Pelz) @ 2020-04-09  4:14 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 40493-done

On Wed, Apr 08, 2020 at 03:22:34PM +0200, Ludovic Courtès wrote:
> Go for it, thank you!

I added some more heuristics on whether a layout is Latin or not and
after much testing pushed as 91c231a2223440081426929828a23c7baa0214fd.
There are still few false positives like non-Kana Japanese layouts
that are Latin but toggle to U.S.  They can be fixed later.

More importantly with 7bc71025ccd0fabd739803889825e10341fbabdf I also
fixed a layout’s empty variant "" not being a choice in the installer.
The "" variant is the only variant of the Azerbaijani layout providing
the Latin script Azerbaijan uses since a few decades, so it is
important.  I hope the code is alright; maybe I should not have just
pushed, but I believe it is alright.

Marking as done.

Regards,
Florian

^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#40493: installer: Provide a way to select multiple keyboard layouts
  2020-04-09  4:14         ` pelzflorian (Florian Pelz)
@ 2020-04-09  4:21           ` pelzflorian (Florian Pelz)
  2020-04-09  7:25           ` Mathieu Othacehe
  2020-04-09  7:54           ` Ludovic Courtès
  2 siblings, 0 replies; 12+ messages in thread
From: pelzflorian (Florian Pelz) @ 2020-04-09  4:21 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 40493-done

On Thu, Apr 09, 2020 at 06:14:11AM +0200, pelzflorian (Florian Pelz) wrote:
> Marking as done.

P.S. Don’t brag with Arabic support in Guix’ installer just yet
because Arabs still have to confusedly read from left to right.

https://bugs.gnu.org/35319

But that is something to solve later.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#40493: installer: Provide a way to select multiple keyboard layouts
  2020-04-09  4:14         ` pelzflorian (Florian Pelz)
  2020-04-09  4:21           ` pelzflorian (Florian Pelz)
@ 2020-04-09  7:25           ` Mathieu Othacehe
  2020-04-09  7:36             ` pelzflorian (Florian Pelz)
  2020-04-09  7:54           ` Ludovic Courtès
  2 siblings, 1 reply; 12+ messages in thread
From: Mathieu Othacehe @ 2020-04-09  7:25 UTC (permalink / raw)
  To: pelzflorian (Florian Pelz); +Cc: 40493-done


Hello Florian,

> I added some more heuristics on whether a layout is Latin or not and
> after much testing pushed as 91c231a2223440081426929828a23c7baa0214fd.
> There are still few false positives like non-Kana Japanese layouts
> that are Latin but toggle to U.S.  They can be fixed later.

Nice! Thanks for taking care of this :)

In the future it would be nice to be able to extract %non-latin-layout
by parsing the base file in xkeyboard-config, rather than by maintaining
this list, but that's a minor point, and I guess new keyboard layouts
are not coming out every day :p

Mathieu

^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#40493: installer: Provide a way to select multiple keyboard layouts
  2020-04-09  7:25           ` Mathieu Othacehe
@ 2020-04-09  7:36             ` pelzflorian (Florian Pelz)
  2020-04-09 15:24               ` Ludovic Courtès
  0 siblings, 1 reply; 12+ messages in thread
From: pelzflorian (Florian Pelz) @ 2020-04-09  7:36 UTC (permalink / raw)
  To: Mathieu Othacehe; +Cc: 40493-done

On Thu, Apr 09, 2020 at 09:25:58AM +0200, Mathieu Othacehe wrote:
> Nice! Thanks for taking care of this :)
> 

:)

> In the future it would be nice to be able to extract %non-latin-layout
> by parsing the base file in xkeyboard-config, rather than by maintaining
> this list, but that's a minor point, and I guess new keyboard layouts
> are not coming out every day :p

Yes, but the source in
/gnu/store/wsykijz9a1p7gx3z8hlmn58v5f5bswp7-xkeyboard-config-2.29/share/X11/xkb/rules/base
looks like this:

// If you want non-latin layouts implicitly include the en_US layout
// uncomment lines below
//! $nonlatin = am ara ben bd bg bt by cs deva ge gh gr guj guru il \
//              in ir iku jp kan kh kr la lao lk mk mm mn mv mal olck \
//              ori pk ru scc sy syr tel th tj tam ua uz

I am not sure if parsing that (and filtering out "kr") is worth it.

Regards,
Florian

^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#40493: installer: Provide a way to select multiple keyboard layouts
  2020-04-09  4:14         ` pelzflorian (Florian Pelz)
  2020-04-09  4:21           ` pelzflorian (Florian Pelz)
  2020-04-09  7:25           ` Mathieu Othacehe
@ 2020-04-09  7:54           ` Ludovic Courtès
  2 siblings, 0 replies; 12+ messages in thread
From: Ludovic Courtès @ 2020-04-09  7:54 UTC (permalink / raw)
  To: pelzflorian (Florian Pelz); +Cc: 40493-done

Hi Florian,

"pelzflorian (Florian Pelz)" <pelzflorian@pelzflorian.de> skribis:

> On Wed, Apr 08, 2020 at 03:22:34PM +0200, Ludovic Courtès wrote:
>> Go for it, thank you!
>
> I added some more heuristics on whether a layout is Latin or not and
> after much testing pushed as 91c231a2223440081426929828a23c7baa0214fd.
> There are still few false positives like non-Kana Japanese layouts
> that are Latin but toggle to U.S.  They can be fixed later.

Awesome!

> More importantly with 7bc71025ccd0fabd739803889825e10341fbabdf I also
> fixed a layout’s empty variant "" not being a choice in the installer.
> The "" variant is the only variant of the Azerbaijani layout providing
> the Latin script Azerbaijan uses since a few decades, so it is
> important.  I hope the code is alright; maybe I should not have just
> pushed, but I believe it is alright.

Good, it’s great you’re paying close attention to this.  The patch seems
reasonable to me.

> P.S. Don’t brag with Arabic support in Guix’ installer just yet
> because Arabs still have to confusedly read from left to right.
>
> https://bugs.gnu.org/35319
>
> But that is something to solve later.

Yeah.

I’ll run the “gui-installed” tests to make sure everything’s is still
fine, then run “make release” and upload files for testing later today.

Thanks a lot, Florian!

Ludo’.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#40493: installer: Provide a way to select multiple keyboard layouts
  2020-04-09  7:36             ` pelzflorian (Florian Pelz)
@ 2020-04-09 15:24               ` Ludovic Courtès
  0 siblings, 0 replies; 12+ messages in thread
From: Ludovic Courtès @ 2020-04-09 15:24 UTC (permalink / raw)
  To: pelzflorian (Florian Pelz); +Cc: 40493-done

"pelzflorian (Florian Pelz)" <pelzflorian@pelzflorian.de> skribis:

> On Thu, Apr 09, 2020 at 09:25:58AM +0200, Mathieu Othacehe wrote:

[...]

>> In the future it would be nice to be able to extract %non-latin-layout
>> by parsing the base file in xkeyboard-config, rather than by maintaining
>> this list, but that's a minor point, and I guess new keyboard layouts
>> are not coming out every day :p
>
> Yes, but the source in
> /gnu/store/wsykijz9a1p7gx3z8hlmn58v5f5bswp7-xkeyboard-config-2.29/share/X11/xkb/rules/base
> looks like this:
>
> // If you want non-latin layouts implicitly include the en_US layout
> // uncomment lines below
> //! $nonlatin = am ara ben bd bg bt by cs deva ge gh gr guj guru il \
> //              in ir iku jp kan kh kr la lao lk mk mm mn mv mal olck \
> //              ori pk ru scc sy syr tel th tj tam ua uz
>
> I am not sure if parsing that (and filtering out "kr") is worth it.

Uh, agreed, it doesn’t look like something parseable.  Also, presumably
that list won’t change much over time :-), so it’s OK to have it
hard-coded in Guix IMO.

Ludo’.

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2020-04-09 15:25 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-07 17:12 bug#40493: installer: Provide a way to select multiple keyboard layouts Mathieu Othacehe
2020-04-07 17:50 ` pelzflorian (Florian Pelz)
2020-04-07 20:38   ` Ludovic Courtès
2020-04-07 21:56     ` pelzflorian (Florian Pelz)
2020-04-08  9:58     ` pelzflorian (Florian Pelz)
2020-04-08 13:22       ` Ludovic Courtès
2020-04-09  4:14         ` pelzflorian (Florian Pelz)
2020-04-09  4:21           ` pelzflorian (Florian Pelz)
2020-04-09  7:25           ` Mathieu Othacehe
2020-04-09  7:36             ` pelzflorian (Florian Pelz)
2020-04-09 15:24               ` Ludovic Courtès
2020-04-09  7:54           ` Ludovic Courtès

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.