improve licensing
[distro-setup] / i3-mouse-warp
1 #!/bin/bash
2 set -e; . /usr/local/lib/bash-bear; set +e
3
4 ## based on:
5 ## https://github.com/i3/i3/issues/2971
6
7 window=$(xdotool getwindowfocus)
8
9 # this brings in variables WIDTH and HEIGHT
10 eval "$(xdotool getwindowgeometry --shell $window)"
11
12
13 if (( HEIGHT > 100 )); then
14 TX=$(( WIDTH / 2))
15 TY=$(( HEIGHT / 2))
16
17 xdotool mousemove -window $window $TX $TY
18 # iank, original says "Check for height of 100 assumes that anything
19 # less than that means no window", and this condition is for "when I
20 # am navigating to a screen that does not have an open window on it". I don't think
21 else
22 rect=$(i3-msg -t get_workspaces | jq -r '.[] | select(.focused==true).rect')
23
24 x=$(jq -r '.x' <<< $rect)
25 y=$(jq -r '.y' <<< $rect)
26 w=$(jq -r '.width' <<< $rect)
27 h=$(jq -r '.height' <<< $rect)
28 TX=$(( x + w / 2))
29 TY=$(( y + h / 2))
30 xdotool mousemove -window $window $TX $TY
31 fi