From 06827c8ee684d1e7e7f15ee0922a885f81fc011f Mon Sep 17 00:00:00 2001 From: Ryan Hughes Date: Fri, 17 Oct 2025 04:58:40 -0400 Subject: [PATCH] Add smart region selection to omarchy-cmd-snapshot (#1714) * Add smart snapshot selection * Add wayfreeze * Update to only include current workspace in rectangles * Fix if there are no windows on screen * Add option to sidestep slurp and copy straight to clipboard * Update capture menu --------- Co-authored-by: David Heinemeier Hansson --- bin/omarchy-cmd-screenshot | 68 +++++++++++++++++++++++++++- bin/omarchy-menu | 7 ++- default/hypr/bindings/utilities.conf | 15 ++---- install/omarchy-base.packages | 3 +- 4 files changed, 77 insertions(+), 16 deletions(-) diff --git a/bin/omarchy-cmd-screenshot b/bin/omarchy-cmd-screenshot index 330dde3..f4450f8 100755 --- a/bin/omarchy-cmd-screenshot +++ b/bin/omarchy-cmd-screenshot @@ -8,10 +8,76 @@ if [[ ! -d "$OUTPUT_DIR" ]]; then exit 1 fi -pkill slurp || hyprshot -m ${1:-region} --raw | +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_DIR/screenshot-$(date +'%Y-%m-%d_%H-%M-%S').png" \ --early-exit \ --actions-on-enter save-to-clipboard \ --save-after-copy \ --copy-command 'wl-copy' +else + grim -g "$SELECTION" - | wl-copy +fi diff --git a/bin/omarchy-menu b/bin/omarchy-menu index edb4373..1dea590 100755 --- a/bin/omarchy-menu +++ b/bin/omarchy-menu @@ -104,10 +104,9 @@ show_capture_menu() { } show_screenshot_menu() { - case $(menu "Screenshot" " Region\n Window\n Display") in - *Region*) omarchy-cmd-screenshot ;; - *Window*) omarchy-cmd-screenshot window ;; - *Display*) omarchy-cmd-screenshot output ;; + case $(menu "Screenshot" " Snap with Editing\n Straight to Clipboard") in + *Editing*) omarchy-cmd-screenshot smart ;; + *Clipboard*) omarchy-cmd-screenshot smart clipboard ;; *) show_capture_menu ;; esac } diff --git a/default/hypr/bindings/utilities.conf b/default/hypr/bindings/utilities.conf index 01577fa..ed44654 100644 --- a/default/hypr/bindings/utilities.conf +++ b/default/hypr/bindings/utilities.conf @@ -29,16 +29,11 @@ bindd = CTRL, F1, Apple Display brightness down, exec, omarchy-cmd-apple-display bindd = CTRL, F2, Apple Display brightness up, exec, omarchy-cmd-apple-display-brightness +5000 bindd = SHIFT CTRL, F2, Apple Display full brightness, exec, omarchy-cmd-apple-display-brightness +60000 -# Screenshots -bindd = , PRINT, Screenshot of region, exec, omarchy-cmd-screenshot -bindd = SHIFT, PRINT, Screenshot of window, exec, omarchy-cmd-screenshot window -bindd = CTRL, PRINT, Screenshot of display, exec, omarchy-cmd-screenshot output - -# Screen recordings -bindd = ALT, PRINT, Screen record menu, exec, omarchy-menu screenrecord - -# Color picker -bindd = SUPER, PRINT, Color picker, exec, pkill hyprpicker || hyprpicker -a +# Captures +bindd = , PRINT, Screenshot, exec, omarchy-cmd-screenshot +bindd = SHIFT, PRINT, Screenshot, exec, omarchy-cmd-screenshot smart clipboard +bindd = ALT, PRINT, Screenrecording, exec, omarchy-menu screenrecord +bindd = SUPER, PRINT, Color picking, exec, pkill hyprpicker || hyprpicker -a # File sharing bindd = CTRL SUPER, S, Share, exec, omarchy-menu share diff --git a/install/omarchy-base.packages b/install/omarchy-base.packages index 06fbf47..df97780 100644 --- a/install/omarchy-base.packages +++ b/install/omarchy-base.packages @@ -48,6 +48,7 @@ github-cli gnome-calculator gnome-keyring gnome-themes-extra +grim gpu-screen-recorder gum gvfs-mtp @@ -57,7 +58,6 @@ hyprland hyprland-qtutils hyprlock hyprpicker -hyprshot hyprsunset imagemagick impala @@ -130,6 +130,7 @@ unzip uwsm walker waybar +wayfreeze whois wireless-regdb wiremix