aboutsummaryrefslogtreecommitdiff
path: root/gnu/installer/newt/keymap.scm
blob: c5d4be6792596b81c16ae821192321272a19a9aa (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
;;; 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.
;;;
;;; 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)
  #:use-module (srfi srfi-26)
  #:use-module (srfi srfi-34)
  #:use-module (srfi srfi-35)
  #:use-module (ice-9 i18n)
  #:use-module (ice-9 match)
  #:export (run-keymap-page
            keyboard-layout->configuration))

(define (run-layout-page layouts layout->text context)
  (let ((title (G_ "Layout")))
    (run-listbox-selection-page
     #:title title
     #:info-text
     (case context
       ((param) (G_ "Please choose your keyboard layout. \
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. \
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
     #:button-text
     (case context
       ((param) (G_ "Continue"))
       (else (G_ "Exit")))
     #:button-callback-procedure
     (case context
       ((param) (const #f))
       (else
        (lambda _
          (abort-to-prompt 'installer-step 'abort)))))))

(define (run-variant-page variants variant->text)
  (let ((title (G_ "Variant")))
    (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
     #:sort-listbox-items? #f
     #:button-text (G_ "Back")
     #:button-callback-procedure
     (lambda _
       (abort-to-prompt 'installer-step 'abort)))))

(define (sort-layouts layouts)
  "Sort LAYOUTS list by putting the US layout ahead and return it."
  (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"))

  (call-with-values
      (lambda ()
        (partition
         (lambda (layout)
           ;; 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)))
         layouts))
    (lambda (main others)
      (append (sort main layout<?)
              (sort others layout<?)))))

(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))

(define (sort-variants variants)
  "Sort VARIANTS list by putting the international variant ahead and return it."
  (call-with-values
      (lambda ()
        (partition
         (lambda (variant)
           (and variant
                (let ((name (x11-keymap-variant-name variant)))
                  (string=? name "altgr-intl"))))
         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.  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
      (id 'layout)
      (compute
       (lambda _
         (run-layout-page
          (sort-layouts layouts)
          (lambda (layout)
            (gettext (x11-keymap-layout-description layout)
                     "xkeyboard-config"))
          context))))
     ;; Propose the user to select a variant among those supported by the
     ;; previously selected layout.
     (installer-step
      (id 'variant)
      (compute
       (lambda (result _)
         (let* ((layout (result-step result 'layout))
                (variants (if layout
                              (x11-keymap-layout-variants layout)
                              '())))
           ;; Return #f if the layout does not have any variant.
           (and (not (null? variants))
                (run-variant-page
                 (sort-variants (add-empty-variant variants))
                 (lambda (variant)
                   (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")))))))))))

  (define (format-result layout variant)
    (let ((layout (x11-keymap-layout-name layout))
          (variant (and=> variant
                          (lambda (variant)
                            (gettext (x11-keymap-variant-name variant)
                                     "xkeyboard-config")))))
      (toggleable-latin-layout layout variant)))

  (let* ((result (run-installer-steps #:steps keymap-steps))
         (layout (result-step result 'layout))
         (variant (result-step result 'variant)))
    (and layout
         (format-result layout variant))))

(define (keyboard-layout->configuration keymap)
  "Return the operating system configuration snippet to install KEYMAP."
  (match keymap
    ((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 "grp:alt_shift_toggle")
     `((keyboard-layout (keyboard-layout ,name ,variant
                                         #:options '("grp:alt_shift_toggle")))))
    ((name variant _)
     `((keyboard-layout (keyboard-layout ,name ,variant))))))
l.scm, gnu/packages/opencog.scm, gnu/packages/pantheon.scm, gnu/packages/password-utils.scm, gnu/packages/patchutils.scm, gnu/packages/pdf.scm, gnu/packages/perl6.scm, gnu/packages/phabricator.scm, gnu/packages/popt.scm, gnu/packages/printers.scm, gnu/packages/prolog.scm, gnu/packages/protobuf.scm, gnu/packages/pulseaudio.scm, gnu/packages/python-crypto.scm, gnu/packages/python-web.scm, gnu/packages/python-xyz.scm, gnu/packages/qt.scm, gnu/packages/radio.scm, gnu/packages/rails.scm, gnu/packages/rdf.scm, gnu/packages/rednotebook.scm, gnu/packages/rpc.scm, gnu/packages/rsync.scm, gnu/packages/ruby.scm, gnu/packages/rust.scm, gnu/packages/scheme.scm, gnu/packages/screen.scm, gnu/packages/security-token.scm, gnu/packages/selinux.scm, gnu/packages/serialization.scm, gnu/packages/shells.scm, gnu/packages/shellutils.scm, gnu/packages/simh.scm, gnu/packages/sml.scm, gnu/packages/ssh.scm, gnu/packages/statistics.scm, gnu/packages/stenography.scm, gnu/packages/sync.scm, gnu/packages/syncthing.scm, gnu/packages/synergy.scm, gnu/packages/telephony.scm, gnu/packages/terminals.scm, gnu/packages/tex.scm, gnu/packages/texinfo.scm, gnu/packages/text-editors.scm, gnu/packages/textutils.scm, gnu/packages/time.scm, gnu/packages/tmux.scm, gnu/packages/tor.scm, gnu/packages/toys.scm, gnu/packages/version-control.scm, gnu/packages/video.scm, gnu/packages/vim.scm, gnu/packages/virtualization.scm, gnu/packages/vlang.scm, gnu/packages/vnc.scm, gnu/packages/vpn.scm, gnu/packages/web-browsers.scm, gnu/packages/web.scm, gnu/packages/wireservice.scm, gnu/packages/wm.scm, gnu/packages/wxwidgets.scm, gnu/packages/xdisorg.scm, gnu/packages/xml.scm, gnu/packages/xorg.scm, tests/lint.scm: Remove trailing ".git" from 'git-reference' URL. Ludovic Courtès 2020-06-13gnu: jucipp: Build with Clang 10....* gnu/packages/text-editors.scm (jucipp)[inputs]: Change from CLANG to CLANG-10. Marius Bakke 2020-06-10gnu: scintilla: Update to 4.4.3....* gnu/packages/text-editors.scm (scintilla): Update to 4.4.3. Nicolas Goaziou 2020-06-02gnu: ghostwriter: Update to 1.8.1....* gnu/packages/text-editors.scm (ghostwriter): Update to 1.8.1. Tobias Geerinckx-Rice 2020-06-01gnu: scintilla: Update to 4.4.0....* gnu/packages/text-editors.scm (scintilla): Update to 4.4.0. [arguments]: Remove phase building shared library. This is now done out of the box. Nicolas Goaziou 2020-06-01gnu: geany: Un-unbundle scintilla...* gnu/packages/text-editors.scm (geany)[source]: Do not un-bundle scintilla. [arguments]: Remove phase using our shared library. Use bundled one instead. Nicolas Goaziou 2020-06-01gnu: geany: Fix crash when displaying file selection...* gnu/packages/text-editors.scm (geany)[arguments]: Wrap GTK to prevent errors when opening file selection menu. Nicolas Goaziou 2020-06-01gnu: vis: Fix configuration load order....* gnu/packages/text-editors.scm (vis)[native-search-paths]: Remove. There is no need to set $VIS_PATH to $prefix/share/vis as VIS_PATH (#define), which is also in search path (https://github.com/martanne/vis/blob/7648280a95954304e5e935e2cead16d836b86eda/vis-lua.c#L2662), is already set by Makefile to $prefix/share/vis (https://github.com/martanne/vis/blob/7648280a95954304e5e935e2cead16d836b86eda/Makefile#L37). This fixes issue https://issues.guix.gnu.org/39394 Signed-off-by: Jakub Kądziołka <kuba@kadziolka.net> tsmish 2020-05-27gnu: jucipp: Update to 1.6.0....* gnu/packages/text-editors.scm (jucipp): Update to 1.6.0. [arguments]: Remove obsolete phase. [inputs]: Add UNIVERSAL-CTAGS. Marius Bakke 2020-05-13mailmap: Update entries for Nikita....* .mailmap: change email and name for Nikita. * Makefile.am, doc/guix.texi, etc/completion/fish/guix.fish, gnu/packages/accessibility.scm, gnu/packages/admin.scm, gnu/packages/audio.scm, gnu/packages/autotools.scm, gnu/packages/cdrom.scm, gnu/packages/check.scm, gnu/packages/cinnamon.scm, gnu/packages/compression.scm, gnu/packages/crypto.scm, gnu/packages/databases.scm, gnu/packages/django.scm, gnu/packages/dns.scm, gnu/packages/elixir.scm, gnu/packages/emacs-xyz.scm, gnu/packages/emacs.scm, gnu/packages/enlightenment.scm, gnu/packages/erlang.scm, gnu/packages/fonts.scm, gnu/packages/fontutils.scm, gnu/packages/forth.scm, gnu/packages/fvwm.scm, gnu/packages/games.scm, gnu/packages/gl.scm, gnu/packages/gnome.scm, gnu/packages/gnunet.scm, gnu/packages/gnupg.scm, gnu/packages/gtk.scm, gnu/packages/guile-wm.scm, gnu/packages/guile-xyz.scm, gnu/packages/haskell-apps.scm, gnu/packages/haskell-check.scm, gnu/packages/haskell-crypto.scm, gnu/packages/haskell-xyz.scm, gnu/packages/haskell.scm, gnu/packages/image-viewers.scm, gnu/packages/image.scm, gnu/packages/irc.scm, gnu/packages/language.scm, gnu/packages/libcanberra.scm, gnu/packages/linux.scm, gnu/packages/lisp-xyz.scm, gnu/packages/lisp.scm, gnu/packages/lolcode.scm, gnu/packages/lxde.scm, gnu/packages/lxqt.scm, gnu/packages/mail.scm, gnu/packages/markup.scm, gnu/packages/mate.scm, gnu/packages/maths.scm, gnu/packages/mc.scm, gnu/packages/messaging.scm, gnu/packages/music.scm, gnu/packages/ncurses.scm, gnu/packages/networking.scm, gnu/packages/nickle.scm, gnu/packages/openbox.scm, gnu/packages/pdf.scm, gnu/packages/perl-check.scm, gnu/packages/perl.scm, gnu/packages/python-compression.scm, gnu/packages/python-crypto.scm, gnu/packages/python-web.scm, gnu/packages/python-xyz.scm, gnu/packages/python.scm, gnu/packages/qt.scm, gnu/packages/ruby.scm, gnu/packages/rust.scm, gnu/packages/scheme.scm, gnu/packages/serialization.scm, gnu/packages/shells.scm, gnu/packages/ssh.scm, gnu/packages/suckless.scm, gnu/packages/tbb.scm, gnu/packages/telephony.scm, gnu/packages/text-editors.scm, gnu/packages/textutils.scm, gnu/packages/time.scm, gnu/packages/tls.scm, gnu/packages/tor.scm, gnu/packages/version-control.scm, gnu/packages/video.scm, gnu/packages/vim.scm, gnu/packages/web.scm, gnu/packages/wm.scm, gnu/packages/xdisorg.scm, gnu/packages/xfce.scm, gnu/packages/xml.scm, gnu/packages/xorg.scm, gnu/services/certbot.scm, gnu/services/desktop.scm, gnu/services/version-control.scm, gnu/services/web.scm, guix/import/hackage.scm, guix/licenses.scm: Likewise. Signed-off-by: Efraim Flashner <efraim@flashner.co.il> nikita 2020-05-06gnu: Add hexer....* gnu/packages/text-editors.scm (hexer): New Variable. TomZ 2020-05-01gnu: scintilla: Update to 4.3.3....* gnu/packages/text-editors.scm (scintilla): Update to 4.3.3. Nicolas Goaziou 2020-04-28gnu: kakoune: Update to 2020.01.16....* gnu/packages/text-editors.scm (kakoune): Update to 2020.01.16. Nicolas Goaziou 2020-04-12gnu: fe: Fix grammar "allows to fold" to "folds"....* gnu/packages/text-editors (fe): Fix grammar. Vagrant Cascadian 2020-04-12gnu: Add jucipp....* gnu/packages/text-editors.scm (jucipp): New public variable. Marius Bakke