~ruther/guix-config

ref: 533da78a46862b2d0620c6b2fbee11558f04345c guix-config/home/modules/ruther/home/dwl/scripts.scm -rw-r--r-- 3.2 KiB
533da78a — Rutherther feat(dwl): autostart apps and pin them to tags via custom rules 9 days ago
                                                                                
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
(define-module (ruther home dwl scripts)
  #:use-module (guix gexp)
  #:use-module (guix records)
  #:use-module (guix packages)
  #:use-module (ruther packages wayland)
  #:use-module (gnu packages admin)
  #:use-module (gnu packages glib)
  #:use-module (gnu packages xdisorg)
  #:use-module (gnu packages wm)
  #:use-module (gnu packages emacs)
  #:use-module (gnu packages networking)
  #:use-module (gnu packages gnome)
  #:use-module (gnu packages freedesktop)

  #:export
  (wlr-output
   wlr-randr-config
   swayidle-timeout
   swayidle-config

   start-dwl))

(define wlopm-all-screens-gexp
  #~(begin
      (use-modules
       (guix build utils)
       (ice-9 rdelim)
       (ice-9 popen))

      (define operation
        (car (cdr (program-arguments))))

      (define (first-word str)
        (car (string-split str #\space)))

      (let* ((wlopm (string-append #$wlopm "/bin/wlopm"))
             (port (open-input-pipe wlopm))
             (outputs (map first-word (string-split (string-trim-both (read-string port)) #\newline))))
        (close-pipe port)
        (for-each (lambda (output)
                    (invoke wlopm (string-append "--" operation) output))
                  outputs))))

(define wlopm-all-screens-bin-gexp
  (with-imported-modules '((guix build utils))
    #~(begin
        (use-modules (guix build utils))
        (mkdir-p (string-append #$output "/bin"))
        (symlink
         #$(program-file "wlopm-all-screens" wlopm-all-screens-gexp)
         (string-append #$output "/bin/wlopm-all-screens")))))


(define (dwl-startup-cmd-gexp waybar)
  #~(begin
      (use-modules (guix build utils)
                   (srfi srfi-34))

      (spawn (string-append #$dbus "/bin/dbus-update-activation-environment")
             '("dbus-update-activation-environment"
               "XDG_DESKTOP_PORTAL_DIR"
               "WAYLAND_DISPLAY"
               "XDG_CURRENT_DESKTOP"
               "DISPLAY"))

      ;; In case it has been started already, stop it
      (invoke
       (string-append #$shepherd "/bin/herd")
       "stop"
       "wlr-services"
       "no" ;; do not stop the child services.
       )
      ;; Start wlr-services now
      (invoke
       (string-append #$shepherd "/bin/herd")
       "start"
       "wlr-services"
       (getenv "WAYLAND_DISPLAY")
       (getenv "DISPLAY"))

      (system "librewolf &")
      (system "firefox &")
      (system "element-desktop &")
      (system "dev.vencord.Vesktop &")))

(define (start-dwl-gexp dwl waybar)
  #~(begin
      (use-modules (guix build utils))
      (setenv "XDG_CURRENT_DESKTOP" "wlroots")
      (setenv "XDG_BACKEND" "wayland")
      (setenv "QT_QPA_PLATFORM" "wayland;xcb")
      (setenv "MOZ_ENABLE_WAYLAND" "1")
      (setenv "_JAVA_AWT_WM_NONREPARENTING" "1")

      (execl (string-append #$dwl "/bin/dwl")
             "dwl"
              "-s" #$(program-file "dwl-startup-cmd" (dwl-startup-cmd-gexp waybar)))))

(define* (start-dwl #:key (dwl dwl-0.7) (waybar waybar))
  (program-file "start-dwl" (start-dwl-gexp dwl waybar)))

(define-public wlopm-all-screens
  (program-file "wlopm-all-screens" wlopm-all-screens-gexp))

(define-public wlopm-all-screens-bin
  (computed-file "wlopm-all-screens" wlopm-all-screens-bin-gexp))