From 87c7040239be7d5cd7e9fd2b789a9138dfbd8202 Mon Sep 17 00:00:00 2001 From: Joshua Yuen Date: Sat, 12 Sep 2026 20:45:33 -0400 Subject: [PATCH] Add screenshot tool with SUPER+SHIFT+S bind --- modules/home/default.nix | 1 + modules/home/screenshot.nix | 58 ++++++++++++++++++++++++++++++++++ modules/options/default.nix | 1 + modules/options/screenshot.nix | 13 ++++++++ profiles/desktop/default.nix | 2 ++ 5 files changed, 75 insertions(+) create mode 100644 modules/home/screenshot.nix create mode 100644 modules/options/screenshot.nix diff --git a/modules/home/default.nix b/modules/home/default.nix index 9e9faec..d451971 100644 --- a/modules/home/default.nix +++ b/modules/home/default.nix @@ -11,6 +11,7 @@ ./fzf.nix ./hyprland ./kitty.nix + ./screenshot.nix ./stylix.nix ./vscodium.nix ./walker.nix diff --git a/modules/home/screenshot.nix b/modules/home/screenshot.nix new file mode 100644 index 0000000..5e4b218 --- /dev/null +++ b/modules/home/screenshot.nix @@ -0,0 +1,58 @@ +{ + config, + lib, + pkgs, + ... +}: +with lib; +let + cfg = config.modules.screenshot; + hyprlandCfg = config.modules.hyprland; + + runtimeDeps = with pkgs; [ + coreutils + grim + libnotify + slurp + util-linux + wl-clipboard + ]; + + screenshot = pkgs.writeShellScriptBin "screenshot" '' + PATH=${lib.makeBinPath runtimeDeps}:''${PATH:-} + set -euo pipefail + + pictures_dir="$(xdg-user-dir PICTURES 2>/dev/null || echo "$HOME/Pictures")" + mkdir -p "$pictures_dir" + + file="$pictures_dir/screenshot_$(date +%Y-%m-%d_%H-%M-%S).png" + + notify() { + notify-send -t 2500 -u low "Screenshot" "$1" 2>/dev/null || true + } + + # Pick a region (Escape or a plain click cancels) + geometry="$(slurp 2>/dev/null)" || exit 0 + + if ! grim -g "$geometry" "$file"; then + rm -f "$file" + notify "Capture failed" + exit 1 + fi + + wl-copy < "$file" 2>/dev/null || true + + notify "Saved to $file (also copied to clipboard)" + ''; +in +{ + config = mkIf cfg.enable { + home.packages = [ screenshot ]; + + wayland.windowManager.hyprland = mkIf hyprlandCfg.enable { + settings = { + bind = [ "SUPER SHIFT, S, exec, screenshot" ]; + }; + }; + }; +} diff --git a/modules/options/default.nix b/modules/options/default.nix index b7e1f7b..0706940 100644 --- a/modules/options/default.nix +++ b/modules/options/default.nix @@ -12,6 +12,7 @@ ./localsend.nix ./pipewire.nix ./plasma.nix + ./screenshot.nix ./shell.nix ./system.nix ./tailscale.nix diff --git a/modules/options/screenshot.nix b/modules/options/screenshot.nix new file mode 100644 index 0000000..016474d --- /dev/null +++ b/modules/options/screenshot.nix @@ -0,0 +1,13 @@ +{ + lib, + ... +}: +with lib; +{ + options.modules.screenshot = { + enable = mkEnableOption { + default = false; + description = "Enable screenshot capture tool (SUPER+SHIFT+S)"; + }; + }; +} diff --git a/profiles/desktop/default.nix b/profiles/desktop/default.nix index 74d72a2..cad0ff6 100644 --- a/profiles/desktop/default.nix +++ b/profiles/desktop/default.nix @@ -24,5 +24,7 @@ modules.dictation.enable = true; + modules.screenshot.enable = true; + modules.tailscale.enable = true; }