From patchwork Thu Mar 16 13:03:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Miguel_=C3=81ngel_Moreno?= X-Patchwork-Id: 48051 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 14C6F16E33; Thu, 16 Mar 2023 13:04:28 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 9222216E0A for ; Thu, 16 Mar 2023 13:04:26 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pcnH3-00051I-0o; Thu, 16 Mar 2023 09:04:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pcnH0-00050h-Vd for guix-patches@gnu.org; Thu, 16 Mar 2023 09:04:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pcnH0-0004Iu-N5 for guix-patches@gnu.org; Thu, 16 Mar 2023 09:04:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pcnH0-0007Qy-85 for guix-patches@gnu.org; Thu, 16 Mar 2023 09:04:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#62101] [PATCH v2] home: services: Add home-xmodmap-service-type. References: <867cvo9y6b.fsf@conses.eu> In-Reply-To: <867cvo9y6b.fsf@conses.eu> Resent-From: conses Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 16 Mar 2023 13:04:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 62101 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Ludovic =?utf-8?q?Court=C3=A8s?= Cc: contact@conses.eu, 62101@debbugs.gnu.org Received: via spool by 62101-submit@debbugs.gnu.org id=B62101.167897182628551 (code B ref 62101); Thu, 16 Mar 2023 13:04:02 +0000 Received: (at 62101) by debbugs.gnu.org; 16 Mar 2023 13:03:46 +0000 Received: from localhost ([127.0.0.1]:41459 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pcnGj-0007QR-OZ for submit@debbugs.gnu.org; Thu, 16 Mar 2023 09:03:46 -0400 Received: from relay3-d.mail.gandi.net ([217.70.183.195]:53425) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pcnGh-0007Q9-Nk for 62101@debbugs.gnu.org; Thu, 16 Mar 2023 09:03:44 -0400 Received: (Authenticated sender: contact@conses.eu) by mail.gandi.net (Postfix) with ESMTPSA id E7E3560016; Thu, 16 Mar 2023 13:03:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=conses.eu; s=gm1; t=1678971817; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=0++0oWJxtxz2RK0NRP4AsC5gDXyjd/mgehbPwsVc3MU=; b=a1/QRAokSb8kouz6GyyTJRCwQ/haVtJJ7TxgANfa8GQL39W04J6AdVzna0ZspzCK++0jTL 1UFvVY0MjbJr+EBNucJhj/QPdHIg+4sDSbkcS6OI+Lr28vSJ6wpcnna+xXJDvi0B+xy0TD xcANA8ALlCu+zvr8i+txSoLvpNQZ1GMGPftws4Z8BmhBObrcbFZVt4ME+swdBe5oLyMqXC MYpRFF4tOmPguUYSG40Sl73JVKBCbpQF/gNx/u2dxE9qj/Is2lDDpcH7R6uAdZrrCzvErZ 7cBShQX8veg1s3nU0bwpV2WCWMy7l6HfUwKS+rnhwUOFv/TS8ZdQMeD4CiR2aA== From: conses Date: Thu, 16 Mar 2023 14:03:34 +0100 Message-ID: <86edpox2zd.fsf@conses.eu> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * gnu/home/services/desktop.scm (home-xmodmap-service-type) (home-xmodmap-configuration): New variables; (xmodmap-shepherd-service) (get-xmodmap-configuration) (get-xmodmap-file) (add-xmodmap-config-file) (add-xmodmap-package): New procedures; * doc/guix.texi (Desktop Services): Document it. --- doc/guix.texi | 51 +++++++++++++++++++++ gnu/home/services/desktop.scm | 85 +++++++++++++++++++++++++++++++++++ 2 files changed, 136 insertions(+) diff --git a/doc/guix.texi b/doc/guix.texi index 6671ba9305..c9ec781e8b 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -42541,6 +42541,57 @@ Desktop Home Services @end table @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 syntax for the expression grammar is quite straightforward. You can +either provide a list of cons cells and strings like this: + +@lisp +(service home-xmodmap-service-type + (home-xmodmap-configuration + (config '(("add mod4" . "Print") + "clear lock" + "clear control" + ("keycode 66" . "Control_L") + ("add control" . "Control_L Control_R"))))) +@end lisp + +Alternatively, there is a more Lisp-like configuration syntax via Scheme +symbols, lists, and vectors, that you can use like this: + +@lisp +(service home-xmodmap-service-type + (home-xmodmap-configuration + (config '((#(add mod4) . Print) + (clear lock) + (clear control) + (#(keycode 66) . Control_L) + (#(add control) . #(Control_L Control_R)))))) +@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{config} (default: @code{config}) (type: list) +The list of expressions to be placed in the +@file{~/.config/xmodmap/config} configuration file and read 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 cb25b03b64..8bc3d82cba 100644 --- a/gnu/home/services/desktop.scm +++ b/gnu/home/services/desktop.scm @@ -22,10 +22,12 @@ (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) (setxkbmap xmodmap) #:autoload (gnu packages xdisorg) (redshift) #: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 +228,86 @@ (define home-dbus-service-type (default-value (home-dbus-configuration)) (description "Run the session-specific D-Bus inter-process message bus."))) + + +;;; +;;; xmodmap +;;; + +(define-configuration/no-serialization home-xmodmap-configuration + (xmodmap + (file-like xmodmap) + "The @code{xmodmap} package to use.") + (config + (list '()) + "List of expressions to be inserted in the @file{.config/xmodmap/config} +configuration file.")) + +(define (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") + #$(get-xmodmap-file config))))) + (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 (get-xmodmap-configuration field-name val) + (define serialize-term + (match-lambda + ((? vector? e) + (string-join + (vector-fold (lambda (_ 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 serialize-term 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 (get-xmodmap-file config) + (mixed-text-file + "config" + (get-xmodmap-configuration + #f (home-xmodmap-configuration-config config)))) + +(define (add-xmodmap-config-file config) + `(("xmodmap/config" + ,(get-xmodmap-file config)))) + +(define (add-xmodmap-package 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 + add-xmodmap-package) + (service-extension home-xdg-configuration-files-service-type + add-xmodmap-config-file) + (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.")))