aboutsummaryrefslogtreecommitdiff
path: root/bin/screenshot
blob: 94e3bd3453542c840310f0e33c47af526f71a0ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env bash

set -o nounset
set -o pipefail
if [[ "${TRACE-0}" == "1" ]]; then
    set -o xtrace
fi


FOCUSED=$(swaymsg -t get_tree | jq '.. | (.nodes? // empty)[] | select(.focused) | .rect | "\(.x),\(.y) \(.width)x\(.height)"')

main() {
  rect="$(slurp)"
  if [ $? -eq 0 ]; then
    grim -g "$rect" -t png - | wl-copy -t image/png
  else
    grim -g "$(eval echo "$FOCUSED")" -t png - | wl-copy -t image/png
  fi

}

main "$@"