This repository has been archived on 2024-09-01. You can view files and clone it, but cannot push or open issues or pull requests.
al-skel/sway-home/.local/bin/screenshot

28 lines
866 B
Plaintext
Raw Normal View History

2021-12-22 14:13:19 -06:00
#!/bin/bash
# Shortened version of https://github.com/moverest/sway-interactive-screenshot
# w/o rofi, for use with key bindings
list_geometry()
{
swaymsg -t get_tree | jq -r '.. | (.nodes? // empty)[] | select(.'"$1"' and .pid) | "\(.rect.x),\(.rect.y) \(.rect.width)x\(.rect.height)''"'
}
FOCUSED=$(list_geometry focused)
CHOICE=$1
DIR=${SCREENSHOT_DIR:=$HOME/Screenshots}
FILENAME="${DIR/#\~/$HOME}/$(date +'%Y-%m-%d-%H%M%S_screenshot.png')"
mkdir -p "$DIR"
case $CHOICE in
fullscreen) grim "$FILENAME" ;;
region) grim -g "$(slurp)" "$FILENAME" ;;
focused) grim -g "$FOCUSED" "$FILENAME" ;;
display) grim -o "$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .name')" "$FILENAME"
;;
esac
wl-copy < "$FILENAME"
notify-send "Screenshot" "File saved as <i>'$FILENAME'</i> and copied to the clipboard." -i "$FILENAME"