Created
February 3, 2023 07:55
-
-
Save haxibami/bb0c84ec014fd4956a8a02b525fde8b5 to your computer and use it in GitHub Desktop.
Freezes the focused screen, allows capturing an area, even with floating / hover windows (ex. IME window)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# based on the script by @lbatalha | |
# https://github.com/emersion/slurp/issues/104#issuecomment-1381110649 | |
# requirements: sway, grim, slurp, swayimg, libvips, wl-clipboard | |
# Freezes the focused screen, allows capturing an area, even with floating / hover windows (ex. IME window) | |
# imagemagick and ffmpeg can also be used instead of libvips | |
TMPIMG="$(mktemp --suffix ss.png)" | |
IMGCLASS="sway-crop-screen" | |
FOCUSED=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused)') | |
SWAYIMG_GEOM=$(echo "$FOCUSED" | jq -r '.rect | "\(.x),\(.y),\(.width),\(.height)"') | |
GRIM_GEOM=$(echo "$FOCUSED" | jq -r '.rect | "\(.x),\(.y) \(.width)x\(.height)"') | |
grim -c -l 0 -g "$GRIM_GEOM" "$TMPIMG" | |
swayimg -b none -c "$IMGCLASS" -g "$SWAYIMG_GEOM" "$TMPIMG" & | |
(vips crop "$TMPIMG" .png $(slurp -f '%x %y %w %h'); \ | |
swaymsg -q "[app_id=$IMGCLASS] focus; kill" 1>&2) \ | |
| wl-copy | |
rm "$TMPIMG" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment