diff options
| author | Arnaud Daby-Seesaram <ds-ac@nanein.fr> | 2025-08-09 13:11:07 +0200 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2025-09-14 18:13:07 +0200 |
| commit | aec2a05e359f73fc5d0fd786bfc94f243e35120a (patch) | |
| tree | 201e6812f1ddfc87d7ab36b825f2702dc7037a58 | |
| parent | 0b0f8702ea89de6fa0dd2e4ef18717001b395c1b (diff) | |
home: services: home-sway-service-type: Enable extensions.
* gnu/home/services/sway.scm (%empty-sway-configuration): New value.
(sway-combine): New procedure.
(sway-compose): New procedure.
(sway-extend): New procedure.
(home-sway-service-type) [compose/extend]: New fields.
* doc/guix.texi (Sway window manager): Document this.
Change-Id: I548a18a6a273380be90c9b5b365f65a93cc02416
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
| -rw-r--r-- | doc/guix.texi | 15 | ||||
| -rw-r--r-- | gnu/home/services/sway.scm | 68 |
2 files changed, 82 insertions, 1 deletions
diff --git a/doc/guix.texi b/doc/guix.texi index 622a4e76f06..13665b568d7 100644 --- a/doc/guix.texi +++ b/doc/guix.texi | |||
| @@ -52511,6 +52511,21 @@ providing a @file{~/.config/sway/config} file, | |||
| 52511 | @item | 52511 | @item |
| 52512 | adding Sway-related packages to your profile. | 52512 | adding Sway-related packages to your profile. |
| 52513 | @end itemize | 52513 | @end itemize |
| 52514 | |||
| 52515 | It is possible to extend this service (@pxref{Service Composition}). | ||
| 52516 | The resulting configuration file contains the concatenation of | ||
| 52517 | keybindings, modes, @i{etc.}@: found in all extensions. | ||
| 52518 | |||
| 52519 | @quotation Note | ||
| 52520 | At the moment, only one bar configuration is allowed. If more are | ||
| 52521 | found, an error will be raised. | ||
| 52522 | @end quotation | ||
| 52523 | @end defvar | ||
| 52524 | |||
| 52525 | @defvar %empty-sway-configuration | ||
| 52526 | The variable @code{%empty-sway-configuration} contains an empty | ||
| 52527 | @code{sway-configuration} record. This value can help users write | ||
| 52528 | simple service extensions. | ||
| 52514 | @end defvar | 52529 | @end defvar |
| 52515 | 52530 | ||
| 52516 | @deftp {Data Type} sway-configuration | 52531 | @deftp {Data Type} sway-configuration |
diff --git a/gnu/home/services/sway.scm b/gnu/home/services/sway.scm index 4e521091900..34447e95f2e 100644 --- a/gnu/home/services/sway.scm +++ b/gnu/home/services/sway.scm | |||
| @@ -50,7 +50,10 @@ | |||
| 50 | %sway-default-modes | 50 | %sway-default-modes |
| 51 | %sway-default-keybindings | 51 | %sway-default-keybindings |
| 52 | %sway-default-startup-programs | 52 | %sway-default-startup-programs |
| 53 | %sway-default-packages)) | 53 | %sway-default-packages |
| 54 | |||
| 55 | ;; Convenient value to inherit for extensions. | ||
| 56 | %empty-sway-configuration)) | ||
| 54 | 57 | ||
| 55 | ;; Helper function. | 58 | ;; Helper function. |
| 56 | (define (flatmap f l) | 59 | (define (flatmap f l) |
| @@ -894,9 +897,70 @@ | |||
| 894 | ;;; Definition of the Home Service. | 897 | ;;; Definition of the Home Service. |
| 895 | ;;; | 898 | ;;; |
| 896 | 899 | ||
| 900 | (define %empty-sway-configuration | ||
| 901 | (sway-configuration | ||
| 902 | (variables '()) | ||
| 903 | (keybindings '()) | ||
| 904 | (gestures '()) | ||
| 905 | (packages '()) | ||
| 906 | (inputs '()) | ||
| 907 | (outputs '()) | ||
| 908 | (modes '()) | ||
| 909 | (startup+reload-programs '()) | ||
| 910 | (startup-programs '()))) | ||
| 911 | |||
| 897 | (define (sway-configuration->files sway-conf) | 912 | (define (sway-configuration->files sway-conf) |
| 898 | `((".config/sway/config" ,(sway-configuration->file sway-conf)))) | 913 | `((".config/sway/config" ,(sway-configuration->file sway-conf)))) |
| 899 | 914 | ||
| 915 | (define (sway-combine config1 config2) | ||
| 916 | (sway-configuration | ||
| 917 | (keybindings (append (sway-configuration-keybindings config1) | ||
| 918 | (sway-configuration-keybindings config2))) | ||
| 919 | (gestures (append (sway-configuration-gestures config1) | ||
| 920 | (sway-configuration-gestures config2))) | ||
| 921 | (packages (append (sway-configuration-packages config1) | ||
| 922 | (sway-configuration-packages config2))) | ||
| 923 | (variables (append (sway-configuration-variables config1) | ||
| 924 | (sway-configuration-variables config2))) | ||
| 925 | (inputs (append (sway-configuration-inputs config1) | ||
| 926 | (sway-configuration-inputs config2))) | ||
| 927 | (outputs (append (sway-configuration-outputs config1) | ||
| 928 | (sway-configuration-outputs config2))) | ||
| 929 | (bar (let ((bar1 (sway-configuration-bar config1)) | ||
| 930 | (bar2 (sway-configuration-bar config2))) | ||
| 931 | (if (eq? bar1 %unset-value) | ||
| 932 | bar2 | ||
| 933 | (if (eq? bar2 %unset-value) | ||
| 934 | bar1 | ||
| 935 | (throw "[Sway configuration] Too many bar configurations \ | ||
| 936 | have been found."))))) | ||
| 937 | (modes (append (sway-configuration-modes config1) | ||
| 938 | (sway-configuration-modes config2))) | ||
| 939 | (startup+reload-programs | ||
| 940 | (append (sway-configuration-startup+reload-programs config1) | ||
| 941 | (sway-configuration-startup+reload-programs config2))) | ||
| 942 | (startup-programs | ||
| 943 | (append (sway-configuration-startup-programs config1) | ||
| 944 | (sway-configuration-startup-programs config2))) | ||
| 945 | (extra-content | ||
| 946 | (append (sway-configuration-extra-content config1) | ||
| 947 | (sway-configuration-extra-content config2))))) | ||
| 948 | |||
| 949 | (define (sway-compose lst) | ||
| 950 | "Naive composition procedure for @code{home-sway-service-type}. Most fields | ||
| 951 | of above configuration records are lists. The composition procedure simply | ||
| 952 | concatenates them." | ||
| 953 | (match lst | ||
| 954 | (() %unset-value) | ||
| 955 | ((h) h) | ||
| 956 | ((h . t) | ||
| 957 | (fold sway-combine h t)))) | ||
| 958 | |||
| 959 | (define (sway-extend ini res) | ||
| 960 | (if (eq? res %unset-value) | ||
| 961 | ini | ||
| 962 | (sway-combine ini res))) | ||
| 963 | |||
| 900 | (define home-sway-service-type | 964 | (define home-sway-service-type |
| 901 | (service-type | 965 | (service-type |
| 902 | (name 'home-sway-config) | 966 | (name 'home-sway-config) |
| @@ -905,6 +969,8 @@ | |||
| 905 | sway-configuration->files) | 969 | sway-configuration->files) |
| 906 | (service-extension home-profile-service-type | 970 | (service-extension home-profile-service-type |
| 907 | sway-configuration-packages))) | 971 | sway-configuration-packages))) |
| 972 | (compose sway-compose) | ||
| 973 | (extend sway-extend) | ||
| 908 | (description "Configure Sway by providing a file | 974 | (description "Configure Sway by providing a file |
| 909 | @file{~/.config/sway/config}.") | 975 | @file{~/.config/sway/config}.") |
| 910 | (default-value (sway-configuration)))) | 976 | (default-value (sway-configuration)))) |
