commit ea9e17a
hovercats
·
2022-03-03 11:16:33 +0000 UTC
parent fdf6a2d
focus.sh: add
1 files changed,
+50,
-0
A
focus.sh
A
focus.sh
+50,
-0
1@@ -0,0 +1,50 @@
2+#!/bin/sh
3+#
4+# z3bra - 2014 (c) wtfpl
5+# window focus wrapper that sets borders and can focus next/previous window
6+
7+BW=${BW:-2} # border width
8+ACTIVE=${ACTIVE:-0xffffff} # active border color
9+INACTIVE=${INACTIVE:-0x333333} # inactive border color
10+
11+# get current window id
12+CUR=$(pfw)
13+
14+usage() {
15+ echo "usage: $(basename "$0") <next|prev|wid>"
16+ exit 1
17+}
18+
19+setborder() {
20+ ROOT=$(lsw -r)
21+
22+ # check if window exists
23+ wattr "$2" || return
24+
25+ # do not modify border of fullscreen windows
26+ test "$(wattr xywh "$2")" = "$(wattr xywh "$ROOT")" && return
27+
28+ case $1 in
29+ active) chwb -s "$BW" -c "$ACTIVE" "$2" ;;
30+ inactive) chwb -s "$BW" -c "$INACTIVE" "$2" ;;
31+ esac
32+}
33+
34+case $1 in
35+ next) wid=$(lsw|grep -v "$CUR"|sed '1 p;d') ;;
36+ prev) wid=$(lsw|grep -v "$CUR"|sed '$ p;d') ;;
37+ 0x*) wattr "$1" && wid=$1 ;;
38+ *) usage ;;
39+esac
40+
41+# exit if we can't find another window to focus
42+test -z "$wid" && echo "$(basename "$0"): can't find a window to focus" >&2 && exit 1
43+
44+setborder inactive "$CUR" # set inactive border on current window
45+setborder active "$wid" # activate the new window
46+chwso -r "$wid" # put it on top of the stack
47+wtf "$wid" # set focus on it
48+
49+# you might want to remove this for sloppy focus
50+wmp -a "$(wattr xy "$wid")" # move the mouse cursor to
51+wmp -r "$(wattr wh "$wid")" # .. its bottom right corner