From: conses <contact@conses.eu>
To: 62101@debbugs.gnu.org
Cc: contact@conses.eu, Andrew Tropin <andrew@trop.in>
Subject: [bug#62101] [PATCH] home: services: Add xmodmap.
Date: Fri, 10 Mar 2023 20:57:48 +0100 [thread overview]
Message-ID: <867cvo9y6b.fsf@conses.eu> (raw)
---
gnu/home/services/desktop.scm | 109 ++++++++++++++++++++++++++++++++++
1 file changed, 109 insertions(+)
diff --git a/gnu/home/services/desktop.scm b/gnu/home/services/desktop.scm
index cb25b03b64..b3c60b017e 100644
--- a/gnu/home/services/desktop.scm
+++ b/gnu/home/services/desktop.scm
@@ -22,10 +22,13 @@ (define-module (gnu home services desktop)
#:use-module (gnu home services shepherd)
#:use-module (gnu services configuration)
#:autoload (gnu packages glib) (dbus)
+ #:autoload (gnu packages xorg) (xmodmap)
#:autoload (gnu packages xdisorg) (redshift)
+ #:use-module (guix packages)
#:use-module (guix records)
#:use-module (guix gexp)
#:use-module (srfi srfi-1)
+ #:use-module (srfi srfi-43)
#:use-module (ice-9 match)
#:export (home-redshift-configuration
home-redshift-configuration?
@@ -226,3 +229,109 @@ (define home-dbus-service-type
(default-value (home-dbus-configuration))
(description
"Run the session-specific D-Bus inter-process message bus.")))
+
+\f
+;;;
+;;; xmodmap
+;;;
+
+(define-configuration/no-serialization home-xmodmap-configuration
+ (xmodmap
+ (package xmodmap)
+ "The @code{xmodmap} package to use.")
+ (config
+ (alist '())
+ "Association list of key and value pairs for the
+ @code{xmodmap} configuration file. Its syntax can take something like
+the following:
+
+@example
+'((#(add mod4) . Print)
+ (clear lock)
+ (clear control)
+ (#(keycode 66) . Control_L)
+ (#(add control) . #(Control_L Control_R)))
+@end example"))
+
+(define (home-xmodmap-shepherd-service config)
+ (list
+ (shepherd-service
+ (provision '(xmodmap))
+ (start #~(make-system-constructor
+ (string-join
+ (list #$(file-append
+ (home-xmodmap-configuration-xmodmap config)
+ "/bin/xmodmap")
+ #$(home-xmodmap-file config)))))
+ (one-shot? #t))))
+
+(define (get-xmodmap-configuration field-name val)
+ (define serialize-term
+ (match-lambda
+ ((? vector? e)
+ (string-join
+ (vector-fold
+ (lambda (i acc e)
+ (append
+ acc
+ (list (serialize-term e))))
+ '() e) " "))
+ ((? symbol? e) (symbol->string e))
+ ((? number? e) (number->string e))
+ (e e)))
+
+ (define serialize-field
+ (match-lambda
+ ((? list? e)
+ (string-join
+ (map
+ (lambda (x)
+ (serialize-term x))
+ e)
+ " "))
+ ((key . value)
+ (format #f "~a = ~a"
+ (serialize-term key)
+ (serialize-term value)))
+ (key (string-append (serialize-term key)))))
+
+ #~(string-append
+ #$@(interpose
+ (map serialize-field val)
+ "\n" 'suffix)))
+
+(define (home-xmodmap-files-service config)
+ `(("xmodmap/config"
+ ,(home-xmodmap-file config))))
+
+(define (home-xmodmap-file config)
+ (mixed-text-file
+ "config"
+ (get-xmodmap-configuration
+ #f (home-xmodmap-configuration-config config))))
+
+(define (home-xmodmap-profile-service config)
+ (list (home-xmodmap-configuration-xmodmap config)))
+
+(define home-xmodmap-service-type
+ (service-type
+ (name 'home-xmodmap)
+ (extensions
+ (list
+ (service-extension
+ home-profile-service-type
+ home-xmodmap-profile-service)
+ (service-extension
+ home-xdg-configuration-files-service-type
+ home-xmodmap-files-service)
+ (service-extension
+ home-shepherd-service-type
+ home-xmodmap-shepherd-service)))
+ (description "Configure @code{xmodmap} bindings and rules.")
+ (default-value (home-xmodmap-configuration))))
+
+(define (generate-home-xmodmap-documentation)
+ (generate-documentation
+ `((home-xmodmap-configuration
+ ,home-xmodmap-configuration-fields))
+ 'home-xmodmap-configuration))
--
2.39.1
--
Best regards,
conses
next reply other threads:[~2023-03-10 19:59 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-10 19:57 conses [this message]
2023-03-13 14:00 ` [bug#62101] [PATCH] home: services: Add xmodmap Ludovic Courtès
2023-03-16 13:15 ` conses
2023-03-16 13:03 ` [bug#62101] [PATCH v2] home: services: Add home-xmodmap-service-type conses
2023-03-16 21:43 ` [bug#62101] [PATCH] home: services: Add xmodmap Ludovic Courtès
2023-03-17 12:06 ` [bug#62101] [PATCH v3] home: services: Add home-xmodmap-service-type conses
2023-03-17 21:50 ` bug#62101: " Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=867cvo9y6b.fsf@conses.eu \
--to=contact@conses.eu \
--cc=62101@debbugs.gnu.org \
--cc=andrew@trop.in \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).