From: conses <contact@conses.eu>
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: contact@conses.eu, 62101@debbugs.gnu.org
Subject: [bug#62101] [PATCH v3] home: services: Add home-xmodmap-service-type.
Date: Fri, 17 Mar 2023 13:06:35 +0100 [thread overview]
Message-ID: <863563oa44.fsf@conses.eu> (raw)
In-Reply-To: <867cvo9y6b.fsf@conses.eu>
* gnu/home/services/desktop.scm (home-xmodmap-service-type)
(home-xmodmap-configuration): New variables;
(serialize-xmodmap-configuration)
(xmodmap-shepherd-service): New procedures;
* doc/guix.texi (Desktop Services): Document it.
---
- Tweak manual as per latest comments.
- Remove profile and xdg-configuration-file service extensions.
- config -> key-map in home-xmodmap-configuration.
doc/guix.texi | 41 +++++++++++++++++++++++++
gnu/home/services/desktop.scm | 57 +++++++++++++++++++++++++++++++++++
2 files changed, 98 insertions(+)
diff --git a/doc/guix.texi b/doc/guix.texi
index aa98d7df4b..baa5fb5ea5 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -42587,6 +42587,47 @@ Desktop Home Services
@end deftp
+@defvar home-xmodmap-service-type
+This is the service type for the
+@uref{https://gitlab.freedesktop.org/xorg/app/xmodmap,xmodmap} utility
+to modify keymaps and pointer button mappings under the Xorg display
+server. Its associated value must be a
+@code{home-xmodmap-configuration} record, as shown below.
+
+The @code{key-map} field takes a list of objects, each of which is
+either a @dfn{statement} (a string) or an @dfn{assignment} (a pair of
+strings). As an example, the snippet below swaps around the
+@kbd{Caps_Lock} and the @kbd{Control_L} keys, by first removing the
+keysyms (on the right-hand side) from the corresponding modifier maps
+(on the left-hand side), re-assigning them by swapping each other out,
+and finally adding back the keysyms to the modifier maps.
+
+@lisp
+(service home-xmodmap-service-type
+ (home-xmodmap-configuration
+ (key-map '(("remove Lock" . "Caps_Lock")
+ ("remove Control" . "Control_L")
+ ("keysym Control_L" . "Caps_Lock")
+ ("keysym Caps_Lock" . "Control_L")
+ ("add Lock" . "Caps_Lock")
+ ("add Control" . "Control_L")))))
+@end lisp
+@end defvar
+
+@deftp {Data Type} home-xmodmap-configuration
+The configuration record for @code{home-xmodmap-service-type}. Its
+available fields are:
+
+@table @asis
+@item @code{xmodmap} (default: @code{xmodmap}) (type: file-like)
+The @code{xmodmap} package to use.
+
+@item @code{key-map} (default: @code{'()}) (type: list)
+The list of expressions to be read by @code{xmodmap} on service startup.
+
+@end table
+@end deftp
+
@node Guix Home Services
@subsection Guix Home Services
diff --git a/gnu/home/services/desktop.scm b/gnu/home/services/desktop.scm
index ab2b871539..fb1cd44060 100644
--- a/gnu/home/services/desktop.scm
+++ b/gnu/home/services/desktop.scm
@@ -24,6 +24,7 @@ (define-module (gnu home services desktop)
#:use-module (gnu services configuration)
#:autoload (gnu packages glib) (dbus)
#:autoload (gnu packages xdisorg) (redshift unclutter)
+ #:autoload (gnu packages xorg) (setxkbmap xmodmap)
#:use-module (guix records)
#:use-module (guix gexp)
#:use-module (srfi srfi-1)
@@ -275,3 +276,59 @@ (define home-unclutter-service-type
(description "Run the @code{unclutter} daemon, which, on systems using the
Xorg graphical display server, automatically hides the cursor after a
user-defined timeout has expired.")))
+
+\f
+;;;
+;;; Xmodmap.
+;;;
+
+(define-configuration/no-serialization home-xmodmap-configuration
+ (xmodmap
+ (file-like xmodmap)
+ "The @code{xmodmap} package to use.")
+ (key-map
+ (list '())
+ "List of expressions to be read by @code{xmodmap} on service startup."))
+
+(define (serialize-xmodmap-configuration field-name val)
+ (define serialize-field
+ (match-lambda
+ ((key . value)
+ (format #f "~a = ~a" key value))
+ (e e)))
+
+ #~(string-append
+ #$@(interpose (map serialize-field val) "\n" 'suffix)))
+
+(define (xmodmap-shepherd-service config)
+ (define config-file
+ (mixed-text-file
+ "config"
+ (serialize-xmodmap-configuration
+ #f (home-xmodmap-configuration-key-map config))))
+
+ (list
+ (shepherd-service
+ (provision '(xmodmap))
+ (start #~(make-system-constructor
+ (string-join
+ (list #$(file-append
+ (home-xmodmap-configuration-xmodmap config)
+ "/bin/xmodmap")
+ #$config-file))))
+ (stop #~(make-system-constructor
+ #$(file-append setxkbmap "/bin/setxkbmap")))
+ (documentation "On startup, run @code{xmodmap} and read the expressions in
+the configuration file. On stop, reset all the mappings back to the
+defaults."))))
+
+(define home-xmodmap-service-type
+ (service-type
+ (name 'home-xmodmap)
+ (extensions
+ (list
+ (service-extension home-shepherd-service-type
+ xmodmap-shepherd-service)))
+ (default-value (home-xmodmap-configuration))
+ (description "Run the @code{xmodmap} utility to modify keymaps and pointer
+buttons under the Xorg display server via user-defined expressions.")))
--
2.39.1
--
Best regards,
conses
next prev parent reply other threads:[~2023-03-17 12:07 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-10 19:57 [bug#62101] [PATCH] home: services: Add xmodmap conses
2023-03-13 14:00 ` 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 ` conses [this message]
2023-03-17 21:50 ` bug#62101: [PATCH v3] home: services: Add home-xmodmap-service-type 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=863563oa44.fsf@conses.eu \
--to=contact@conses.eu \
--cc=62101@debbugs.gnu.org \
--cc=ludo@gnu.org \
/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).