Created
October 7, 2024 18:54
-
-
Save Excedrin/91cf98f60f66bf46fcdc4b3834793fb9 to your computer and use it in GitHub Desktop.
sway better image capture, with cursors and mouse over by first capturing all outputs, then displaying each captured image on each output and using slurp and grim to select and capture from these "overlay" images. Requires: sway, grim, jq, swayimg, slurp.
This file contains hidden or 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 | |
# Create a temporary directory for screenshots | |
tmpdir=$(mktemp -d) | |
# Get the list of active outputs | |
outputs=$(swaymsg -t get_outputs | jq -r '.[] | select(.active) | .name') | |
initial_focus=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .name') | |
# Capture and display each output | |
for output in $outputs; do | |
# Capture the entire screen for the current output | |
grim -c -o "$output" "$tmpdir/$output.png" | |
done | |
# Display the screenshot in fullscreen on the corresponding output | |
for output in $outputs; do | |
swaymsg focus output "$output" | |
swayimg -f "$tmpdir/$output.png" & | |
# Wait a moment for the images to display | |
sleep 0.1 | |
done | |
swaymsg focus output "$initial_focus" | |
# Select a region | |
region=$(slurp) | |
if [ -n "$region" ]; then | |
# Capture the selected region and copy to clipboard | |
grim -g "$region" - | wl-copy | |
fi | |
# Kill the image viewer | |
pkill swayimg | |
# Clean up temporary files | |
rm -rf "$tmpdir" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment