2023-03-23 16:15:34 +01:00
|
|
|
#!/usr/bin/bash
|
2023-03-23 15:46:11 +01:00
|
|
|
# This script will take a screenshot
|
2023-03-23 16:15:34 +01:00
|
|
|
# Dependencies: sway, grim, slurp
|
2023-03-23 15:46:11 +01:00
|
|
|
|
|
|
|
FILENAME="$HOME/screenshot-$(date +'%Y-%m-%d-%H%M%S.png')"
|
|
|
|
|
|
|
|
case $1 in
|
|
|
|
all) #Screenshot of all outputs
|
|
|
|
grim -t jpeg -q 100 $FILENAME ;;
|
|
|
|
|
|
|
|
focus) # Screenshot of focused window
|
2023-03-25 23:21:28 +01:00
|
|
|
geometry=$(
|
2023-03-24 11:33:13 +01:00
|
|
|
swaymsg -t get_tree |
|
2023-03-25 23:21:28 +01:00
|
|
|
awk '
|
|
|
|
BEGIN { ORS=" " };
|
|
|
|
lines_after&&lines_after-- {print $2+0}; #loop over n lines. Print only numbers
|
|
|
|
/focused": true/,/window_rect/ {
|
|
|
|
if($1=="\"window_rect\":") lines_after=4;
|
|
|
|
if($1=="\"rect\":") lines_after=2
|
|
|
|
}' |
|
|
|
|
awk '{printf "%d,%d %dx%d", $1+$3,$2+$4,$5,$6}')
|
2023-03-23 15:46:11 +01:00
|
|
|
grim -t jpeg -q 100 -g "$geometry" $FILENAME ;;
|
|
|
|
|
|
|
|
choice) #Screenshot von Auswahl
|
|
|
|
grim -t jpeg -q 100 -g "$(slurp)" $FILENAME ;;
|
|
|
|
|
|
|
|
*) #Default: Screenshot of focused output
|
|
|
|
focused_output="$(
|
|
|
|
swaymsg -p -t get_outputs |
|
|
|
|
grep focused |
|
|
|
|
awk '{print $2}')"
|
|
|
|
grim -t jpeg -q 100 -o $focused_output $FILENAME ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit 0
|