From abb4d47635f1be8199537381c775188745a6cc42 Mon Sep 17 00:00:00 2001 From: Muhammed Hussein Karimi Date: Sun, 2 Feb 2025 01:35:30 +0330 Subject: [PATCH] :sparkles: Add hyprshot gui Signed-off-by: Muhammed Hussein Karimi --- README.md | 1 + hyprshot | 2 +- hyprshot-gui | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100755 hyprshot-gui diff --git a/README.md b/README.md index ddbcf18..8c2e088 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ Activate wayland overlay as described in [README](https://github.com/bsd-ac/wayl ### Optional Dependencies - hyprpicker (to freeze the screen contents with the `--freeze` flag) +- yad (to be able to use the GUI mode) ### Manual diff --git a/hyprshot b/hyprshot index 0fb976f..882a6de 100755 --- a/hyprshot +++ b/hyprshot @@ -254,7 +254,7 @@ function args() { FILENAME=$1 ;; -D | --delay) - shift; + shift; DELAY=$1 ;; -m | --mode) diff --git a/hyprshot-gui b/hyprshot-gui new file mode 100755 index 0000000..6ea2b58 --- /dev/null +++ b/hyprshot-gui @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +CHOICE=$(yad --form --title="Hyprshot" --text="Select Screenshot Mode" \ + --field="Mode:CB" "window!active window!output!region!selected monitor" \ + --field="Delay (seconds):NUM" 0 \ + --field="📋 Clipboard only:CHK" FALSE \ + --button="🎯 Capture":0 --button="❌ Cancel":1 \ + --undecorated --borders=20 --fixed) + +# Exit if the user cancels +if [[ $? -ne 0 ]]; then + exit 1 +fi + +MODE=$(echo "$CHOICE" | cut -d'|' -f1) +DELAY=$(echo "$CHOICE" | cut -d'|' -f2) +CLIPBOARD=$(echo "$CHOICE" | cut -d'|' -f3) + +case $MODE in + "active window") MODE="-m window -m active" ;; + "selected monitor") MODE="-m output -m $(hyprctl monitors -j | jq -r '.[0].name')" ;; + *) MODE="-m $MODE" ;; +esac + +while [ $DELAY -gt 0 ]; do + echo $((DELAY * 100 / 60)) + sleep 1 + DELAY=$((DELAY - 1)) +done | yad --progress --title="Hyprshot Delay" --text="Time remaining:" --percentage=0 --auto-close --fixed + +if [[ "$CLIPBOARD" == "TRUE" ]]; then + hyprshot $MODE --clipboard-only +else + hyprshot $MODE +fi