M home/home-configuration.scm => home/home-configuration.scm +53 -1
@@ 21,7 21,8 @@
(ruther home dwl wm)
(ruther home dwl scripts)
(ruther home themes)
- (ruther home services gtk))
+ (ruther home services gtk)
+ (ruther home services kanshi))
(home-environment
;; Below is the list of packages that will show up in your
@@ 192,6 193,57 @@
("x-scheme-handler/https" . "librewolf.desktop")
("x-scheme-handler/unknown" . "librewolf.desktop")))))
+ (service home-kanshi-service-type
+ (home-kanshi-configuration
+ (config (kanshi-configuration
+ (profiles
+ (list
+ (kanshi-profile
+ (name "notebook")
+ (outputs
+ (list
+ (kanshi-output
+ (name "eDP-1")
+ (enable #t)))))
+ (kanshi-profile
+ (name "docked")
+ (outputs
+ (list
+ (kanshi-output
+ (name "eDP-1")
+ (enable #f))
+ (kanshi-output
+ (name "DP-9")
+ (position '(0 . 0))
+ (enable #t))
+ (kanshi-output
+ (name "DP-8")
+ (position '(3840 . 0))
+ (enable #t))
+ (kanshi-output
+ (name "DP-7")
+ (position '(1920 . 0))
+ (enable #t)))))
+ (kanshi-profile
+ (name "docked-alt")
+ (outputs
+ (list
+ (kanshi-output
+ (name "eDP-1")
+ (enable #f))
+ (kanshi-output
+ (name "DP-12")
+ (position '(0 . 0))
+ (enable #t))
+ (kanshi-output
+ (name "DP-11")
+ (position '(3840 . 0))
+ (enable #t))
+ (kanshi-output
+ (name "DP-10")
+ (position '(1920 . 0))
+ (enable #t)))))))))))
+
(service home-gpg-agent-service-type
(home-gpg-agent-configuration
(pinentry-program
A home/modules/ruther/home/services/kanshi.scm => home/modules/ruther/home/services/kanshi.scm +147 -0
@@ 0,0 1,147 @@
+(define-module (ruther home services kanshi)
+ #:use-module (guix gexp)
+ #:use-module (gnu packages wm)
+ #:use-module (gnu services)
+ #:use-module (gnu services configuration)
+ #:use-module (gnu services shepherd)
+ #:use-module (srfi srfi-26)
+ #:use-module (srfi srfi-1)
+ #:use-module (gnu home services)
+ #:use-module (gnu home services shepherd)
+ #:export (kanshi-configuration
+ kanshi-profile
+ kanshi-output
+
+ home-kanshi-configuration))
+
+(define-maybe string)
+(define-maybe cons)
+(define-maybe float)
+(define-maybe boolean)
+(define-maybe list-of-strings)
+(define-maybe position)
+
+(define (position? value)
+ (and
+ (pair? value)
+ (integer? (car value))
+ (integer? (cdr value))))
+
+(define (serialize-name name value)
+ (format #f
+ "~a "
+ value))
+
+(define (serialize-position name value)
+ (format #f
+ "~a ~a,~a "
+ name
+ (car value)
+ (cdr value)))
+
+(define (serialize-enable name value)
+ (if value "enable " "disable "))
+
+(define (serialize-boolean name value)
+ (format #f
+ "~a ~a "
+ name
+ (if value "yes" "no")))
+
+(define (list-of-strings? lst)
+ (every string? lst))
+
+(define (serialize-list-of-strings name value)
+ (string-join " "
+ (map serialize-string value)))
+
+(define-configuration kanshi-output
+ (name string "Identifier of the output" (serializer serialize-name))
+ (mode maybe-string "The mode to use")
+ (position maybe-position "A cons containing x in car, and y in cdr")
+ (enable maybe-boolean "Whether to enable the output" (serializer serialize-enable))
+ (scale maybe-float "Scale of the output mode")
+ (adaptive-sync maybe-boolean "Whether to enable adaptive sync for the output"))
+
+(define (list-of-kanshi-outputs? lst)
+ (every kanshi-output? lst))
+
+(define (serialize-list-of-kanshi-outputs lst)
+ #~(string-join
+ (map (lambda (x) (string-append " output " x))
+ (list #$@(map
+ (cut serialize-configuration <> kanshi-output-fields)
+ lst)))
+ "\n"))
+
+(define-configuration/no-serialization kanshi-profile
+ (name
+ string
+ "Name of the profile")
+ (outputs
+ list-of-kanshi-outputs
+ "List of the outputs for this profile")
+ ;; (commands
+ ;; maybe-list-of-strings
+ ;; "List of the commands to execute. These map to `exec`")
+ )
+
+(define (list-of-kanshi-profiles? lst)
+ (every kanshi-profile? lst))
+
+(define-public (serialize-kanshi-profile config)
+ #~(format #f
+ "profile ~a {~%~a~%}~%~%"
+ #$(kanshi-profile-name config)
+ #$(serialize-list-of-kanshi-outputs (kanshi-profile-outputs config))))
+
+(define (serialize-list-of-kanshi-profiles name lst)
+ #~(string-append #$@(map serialize-kanshi-profile lst)))
+
+(define-configuration kanshi-configuration
+ (profiles
+ list-of-kanshi-profiles
+ "List of the profiles inside of the kanshi configuration."))
+
+(define-public (serialize-kanshi-configuration config)
+ (mixed-text-file
+ "config"
+ (serialize-configuration config kanshi-configuration-fields)))
+
+(define-configuration/no-serialization home-kanshi-configuration
+ (kanshi (file-like kanshi) "Kanshi package to use.")
+ (config kanshi-configuration "Configuration of the kanshi program itself. Goes into .config/kanshi/config"))
+
+(define (home-kanshi-shepherd-services config)
+ (list
+ (shepherd-service
+ (documentation "Run the kanshi daemon for managing outputs.")
+ (provision '(kanshi))
+ (auto-start? #f)
+ (start #~(lambda (wayland-display)
+ (setenv "WAYLAND_DISPLAY" wayland-display)
+ (fork+exec-command
+ (list
+ #$(file-append
+ (home-kanshi-configuration-kanshi config)
+ "/bin/kanshi"))
+ #:log-file (string-append
+ (or (getenv "XDG_STATE_HOME")
+ (format #f "~a/.local/state"
+ (getenv "HOME")))
+ "/log/kanshi.log"))))
+ (stop #~(make-kill-destructor)))))
+
+(define (add-home-kanshi-config-file config)
+ `((".config/kanshi/config"
+ ,(serialize-kanshi-configuration (home-kanshi-configuration-config config)))))
+
+(define-public home-kanshi-service-type
+ (service-type
+ (name 'home-kanshi)
+ (description "A service for configuring and running kanshi through Shepherd")
+ (extensions
+ (list (service-extension home-shepherd-service-type
+ home-kanshi-shepherd-services)
+ (service-extension home-files-service-type
+ add-home-kanshi-config-file)))))