Subject: [PATCH] services: Add xremap service.

From: VÖRÖSKŐI András <[email-masked]>
Date: Sat, 4 Nov 2023 16:17:35 +0100

* gnu/services/desktop.scm (<xremap-configuration>): New record.
(xremap-shepherd-service): New procedure.
(xremap-service-type): New variable.
* doc/guix.texi (Desktop Services): Document this.

Change-Id: I76f9e238c72fb47226140e2b86dd9490cd9c9351
---
 doc/guix.texi            | 37 ++++++++++++++++++++++++++++++++++++
 gnu/services/desktop.scm | 41 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 78 insertions(+)

diff --git a/doc/guix.texi b/doc/guix.texi
index b90078be06..e61b4e2650 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -119,6 +119,7 @@
 Copyright @copyright{} 2023 Zheng Junjie@*
 Copyright @copyright{} 2023 Brian Cully@*
 Copyright @copyright{} 2023 Felix Lechner@*
+Copyright @copyright{} 2023 VÖRÖSKŐI András@*
 
 Permission is granted to copy, distribute and/or modify this document
 under the terms of the GNU Free Documentation License, Version 1.3 or
@@ -25011,6 +25012,42 @@ Desktop Services
 @end table
 @end deftp
 
+@defvar xremap-service-type
+@uref{https://github.com/k0kubun/xremap/, xremap} xremap is a key remapper for
+Linux. Unlike xmodmap, it supports app-specific remapping and Wayland.
+
+@lisp
+(append
+  (list
+   (service xremap-service-type
+                    (xremap-configuration
+                     (config-file (plain-file "xremap.yml"
+"modmap:
+  - name: Global
+    remap:
+      CAPSLOCK:
+        held: CONTROL_L
+        alone: Esc
+        alone_timeout_millis: 1000"))))
+
+  ;; normally one would want %base-services
+  %base-services)
+
+@end lisp
+@end defvar
+
+@deftp {Data Type} xremap-configuration
+Configuration record for the xremap daemon service.
+
+@table @asis
+@item @code{package} (default: @code{rust-xremap})
+The xremap package to use.
+
+@item @code{config-file} (default: @samp{(plain-file "xremap.yml" "")})
+Config file to use with xremap.
+
+@end table
+@end deftp
 
 @node Sound Services
 @subsection Sound Services
diff --git a/gnu/services/desktop.scm b/gnu/services/desktop.scm
index 5b79fbcda1..1cfa7c2169 100644
--- a/gnu/services/desktop.scm
+++ b/gnu/services/desktop.scm
@@ -17,6 +17,7 @@
 ;;; Copyright © 2021, 2022 muradm <[email-masked]>
 ;;; Copyright © 2023 Bruno Victal <[email-masked]>
 ;;; Copyright © 2023 Zheng Junjie <[email-masked]>
+;;; Copyright © 2023 VÖRÖSKŐI András <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -72,6 +73,7 @@ (define-module (gnu services desktop)
   #:use-module (gnu packages mate)
   #:use-module (gnu packages nfs)
   #:use-module (gnu packages enlightenment)
+  #:use-module (gnu packages rust-apps)
   #:use-module (guix deprecation)
   #:use-module (guix records)
   #:use-module (guix packages)
@@ -184,6 +186,9 @@ (define-module (gnu services desktop)
             seatd-configuration
             seatd-service-type
 
+	    xremap-configuration
+	    xremap-service-type
+
             %desktop-services))
 
 ;;; Commentary:
@@ -1863,6 +1868,42 @@ (define seatd-service-type
      (service-extension shepherd-root-service-type seatd-shepherd-service)))
    (default-value (seatd-configuration))))
 
+;;;
+;;; xremap
+;;;
+
+(define-record-type* <xremap-configuration>
+  xremap-configuration make-xremap-configuration
+  xremap-configuration?
+  (package xremap-configuration-package
+           (default rust-xremap))
+  (config-file xremap-configuration-config-file
+           (default (plain-file "xremap.yml" ""))))
+
+(define (xremap-shepherd-service config)
+  "Return an <sheperd-service> for xremap with CONFIG"
+  (match-record config <xremap-configuration>
+                (package config-file)
+                (list
+                (shepherd-service
+                 (provision '(xremap))
+                 (documentation "xremap daemon")
+                 (requirement '())
+                 (start #~(make-forkexec-constructor
+                           (list #$(file-append package "/bin/xremap")
+                                 #$config-file)))
+                 (stop #~(make-kill-destructor))))))
+
+(define xremap-service-type
+  (service-type
+   (name 'xremap)
+   (extensions
+    (list
+     (service-extension shepherd-root-service-type
+                        xremap-shepherd-service)))
+   (default-value (xremap-configuration))
+   (description "Run the @code{xremap} utility to modify keymaps system wide.")))
+
 
 ;;;
 ;;; The default set of desktop services.

base-commit: 9dcd8802f5bc472579f23a38dcf437f8a9ac976c
-- 
2.41.0