2018-11-16 11:43:55 +00:00
|
|
|
;;; GNU Guix --- Functional package management for GNU
|
|
|
|
;;; Copyright © 2018 Mathieu Othacehe <m.othacehe@gmail.com>
|
2019-03-25 22:21:08 +00:00
|
|
|
;;; Copyright © 2019 Ludovic Courtès <ludo@gnu.org>
|
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
|
|
|
|
|
|
|
(define (run-layout-page layouts layout->text)
|
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
|
|
|
|
#:info-text (G_ "Please choose your keyboard layout.")
|
|
|
|
#:listbox-items layouts
|
|
|
|
#:listbox-item->text layout->text
|
2019-01-12 17:26:11 +00:00
|
|
|
#:sort-listbox-items? #f
|
2018-12-05 10:50:17 +00:00
|
|
|
#:button-text (G_ "Exit")
|
2018-11-16 11:43:55 +00:00
|
|
|
#:button-callback-procedure
|
|
|
|
(lambda _
|
|
|
|
(raise
|
|
|
|
(condition
|
|
|
|
(&installer-step-abort)))))))
|
|
|
|
|
|
|
|
(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 _
|
|
|
|
(raise
|
|
|
|
(condition
|
|
|
|
(&installer-step-abort)))))))
|
|
|
|
|
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
|
|
|
|
|
|
|
(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)
|
|
|
|
(let ((name (x11-keymap-variant-name variant)))
|
|
|
|
(string=? name "altgr-intl")))
|
|
|
|
variants))
|
|
|
|
(cut append <> <>)))
|
|
|
|
|
2018-12-05 05:36:22 +00:00
|
|
|
(define* (run-keymap-page layouts)
|
|
|
|
"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."
|
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)
|
|
|
|
"xkeyboard-config"))))))
|
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))
|
|
|
|
(variants (x11-keymap-layout-variants layout)))
|
|
|
|
;; 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
|
|
|
|
(sort-variants variants)
|
|
|
|
(lambda (variant)
|
2019-04-17 13:11:21 +00:00
|
|
|
(gettext (x11-keymap-variant-description variant)
|
|
|
|
"xkeyboard-config"))))))))))
|
2018-11-16 11:43:55 +00:00
|
|
|
|
|
|
|
(define (format-result result)
|
2018-12-05 05:36:22 +00:00
|
|
|
(let ((layout (x11-keymap-layout-name
|
2018-11-16 11:43:55 +00:00
|
|
|
(result-step result 'layout)))
|
|
|
|
(variant (and=> (result-step result 'variant)
|
|
|
|
(lambda (variant)
|
2019-04-17 13:11:21 +00:00
|
|
|
(gettext (x11-keymap-variant-name variant)
|
|
|
|
"xkeyboard-config")))))
|
2018-12-05 05:36:22 +00:00
|
|
|
(list layout (or variant ""))))
|
2018-11-16 11:43:55 +00:00
|
|
|
(format-result
|
|
|
|
(run-installer-steps #:steps keymap-steps)))
|
2019-03-25 22:21:08 +00:00
|
|
|
|
|
|
|
(define (keyboard-layout->configuration keymap)
|
|
|
|
"Return the operating system configuration snippet to install KEYMAP."
|
|
|
|
(match keymap
|
|
|
|
((name "")
|
|
|
|
`((keyboard-layout (keyboard-layout ,name))))
|
|
|
|
((name variant)
|
|
|
|
`((keyboard-layout (keyboard-layout ,name ,variant))))))
|