1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2018 Mathieu Othacehe <m.othacehe@gmail.com>
4 ;;; This file is part of GNU Guix.
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19 (define-module (gnu installer keymap)
20 #:use-module (guix records)
21 #:use-module (sxml match)
22 #:use-module (sxml simple)
23 #:use-module (ice-9 binary-ports)
24 #:use-module (ice-9 ftw)
25 #:use-module (ice-9 match)
26 #:use-module (ice-9 regex)
27 #:export (<x11-keymap-model>
32 x11-keymap-model-description
36 make-x11-keymap-layout
38 x11-keymap-layout-name
39 x11-keymap-layout-synopsis
40 x11-keymap-layout-description
41 x11-keymap-layout-variants
45 make-x11-keymap-variant
47 x11-keymap-variant-name
48 x11-keymap-variant-description
50 default-keyboard-model
51 xkb-rules->models+layouts
52 kmscon-update-keymap))
54 (define-record-type* <x11-keymap-model>
55 x11-keymap-model make-x11-keymap-model
57 (name x11-keymap-model-name) ;string
58 (description x11-keymap-model-description)) ;string
60 (define-record-type* <x11-keymap-layout>
61 x11-keymap-layout make-x11-keymap-layout
63 (name x11-keymap-layout-name) ;string
64 (synopsis x11-keymap-layout-synopsis) ;string (e.g., "en")
65 (description x11-keymap-layout-description) ;string (a whole phrase)
66 (variants x11-keymap-layout-variants)) ;list of <x11-keymap-variant>
68 (define-record-type* <x11-keymap-variant>
69 x11-keymap-variant make-x11-keymap-variant
71 (name x11-keymap-variant-name) ;string
72 (description x11-keymap-variant-description)) ;string
74 ;; Assume all modern keyboards have this model.
75 (define default-keyboard-model (make-parameter "pc105"))
77 (define (xkb-rules->models+layouts file)
78 "Parse FILE and return two values, the list of supported X11-KEYMAP-MODEL
79 and X11-KEYMAP-LAYOUT records. FILE is an XML file from the X Keyboard
80 Configuration Database, describing possible XKB configurations."
86 (description ,description)
90 (description description))]))
95 ;; According to xbd-rules DTD, the definition of a
96 ;; configItem is: <!ELEMENT configItem
97 ;; (name,shortDescription*,description*,vendor?,
98 ;; countryList?,languageList?,hwList?)>
100 ;; shortDescription and description are optional elements
101 ;; but sxml-match does not support default values for
102 ;; elements (only attributes). So to avoid writing as many
103 ;; patterns as existing possibilities, gather all the
104 ;; remaining elements but name in REST-VARIANT.
111 (assoc-ref rest-variant 'description))))]))
119 (variantList ,[variant -> v] ...))
123 (assoc-ref rest-layout 'shortDescription)))
125 (assoc-ref rest-layout 'description)))
126 (variants (list v ...)))]
134 (assoc-ref rest-layout 'shortDescription)))
136 (assoc-ref rest-layout 'description)))
139 (let ((sxml (call-with-input-file file
141 (xml->sxml port #:trim-whitespace? #t)))))
148 (modelList ,[model -> m] ...)
149 (layoutList ,[layout -> l] ...)
155 (values models layouts)))))
157 (define (kmscon-update-keymap model layout variant)
158 "Update kmscon keymap with the provided MODEL, LAYOUT and VARIANT."
160 (getenv "KEYMAP_UPDATE")
161 (lambda (keymap-file)
162 (unless (file-exists? keymap-file)
163 (error "Unable to locate keymap update file"))
165 ;; See file gnu/packages/patches/kmscon-runtime-keymap-switch.patch.
166 ;; This dirty hack makes possible to update kmscon keymap at runtime by
167 ;; writing an X11 keyboard model, layout and variant to a named pipe
168 ;; referred by KEYMAP_UPDATE environment variable.
169 (call-with-output-file keymap-file
177 (format port variant)