diff mbox series

[bug#66932] services: Add xremap service.

Message ID 57d94dcb19152592014053ef0bc81e95e4f6b602.1699111054.git.voroskoi@gmail.com
State New
Headers show
Series [bug#66932] services: Add xremap service. | expand

Commit Message

VÖRÖSKŐI András Nov. 4, 2023, 3:17 p.m. UTC
* 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(+)


base-commit: 9dcd8802f5bc472579f23a38dcf437f8a9ac976c

Comments

Ludovic Courtès Dec. 2, 2023, 10:48 a.m. UTC | #1
Hi András,

VÖRÖSKŐI András <voroskoi@gmail.com> skribis:

> * 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

Nice!

> +(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"))))

Did you consider writing “bindings” so that one can configure it Scheme,
as is the case for most other services?  (To be clear, I think we should
still allow people to provide their own Yaml file as is done here.)

If that’s too tricky/impractical, we can keep the patch as is, but
adding “native” configuration on top of that would be sweet.

I wonder if it would make sense, in a future patch, to also provide
‘home-xremap-service-type’ as a direct mapping of this service.  Food
for thought.

Thanks,
Ludo’.
VÖRÖSKŐI András Dec. 4, 2023, 5:43 p.m. UTC | #2
Hi Ludo,

Thanks for the reply.

On Sat Dec 2, 2023 at 11:48 AM CET, Ludovic Courtès wrote:
> Hi András,
>
> Did you consider writing “bindings” so that one can configure it Scheme,
> as is the case for most other services?  (To be clear, I think we should
> still allow people to provide their own Yaml file as is done here.)

I did consider that, but I am not familiar with guile, so that is too
hard for me and there are a lot of combinations to handle.

> If that’s too tricky/impractical, we can keep the patch as is, but
> adding “native” configuration on top of that would be sweet.

It is tricky for me and telling the truth I do not see the benefit.

> I wonder if it would make sense, in a future patch, to also provide
> ‘home-xremap-service-type’ as a direct mapping of this service.  Food
> for thought.

I was thinking about that, but was not sure. There is a section in the README about that:
https://github.com/k0kubun/xremap#running-xremap-without-sudo

The basic idea is creating an input group with write permission for every
input type.
I think we can not automate the "add user to input group" in the home-service,
so that would be still a manual task.

Is this solution acceptable?

Thanks,
András
diff mbox series

Patch

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 <mail@muradm.net>
 ;;; Copyright © 2023 Bruno Victal <mirai@makinata.eu>
 ;;; Copyright © 2023 Zheng Junjie <873216071@qq.com>
+;;; Copyright © 2023 VÖRÖSKŐI András <voroskoi@gmail.com>
 ;;;
 ;;; 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.