| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | time=$(date "+%d-%b_%H-%M-%S") |
| 7 | dir="$(xdg-user-dir)/Pictures/Screenshots" |
| 8 | file="Screenshot_${time}_${RANDOM}.png" |
| 9 | |
| 10 | iDIR="$HOME/.config/swaync/icons" |
| 11 | iDoR="$HOME/.config/swaync/images" |
| 12 | sDIR="$HOME/.config/hypr/scripts" |
| 13 | |
| 14 | active_window_class=$(hyprctl -j activewindow | jq -r '(.class)') |
| 15 | active_window_file="Screenshot_${time}_${active_window_class}.png" |
| 16 | active_window_path="${dir}/${active_window_file}" |
| 17 | |
| 18 | notify_cmd_base="notify-send -t 10000 -A action1=Open -A action2=Delete -h string:x-canonical-private-synchronous:shot-notify" |
| 19 | notify_cmd_shot="${notify_cmd_base} -i ${iDIR}/picture.png " |
| 20 | notify_cmd_shot_win="${notify_cmd_base} -i ${iDIR}/picture.png " |
| 21 | notify_cmd_NOT="notify-send -u low -i ${iDoR}/note.png " |
| 22 | |
| 23 | |
| 24 | notify_view() { |
| 25 | if [[ "$1" == "active" ]]; then |
| 26 | if [[ -e "${active_window_path}" ]]; then |
| 27 | "${sDIR}/Sounds.sh" --screenshot |
| 28 | resp=$(timeout 5 ${notify_cmd_shot_win} " Screenshot of:" " ${active_window_class} Saved.") |
| 29 | case "$resp" in |
| 30 | action1) |
| 31 | xdg-open "${active_window_path}" & |
| 32 | ;; |
| 33 | action2) |
| 34 | rm "${active_window_path}" & |
| 35 | ;; |
| 36 | esac |
| 37 | else |
| 38 | ${notify_cmd_NOT} " Screenshot of:" " ${active_window_class} NOT Saved." |
| 39 | "${sDIR}/Sounds.sh" --error |
| 40 | fi |
| 41 | |
| 42 | elif [[ "$1" == "swappy" ]]; then |
| 43 | "${sDIR}/Sounds.sh" --screenshot |
| 44 | resp=$(${notify_cmd_shot} " Screenshot:" " Captured by Swappy") |
| 45 | case "$resp" in |
| 46 | action1) |
| 47 | swappy -f - <"$tmpfile" |
| 48 | ;; |
| 49 | action2) |
| 50 | rm "$tmpfile" |
| 51 | ;; |
| 52 | esac |
| 53 | |
| 54 | else |
| 55 | local check_file="${dir}/${file}" |
| 56 | if [[ -e "$check_file" ]]; then |
| 57 | "${sDIR}/Sounds.sh" --screenshot |
| 58 | resp=$(timeout 5 ${notify_cmd_shot} " Screenshot" " Saved") |
| 59 | case "$resp" in |
| 60 | action1) |
| 61 | xdg-open "${check_file}" & |
| 62 | ;; |
| 63 | action2) |
| 64 | rm "${check_file}" & |
| 65 | ;; |
| 66 | esac |
| 67 | else |
| 68 | ${notify_cmd_NOT} " Screenshot" " NOT Saved" |
| 69 | "${sDIR}/Sounds.sh" --error |
| 70 | fi |
| 71 | fi |
| 72 | } |
| 73 | |
| 74 | |
| 75 | countdown() { |
| 76 | for sec in $(seq $1 -1 1); do |
| 77 | notify-send -h string:x-canonical-private-synchronous:shot-notify -t 1000 -i "$iDIR"/timer.png " Taking shot" " in: $sec secs" |
| 78 | sleep 1 |
| 79 | done |
| 80 | } |
| 81 | |
| 82 | |
| 83 | shotnow() { |
| 84 | cd ${dir} && grim - | tee "$file" | wl-copy |
| 85 | sleep 2 |
| 86 | notify_view |
| 87 | } |
| 88 | |
| 89 | shot5() { |
| 90 | countdown '5' |
| 91 | sleep 1 && cd ${dir} && grim - | tee "$file" | wl-copy |
| 92 | sleep 1 |
| 93 | notify_view |
| 94 | } |
| 95 | |
| 96 | shot10() { |
| 97 | countdown '10' |
| 98 | sleep 1 && cd ${dir} && grim - | tee "$file" | wl-copy |
| 99 | notify_view |
| 100 | } |
| 101 | |
| 102 | shotwin() { |
| 103 | w_pos=$(hyprctl activewindow | grep 'at:' | cut -d':' -f2 | tr -d ' ' | tail -n1) |
| 104 | w_size=$(hyprctl activewindow | grep 'size:' | cut -d':' -f2 | tr -d ' ' | tail -n1 | sed s/,/x/g) |
| 105 | cd ${dir} && grim -g "$w_pos $w_size" - | tee "$file" | wl-copy |
| 106 | notify_view |
| 107 | } |
| 108 | |
| 109 | shotarea() { |
| 110 | tmpfile=$(mktemp) |
| 111 | grim -g "$(slurp)" - >"$tmpfile" |
| 112 | |
| 113 | |
| 114 | if [[ -s "$tmpfile" ]]; then |
| 115 | wl-copy <"$tmpfile" |
| 116 | mv "$tmpfile" "$dir/$file" |
| 117 | fi |
| 118 | notify_view |
| 119 | } |
| 120 | |
| 121 | shotactive() { |
| 122 | active_window_class=$(hyprctl -j activewindow | jq -r '(.class)') |
| 123 | active_window_file="Screenshot_${time}_${active_window_class}.png" |
| 124 | active_window_path="${dir}/${active_window_file}" |
| 125 | |
| 126 | hyprctl -j activewindow | jq -r '"\(.at[0]),\(.at[1]) \(.size[0])x\(.size[1])"' | grim -g - "${active_window_path}" |
| 127 | sleep 1 |
| 128 | notify_view "active" |
| 129 | } |
| 130 | |
| 131 | shotswappy() { |
| 132 | tmpfile=$(mktemp) |
| 133 | grim -g "$(slurp)" - >"$tmpfile" |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | if [[ -s "$tmpfile" ]]; then |
| 139 | wl-copy <"$tmpfile" |
| 140 | notify_view "swappy" |
| 141 | fi |
| 142 | } |
| 143 | |
| 144 | if [[ ! -d "$dir" ]]; then |
| 145 | mkdir -p "$dir" |
| 146 | fi |
| 147 | |
| 148 | if [[ "$1" == "--now" ]]; then |
| 149 | shotnow |
| 150 | elif [[ "$1" == "--in5" ]]; then |
| 151 | shot5 |
| 152 | elif [[ "$1" == "--in10" ]]; then |
| 153 | shot10 |
| 154 | elif [[ "$1" == "--win" ]]; then |
| 155 | shotwin |
| 156 | elif [[ "$1" == "--area" ]]; then |
| 157 | shotarea |
| 158 | elif [[ "$1" == "--active" ]]; then |
| 159 | shotactive |
| 160 | elif [[ "$1" == "--swappy" ]]; then |
| 161 | shotswappy |
| 162 | else |
| 163 | echo -e "Available Options : --now --in5 --in10 --win --area --active --swappy" |
| 164 | fi |
| 165 | |
| 166 | exit 0 |