aboutsummaryrefslogtreecommitdiff
path: root/tw/services/files/wlprop
blob: f713b6f1019ea57ef71d8e2992da027473b03fd6 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/bin/sh -e
# https://gist.github.com/crispyricepc/f313386043395ff06570e02af2d9a8e0

# Get the sway tree and store the output
sway_tree=$(swaymsg -t get_tree | jq -r '.. | select(.pid? and .visible?)')

# Invoke slurp to let the user select a window, and extract
# the x, y, width, and height from the selection.
IFS=', x' read -r x y w h < <(echo "$sway_tree" | jq -r '.rect | "\(.x),\(.y) \(.width)x\(.height)"' | slurp -r)

# Find the window matching the selection.
echo "$sway_tree" |
  jq --argjson x "$x" --argjson y "$y" --argjson w "$w" --argjson h "$h" \
     '. | select(.rect.x == $x and .rect.y == $y and .rect.width == $w and .rect.height == $h)'