From dc6ed8b930a413440a5f7996e0553c8570ffe30f Mon Sep 17 00:00:00 2001 From: Hilton Chain Date: Fri, 27 Jun 2025 20:14:16 +0800 Subject: [PATCH] services: Add %rosenthal-set-keymap-script. * modules/rosenthal/services/desktop.scm (%rosenthal-set-keymap-script): New variable. * modules/rosenthal/examples/niri.kdl: Adjust configuration. --- modules/rosenthal/examples/niri.kdl | 18 +++--- modules/rosenthal/services/desktop.scm | 85 ++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 8 deletions(-) diff --git a/modules/rosenthal/examples/niri.kdl b/modules/rosenthal/examples/niri.kdl index 92b963e..114e590 100644 --- a/modules/rosenthal/examples/niri.kdl +++ b/modules/rosenthal/examples/niri.kdl @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2023-2025 Ivan Molodetskikh // // SPDX-License-Identifier: GPL-3.0-or-later -// + // This config is in the KDL format: https://kdl.dev // "/-" comments out the following node. // Check the wiki for a full description of the configuration: @@ -12,8 +12,6 @@ // https://github.com/YaLTeR/niri/wiki/Configuration:-Input input { keyboard { - repeat-delay 300 - repeat-rate 30 xkb { // You can set rules, model, layout, variant and options. // For more information, see xkeyboard-config(7). @@ -22,6 +20,8 @@ input { // layout "us,ru" // options "grp:win_space_toggle,compose:ralt,ctrl:nocaps" } + repeat-delay 300 + repeat-rate 30 } // Next sections include libinput settings. @@ -252,7 +252,7 @@ layout { // Note that running niri as a session supports xdg-desktop-autostart, // which may be more convenient to use. // See the binds section below for more spawn examples. -// spawn-at-startup "alacritty" "-e" "fish" +// spawn-at-startup "foot" "fish" // Uncomment this line to ask the clients to omit their client-side decorations if possible. // If the client will specifically ask for CSD, the request will be honored. @@ -317,7 +317,7 @@ window-rule { // Example: enable rounded corners for all windows. // (This example rule is commented out with a "/-" in front.) -window-rule { +/-window-rule { geometry-corner-radius 12 clip-to-geometry true } @@ -344,7 +344,7 @@ binds { // You can also use a shell. Do this if you need pipes, multiple commands, etc. // Note: the entire command goes as a single argument in the end. - // Mod+T { spawn "bash" "-c" "notify-send hello && exec alacritty"; } + // Mod+T { spawn "bash" "-c" "notify-send hello && exec foot"; } // Example volume keys mappings for PipeWire & WirePlumber. // The allow-when-locked=true property makes them work even when the session is locked. @@ -576,9 +576,11 @@ binds { Mod+Shift+P { power-off-monitors; } } -prefer-no-csd -spawn-at-startup "sh" "-c" "pgrep --uid $USER shepherd > /dev/null || shepherd" +// Rootless Xwayland support spawn-at-startup "xwayland-satellite" ":233" environment { DISPLAY ":233" } + +// Start user Shepherd +spawn-at-startup "sh" "-c" "pgrep --uid $USER shepherd > /dev/null || shepherd" diff --git a/modules/rosenthal/services/desktop.scm b/modules/rosenthal/services/desktop.scm index ee7aed4..3e0e2c8 100644 --- a/modules/rosenthal/services/desktop.scm +++ b/modules/rosenthal/services/desktop.scm @@ -4,6 +4,7 @@ (define-module (rosenthal services desktop) #:use-module (guix gexp) + #:use-module (guix modules) #:use-module (guix records) #:use-module (guix utils) #:use-module (rosenthal utils file) @@ -55,6 +56,7 @@ home-waybar-configuration home-waybar-service-type + %rosenthal-set-keymap-script %rosenthal-skeletons %rosenthal-desktop-services %rosenthal-desktop-home-services)) @@ -467,6 +469,89 @@ gtk-key-theme-name = ~a~%" ;;; Configuration file presets. ;;; +(define %rosenthal-set-keymap-script + (program-file "set-keymap" + (with-imported-modules (source-module-closure '((guix build utils))) + #~(begin + (use-modules (srfi srfi-1) + (srfi srfi-26) + (srfi srfi-37) + (ice-9 match) + (ice-9 popen) + (guix build utils)) + + (define* (build-keyboard-layout file layout #:optional variant #:key model options) + (define pipe + (apply open-pipe* OPEN_READ + #$(file-append (spec->pkg "console-setup") "/bin/ckbcomp") + (string-append "-I" #$(spec->pkg "xkeyboard-config") "/share/X11/xkb") + "-rules" "base" + `(,@(if model + '("-model" ,model) + '()) + ,layout + ,(or variant "") + ,(string-join options ",")))) + (mkdir-p (dirname file)) + (call-with-output-file file + (lambda (output) + (dump-port pipe output)))) + + (define* (set-keyboard-layout layout #:optional variant #:key model options) + (define file-name "/tmp/keymaps/console-keymap") + (build-keyboard-layout file-name layout variant #:model model #:options options) + (invoke "sudo" #$(file-append (spec->pkg "kbd") "/bin/loadkeys") file-name) + (when (getenv "WAYLAND_DISPLAY") + (substitute* (in-vicinity (getenv "XDG_CONFIG_HOME") "niri/config.kdl") + (("^ (layout|variant|model|options) .*") "") + (("^ xkb \\{.*" line) + (string-append + line + (format #f " layout ~s~%" layout) + (if variant (format #f " variant ~s~%" variant) "") + (if model (format #f " model ~s~%" model) "") + (format #f " options ~s~%" (string-join options ","))))))) + + (define (show-help-and-exit) + (display "\ +Usage: set-keymap LAYOUT [VARIANT] [-m MODEL] [-o OPTIONS] + +OPTIONS are comma-separated e.g. \"ctrl:nocaps,grp:alt_shift_toggle\" + +Examples: +set-keymap us +set-keymap us dvorak +set-keymap us dvorak -o ctrl:nocaps\n") + (quit)) + + (define (parse-options) + (args-fold (cdr (program-arguments)) + (list (option '(#\m "model") #t #f + (lambda (opt name arg result) + (alist-cons 'model arg result))) + (option '(#\o "options") #t #f + (lambda (opt name arg result) + (alist-cons 'options (string-split arg #\,) + result))) + (option '("help") #f #f + (lambda _ + (show-help-and-exit)))) + (lambda (opt name arg loads) + (error "Unrecognized option `~A'" name)) + (lambda (opt loads) (cons opt loads)) + '())) + + (let* ((opts (parse-options)) + (model (assoc-ref opts 'model)) + (options (or (assoc-ref opts 'options) '())) + (args (remove pair? (reverse opts)))) + (match args + ((layout) + (set-keyboard-layout layout #:model model #:options options)) + ((layout variant) + (set-keyboard-layout layout variant #:model model #:options options)) + (_ + (show-help-and-exit)))))))) (define %rosenthal-skeletons `((".config/emacs/fonts.el"