1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2018 Mathieu Othacehe <m.othacehe@gmail.com>
3 ;;; Copyright © 2020 Florian Pelz <pelzflorian@pelzflorian.de>
5 ;;; This file is part of GNU Guix.
7 ;;; GNU Guix is free software; you can redistribute it and/or modify it
8 ;;; under the terms of the GNU General Public License as published by
9 ;;; the Free Software Foundation; either version 3 of the License, or (at
10 ;;; your option) any later version.
12 ;;; GNU Guix is distributed in the hope that it will be useful, but
13 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;;; GNU General Public License for more details.
17 ;;; You should have received a copy of the GNU General Public License
18 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20 (define-module (gnu installer keymap)
21 #:use-module (guix records)
22 #:use-module (sxml match)
23 #:use-module (sxml simple)
24 #:use-module (ice-9 binary-ports)
25 #:use-module (ice-9 ftw)
26 #:use-module (ice-9 match)
27 #:use-module (ice-9 regex)
28 #:export (<x11-keymap-model>
33 x11-keymap-model-description
37 make-x11-keymap-layout
39 x11-keymap-layout-name
40 x11-keymap-layout-synopsis
41 x11-keymap-layout-description
42 x11-keymap-layout-variants
46 make-x11-keymap-variant
48 x11-keymap-variant-name
49 x11-keymap-variant-description
51 default-keyboard-model
52 xkb-rules->models+layouts
53 kmscon-update-keymap))
55 (define-record-type* <x11-keymap-model>
56 x11-keymap-model make-x11-keymap-model
58 (name x11-keymap-model-name) ;string
59 (description x11-keymap-model-description)) ;string
61 (define-record-type* <x11-keymap-layout>
62 x11-keymap-layout make-x11-keymap-layout
64 (name x11-keymap-layout-name) ;string
65 (synopsis x11-keymap-layout-synopsis) ;string (e.g., "en")
66 (description x11-keymap-layout-description) ;string (a whole phrase)
67 (variants x11-keymap-layout-variants)) ;list of <x11-keymap-variant>
69 (define-record-type* <x11-keymap-variant>
70 x11-keymap-variant make-x11-keymap-variant
72 (name x11-keymap-variant-name) ;string
73 (description x11-keymap-variant-description)) ;string
75 ;; Assume all modern keyboards have this model.
76 (define default-keyboard-model (make-parameter "pc105"))
78 (define (xkb-rules->models+layouts file)
79 "Parse FILE and return two values, the list of supported X11-KEYMAP-MODEL
80 and X11-KEYMAP-LAYOUT records. FILE is an XML file from the X Keyboard
81 Configuration Database, describing possible XKB configurations."
87 (description ,description)
91 (description description))]))
96 ;; According to xbd-rules DTD, the definition of a
97 ;; configItem is: <!ELEMENT configItem
98 ;; (name,shortDescription*,description*,vendor?,
99 ;; countryList?,languageList?,hwList?)>
101 ;; shortDescription and description are optional elements
102 ;; but sxml-match does not support default values for
103 ;; elements (only attributes). So to avoid writing as many
104 ;; patterns as existing possibilities, gather all the
105 ;; remaining elements but name in REST-VARIANT.
112 (assoc-ref rest-variant 'description))))]))
120 (variantList ,[variant -> v] ...))
124 (assoc-ref rest-layout 'shortDescription)))
126 (assoc-ref rest-layout 'description)))
127 (variants (list v ...)))]
135 (assoc-ref rest-layout 'shortDescription)))
137 (assoc-ref rest-layout 'description)))
140 (let ((sxml (call-with-input-file file
142 (xml->sxml port #:trim-whitespace? #t)))))
149 (modelList ,[model -> m] ...)
150 (layoutList ,[layout -> l] ...)
156 (values models layouts)))))
158 (define (kmscon-update-keymap model layout variant options)
159 "Update kmscon keymap with the provided MODEL, LAYOUT, VARIANT and OPTIONS."
161 (getenv "KEYMAP_UPDATE")
162 (lambda (keymap-file)
163 (unless (file-exists? keymap-file)
164 (error "Unable to locate keymap update file"))
166 ;; See file gnu/packages/patches/kmscon-runtime-keymap-switch.patch.
167 ;; This dirty hack makes possible to update kmscon keymap at runtime by
168 ;; writing an X11 keyboard model, layout and variant to a named pipe
169 ;; referred by KEYMAP_UPDATE environment variable.
170 (call-with-output-file keymap-file
178 (format port (or variant ""))
181 (format port (or options ""))