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-description
40 x11-keymap-layout-variants
44 make-x11-keymap-variant
46 x11-keymap-variant-name
47 x11-keymap-variant-description
49 default-keyboard-model
50 xkb-rules->models+layouts
51 kmscon-update-keymap))
53 (define-record-type* <x11-keymap-model>
54 x11-keymap-model make-x11-keymap-model
56 (name x11-keymap-model-name) ;string
57 (description x11-keymap-model-description)) ;string
59 (define-record-type* <x11-keymap-layout>
60 x11-keymap-layout make-x11-keymap-layout
62 (name x11-keymap-layout-name) ;string
63 (description x11-keymap-layout-description) ;string
64 (variants x11-keymap-layout-variants)) ;list of <x11-keymap-variant>
66 (define-record-type* <x11-keymap-variant>
67 x11-keymap-variant make-x11-keymap-variant
69 (name x11-keymap-variant-name) ;string
70 (description x11-keymap-variant-description)) ;string
72 ;; Assume all modern keyboards have this model.
73 (define default-keyboard-model (make-parameter "pc105"))
75 (define (xkb-rules->models+layouts file)
76 "Parse FILE and return two values, the list of supported X11-KEYMAP-MODEL
77 and X11-KEYMAP-LAYOUT records. FILE is an XML file from the X Keyboard
78 Configuration Database, describing possible XKB configurations."
84 (description ,description)
88 (description description))]))
93 ;; According to xbd-rules DTD, the definition of a
94 ;; configItem is: <!ELEMENT configItem
95 ;; (name,shortDescription*,description*,vendor?,
96 ;; countryList?,languageList?,hwList?)>
98 ;; shortDescription and description are optional elements
99 ;; but sxml-match does not support default values for
100 ;; elements (only attributes). So to avoid writing as many
101 ;; patterns as existing possibilities, gather all the
102 ;; remaining elements but name in REST-VARIANT.
109 (assoc-ref rest-variant 'description))))]))
117 (variantList ,[variant -> v] ...))
121 (assoc-ref rest-layout 'description)))
122 (variants (list v ...)))]
130 (assoc-ref rest-layout 'description)))
133 (let ((sxml (call-with-input-file file
135 (xml->sxml port #:trim-whitespace? #t)))))
142 (modelList ,[model -> m] ...)
143 (layoutList ,[layout -> l] ...)
149 (values models layouts)))))
151 (define (kmscon-update-keymap model layout variant)
152 (let ((keymap-file (getenv "KEYMAP_UPDATE")))
153 (unless (and keymap-file
154 (file-exists? keymap-file))
155 (error "Unable to locate keymap update file"))
157 (call-with-output-file keymap-file
165 (format port variant)