mirror of
https://github.com/LukeHagar/omarchy.git
synced 2025-12-08 20:47:46 +00:00
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 <david@hey.com>
This commit is contained in:
@@ -8,10 +8,76 @@ if [[ ! -d "$OUTPUT_DIR" ]]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
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 - \
|
satty --filename - \
|
||||||
--output-filename "$OUTPUT_DIR/screenshot-$(date +'%Y-%m-%d_%H-%M-%S').png" \
|
--output-filename "$OUTPUT_DIR/screenshot-$(date +'%Y-%m-%d_%H-%M-%S').png" \
|
||||||
--early-exit \
|
--early-exit \
|
||||||
--actions-on-enter save-to-clipboard \
|
--actions-on-enter save-to-clipboard \
|
||||||
--save-after-copy \
|
--save-after-copy \
|
||||||
--copy-command 'wl-copy'
|
--copy-command 'wl-copy'
|
||||||
|
else
|
||||||
|
grim -g "$SELECTION" - | wl-copy
|
||||||
|
fi
|
||||||
|
|||||||
@@ -104,10 +104,9 @@ show_capture_menu() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
show_screenshot_menu() {
|
show_screenshot_menu() {
|
||||||
case $(menu "Screenshot" " Region\n Window\n Display") in
|
case $(menu "Screenshot" " Snap with Editing\n Straight to Clipboard") in
|
||||||
*Region*) omarchy-cmd-screenshot ;;
|
*Editing*) omarchy-cmd-screenshot smart ;;
|
||||||
*Window*) omarchy-cmd-screenshot window ;;
|
*Clipboard*) omarchy-cmd-screenshot smart clipboard ;;
|
||||||
*Display*) omarchy-cmd-screenshot output ;;
|
|
||||||
*) show_capture_menu ;;
|
*) show_capture_menu ;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 = 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
|
bindd = SHIFT CTRL, F2, Apple Display full brightness, exec, omarchy-cmd-apple-display-brightness +60000
|
||||||
|
|
||||||
# Screenshots
|
# Captures
|
||||||
bindd = , PRINT, Screenshot of region, exec, omarchy-cmd-screenshot
|
bindd = , PRINT, Screenshot, exec, omarchy-cmd-screenshot
|
||||||
bindd = SHIFT, PRINT, Screenshot of window, exec, omarchy-cmd-screenshot window
|
bindd = SHIFT, PRINT, Screenshot, exec, omarchy-cmd-screenshot smart clipboard
|
||||||
bindd = CTRL, PRINT, Screenshot of display, exec, omarchy-cmd-screenshot output
|
bindd = ALT, PRINT, Screenrecording, exec, omarchy-menu screenrecord
|
||||||
|
bindd = SUPER, PRINT, Color picking, exec, pkill hyprpicker || hyprpicker -a
|
||||||
# Screen recordings
|
|
||||||
bindd = ALT, PRINT, Screen record menu, exec, omarchy-menu screenrecord
|
|
||||||
|
|
||||||
# Color picker
|
|
||||||
bindd = SUPER, PRINT, Color picker, exec, pkill hyprpicker || hyprpicker -a
|
|
||||||
|
|
||||||
# File sharing
|
# File sharing
|
||||||
bindd = CTRL SUPER, S, Share, exec, omarchy-menu share
|
bindd = CTRL SUPER, S, Share, exec, omarchy-menu share
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ github-cli
|
|||||||
gnome-calculator
|
gnome-calculator
|
||||||
gnome-keyring
|
gnome-keyring
|
||||||
gnome-themes-extra
|
gnome-themes-extra
|
||||||
|
grim
|
||||||
gpu-screen-recorder
|
gpu-screen-recorder
|
||||||
gum
|
gum
|
||||||
gvfs-mtp
|
gvfs-mtp
|
||||||
@@ -57,7 +58,6 @@ hyprland
|
|||||||
hyprland-qtutils
|
hyprland-qtutils
|
||||||
hyprlock
|
hyprlock
|
||||||
hyprpicker
|
hyprpicker
|
||||||
hyprshot
|
|
||||||
hyprsunset
|
hyprsunset
|
||||||
imagemagick
|
imagemagick
|
||||||
impala
|
impala
|
||||||
@@ -130,6 +130,7 @@ unzip
|
|||||||
uwsm
|
uwsm
|
||||||
walker
|
walker
|
||||||
waybar
|
waybar
|
||||||
|
wayfreeze
|
||||||
whois
|
whois
|
||||||
wireless-regdb
|
wireless-regdb
|
||||||
wiremix
|
wiremix
|
||||||
|
|||||||
Reference in New Issue
Block a user