aboutsummaryrefslogtreecommitdiffstats
path: root/oni/home/services/unclutter.scm
blob: 7794256afb8262c9e96fd42de451a5446d945d75 (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
(define-module (oni home services unclutter)
  #:use-module (gnu services configuration)
  #:use-module (gnu packages xdisorg)
  #: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-unclutter-service-type
            home-unclutter-configuration))

(define-configuration home-unclutter-configuration
  (package
   (package unclutter)
   "Which package to use to provide unclutter.")
  (timeout
   (integer 5)
   "The number of seconds after which the cursor should be hidden.")
  (jitter
   (integer 0)
   "Ignore cursor movements within this radius.")
  (exclude-root
   (boolean #f)
   "Don't hide the cursor if it is over the root window.")
  (ignore-scrolling
   (boolean #f)
   "Don't make the cursor appear when you scroll.")
  (ignore-buttons
   (list '())
   "Don't make the cursor appear when these buttons are used.")
  (hide-on-touch
   (boolean #f)
   "Hide the cursor on touch events.")
  (start-hidden
   (boolean #f)
   "Hide the cursor on startup.")
  (no-serialization))

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

(define (home-unclutter-shepherd-service config)
  (list
   (shepherd-service
    (documentation "Start unclutter")
    (provision '(unclutter))
    (auto-start? #t)
    (start
     #~(make-forkexec-constructor
        '#$(append
            (delete #f
                   (list (file-append (home-unclutter-configuration-package config) "/bin/unclutter")
                          "--timeout" (number->string (home-unclutter-configuration-timeout config))
                          "--jitter" (number->string (home-unclutter-configuration-jitter config))
                          (and (home-unclutter-configuration-exclude-root config) "--exclude-root")
                          (and (home-unclutter-configuration-ignore-scrolling config) "--ignore-scrolling")
                          (and (home-unclutter-configuration-hide-on-touch config) "--hide-on-touch")
                          (and (home-unclutter-configuration-start-hidden config) "--start-hidden")))
            (let ((buttons (home-unclutter-configuration-ignore-buttons config)))
              (if (> (length buttons) 0)
                  (list
                   "--ignore-buttons"
                   (string-join (map (λ (i) (format #f "~s" i)) buttons) ","))
                  '())))
        #:log-file (format #f "~a/.local/var/log/unclutter.log" (getenv "HOME"))))
    (stop #~(make-kill-destructor)))))

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