summaryrefslogtreecommitdiff
path: root/sigils/home/services/hyprland.scm
blob: 79a560e0f2df057965766ee4a4cdf5ba53d1d231 (plain) (blame)
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
(define-module (sigils home services hyprland)
  #:use-module (guix gexp)
  #:use-module (guix packages)
  #:use-module (gnu home services)
  #:use-module (gnu services configuration)
  #:use-module (sigils packages hyprland)

  #:use-module (srfi srfi-1)
  #:use-module (ice-9 match)

  #:export (hypr-config?

            %default-hyprland-config

            home-hyprland-configuration
            home-hyprland-service-type))

(define hypr-config? list?)

(define (serialize-hypr-config var)
  (define (align nestness)
    (apply string-append
           (map (const "    ") (iota nestness))))

  (define (serialize-term term)
    (match term
      (#t "true")
      (#f "false")
      ((? symbol? e) (symbol->string e))
      ((? number? e) (number->string e))
      ((? string? e) e)
      (() "")
      (('rgba color) (format #f "rgba(~a)" (symbol->string color)))
      ;; Turn a list into a series of comma-separated terms
      ((e lst ...)
       (apply string-append
              `(,(serialize-term e)
                ,@(append-map
                   (lambda (n)
                     `(", " ,(serialize-term n))) lst))))
      (e e)))

  (define* (serialize-config
            config #:optional (nestness 0))
    (match config
      ((term ((expressions ...) ...))
       (apply string-append
              `(,(align nestness) ,(serialize-term term) " {\n"
                ,@(map (lambda (e)
                         ;; (serialize-config e (1+ nestness))
                         (serialize-config e (1+ nestness)))
                       expressions)
                ,(align nestness) "}\n")))

      ((term . rest)
       (format #f "~a~a = ~a\n"
               (align nestness)
               term
               (serialize-term rest)))))

  (apply string-append
         (map serialize-config var)))

(define %default-hyprland-config
  '(($terminal kitty)
    ($fileManager 'dolphin)
    ($menu "wofi --show drun")
    ($mainMod "SUPER")
    ;; autogenerated
    (autogenerated 0)
    ;; monitors
    (monitor () preferred auto auto)
    ;; general
    (general ((gaps_in 5)
              (gaps_out 20)
              (border_size 2)
              (col.active_border "rgba(33ccffee) rgba(00ff99ee) 45deg") ;; TODO
              (col.inactive_border (rgba 595959aa))
              (resize_on_border #f)
              (allow_tearing #f)
              (layout dwindle)))
    ;; decoration
    (decoration ((rounding 10)
                 (active_opacity 1.0)
                 (inactive_opacity 1.0)
                 (drop_shadow #t)
                 (shadow_range 4)
                 (shadow_render_power 3)
                 (col.shadow (rgba 1a1a1aee))
                 (blur ((enabled #t)
                        (size 3)
                        (passes 1)
                        (vibrancy 0.1696)))))
    ;; animations
    (animations ((enabled #t)
                 (bezier myBezier 0.05 0.9 0.1 1.05)
                 (animation windows 1 7 myBezier)
                 (animation windowsOut 1 7 default "popin 80%")
                 (animation border 1 10 default)
                 (animation borderangle 1 8 default)
                 (animation fade 1 7 default)
                 (animation workspaces 1 6 default)))
    ;; dwindle
    (dwindle ((pseudotile #t)
              (preserve_split #t)))
    ;; master
    (master ((new_status master)))
    ;; misc
    (misc ((force_default_wallpaper -1)
           (disable_hyprland_logo #f)))
    ;; input
    (input ((kb_layout us)
            (kb_variant)
            (kb_model)
            (kb_options)
            (kb_rules)
            (follow_mouse 1)
            (sensitivity 0)
            (touchpad ((natural_scroll #f)))))
    ;; gestures
    (gestures ((workspace_swipe #f)))
    ;; device
    (device ((name epic-mouse-v1)
             (sensitivity -0.5)))
    ;; binds
    (bind $mainMod Q exec $terminal)
    (bind $mainMod C killactive ())
    (bind $mainMod M exit ())
    (bind $mainMod E exec $fileManager)
    (bind $mainMod V togglefloating ())
    (bind $mainMod R exec $menu)
    (bind $mainMod P pseudo ())
    (bind $mainMod J togglesplit ())
    (bind $mainMod left movefocus l)
    (bind $mainMod right movefocus r)
    (bind $mainMod up movefocus u)
    (bind $mainMod down movefocus d)
    (bind $mainMod 1 workspace 1)
    (bind $mainMod 2 workspace 2)
    (bind $mainMod 3 workspace 3)
    (bind $mainMod 4 workspace 4)
    (bind $mainMod 5 workspace 5)
    (bind $mainMod 6 workspace 6)
    (bind $mainMod 7 workspace 7)
    (bind $mainMod 8 workspace 8)
    (bind $mainMod 9 workspace 9)
    (bind $mainMod 0 workspace 10)
    (bind "$mainMod SHIFT" 1 movetoworkspace 1)
    (bind "$mainMod SHIFT" 2 movetoworkspace 2)
    (bind "$mainMod SHIFT" 3 movetoworkspace 3)
    (bind "$mainMod SHIFT" 4 movetoworkspace 4)
    (bind "$mainMod SHIFT" 5 movetoworkspace 5)
    (bind "$mainMod SHIFT" 6 movetoworkspace 6)
    (bind "$mainMod SHIFT" 7 movetoworkspace 7)
    (bind "$mainMod SHIFT" 8 movetoworkspace 8)
    (bind "$mainMod SHIFT" 9 movetoworkspace 9)
    (bind "$mainMod SHIFT" 0 movetoworkspace 10)
    (bind $mainMod S togglespecialworkspace magic)
    (bind "$mainMod SHIFT" S movetoworkspace special:magic)
    (bind $mainMod mouse_down workspace e+1)
    (bind $mainMod mouse_up workspace e-1)
    (bindm $mainMod mouse:272 movewindow)
    (bindm $mainMod mouse:273 resizewindow)
    (bindel () XF86AudioRaiseVolume exec "wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+")
    (bindel () XF86AudioLowerVolume exec "wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%-")
    (bindel () XF86AudioMute exec "wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle")
    (bindel () XF86AudioMicMute exec "wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle")
    (bindel () XF86MonBrightnessUp exec "brightnessctl s 10%+")
    (bindel () XF86MonBrightnessDown exec "brightnessctl s 10%-")
    (bindl () XF86AudioNext exec "playerctl next")
    (bindl () XF86AudioPause exec "playerctl play-pause")
    (bindl () XF86AudioPlay exec "playerctl play-pause")
    (bindl () XF86AudioPrev exec "playerctl previous")
    ;; windowrules
    (windowrulev2 "suppressevent maximize" class:.*)
    (windowrulev2 nofocus class:^$ title:^$ xwayland:1 floating:1 fullscreen:0 pinned:0)))

(define-configuration/no-serialization home-hyprland-configuration
  (plugins
   (list-of-packages '())
   "Additional plugins to load with Hyprland.")
  (config
   (hypr-config %default-hyprland-config)
   "Hyprland configuration"))

(define (hyprland-configuration->file config)
  `(("hypr/hyprland.conf"
     ,(apply
       mixed-text-file
       "hyprland-config"
       `(,@(append-map (lambda (plugin)
                         `("plugin = " ,plugin "/lib/lib" ,(package-name plugin) ".so\n"))
                       (home-hyprland-configuration-plugins config))
         ,(serialize-hypr-config
           (home-hyprland-configuration-config config)))))))

(define hyprctl-reload-gexp
  #~(begin
      (system* (string-append #+hyprland "/bin/hyprctl") "reload")))

(define home-hyprland-service-type
  (service-type
   (name 'home-hyprland)
   (extensions
    (list (service-extension
           home-xdg-configuration-files-service-type
           hyprland-configuration->file)
          (service-extension
           home-activation-service-type
           (const hyprctl-reload-gexp))))
   (compose identity)
   (default-value (home-hyprland-configuration))
   (description "Configure Hyprland by providing @file{~/.config/hypr/hyprland.conf}")))


(define-configuration/no-serialization home-hyprpaper-configuration
  (config
   (hypr-config '())
   "Hyprpaper configuration"))

(define (hyprpaper-configuration->file config)
  `(("hypr/hyprpaper.conf"
     ,(apply
       mixed-text-file
       "hyprpaper-config"
       (serialize-hypr-config
        (home-hyprpaper-configuration-config config))))))

(define home-hyprpaper-service-type
  (service-type
   (name 'home-hyprpaper)
   (extensions
    (list (service-extension
           home-xdg-configuration-files-service-type
           hyprpaper-configuration->file)))
   (compose identity)
   (default-value (home-hyprpaper-configuration))
   (description "Configure Hyprpaper by providing @file{~/.config/hypr/hyprpaper.conf}")))