aboutsummaryrefslogtreecommitdiffstats
path: root/oni/home/services/compton.scm
blob: a1aedf69b81ed58ce4636fb83c23218bf06db17f (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
(define-module (oni home services compton)
  #:use-module (gnu services configuration)
  #:use-module (gnu packages compton)
  #:use-module (gnu services 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)
  #:use-module (guix records)
  #:use-module (guix i18n)
  #:use-module (guix modules)
  #:use-module (guix diagnostics)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-26)
  #:use-module (ice-9 match)

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

;;; This module has been copied from
;;; https://github.com/nouun/jayu/blob/92ff6629da686f0ddc96a4d6cb2a657c76795bc6/jayu/home/services/xdisorg.scm
;;; With some slight modifications to make my configuration work.

(define-configuration/no-serialization home-picom-configuration
  (package
   (package picom)
   "Package to use for setting Picom")
  (config
   (alist '())
   ""))

(define (format-picom-list vals depth)
  (if (not (eq? vals '()))
      (let ((is-pair? (pair? (car vals))))
        (string-append
         (if is-pair? "{" "[")
         "\n  "
         (string-join
          (map (lambda (val)
                (if (pair? val)
                    (string-append
                     (maybe-object->string (car val))
                     " = " (format-picom-value (cdr val) (+ depth 1))
                     (if (> depth 0) "," ";"))
                    (format-picom-value val (+ depth 1))))
               vals)
          (string-append
           (if is-pair? "" ",")
           "\n  "))
         "\n"
         (if is-pair? "}" "]")))
      "[]"))

(define (format-picom-value val depth)
  (cond
   ((list? val)
    (format-picom-list (car val) (+ depth 1)))
   ((pair? val)
    (format-picom-value `(,(car val)) (+ depth 1)))
   ((boolean? val)
    (if val "true" "false"))
   ((or (symbol? val) (number? val))
    (maybe-object->string val))
   ((string? val)
    (string-append "\"" val "\""))
   (else val)))

(define (format-picom-config key val)
  (list (string-append (maybe-object->string key)
                       " = "
                       (format-picom-value val 0)
                       ";\n")))

(define (serialize-picom-config config)
  (generic-serialize-alist append format-picom-config config))

(define (home-picom-config-file config)
  (apply mixed-text-file
     "picom.conf"
     (serialize-picom-config
       (home-picom-configuration-config config))))

(define (home-picom-files-service config)
  `(("config/picom/picom.conf"
     ,(home-picom-config-file config))))

(define (home-picom-profile-service config)
  (list (home-picom-configuration-package config)))

(define (home-picom-shepherd-service config)
  (list
    (shepherd-service
      (documentation "Start Picom")
      (provision '(picom))
      ;; TODO: Figure out how to start when x starts
      ;(requirement '(xorg-server))
      (auto-start? #t)
      (start
       #~(make-forkexec-constructor
          (list #$(file-append (home-picom-configuration-package config) "/bin/picom")
                "--config" #$(home-picom-config-file config))
          #:log-file (format #f "~a/.local/var/log/picom.log" (getenv "HOME"))))
      (stop #~(make-kill-destructor)))))

(define (home-picom-extension old-config extension-configs)
  (match old-config
    (($ <home-picom-configuration> _ package* config*)
     (home-picom-configuration
      (package package*)
      (config (append config*
                      (append-map home-picom-configuration-config
                                  extension-configs)))))))

(define home-picom-service-type
  (service-type (name 'home-picom)
                (extensions
                 (list (service-extension
                        home-files-service-type
                        home-picom-files-service)
                       (service-extension
                        home-profile-service-type
                        home-picom-profile-service)
                       (service-extension
                        home-shepherd-service-type
                        home-picom-shepherd-service)))
                (compose concatenate)
                (extend home-picom-extension)
                (default-value (home-picom-configuration))
                (description "Configure Picom")))

(define (generate-home-picom-documentation)
  (generate-documentation
   `((home-picom-configuration
      ,home-picom-configuration-fields))
   'home-picom-configuration))