From f5d579193651a8bf1d61a17c5c8821883f337061 Mon Sep 17 00:00:00 2001 From: Rutherther Date: Fri, 21 Mar 2025 20:57:31 +0100 Subject: [PATCH] fix: wayland display service, add x wayland display service --- ruther/home/services/kanshi.scm | 30 +++++---- ruther/home/services/wayland.scm | 103 ++++++++++++++++++++++++++----- 2 files changed, 107 insertions(+), 26 deletions(-) diff --git a/ruther/home/services/kanshi.scm b/ruther/home/services/kanshi.scm index 13bde87..334f33d 100644 --- a/ruther/home/services/kanshi.scm +++ b/ruther/home/services/kanshi.scm @@ -36,12 +36,15 @@ (documentation "Run the kanshi daemon for managing outputs.") (provision '(kanshi)) (requirement '(wayland-display)) - (start #~(make-forkexec-constructor - (list #$(file-append - (home-kanshi-configuration-kanshi config) - "/bin/kanshi") - "-c" - #$(serialize-kanshi-configuration (home-kanshi-configuration-config config))))) + (modules %display-environ-modules) + (start #~(lambda _ + (fork+exec-command + (list #$(file-append + (home-kanshi-configuration-kanshi config) + "/bin/kanshi") + "-c" + #$(serialize-kanshi-configuration (home-kanshi-configuration-config config))) + #:environment-variables #$%wayland-display-environ))) (stop #~(make-kill-destructor))))) (define-public home-kanshi-service-type @@ -64,12 +67,15 @@ (documentation "Run the swayidle daemon for managing commands executed when idle.") (provision '(swayidle)) (requirement '(wayland-display)) - (start #~(make-forkexec-constructor - (list #$(file-append - (home-swayidle-configuration-swayidle config) - "/bin/swayidle") - "-wC" - #$(serialize-swayidle-configuration (home-swayidle-configuration-config config))))) + (modules %display-environ-modules) + (start #~(lambda _ + (fork+exec-command + (list #$(file-append + (home-swayidle-configuration-swayidle config) + "/bin/swayidle") + "-wC" + #$(serialize-swayidle-configuration (home-swayidle-configuration-config config))) + #:environment-variables #$%wayland-display-environ))) (stop #~(make-kill-destructor))))) (define-public home-swayidle-service-type diff --git a/ruther/home/services/wayland.scm b/ruther/home/services/wayland.scm index 8c7538a..2d9c122 100644 --- a/ruther/home/services/wayland.scm +++ b/ruther/home/services/wayland.scm @@ -17,9 +17,19 @@ home-network-manager-applet-configuration home-blueman-applet-configuration home-waybar-configuration - home-gammastep-configuration)) + home-gammastep-configuration -(define wayland-display-environ + %display-environ-modules + %wayland-display-environ + %x-display-environ)) + +(define %display-environ-modules + '((srfi srfi-1) + (srfi srfi-26) + (shepherd service) + (shepherd support))) + +(define %wayland-display-environ #~(begin (use-modules (shepherd service) (shepherd support)) @@ -31,6 +41,55 @@ (remove (cut string-prefix? "WAYLAND_DISPLAY=" <>) (default-environment-variables)))))) +(define %x-display-environ + #~(begin + (use-modules (shepherd service) + (shepherd support)) + (let* ((display-service (lookup-service 'x-display)) + (display (or (and display-service + (service-running-value display-service)) + "FAILED_TO_OBTAIN"))) + (cons (string-append "DISPLAY=" display) + (remove (cut string-prefix? "DISPLAY=" <>) + (default-environment-variables)))))) + +(define %xwayland-display-environ + #~(begin + (use-modules (shepherd service) + (shepherd support)) + (let* ((display-service (lookup-service 'x-display)) + (wayland-display-service (lookup-service 'wayland-display)) + (wayland-display (or (and wayland-display-service + (service-running-value wayland-display-service)) + "FAILED_TO_OBTAIN")) + (display (or (and display-service + (service-running-value display-service)) + "FAILED_TO_OBTAIN"))) + (cons* (string-append "DISPLAY=" display) + (string-append "WAYLAND_DISPLAY=" wayland-display) + (remove (lambda (var) (or (string-prefix? "DISPLAY=" var) + (string-prefix? "WAYLAND_DISPLAY=" var))) + (default-environment-variables)))))) + +(define (x-display-shepherd-service config) + (list + (shepherd-service + (documentation "Sets X_DISPLAY to argument passed in. +This should be called from a x compositor like this: `herd start x-display $DISPLAY`") + (provision '(x-display)) + (auto-start? #f) + (start #~(lambda (x-display) x-display)) + (stop #~(lambda _ #f))))) + +(define-public home-x-display-service-type + (service-type + (name 'home-x-display) + (description "A service to set DISPLAY environment variable inside of the shepherd process.") + (default-value #f) + (extensions + (list (service-extension home-shepherd-service-type + x-display-shepherd-service))))) + (define (wayland-display-shepherd-service config) (list (shepherd-service @@ -50,6 +109,15 @@ This should be called from a wayland compositor like this: `herd start wayland-d (list (service-extension home-shepherd-service-type wayland-display-shepherd-service))))) +(define-public home-x-display-service-type + (service-type + (name 'home-wayland-display) + (description "A service to set DISPLAY environment variable inside of the shepherd process.") + (default-value #f) + (extensions + (list (service-extension home-shepherd-service-type + x-display-shepherd-service))))) + (define (wlr-services-shepherd-service services) (list @@ -58,15 +126,20 @@ This should be called from a wayland compositor like this: `herd start wayland-d (provision '(wlr-services)) (auto-start? #f) (start - #~(lambda* (#:optional (wayland-display #f)) + #~(lambda* (#:optional (wayland-display #f) (x-display #f)) (use-modules (shepherd service) (shepherd support)) - (let ((display-service (lookup-service 'wayland-display))) + (let ((display-service (lookup-service 'wayland-display)) + (x-display-service (lookup-service 'x-display))) (when (and wayland-display (service-stopped? display-service)) (start-service display-service wayland-display)) + (when (and x-display + (service-stopped? x-display-service)) + (start-service x-display-service + x-display)) (if (service-running? display-service) (for-each (lambda (service) @@ -98,6 +171,8 @@ This should be called from a wayland compositor like this: `herd start wayland-d (extensions (list (service-extension home-shepherd-service-type wlr-services-shepherd-service) + (service-extension home-x-display-service-type + (const #f)) (service-extension home-wayland-display-service-type (const #f)))))) @@ -112,17 +187,14 @@ This should be called from a wayland compositor like this: `herd start wayland-d (requirement '(wayland-display dbus)) (provision '(emacs)) (auto-start? #f) - (modules '((srfi srfi-1) - (srfi srfi-26) - (shepherd service) - (shepherd support))) + (modules %display-environ-modules) (start #~(lambda _ (fork+exec-command (cons* #$(file-append (home-emacs-configuration-emacs config) "/bin/emacs") "--fg-daemon" '#$(home-emacs-configuration-extra-arguments config)) - #:environment-variables #$wayland-display-environ))) + #:environment-variables #$%xwayland-display-environ))) (stop #~(make-kill-destructor))))) (define-public home-emacs-service-type @@ -215,11 +287,14 @@ ie. to get manager running when applet is clicked on.") (requirement '(dbus)) (provision '(waybar)) (auto-start? #f) - (start #~(make-forkexec-constructor - (cons* #$(file-append - (home-waybar-configuration-waybar config) - "/bin/waybar") - '#$(home-waybar-configuration-extra-arguments config)))) + (modules %display-environ-modules) + (start #~(lambda _ + (fork+exec-command + (cons* #$(file-append + (home-waybar-configuration-waybar config) + "/bin/waybar") + '#$(home-waybar-configuration-extra-arguments config)) + #:environment-variables #$%wayland-display-environ))) (stop #~(make-kill-destructor))))) (define-public home-waybar-service-type -- 2.48.1