diff options
Diffstat (limited to 'scripts/dot-local/bin/screenshot-hypr')
| -rwxr-xr-x | scripts/dot-local/bin/screenshot-hypr | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/scripts/dot-local/bin/screenshot-hypr b/scripts/dot-local/bin/screenshot-hypr new file mode 100755 index 0000000..d949a80 --- /dev/null +++ b/scripts/dot-local/bin/screenshot-hypr @@ -0,0 +1,82 @@ +#!/usr/bin/env bash + +OUTPUT_DIR="$HOME/Pictures/scrots" +TIMESTAMP="$(date +'%Y-%m-%d_%H-%M-%S')" +OUTPUT_FILE="$OUTPUT_DIR/screenshot-$TIMESTAMP.png" + +pkill slurp && exit 0 + +MODE="${1:-smart}" +PROCESSING="${2:-slurp}" + +get_rectangles() +{ + local active_workspace=$(hyprctl monitors -j | jq -r '.[] | select(.focused == true) | .activeWorkspace.id') + hyprctl monitors -j | jq -r --arg ws "$active_workspace" '.[] | select(.activeWorkspace.id == ($ws | tonumber)) | "\(.x),\(.y) \((.width / .scale) | floor)x\((.height / .scale) | floor)"' + hyprctl clients -j | jq -r --arg ws "$active_workspace" '.[] | select(.workspace.id == ($ws | tonumber)) | "\(.at[0]),\(.at[1]) \(.size[0])x\(.size[1])"' +} + +# Select based on mode +case "$MODE" in + region) + wayfreeze & + PID=$! + sleep .1 + SELECTION=$(slurp 2>/dev/null) + kill $PID 2>/dev/null + ;; + windows) + wayfreeze & + PID=$! + sleep .1 + SELECTION=$(get_rectangles | slurp -r 2>/dev/null) + kill $PID 2>/dev/null + ;; + fullscreen) + SELECTION=$(hyprctl monitors -j | jq -r '.[] | select(.focused == true) | "\(.x),\(.y) \((.width / .scale) | floor)x\((.height / .scale) | floor)"') + ;; + smart | *) + RECTS=$(get_rectangles) + wayfreeze & + PID=$! + sleep .1 + SELECTION=$(echo "$RECTS" | slurp 2>/dev/null) + kill $PID 2>/dev/null + + # If the selction area is L * W < 20, we'll assume you were trying to select whichever + # window or output it was inside of to prevent accidental 2px snapshots + if [[ "$SELECTION" =~ ^([0-9]+),([0-9]+)[[:space:]]([0-9]+)x([0-9]+)$ ]]; then + if ((${BASH_REMATCH[3]} * ${BASH_REMATCH[4]} < 20)); then + click_x="${BASH_REMATCH[1]}" + click_y="${BASH_REMATCH[2]}" + + while IFS= read -r rect; do + if [[ "$rect" =~ ^([0-9]+),([0-9]+)[[:space:]]([0-9]+)x([0-9]+) ]]; then + rect_x="${BASH_REMATCH[1]}" + rect_y="${BASH_REMATCH[2]}" + rect_width="${BASH_REMATCH[3]}" + rect_height="${BASH_REMATCH[4]}" + + if ((click_x >= rect_x && click_x < rect_x + rect_width && click_y >= rect_y && click_y < rect_y + rect_height)); then + SELECTION="${rect_x},${rect_y} ${rect_width}x${rect_height}" + break + fi + fi + done <<<"$RECTS" + fi + fi + ;; +esac + +[ -z "$SELECTION" ] && exit 0 + +if [[ $PROCESSING == "slurp" ]]; then + grim -g "$SELECTION" - | + satty --filename - \ + --output-filename "$OUTPUT_FILE" \ + --actions-on-enter="save-to-file,exit" \ + --actions-on-escape="save-to-clipboard,exit" \ + --initial-tool=arrow +else + grim -g "$SELECTION" - | wl-copy +fi |
