From eb3ec613d758f52bbe5471a7fe69e299ad6ec0aa Mon Sep 17 00:00:00 2001 From: Kiran George Date: Sun, 12 Jan 2025 10:46:33 +0530 Subject: Screenshot notification improvement --- config/hypr/scripts/ScreenShot.sh | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/config/hypr/scripts/ScreenShot.sh b/config/hypr/scripts/ScreenShot.sh index d8c4b604..bd3814e4 100755 --- a/config/hypr/scripts/ScreenShot.sh +++ b/config/hypr/scripts/ScreenShot.sh @@ -4,7 +4,6 @@ iDIR="$HOME/.config/swaync/icons" sDIR="$HOME/.config/hypr/scripts" -notify_cmd_shot="notify-send -h string:x-canonical-private-synchronous:shot-notify -u low -i ${iDIR}/picture.png" time=$(date "+%d-%b_%H-%M-%S") dir="$(xdg-user-dir)/Pictures/Screenshots" @@ -14,23 +13,51 @@ active_window_class=$(hyprctl -j activewindow | jq -r '(.class)') active_window_file="Screenshot_${time}_${active_window_class}.png" active_window_path="${dir}/${active_window_file}" +notify_cmd_base="notify-send -t 10000 -A action1=Open -A action2=Delete -h string:x-canonical-private-synchronous:shot-notify" +notify_cmd_shot="${notify_cmd_base} -i ${dir}/${file}" +notify_cmd_shot_win="${notify_cmd_base} -i ${active_window_path}" + # notify and view screenshot notify_view() { if [[ "$1" == "active" ]]; then if [[ -e "${active_window_path}" ]]; then - ${notify_cmd_shot} "Screenshot of '${active_window_class}' Saved." + resp=$(${notify_cmd_shot_win} "Screenshot of '${active_window_class}' Saved.") "${sDIR}/Sounds.sh" --screenshot + case "$resp" in + action1) + xdg-open "${active_window_path}" & + ;; + action2) + rm "${active_window_path}" & + ;; + esac else ${notify_cmd_shot} "Screenshot of '${active_window_class}' not Saved" "${sDIR}/Sounds.sh" --error fi elif [[ "$1" == "swappy" ]]; then - ${notify_cmd_shot} "Screenshot Captured." + resp=$(${notify_cmd_shot} "Screenshot Captured.") + case "$resp" in + action1) + xdg-open "${dir}/${file}" & + ;; + action2) + rm "${dir}/${file}" & + ;; + esac else - local check_file="$dir/$file" + local check_file="${dir}/${file}" if [[ -e "$check_file" ]]; then - ${notify_cmd_shot} "Screenshot Saved." + resp=$(timeout 10 ${notify_cmd_shot} "Screenshot Saved.") "${sDIR}/Sounds.sh" --screenshot + case "$resp" in + action1) + xdg-open "${check_file}" & + ;; + action2) + rm "${check_file}" & + ;; + esac else ${notify_cmd_shot} "Screenshot NOT Saved." "${sDIR}/Sounds.sh" --error @@ -93,7 +120,7 @@ shotactive() { hyprctl -j activewindow | jq -r '"\(.at[0]),\(.at[1]) \(.size[0])x\(.size[1])"' | grim -g - "${active_window_path}" sleep 1 - notify_view "active" + notify_view "active" } shotswappy() { -- cgit v1.2.3 From 3c653c8a11c793b6377884f02ee80f7cd638d8df Mon Sep 17 00:00:00 2001 From: Kiran George Date: Sun, 12 Jan 2025 10:51:47 +0530 Subject: Added timeout --- config/hypr/scripts/ScreenShot.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/hypr/scripts/ScreenShot.sh b/config/hypr/scripts/ScreenShot.sh index bd3814e4..ceef9dad 100755 --- a/config/hypr/scripts/ScreenShot.sh +++ b/config/hypr/scripts/ScreenShot.sh @@ -21,7 +21,7 @@ notify_cmd_shot_win="${notify_cmd_base} -i ${active_window_path}" notify_view() { if [[ "$1" == "active" ]]; then if [[ -e "${active_window_path}" ]]; then - resp=$(${notify_cmd_shot_win} "Screenshot of '${active_window_class}' Saved.") + resp=$(timeout 10 ${notify_cmd_shot_win} "Screenshot of '${active_window_class}' Saved.") "${sDIR}/Sounds.sh" --screenshot case "$resp" in action1) @@ -36,7 +36,7 @@ notify_view() { "${sDIR}/Sounds.sh" --error fi elif [[ "$1" == "swappy" ]]; then - resp=$(${notify_cmd_shot} "Screenshot Captured.") + resp=$(timeout 10 ${notify_cmd_shot} "Screenshot Captured.") case "$resp" in action1) xdg-open "${dir}/${file}" & -- cgit v1.2.3