aboutsummaryrefslogtreecommitdiff
path: root/gnu/system/keyboard.scm
blob: 5bd13a44be47804f124641186baa2437f15f4812 (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
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2019, 2020 Ludovic Courtès <ludo@gnu.org>
;;;
;;; 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 system keyboard)
  #:use-module (guix gexp)
  #:use-module ((gnu packages xorg)
                #:select (xkeyboard-config console-setup))
  #:use-module (srfi srfi-9 gnu)
  #:use-module (ice-9 match)
  #:export (keyboard-layout?
            keyboard-layout
            keyboard-layout-name
            keyboard-layout-variant
            keyboard-layout-model
            keyboard-layout-options

            keyboard-layout->console-keymap))

;;; Commentary:
;;;
;;; This module provides a data structure to represent keyboard layouts
;;; according to the XKB naming and classification (see the 'xkeyboard-config'
;;; package).
;;;
;;; Code:

(define-immutable-record-type <keyboard-layout>
  (%keyboard-layout name variant model options)
  keyboard-layout?
  (name      keyboard-layout-name)                ;string
  (variant   keyboard-layout-variant)             ;#f | string
  (model     keyboard-layout-model)               ;#f | string
  (options   keyboard-layout-options))            ;list of strings

(define* (keyboard-layout name #:optional variant
                          #:key model (options '()))
  "Return a new keyboard layout with the given NAME and VARIANT.

NAME must be a string such as \"fr\"; VARIANT must be a string such as
\"bepo\" or \"nodeadkeys\".  See the 'xkeyboard-config' package for valid
options."
  (%keyboard-layout name variant model options))

(define* (keyboard-layout->console-keymap layout
                                          #:key
                                          (xkeyboard-config xkeyboard-config))
  "Return a Linux console keymap file for LAYOUT, a <keyboard-layout> record.
Layout information is taken from the XKEYBOARD-CONFIG package."
  (define build
    (with-imported-modules '((guix build utils))
      #~(begin
          (use-modules (guix build utils)
                       (ice-9 popen)
                       (ice-9 match))

          (define pipe
            (open-pipe* OPEN_READ
                        #+(file-append console-setup "/bin/ckbcomp")
                        (string-append "-I"
                                       #+(file-append xkeyboard-config
                                                      "/share/X11/xkb"))
                        "-rules" "base"
                        #$@(match (keyboard-layout-model layout)
                             (#f      '())
                             (model   `("-model" ,model)))
                        #$(keyboard-layout-name layout)
                        #$(or (keyboard-layout-variant layout)
                              "")
                        #$(string-join (keyboard-layout-options layout) ",")))

          (call-with-output-file #$output
            (lambda (output)
              (dump-port pipe output)))

          ;; Note: ckbcomp errors out when the layout name is unknown, but
          ;; merely emits a warning when the variant is unknown.
          (unless (zero? (close-pipe pipe))
            (error "failed to create console keymap for keyboard layout"
                   #$(keyboard-layout-name layout))))))

  (computed-file (string-append "console-keymap."
                                (string-map (match-lambda
                                              (#\, #\-)
                                              (chr chr))
                                            (keyboard-layout-name layout)))
                 build))
1e2f73bf136c6fe0336672eb'>plainabout -rw-r--r--apl.scm2129logplainabout -rw-r--r--apr.scm4303logplainabout -rw-r--r--arcan.scm7629logplainabout -rw-r--r--aspell.scm13442logplainabout -rw-r--r--assembly.scm8248logplainabout -rw-r--r--astronomy.scm7138logplainabout -rw-r--r--attr.scm3169logplainabout -rw-r--r--audio.scm141012logplainabout -rw-r--r--augeas.scm2588logplainabout -rw-r--r--authentication.scm3466logplainabout -rw-r--r--autogen.scm3063logplainabout -rw-r--r--autotools.scm18623logplainabout d---------aux-files151logplain -rw-r--r--avahi.scm4237logplainabout -rw-r--r--avr.scm7146logplainabout -rw-r--r--axoloti.scm16160logplainabout -rw-r--r--backup.scm43175logplainabout -rw-r--r--base.scm58836logplainabout -rw-r--r--bash.scm15925logplainabout -rw-r--r--batik.scm8803logplainabout -rw-r--r--bdw-gc.scm4741logplainabout -rw-r--r--benchmark.scm7275logplainabout -rw-r--r--bioconductor.scm46858logplainabout -rw-r--r--bioinformatics.scm584829logplainabout -rw-r--r--bison.scm2137logplainabout -rw-r--r--bittorrent.scm20317logplainabout -rw-r--r--boost.scm10122logplainabout -rw-r--r--bootloaders.scm37525logplainabout -rw-r--r--bootstrap.scm25228logplainabout d---------bootstrap195logplain -rw-r--r--build-tools.scm11754logplainabout -rw-r--r--busybox.scm5927logplainabout -rw-r--r--c.scm11433logplainabout -rw-r--r--calcurse.scm3487logplainabout -rw-r--r--calendar.scm8568logplainabout -rw-r--r--ccache.scm2447logplainabout -rw-r--r--cdrom.scm35301logplainabout -rw-r--r--certs.scm8919logplainabout -rw-r--r--check.scm84344logplainabout -rw-r--r--chemistry.scm14249logplainabout -rw-r--r--chez.scm27792logplainabout -rw-r--r--chromium.scm31261logplainabout -rw-r--r--ci.scm13560logplainabout -rw-r--r--cinnamon.scm3246logplainabout -rw-r--r--clojure.scm12371logplainabout -rw-r--r--cluster.scm3506logplainabout -rw-r--r--cmake.scm7868logplainabout -rw-r--r--cobol.scm2997logplainabout -rw-r--r--code.scm29395logplainabout -rw-r--r--commencement.scm46490logplainabout -rw-r--r--compression.scm79501logplainabout -rw-r--r--compton.scm4113logplainabout -rw-r--r--conky.scm3311logplainabout -rw-r--r--connman.scm6907logplainabout -rw-r--r--cook.scm3594logplainabout -rw-r--r--coq.scm21831logplainabout -rw-r--r--cpio.scm2038logplainabout -rw-r--r--cpp.scm10891logplainabout -rw-r--r--cppi.scm1775logplainabout -rw-r--r--cran.scm379847logplainabout -rw-r--r--cross-base.scm22566logplainabout -rw-r--r--crypto.scm41108logplainabout -rw-r--r--cryptsetup.scm5257logplainabout -rw-r--r--cups.scm32565logplainabout -rw-r--r--curl.scm10928logplainabout -rw-r--r--cyrus-sasl.scm3020logplainabout -rw-r--r--databases.scm112050logplainabout -rw-r--r--datamash.scm1957logplainabout -rw-r--r--datastructures.scm9962logplainabout -rw-r--r--dav.scm4639logplainabout -rw-r--r--dbm.scm6858logplainabout -rw-r--r--dc.scm2233logplainabout -rw-r--r--debian.scm8225logplainabout -rw-r--r--debug.scm17257logplainabout -rw-r--r--dejagnu.scm3510logplainabout -rw-r--r--dico.scm3527logplainabout -rw-r--r--dictionaries.scm16497logplainabout -rw-r--r--digest.scm2346logplainabout -rw-r--r--direct-connect.scm2610logplainabout -rw-r--r--disk.scm32360logplainabout -rw-r--r--display-managers.scm14879logplainabout -rw-r--r--django.scm35994logplainabout -rw-r--r--djvu.scm2064logplainabout -rw-r--r--dlang.scm15144logplainabout -rw-r--r--dns.scm32836logplainabout -rw-r--r--docbook.scm11877logplainabout -rw-r--r--docker.scm25174logplainabout -rw-r--r--documentation.scm10064logplainabout -rw-r--r--dunst.scm3159logplainabout -rw-r--r--dvtm.scm2311logplainabout -rw-r--r--easyrpg.scm4379logplainabout -rw-r--r--ebook.scm12561logplainabout -rw-r--r--ed.scm2374logplainabout -rw-r--r--education.scm12680logplainabout -rw-r--r--efi.scm8323logplainabout -rw-r--r--electronics.scm10325logplainabout -rw-r--r--elf.scm9841logplainabout -rw-r--r--elixir.scm4143logplainabout -rw-r--r--emacs-xyz.scm523093logplainabout -rw-r--r--emacs.scm14913logplainabout -rw-r--r--embedded.scm49193logplainabout -rw-r--r--emulators.scm55121logplainabout -rw-r--r--enchant.scm3655logplainabout -rw-r--r--engineering.scm81067logplainabout -rw-r--r--enlightenment.scm20120logplainabout -rw-r--r--entr.scm2790logplainabout -rw-r--r--erlang.scm9477logplainabout -rw-r--r--fabric-management.scm6976logplainabout -rw-r--r--fcitx.scm5006logplainabout -rw-r--r--figlet.scm1797logplainabout -rw-r--r--file-systems.scm13147logplainabout -rw-r--r--file.scm2387logplainabout -rw-r--r--finance.scm39965logplainabout -rw-r--r--firmware.scm21717logplainabout -rw-r--r--flashing-tools.scm18786logplainabout -rw-r--r--flex.scm3606logplainabout -rw-r--r--fltk.scm6098logplainabout -rw-r--r--fonts.scm59103logplainabout -rw-r--r--fontutils.scm30130logplainabout -rw-r--r--forth.scm2434logplainabout -rw-r--r--fpga.scm13825logplainabout -rw-r--r--freedesktop.scm49432logplainabout -rw-r--r--freeipmi.scm2072logplainabout -rw-r--r--fribidi.scm1891logplainabout -rw-r--r--ftp.scm10956logplainabout -rw-r--r--fvwm.scm3296logplainabout -rw-r--r--game-development.scm53005logplainabout -rw-r--r--games.scm254786logplainabout -rw-r--r--gawk.scm3785logplainabout -rw-r--r--gcal.scm2889logplainabout -rw-r--r--gcc.scm43732logplainabout -rw-r--r--gd.scm6817logplainabout -rw-r--r--gdb.scm4600logplainabout -rw-r--r--genimage.scm8251logplainabout -rw-r--r--geo.scm34480logplainabout -rw-r--r--gettext.scm9126logplainabout -rw-r--r--ghostscript.scm15277logplainabout -rw-r--r--gimp.scm15312logplainabout -rw-r--r--gkrellm.scm2451logplainabout -rw-r--r--gl.scm30703logplainabout -rw-r--r--glib.scm35313logplainabout -rw-r--r--gnome.scm295830logplainabout -rw-r--r--gnu-doc.scm4109logplainabout -rw-r--r--gnu-pw-mgr.scm2378logplainabout -rw-r--r--gnucash.scm13973logplainabout -rw-r--r--gnunet.scm15014logplainabout -rw-r--r--gnupg.scm42503logplainabout -rw-r--r--gnustep.scm11910logplainabout -rw-r--r--gnuzilla.scm49744logplainabout -rw-r--r--gobby.scm7921logplainabout -rw-r--r--golang.scm144166logplainabout -rw-r--r--gperf.scm2354logplainabout -rw-r--r--gprolog.scm2742logplainabout -rw-r--r--gps.scm9000logplainabout -rw-r--r--graph.scm8572logplainabout -rw-r--r--graphics.scm34395logplainabout -rw-r--r--graphviz.scm13810logplainabout -rw-r--r--groff.scm8413logplainabout -rw-r--r--groovy.scm47230logplainabout -rw-r--r--gsasl.scm4640logplainabout -rw-r--r--gstreamer.scm18464logplainabout -rw-r--r--gtk.scm68958logplainabout -rw-r--r--guile-wm.scm6932logplainabout -rw-r--r--guile-xyz.scm83251logplainabout -rw-r--r--guile.scm25781logplainabout -rw-r--r--gv.scm3247logplainabout -rw-r--r--gxmessage.scm2352logplainabout -rw-r--r--ham-radio.scm3231logplainabout -rw-r--r--hardware.scm11664logplainabout -rw-r--r--haskell-check.scm30571logplainabout -rw-r--r--haskell-crypto.scm29004logplainabout -rw-r--r--haskell-web.scm46883logplainabout -rw-r--r--haskell.scm437918logplainabout -rw-r--r--hexedit.scm3222logplainabout -rw-r--r--hugs.scm3688logplainabout -rw-r--r--hurd.scm13091logplainabout -rw-r--r--ibus.scm27369logplainabout -rw-r--r--icu4c.scm4421logplainabout -rw-r--r--idris.scm11486logplainabout -rw-r--r--idutils.scm2816logplainabout -rw-r--r--image-processing.scm20297logplainabout -rw-r--r--image-viewers.scm16805logplainabout -rw-r--r--image.scm64324logplainabout -rw-r--r--imagemagick.scm9406logplainabout -rw-r--r--inklingreader.scm2239logplainabout -rw-r--r--inkscape.scm3474logplainabout -rw-r--r--ipfs.scm12732logplainabout -rw-r--r--irc.scm18342logplainabout -rw-r--r--iso-codes.scm4113logplainabout -rw-r--r--java-compression.scm13337logplainabout -rw-r--r--java-maths.scm3552logplainabout -rw-r--r--java.scm470430logplainabout -rw-r--r--javascript.scm19434logplainabout -rw-r--r--jemalloc.scm3218logplainabout -rw-r--r--jose.scm1999logplainabout -rw-r--r--jrnl.scm2394logplainabout