From d46b5f0e6dcf3bcc78de2b0d825109b28fb1a257 Mon Sep 17 00:00:00 2001 From: Tigor Hutasuhut Date: Sun, 3 Nov 2024 11:18:52 +0700 Subject: [PATCH] hyprland: move back to grimblast for screenshots because hyprshot cannot use second screen for screenshots --- home/modules/hyprland/default.nix | 5 +-- home/modules/hyprland/grimblast.nix | 53 +++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 home/modules/hyprland/grimblast.nix diff --git a/home/modules/hyprland/default.nix b/home/modules/hyprland/default.nix index c7ffd18..dcbc4a5 100644 --- a/home/modules/hyprland/default.nix +++ b/home/modules/hyprland/default.nix @@ -14,7 +14,7 @@ in ./hypridle.nix ./hyprland.nix ./hyprlock.nix - ./hyprshot.nix + # ./hyprshot.nix # hyprpaper seems to be broken with out of memory and failure to swap wallpapers correctly. # Use swww for now until the application is stable. # ./hyprpaper.nix @@ -22,6 +22,7 @@ in ./rofi.nix ./waybar.nix ./wlogout.nix + ./grimblast.nix # ./swappy.nix ./alacritty.nix ./swayosd.nix @@ -40,7 +41,7 @@ in pasystray graphicsmagick - pkgs.swayosd + swayosd image-roll # image viewer ]; diff --git a/home/modules/hyprland/grimblast.nix b/home/modules/hyprland/grimblast.nix new file mode 100644 index 0000000..7f7d049 --- /dev/null +++ b/home/modules/hyprland/grimblast.nix @@ -0,0 +1,53 @@ +{ + config, + lib, + pkgs, + inputs, + ... +}: +let + inherit (lib) mkIf; + inherit (lib.meta) getExe; + cfg = config.profile.hyprland; + saveDir = "${config.home.homeDirectory}/Pictures/screenshots"; + grimblast = inputs.hyprland-contrib.packages.${pkgs.system}.grimblast; + script = + mode: + pkgs.writeShellScriptBin "grimblast-${mode}.sh" '' + mkdir -p "${saveDir}/original" "${saveDir}/edit" + + file=$(date +%Y-%m-%d_%H%M%S).png + filename=${saveDir}/original/$file + ${grimblast}/bin/grimblast save ${mode} "$filename" + action=$(notify-send --icon="$filename" --app-name="grimblast" --action="copy=Copy" --action="edit=Edit" --action="delete=Delete" "Grimblast" "Screenshot saved to $filename") + case $action in + "copy") + wl-copy < "$filename" + notify-send --icon="$filename" --app-name="grimblast" "Grimblast" "Screenshot copied to clipboard" + ;; + "edit") + satty --save-after-copy --filename "$filename" --fullscreen --output-filename "${saveDir}/edit/$(date +%Y-%m-%d_%H%M%S).png" + ;; + "delete") + rm "$filename" + notify-send --app-name="grimblast" "Grimblast" "Screenshot $filename deleted" + ;; + esac + ''; + saveAreaScript = script "area"; + saveOutputScript = script "output"; +in +{ + config = mkIf cfg.enable { + home.packages = [ + grimblast + pkgs.satty + pkgs.libnotify + ]; + + wayland.windowManager.hyprland.settings.bind = [ + ", PRINT, exec, ${getExe saveAreaScript}" + "$mod, PRINT, exec, ${getExe saveOutputScript}" + ]; + }; +}