about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-07-01 13:00:39 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-07-01 13:00:39 +0200
commit9fff92e00a285885910cafd508df6d98ef0921e2 (patch)
tree7e1e816556b7bd62c6f8fd257c76dee85d74b20e
parentmodules/river/keymap: Avoid Ctrl in keymaps (diff)
downloadnixos-config-9fff92e00a285885910cafd508df6d98ef0921e2.zip
{modules/river,pkgs/river-mk-keymap}: Support `once` key mappings
Otherwise, the prompt for the new screenshot is overshadowed by the
normal key mappings in the `run` mode.
Diffstat (limited to '')
-rw-r--r--modules/by-name/ri/river/keymap.nix20
-rw-r--r--pkgs/by-name/ri/river-mk-keymap/src/key_map/commands.rs16
-rw-r--r--pkgs/by-name/ri/river-mk-keymap/src/key_map/mod.rs5
3 files changed, 32 insertions, 9 deletions
diff --git a/modules/by-name/ri/river/keymap.nix b/modules/by-name/ri/river/keymap.nix
index 8ad341aa..6873f40e 100644
--- a/modules/by-name/ri/river/keymap.nix
+++ b/modules/by-name/ri/river/keymap.nix
@@ -8,15 +8,19 @@
   index2tag = input: builtins.toString (libraries.base.pow 2 (input - 1));
 
   mkTagCommand = name: index: [name (index2tag index)];
-  mkSpawn' = pkg: binaryName: args: {
-    command = [
-      "spawn"
-      "${lib.getExe' pkg binaryName} ${args}"
-    ];
+  mkSpawnInner = pkg: binaryName: args: further: (further
+    // {
+      command = [
+        "spawn"
+        "${lib.getExe' pkg binaryName} ${args}"
+      ];
 
-    description = "${binaryName} ${args}";
-  };
+      description = "${binaryName} ${args}";
+    });
+
+  mkSpawnOnce = pkg: args: (mkSpawnInner pkg pkg.meta.mainProgram args {once = true;});
   mkSpawn = pkg: args: (mkSpawn' pkg pkg.meta.mainProgram args);
+  mkSpawn' = pkg: binaryName: args: (mkSpawnInner pkg binaryName args {});
 
   cfg = config.soispha.programs.river;
 in {
@@ -36,7 +40,7 @@ in {
         "b" = mkSpawn pkgs.tskm "open select";
         "k" = mkSpawn pkgs.keepassxc "";
         "s" = mkSpawn pkgs.signal-desktop "";
-        "p" = mkSpawn pkgs.screenshot_persistent "";
+        "p" = mkSpawnOnce pkgs.screenshot_persistent "";
       };
 
       # Client changes
diff --git a/pkgs/by-name/ri/river-mk-keymap/src/key_map/commands.rs b/pkgs/by-name/ri/river-mk-keymap/src/key_map/commands.rs
index 058606c9..52a6ba8a 100644
--- a/pkgs/by-name/ri/river-mk-keymap/src/key_map/commands.rs
+++ b/pkgs/by-name/ri/river-mk-keymap/src/key_map/commands.rs
@@ -145,9 +145,23 @@ impl KeyMap {
                             (Some(mode_name), acc_vec)
                         });
 
+                let command = if value.once {
+                    vec![
+                        "spawn".to_owned(),
+                        format!(
+                            "riverctl {} && {}",
+                            shlex::try_join(value.command.iter().map(String::as_str))
+                                .expect("Should work"),
+                            shlex::try_join(["riverctl", "enter-mode", "normal"])
+                                .expect("Should work"),
+                        ),
+                    ]
+                } else {
+                    value.command
+                };
                 base.extend(key_to_command(
                     mapping[0],
-                    &value.command,
+                    &command,
                     final_mode.as_ref().map_or("normal", |v| v.as_str()),
                     value.allow_locked,
                 ));
diff --git a/pkgs/by-name/ri/river-mk-keymap/src/key_map/mod.rs b/pkgs/by-name/ri/river-mk-keymap/src/key_map/mod.rs
index 5c89c2e2..16dc02f4 100644
--- a/pkgs/by-name/ri/river-mk-keymap/src/key_map/mod.rs
+++ b/pkgs/by-name/ri/river-mk-keymap/src/key_map/mod.rs
@@ -30,6 +30,10 @@ pub struct KeyConfig {
     #[serde(default)]
     allow_locked: bool,
 
+    /// Whether to go back to the normal mode, after running this command.
+    #[serde(default)]
+    once: bool,
+
     /// Use a different description to display this command, instead of the `command`.
     description: Option<String>,
 }
@@ -51,6 +55,7 @@ impl FromStr for KeyMap {
                         .collect::<Option<_>>()
                         .ok_or(anyhow!("A array contained a non-string value: {value:#?}"))?,
                     allow_locked: false,
+                    once: false,
                     description: None,
                 }
             } else if let Some(object) = value.as_object() {