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 xkb-rules->models+layouts
50 kmscon-update-keymap))
52 (define-record-type* <x11-keymap-model>
53 x11-keymap-model make-x11-keymap-model
55 (name x11-keymap-model-name) ;string
56 (description x11-keymap-model-description)) ;string
58 (define-record-type* <x11-keymap-layout>
59 x11-keymap-layout make-x11-keymap-layout
61 (name x11-keymap-layout-name) ;string
62 (description x11-keymap-layout-description) ;string
63 (variants x11-keymap-layout-variants)) ;list of <x11-keymap-variant>
65 (define-record-type* <x11-keymap-variant>
66 x11-keymap-variant make-x11-keymap-variant
68 (name x11-keymap-variant-name) ;string
69 (description x11-keymap-variant-description)) ;string
71 (define (xkb-rules->models+layouts file)
72 "Parse FILE and return two values, the list of supported X11-KEYMAP-MODEL
73 and X11-KEYMAP-LAYOUT records. FILE is an XML file from the X Keyboard
74 Configuration Database, describing possible XKB configurations."
80 (description ,description)
84 (description description))]))
89 ;; According to xbd-rules DTD, the definition of a
90 ;; configItem is: <!ELEMENT configItem
91 ;; (name,shortDescription*,description*,vendor?,
92 ;; countryList?,languageList?,hwList?)>
94 ;; shortDescription and description are optional elements
95 ;; but sxml-match does not support default values for
96 ;; elements (only attributes). So to avoid writing as many
97 ;; patterns as existing possibilities, gather all the
98 ;; remaining elements but name in REST-VARIANT.
105 (assoc-ref rest-variant 'description))))]))
113 (variantList ,[variant -> v] ...))
117 (assoc-ref rest-layout 'description)))
118 (variants (list v ...)))]
126 (assoc-ref rest-layout 'description)))
129 (let ((sxml (call-with-input-file file
131 (xml->sxml port #:trim-whitespace? #t)))))
138 (modelList ,[model -> m] ...)
139 (layoutList ,[layout -> l] ...)
145 (values models layouts)))))
147 (define (kmscon-update-keymap model layout variant)
148 (let ((keymap-file (getenv "KEYMAP_UPDATE")))
149 (unless (and keymap-file
150 (file-exists? keymap-file))
151 (error "Unable to locate keymap update file"))
153 (call-with-output-file keymap-file
161 (format port variant)