aboutsummaryrefslogtreecommitdiff
path: root/bin/screenshot
blob: 3852fa56f8094474448b8a27106cb48c3a49a13e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/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" ~/screenshot.png
  else
    grim -g "$(eval echo "$FOCUSED")" ~/screenshot.png

  fi

  cat ~/screenshot.png | wl-copy -t image/png
}

main "$@"