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
}