2018-11-16 11:43:55 +00:00
|
|
|
;;; GNU Guix --- Functional package management for GNU
|
2020-03-30 10:24:56 +00:00
|
|
|
;;; Copyright © 2018, 2020 Mathieu Othacehe <m.othacehe@gmail.com>
|
2019-03-25 22:21:08 +00:00
|
|
|
;;; Copyright © 2019 Ludovic Courtès <ludo@gnu.org>
|
2020-04-09 00:17:22 +00:00
|
|
|
;;; Copyright © 2020 Florian Pelz <pelzflorian@pelzflorian.de>
|
2018-11-16 11:43:55 +00:00
|
|
|
;;;
|
|
|
|
;;; This file is part of GNU Guix.
|
|
|
|
;;;
|
|
|
|
;;; GNU Guix is free software; you can redistribute it and/or modify it
|
|
|
|
;;; under the terms of the GNU General Public License as published by
|
|
|
|
;;; the Free Software Foundation; either version 3 of the License, or (at
|
|
|
|
;;; your option) any later version.
|
|
|
|
;;;
|
|
|
|
;;; GNU Guix is distributed in the hope that it will be useful, but
|
|
|
|
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;;; GNU General Public License for more details.
|
|
|
|
;;;
|
|
|
|
;;; You should have received a copy of the GNU General Public License
|
|
|
|
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
(define-module (gnu installer newt keymap)
|
|
|
|
#:use-module (gnu installer keymap)
|
|
|
|
#:use-module (gnu installer steps)
|
|
|
|
#:use-module (gnu installer newt page)
|
|
|
|
#:use-module (guix i18n)
|
|
|
|
#:use-module (guix records)
|
|
|
|
#:use-module (newt)
|
|
|
|
#:use-module (srfi srfi-1)
|
2019-01-12 17:26:11 +00:00
|
|
|
#:use-module (srfi srfi-26)
|
2018-11-16 11:43:55 +00:00
|
|
|
#:use-module (srfi srfi-34)
|
|
|
|
#:use-module (srfi srfi-35)
|
2019-04-17 13:16:08 +00:00
|
|
|
#:use-module (ice-9 i18n)
|
2019-03-25 22:21:08 +00:00
|
|
|
#:use-module (ice-9 match)
|
|
|
|
#:export (run-keymap-page
|
|
|
|
keyboard-layout->configuration))
|
2018-11-16 11:43:55 +00:00
|
|
|
|
2020-03-30 10:24:56 +00:00
|
|
|
(define (run-layout-page layouts layout->text context)
|
2018-12-05 05:19:28 +00:00
|
|
|
(let ((title (G_ "Layout")))
|
2018-11-16 11:43:55 +00:00
|
|
|
(run-listbox-selection-page
|
|
|
|
#:title title
|
2020-03-30 10:24:56 +00:00
|
|
|
#:info-text
|
|
|
|
(case context
|
2020-04-08 08:16:25 +00:00
|
|
|
((param) (G_ "Please choose your keyboard layout. \
|
2020-04-09 00:17:22 +00:00
|
|
|
It will only be used during the installation process. \
|
|
|
|
Non-Latin layouts can be toggled with Alt+Shift."))
|
2020-03-30 10:24:56 +00:00
|
|
|
(else (G_ "Please choose your keyboard layout. \
|
|
|
|
It will be used during the install process, and for the installed system. \
|
2020-04-09 00:17:22 +00:00
|
|
|
Non-Latin layouts can be toggled with Alt+Shift. You can switch to a \
|
|
|
|
different layout at any time from the parameters menu.")))
|
2018-11-16 11:43:55 +00:00
|
|
|
#:listbox-items layouts
|
|
|
|
#:listbox-item->text layout->text
|
2019-01-12 17:26:11 +00:00
|
|
|
#:sort-listbox-items? #f
|
2020-03-30 10:24:56 +00:00
|
|
|
#:button-text
|
|
|
|
(case context
|
2020-04-08 08:16:25 +00:00
|
|
|
((param) (G_ "Continue"))
|
2020-03-30 10:24:56 +00:00
|
|
|
(else (G_ "Exit")))
|
2018-11-16 11:43:55 +00:00
|
|
|
#:button-callback-procedure
|
2020-03-30 10:24:56 +00:00
|
|
|
(case context
|
2021-01-12 15:26:07 +00:00
|
|
|
((param) (const #f))
|
2020-03-30 10:24:56 +00:00
|
|
|
(else
|
|
|
|
(lambda _
|
installer: Use named prompt to abort or break installer steps.
* gnu/installer/steps.scm (run-installer-steps): Set up
'installer-step prompt.
* gnu/installer/newt/ethernet.scm (run-ethernet-page)
* gnu/installer/newt/final.scm (run-config-display-page,
run-install-failed-page)
* gnu/installer/newt/keymap.scm (run-layout-page, run-variant-page)
* gnu/installer/newt/locale.scm (run-language-page,
run-territory-page, run-codeset-page, run-modifier-page,
run-locale-page)
* gnu/installer/newt/network.scm (run-technology-page,
wait-service-online)
* gnu/installer/newt/page.scm (run-listbox-selection-page,
run-checkbox-tree-page)
* gnu/installer/newt/partition.scm (button-exit-action)
* gnu/installer/newt/services.scm (run-desktop-environments-cbt-page,
run-networking-cbt-page, run-other-services-cbt-page,
run-network-management-page)
* gnu/installer/newt/timezone.scm (run-timezone-page)
* gnu/installer/newt/user.scm (run-user-page)
* gnu/installer/newt/welcome.scm (run-menu-page)
* gnu/installer/newt/wifi.scm (run-wifi-page): Use the 'installer-step
prompt to abort.
Signed-off-by: Mathieu Othacehe <othacehe@gnu.org>
2022-01-15 13:50:07 +00:00
|
|
|
(abort-to-prompt 'installer-step 'abort)))))))
|
2018-11-16 11:43:55 +00:00
|
|
|
|
|
|
|
(define (run-variant-page variants variant->text)
|
2018-12-05 05:19:28 +00:00
|
|
|
(let ((title (G_ "Variant")))
|
2018-11-16 11:43:55 +00:00
|
|
|
(run-listbox-selection-page
|
|
|
|
#:title title
|
|
|
|
#:info-text (G_ "Please choose a variant for your keyboard layout.")
|
|
|
|
#:listbox-items variants
|
|
|
|
#:listbox-item->text variant->text
|
2019-01-12 17:26:11 +00:00
|
|
|
#:sort-listbox-items? #f
|
2018-11-16 11:43:55 +00:00
|
|
|
#:button-text (G_ "Back")
|
|
|
|
#:button-callback-procedure
|
|
|
|
(lambda _
|
installer: Use named prompt to abort or break installer steps.
* gnu/installer/steps.scm (run-installer-steps): Set up
'installer-step prompt.
* gnu/installer/newt/ethernet.scm (run-ethernet-page)
* gnu/installer/newt/final.scm (run-config-display-page,
run-install-failed-page)
* gnu/installer/newt/keymap.scm (run-layout-page, run-variant-page)
* gnu/installer/newt/locale.scm (run-language-page,
run-territory-page, run-codeset-page, run-modifier-page,
run-locale-page)
* gnu/installer/newt/network.scm (run-technology-page,
wait-service-online)
* gnu/installer/newt/page.scm (run-listbox-selection-page,
run-checkbox-tree-page)
* gnu/installer/newt/partition.scm (button-exit-action)
* gnu/installer/newt/services.scm (run-desktop-environments-cbt-page,
run-networking-cbt-page, run-other-services-cbt-page,
run-network-management-page)
* gnu/installer/newt/timezone.scm (run-timezone-page)
* gnu/installer/newt/user.scm (run-user-page)
* gnu/installer/newt/welcome.scm (run-menu-page)
* gnu/installer/newt/wifi.scm (run-wifi-page): Use the 'installer-step
prompt to abort.
Signed-off-by: Mathieu Othacehe <othacehe@gnu.org>
2022-01-15 13:50:07 +00:00
|
|
|
(abort-to-prompt 'installer-step 'abort)))))
|
2018-11-16 11:43:55 +00:00
|
|
|
|
2019-01-12 17:26:11 +00:00
|
|
|
(define (sort-layouts layouts)
|
|
|
|
"Sort LAYOUTS list by putting the US layout ahead and return it."
|
2019-04-17 13:16:08 +00:00
|
|
|
(define (layout<? layout1 layout2)
|
|
|
|
(let ((text1 (x11-keymap-layout-description layout1))
|
|
|
|
(text2 (x11-keymap-layout-description layout2)))
|
|
|
|
;; XXX: We're calling 'gettext' more than once per item.
|
|
|
|
(string-locale<? (gettext text1 "xkeyboard-config")
|
|
|
|
(gettext text2 "xkeyboard-config"))))
|
|
|
|
|
|
|
|
(define preferred
|
|
|
|
;; Two-letter language tag for the preferred keyboard layout.
|
|
|
|
(or (getenv "LANGUAGE") "us"))
|
|
|
|
|
2019-01-12 17:26:11 +00:00
|
|
|
(call-with-values
|
|
|
|
(lambda ()
|
|
|
|
(partition
|
|
|
|
(lambda (layout)
|
2019-04-17 13:16:08 +00:00
|
|
|
;; The 'synopsis' field is usually a language code (e.g., "en")
|
|
|
|
;; while the 'name' field is a country code (e.g., "us").
|
|
|
|
(or (string=? (x11-keymap-layout-name layout) preferred)
|
|
|
|
(string=? (x11-keymap-layout-synopsis layout) preferred)))
|
2019-01-12 17:26:11 +00:00
|
|
|
layouts))
|
2019-04-17 13:16:08 +00:00
|
|
|
(lambda (main others)
|
|
|
|
(append (sort main layout<?)
|
|
|
|
(sort others layout<?)))))
|
2019-01-12 17:26:11 +00:00
|
|
|
|
2020-04-09 00:38:27 +00:00
|
|
|
(define (add-empty-variant variants)
|
|
|
|
"Prepend #f to VARIANTS so the user has the option to select no variant.
|
|
|
|
The resulting layout may be different from all other variants (e.g. for
|
|
|
|
Azerbaijani)."
|
|
|
|
(cons #f variants))
|
|
|
|
|
2019-01-12 17:26:11 +00:00
|
|
|
(define (sort-variants variants)
|
2019-02-10 14:54:53 +00:00
|
|
|
"Sort VARIANTS list by putting the international variant ahead and return it."
|
2019-01-12 17:26:11 +00:00
|
|
|
(call-with-values
|
|
|
|
(lambda ()
|
|
|
|
(partition
|
|
|
|
(lambda (variant)
|
2020-04-09 00:38:27 +00:00
|
|
|
(and variant
|
|
|
|
(let ((name (x11-keymap-variant-name variant)))
|
|
|
|
(string=? name "altgr-intl"))))
|
2019-01-12 17:26:11 +00:00
|
|
|
variants))
|
|
|
|
(cut append <> <>)))
|
|
|
|
|
2020-04-09 00:17:22 +00:00
|
|
|
(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)))
|
|
|
|
|
2020-03-30 10:24:56 +00:00
|
|
|
(define* (run-keymap-page layouts #:key (context #f))
|
2018-12-05 05:36:22 +00:00
|
|
|
"Run a page asking the user to select a keyboard layout and variant. LAYOUTS
|
2020-04-09 00:17:22 +00:00
|
|
|
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."
|
2018-11-16 11:43:55 +00:00
|
|
|
(define keymap-steps
|
|
|
|
(list
|
|
|
|
(installer-step
|
|
|
|
(id 'layout)
|
|
|
|
(compute
|
|
|
|
(lambda _
|
2018-12-05 12:55:51 +00:00
|
|
|
(run-layout-page
|
2019-01-12 17:26:11 +00:00
|
|
|
(sort-layouts layouts)
|
2018-12-05 12:55:51 +00:00
|
|
|
(lambda (layout)
|
2019-04-17 13:11:21 +00:00
|
|
|
(gettext (x11-keymap-layout-description layout)
|
2020-03-30 10:24:56 +00:00
|
|
|
"xkeyboard-config"))
|
|
|
|
context))))
|
2018-11-16 11:43:55 +00:00
|
|
|
;; Propose the user to select a variant among those supported by the
|
|
|
|
;; previously selected layout.
|
|
|
|
(installer-step
|
|
|
|
(id 'variant)
|
|
|
|
(compute
|
2018-12-05 08:48:36 +00:00
|
|
|
(lambda (result _)
|
2018-12-05 12:55:51 +00:00
|
|
|
(let* ((layout (result-step result 'layout))
|
2021-01-12 15:26:07 +00:00
|
|
|
(variants (if layout
|
|
|
|
(x11-keymap-layout-variants layout)
|
|
|
|
'())))
|
2018-12-05 12:55:51 +00:00
|
|
|
;; Return #f if the layout does not have any variant.
|
|
|
|
(and (not (null? variants))
|
2019-01-12 17:26:11 +00:00
|
|
|
(run-variant-page
|
2020-04-09 00:38:27 +00:00
|
|
|
(sort-variants (add-empty-variant variants))
|
2019-01-12 17:26:11 +00:00
|
|
|
(lambda (variant)
|
2020-04-09 00:38:27 +00:00
|
|
|
(if variant
|
|
|
|
(gettext (x11-keymap-variant-description variant)
|
|
|
|
"xkeyboard-config")
|
|
|
|
;; Text to opt for no variant at all:
|
|
|
|
(gettext (x11-keymap-layout-description layout)
|
|
|
|
"xkeyboard-config")))))))))))
|
2018-11-16 11:43:55 +00:00
|
|
|
|
2021-01-12 15:26:07 +00:00
|
|
|
(define (format-result layout variant)
|
|
|
|
(let ((layout (x11-keymap-layout-name layout))
|
|
|
|
(variant (and=> variant
|
2018-11-16 11:43:55 +00:00
|
|
|
(lambda (variant)
|
2019-04-17 13:11:21 +00:00
|
|
|
(gettext (x11-keymap-variant-name variant)
|
|
|
|
"xkeyboard-config")))))
|
2020-04-09 00:17:22 +00:00
|
|
|
(toggleable-latin-layout layout variant)))
|
2021-01-12 15:26:07 +00:00
|
|
|
|
|
|
|
(let* ((result (run-installer-steps #:steps keymap-steps))
|
|
|
|
(layout (result-step result 'layout))
|
|
|
|
(variant (result-step result 'variant)))
|
|
|
|
(and layout
|
|
|
|
(format-result layout variant))))
|
2019-03-25 22:21:08 +00:00
|
|
|
|
|
|
|
(define (keyboard-layout->configuration keymap)
|
|
|
|
"Return the operating system configuration snippet to install KEYMAP."
|
|
|
|
(match keymap
|
2020-04-09 00:17:22 +00:00
|
|
|
((name #f "grp:alt_shift_toggle")
|
|
|
|
`((keyboard-layout (keyboard-layout ,name
|
|
|
|
#:options '("grp:alt_shift_toggle")))))
|
|
|
|
((name #f _)
|
2019-03-25 22:21:08 +00:00
|
|
|
`((keyboard-layout (keyboard-layout ,name))))
|
2020-04-09 00:17:22 +00:00
|
|
|
((name variant "grp:alt_shift_toggle")
|
|
|
|
`((keyboard-layout (keyboard-layout ,name ,variant
|
|
|
|
#:options '("grp:alt_shift_toggle")))))
|
|
|
|
((name variant _)
|
2019-03-25 22:21:08 +00:00
|
|
|
`((keyboard-layout (keyboard-layout ,name ,variant))))))
|