Commit dcad4f73046b

Vincent Demeester <vincent@sbr.pm>
2026-02-16 15:08:59
fix(niri): use wrapper script for screenshots
Niri doesn't expand shell commands in screenshot-path, so $(hostname) was saved as a literal directory name. Added niri-screenshot wrapper via writeShellApplication that properly expands hostname and passes --path to niri.
1 parent efea8a9
Changed files (2)
dots
config
home
common
desktop
dots/config/niri/config.kdl
@@ -95,7 +95,8 @@ spawn-at-startup "jamesdsp" "-t"
 
 prefer-no-csd
 
-screenshot-path "~/desktop/pictures/screenshots/$(hostname)/%Y-%m-%d-%H%M%S.png"
+// screenshot-path is handled by ~/bin/niri-screenshot wrapper
+screenshot-path null
 
 animations {
     // Uncomment to turn off all animations.
@@ -371,10 +372,10 @@ binds {
     Mod+Space       { switch-layout "next"; }
     Mod+Shift+Space { switch-layout "prev"; }
 
-    XF86SelectiveScreenshot { screenshot; }
-    Print { screenshot-screen; }
-    Ctrl+Print { screenshot; }
-    Alt+Print { screenshot-window; }
+    XF86SelectiveScreenshot { spawn "niri-screenshot" "select"; }
+    Print { spawn "niri-screenshot" "screen"; }
+    Ctrl+Print { spawn "niri-screenshot" "select"; }
+    Alt+Print { spawn "niri-screenshot" "window"; }
 
     // Applications such as rEmote-desktop clients and software KVM switches may
     // request that niri stops processing the keyboard shortcuts defined here
home/common/desktop/niri/default.nix
@@ -1,4 +1,27 @@
 { pkgs, ... }:
+let
+  niri-screenshot = pkgs.writeShellApplication {
+    name = "niri-screenshot";
+    runtimeInputs = with pkgs; [ niri ];
+    text = ''
+      # Wrapper around niri screenshot actions that expands hostname in the path.
+      # Usage: niri-screenshot [screen|window|select]
+      dir="$HOME/desktop/pictures/screenshots/$(hostname)"
+      mkdir -p "$dir"
+      path="$dir/$(date +%Y-%m-%d-%H%M%S).png"
+
+      case "''${1:-select}" in
+          screen) niri msg action screenshot-screen --path "$path" ;;
+          window) niri msg action screenshot-window --path "$path" ;;
+          select) niri msg action screenshot --path "$path" ;;
+          *)
+              echo "Usage: niri-screenshot [screen|window|select]" >&2
+              exit 1
+              ;;
+      esac
+    '';
+  };
+in
 {
   imports = [
     ../sway/mako.nix
@@ -16,6 +39,7 @@
     wlprop
 
     # Screenshots and screen recording
+    niri-screenshot
     grim
     slurp