diff options
Diffstat (limited to 'sigils/home')
-rw-r--r-- | sigils/home/services/hyprland.scm | 79 |
1 files changed, 76 insertions, 3 deletions
diff --git a/sigils/home/services/hyprland.scm b/sigils/home/services/hyprland.scm index 645c60c..c670b04 100644 --- a/sigils/home/services/hyprland.scm +++ b/sigils/home/services/hyprland.scm @@ -84,7 +84,6 @@ ,@(serialize-term rterm) "\n")))) - (append-map serialize-config var)) ;;; Hyprland @@ -226,7 +225,10 @@ "Additional plugins to load with Hyprland.") (config (hypr-config %default-hyprland-config) - "Hyprland configuration")) + "Hyprland configuration") + (tries + (number 10) + "Polls Hyprland up to TRIES.")) (define (hyprland-configuration->file config) `(("hypr/hyprland.conf" @@ -243,6 +245,74 @@ #~(begin (system* (string-append #+hyprland "/bin/hyprctl") "reload"))) +(define (hyprland-shepherd-service config) + (list (shepherd-service + (provision '(hyprland + wayland-display)) + (modules '((ice-9 ftw) + (ice-9 match) + (ice-9 regex) + (srfi srfi-1))) + (start + #~(lambda* (#:optional (instance (getenv "HYPRLAND_INSTANCE_SIGNATURE"))) + (define tries #$(home-hyprland-configuration-tries config)) + (define xdg-runtime-directory + (or (getenv "XDG_RUNTIME_DIR") + (string-append "/run/user" (getuid)))) + + (define hypr-directory + (string-append xdg-runtime-directory "/hypr")) + + (define (socket? directory regex) + (find (match-lambda + ((or "." "..") #f) + (name + (let ((name (in-vicinity directory + name))) + (and (string-match regex name) + (access? name O_RDWR))))) + (or (scandir directory) '()))) + + (define (find-instance tries) + ;; Wait for an accessible socket to show up in + ;; XDG-RUNTIME-DIRECTORY, up to TRIES tries. + (let loop ((attempts tries)) + + (define instance-signature + (socket? hypr-directory "_[0-9]+_[0-9]+")) + + (if instance-signature + (begin + (format #t "Hyprland instance found at ~s.~%" + instance-signature) + instance-signature) + (if (zero? attempts) + (begin + (format (current-error-port) + "Hyprland did not show up; \ +giving up.\n") + #f) + (begin + (sleep 1) + (loop (- attempts 1))))))) + + (let ((instance (or instance (find-instance tries)))) + (when instance + ;; Note: 'make-forkexec-constructor' calls take their + ;; default #:environment-variables value before this service + ;; is started and are thus unaffected by the 'setenv' call + ;; below. Users of this service have to explicitly query + ;; its value. + (setenv "HYPRLAND_INSTANCE_SIGNATURE" instance) + (setenv "WAYLAND_DISPLAY" + (socket? xdg-runtime-directory "wayland-[0-9]+"))) + instance))) + (stop #~(lambda (_) + (unsetenv "HYPRLAND_INSTANCE_SIGNATURE") + (unsetenv "WAYLAND_DISPLAY") + #f)) + (respawn? #f)))) + (define home-hyprland-service-type (service-type (name 'home-hyprland) @@ -252,7 +322,10 @@ hyprland-configuration->file) (service-extension home-activation-service-type - (const hyprctl-reload-gexp)))) + (const hyprctl-reload-gexp)) + (service-extension + home-shepherd-service-type + hyprland-shepherd-service))) (compose identity) (default-value (home-hyprland-configuration)) (description "Configure Hyprland by providing @file{~/.config/hypr/hyprland.conf}"))) |