aboutsummaryrefslogtreecommitdiffstats
path: root/oni/home/services/xmodmap.scm
blob: a4dacdeb3dbab375a558641757ba14759ce2d99e (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
(define-module (oni home services xmodmap)
  #:use-module (gnu services configuration)
  #:use-module (gnu packages xorg)
  #:use-module (gnu home services)
  #:use-module (gnu home services shepherd)
  #:use-module (gnu home services utils)
  #:use-module (guix packages)
  #:use-module (guix gexp)

  #:export (home-xmodmap-service-type
            home-xmodmap-configuration))

(define-configuration/no-serialization home-xmodmap-configuration
  (package
   (package xmodmap)
   "Package to use for setting Xmodmap")
  (auto-start?
   (boolean #t)
   "Should xmodmap be started automatically")
  (pointer
   (list '())
   "List of numbers indicating the order of numbers")
  (extra
   (text-config '())
   "Any other configuration settings."))

(define (serialize-xmodmap-config config)
  (let ((pointer (home-xmodmap-configuration-pointer config)))
    (string-append
     (if pointer
         (string-append "pointer = " (string-join (map number->string pointer) " ") "\n\n")
         "")
     (string-join (home-xmodmap-configuration-extra config) "\n" 'suffix))))

(define (xmodmap-home-config-file config)
  (mixed-text-file
   "Xmodmap"
   (serialize-xmodmap-config config)))

(define (add-xmodmap-packages config)
  (list (home-xmodmap-configuration-package config)))

(define (home-xmodmap-shepherd-service config)
  (list
   (shepherd-service
    (documentation "Start Xmodmap")
    (provision '(xmodmap))
    (auto-start? (home-xmodmap-configuration-auto-start? config))
    (one-shot? #t)
    (start
     #~(make-forkexec-constructor
        '(#$(file-append xmodmap "/bin/xmodmap")
          #$(xmodmap-home-config-file config)))))))

(define home-xmodmap-service-type
  (service-type
   (name 'home-xmodmap)
   (extensions
    (list (service-extension
           home-profile-service-type
           add-xmodmap-packages)
          (service-extension
           home-shepherd-service-type
           home-xmodmap-shepherd-service)))
   (compose identity)
   (default-value (home-xmodmap-configuration))
   (description "Install and configure Xmodmap.")))