diff --git a/bin/omarchy-cmd-screenshot b/bin/omarchy-cmd-screenshot index 57f8a94c..0a7b94ad 100755 --- a/bin/omarchy-cmd-screenshot +++ b/bin/omarchy-cmd-screenshot @@ -51,51 +51,54 @@ get_rectangles() { # 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 +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 selection 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]}" + # If the selection 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]}" + 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 + 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 - done <<< "$RECTS" - fi + fi + done <<<"$RECTS" fi - ;; + fi + ;; esac [[ -z $SELECTION ]] && exit 0 @@ -105,7 +108,7 @@ FILEPATH="$OUTPUT_DIR/$FILENAME" if [[ $PROCESSING == "slurp" ]]; then grim -g "$SELECTION" "$FILEPATH" || exit 1 - wl-copy < "$FILEPATH" + wl-copy <"$FILEPATH" ( ACTION=$(notify-send "Screenshot saved to clipboard and file" "Edit with Super + Alt + , (or click this)" -t 10000 -i "$FILEPATH" -A "default=edit")