commit 90e3785
hovercats
·
2024-06-08 18:03:15 +0000 UTC
parent 6ab38e7
focus/fullscreen/watcher: nits | fix focusing and borders. focus no longer touches borders. this makes the borders set by the WM stay when using groups script to hide/unhide windows. fullscreen now sets border upon returning to windowed mode. watcher script now focues on MAP events, so windows being unhid, will now return focued, as one would expect
3 files changed,
+12,
-35
M
sh/focus
+6,
-31
1@@ -3,10 +3,6 @@
2 # z3bra - 2014 (c) wtfpl
3 # window focus wrapper that sets borders and can focus next/previous window
4
5-BW="${BW:-2}" # border width
6-ACTIVE="${ACTIVE:-0xffffff}" # active border color
7-INACTIVE="${INACTIVE:-0x333333}" # inactive border color
8-
9 # get current window id
10 CUR=$(pfw)
11
12@@ -15,37 +11,16 @@ usage() {
13 exit 1
14 }
15
16-setborder() {
17- ROOT="$(lsw -r)"
18-
19- # check if window exists
20- wattr "$2" || return
21-
22- # do not modify border of fullscreen windows
23- [ "$(wattr xywh "$2")" = "$(wattr xywh "$ROOT")" ] && return
24-
25- case "$1" in
26- active) chwb -s "$BW" -c "$ACTIVE" "$2" ;;
27- inactive) chwb -s "$BW" -c "$INACTIVE" "$2" ;;
28- esac
29-}
30-
31 case $1 in
32 next) wid="$(lsw | grep -v "$CUR" | sed '1 p;d')" ;;
33 prev) wid="$(lsw | grep -v "$CUR" | sed '$ p;d')" ;;
34- top) wid="$(lsw | sed '$ p;d')" ;;
35- 0x*) wattr "$1" && wid="$1" ;;
36- *) usage ;;
37+ top) wid="$(lsw | sed '$ p;d')" ;;
38+ 0x*) wattr "$1" && wid="$1" ;;
39+ *) usage ;;
40 esac
41
42 # exit if we can't find another window to focus
43-[ -z "$wid" ] && printf "$(basename "$0"): %s can't find a window to focus\n" >&2 && exit 1
44-
45-setborder inactive "${CUR}" # set inactive border on current window
46-setborder active "${wid}" # activate the new window
47-chwso -r "${wid}" # put it on top of the stack
48-wtf "${wid}" # set focus on it
49+[ -z "$wid" ] && exit 1
50
51-# you might want to remove this for sloppy focus
52-wmp -a "$(wattr xy "$wid")" # move the mouse cursor to
53-wmp -r "$(wattr wh "$wid")" # .. its bottom right corner
54+chwso -r "${wid}" # put it on top of the stack
55+wtf "${wid}" # set focus on it
+5,
-3
1@@ -4,6 +4,9 @@
2 # toggle the fullscreen state of a window
3 # depends on: focus
4
5+BW="${BW:-2}" # border width
6+ACTIVE="${ACTIVE:-0xffffff}" # active border color
7+
8 # this file is used to store the previous geometry of a window
9 FSFILE="${FSFILE:-/tmp/.fwin}"
10
11@@ -20,7 +23,7 @@ usage() {
12 # this way, there will only be one window in fullscreen at a time, and no window
13 # will loose their previous geometry info
14 # shellcheck disable=2046
15-[ -f "${FSFILE}" ] && wtp $(cat "${FSFILE}")
16+[ -f "${FSFILE}" ] && wtp $(cat "${FSFILE}") && chwb -s "${BW}" -c "${ACTIVE}" $(pfw)
17
18 # if file exist and contain our window id, it means that out window is in
19 # fullscreen mode
20@@ -38,6 +41,5 @@ else
21 wtp $(wattr xywh $(lsw -r)) "$1"
22 fi
23
24-# now focus the window, and put it in front, no matter which state we're in, and
25-# put the cursor on its bottom-right corner (for consistency)
26+# now focus the window, and put it in front
27 focus "$1"
+1,
-1
1@@ -5,7 +5,7 @@
2
3 while read ev wid args; do
4 case $ev in
5- MAP) wattr o $wid || focus top ;;
6+ MAP) wattr o $wid || focus $wid ;;
7 UNMAP) [ ! "$(pfw)" ] && focus top ;;
8 esac
9 done