From b1d09b41e1f80305657aad11494882d15ff183a3 Mon Sep 17 00:00:00 2001 From: jad Date: Wed, 22 Jan 2025 11:50:39 +0000 Subject: [PATCH 1/2] Fixed issue: "Escape cancels selection but still results in "Screenshot saved / image copied to clipboard"" --- hyprshot | 43 ++++++++++++++----- notificationFix.patch | 99 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 132 insertions(+), 10 deletions(-) create mode 100644 notificationFix.patch diff --git a/hyprshot b/hyprshot index 0fb976f..94b5f2e 100755 --- a/hyprshot +++ b/hyprshot @@ -54,14 +54,19 @@ function send_notification() { return 0 fi - local message=$([ $CLIPBOARD -eq 1 ] && \ - echo "Image copied to the clipboard" || \ - echo "Image saved in ${1} and copied to the clipboard.") + local message + if [ $CLIPBOARD -eq 1 ]; then + message="Image copied to the clipboard." + else + message="Image saved in ${1} and copied to the clipboard." + fi + notify-send "Screenshot saved" \ "${message}" \ -t "$NOTIF_TIMEOUT" -i "${1}" -a Hyprshot } + function trim() { Print "Geometry: %s\n" "${1}" local geometry="${1}" @@ -108,6 +113,13 @@ function trim() { function save_geometry() { local geometry="${1}" + + # Check for empty geometry + if [ -z "$geometry" ]; then + Print "Selection canceled or invalid. Exiting.\n" + return 1 + fi + local output="" if [ $RAW -eq 1 ]; then @@ -130,6 +142,7 @@ function save_geometry() { send_notification $output } + function checkRunning() { sleep 1 while [[ 1 == 1 ]]; do @@ -147,34 +160,44 @@ function begin_grab() { HYPRPICKER_PID=$! fi local option=$1 + local geometry="" + case $option in output) if [ $CURRENT -eq 1 ]; then - local geometry=`grab_active_output` + geometry=`grab_active_output` elif [ -z $SELECTED_MONITOR ]; then - local geometry=`grab_output` + geometry=`grab_output` else - local geometry=`grab_selected_output $SELECTED_MONITOR` + geometry=`grab_selected_output $SELECTED_MONITOR` fi ;; region) - local geometry=`grab_region` + geometry=`grab_region` ;; window) if [ $CURRENT -eq 1 ]; then - local geometry=`grab_active_window` + geometry=`grab_active_window` else - local geometry=`grab_window` + geometry=`grab_window` fi - geometry=`trim "${geometry}"` + geometry=`trim "${geometry}"` ;; esac + + if [ -z "$geometry" ]; then + Print "No geometry selected. Cancelling.\n" + return 1 + fi + if [ ${DELAY} -gt 0 ] 2>/dev/null; then sleep ${DELAY} fi + save_geometry "${geometry}" } + function grab_output() { slurp -or } diff --git a/notificationFix.patch b/notificationFix.patch new file mode 100644 index 0000000..4f57390 --- /dev/null +++ b/notificationFix.patch @@ -0,0 +1,99 @@ +--- hyprshotorig 2025-01-22 11:34:36.839190792 +0000 ++++ hyprshot 2025-01-22 11:33:04.391728371 +0000 +@@ -54,14 +54,19 @@ + return 0 + fi + +- local message=$([ $CLIPBOARD -eq 1 ] && \ +- echo "Image copied to the clipboard" || \ +- echo "Image saved in ${1} and copied to the clipboard.") ++ local message ++ if [ $CLIPBOARD -eq 1 ]; then ++ message="Image copied to the clipboard." ++ else ++ message="Image saved in ${1} and copied to the clipboard." ++ fi ++ + notify-send "Screenshot saved" \ + "${message}" \ + -t "$NOTIF_TIMEOUT" -i "${1}" -a Hyprshot + } + ++ + function trim() { + Print "Geometry: %s\n" "${1}" + local geometry="${1}" +@@ -108,6 +113,13 @@ + + function save_geometry() { + local geometry="${1}" ++ ++ # Check for empty geometry ++ if [ -z "$geometry" ]; then ++ Print "Selection canceled or invalid. Exiting.\n" ++ return 1 ++ fi ++ + local output="" + + if [ $RAW -eq 1 ]; then +@@ -130,6 +142,7 @@ + send_notification $output + } + ++ + function checkRunning() { + sleep 1 + while [[ 1 == 1 ]]; do +@@ -147,34 +160,44 @@ + HYPRPICKER_PID=$! + fi + local option=$1 ++ local geometry="" ++ + case $option in + output) + if [ $CURRENT -eq 1 ]; then +- local geometry=`grab_active_output` ++ geometry=`grab_active_output` + elif [ -z $SELECTED_MONITOR ]; then +- local geometry=`grab_output` ++ geometry=`grab_output` + else +- local geometry=`grab_selected_output $SELECTED_MONITOR` ++ geometry=`grab_selected_output $SELECTED_MONITOR` + fi + ;; + region) +- local geometry=`grab_region` ++ geometry=`grab_region` + ;; + window) + if [ $CURRENT -eq 1 ]; then +- local geometry=`grab_active_window` ++ geometry=`grab_active_window` + else +- local geometry=`grab_window` ++ geometry=`grab_window` + fi +- geometry=`trim "${geometry}"` ++ geometry=`trim "${geometry}"` + ;; + esac ++ ++ if [ -z "$geometry" ]; then ++ Print "No geometry selected. Cancelling.\n" ++ return 1 ++ fi ++ + if [ ${DELAY} -gt 0 ] 2>/dev/null; then + sleep ${DELAY} + fi ++ + save_geometry "${geometry}" + } + ++ + function grab_output() { + slurp -or + } From 85d16e9023288d193ed34b18ad65ec8c2516c98e Mon Sep 17 00:00:00 2001 From: Jade Hayward <86536601+jadehnsn@users.noreply.github.com> Date: Wed, 22 Jan 2025 11:54:28 +0000 Subject: [PATCH 2/2] Delete notificationFix.patch --- notificationFix.patch | 99 ------------------------------------------- 1 file changed, 99 deletions(-) delete mode 100644 notificationFix.patch diff --git a/notificationFix.patch b/notificationFix.patch deleted file mode 100644 index 4f57390..0000000 --- a/notificationFix.patch +++ /dev/null @@ -1,99 +0,0 @@ ---- hyprshotorig 2025-01-22 11:34:36.839190792 +0000 -+++ hyprshot 2025-01-22 11:33:04.391728371 +0000 -@@ -54,14 +54,19 @@ - return 0 - fi - -- local message=$([ $CLIPBOARD -eq 1 ] && \ -- echo "Image copied to the clipboard" || \ -- echo "Image saved in ${1} and copied to the clipboard.") -+ local message -+ if [ $CLIPBOARD -eq 1 ]; then -+ message="Image copied to the clipboard." -+ else -+ message="Image saved in ${1} and copied to the clipboard." -+ fi -+ - notify-send "Screenshot saved" \ - "${message}" \ - -t "$NOTIF_TIMEOUT" -i "${1}" -a Hyprshot - } - -+ - function trim() { - Print "Geometry: %s\n" "${1}" - local geometry="${1}" -@@ -108,6 +113,13 @@ - - function save_geometry() { - local geometry="${1}" -+ -+ # Check for empty geometry -+ if [ -z "$geometry" ]; then -+ Print "Selection canceled or invalid. Exiting.\n" -+ return 1 -+ fi -+ - local output="" - - if [ $RAW -eq 1 ]; then -@@ -130,6 +142,7 @@ - send_notification $output - } - -+ - function checkRunning() { - sleep 1 - while [[ 1 == 1 ]]; do -@@ -147,34 +160,44 @@ - HYPRPICKER_PID=$! - fi - local option=$1 -+ local geometry="" -+ - case $option in - output) - if [ $CURRENT -eq 1 ]; then -- local geometry=`grab_active_output` -+ geometry=`grab_active_output` - elif [ -z $SELECTED_MONITOR ]; then -- local geometry=`grab_output` -+ geometry=`grab_output` - else -- local geometry=`grab_selected_output $SELECTED_MONITOR` -+ geometry=`grab_selected_output $SELECTED_MONITOR` - fi - ;; - region) -- local geometry=`grab_region` -+ geometry=`grab_region` - ;; - window) - if [ $CURRENT -eq 1 ]; then -- local geometry=`grab_active_window` -+ geometry=`grab_active_window` - else -- local geometry=`grab_window` -+ geometry=`grab_window` - fi -- geometry=`trim "${geometry}"` -+ geometry=`trim "${geometry}"` - ;; - esac -+ -+ if [ -z "$geometry" ]; then -+ Print "No geometry selected. Cancelling.\n" -+ return 1 -+ fi -+ - if [ ${DELAY} -gt 0 ] 2>/dev/null; then - sleep ${DELAY} - fi -+ - save_geometry "${geometry}" - } - -+ - function grab_output() { - slurp -or - }