master ohmu/wmutils / scripts / bf
ohmu  ·  2026-07-25
 1#!/bin/sh
 2# focus.sh
 3
 4. ~/.theme
 5
 6# get current window id
 7CUR=$(pfw)
 8
 9usage() {
10    echo "usage: $(basename $0) <next|prev|wid>"
11    exit 1
12}
13
14setborder() {
15    ROOT=$(lsw -r)
16    wattr $2 || return
17    test "$(wattr xywh $2)" = "$(wattr xywh $ROOT)" && return
18
19    pkill -f "chwb.*$2" 2>/dev/null
20    
21    case $1 in
22		active)   chwb -s $TBW -c $ACTIVE $2 ;;
23        inactive)   chwb -s $TBW -c $INACTIVE $2 ;;
24    esac
25}
26
27case $1 in
28    next) wid=$(lsw|grep -v $CUR|sed '1 p;d') ;;
29    prev) wid=$(lsw|grep -v $CUR|sed '$ p;d') ;;
30    0x*) wattr $1 && wid=$1 ;;
31    *) usage ;;
32esac
33
34if [ -z "$wid" ]; then
35    for w in $(lsw); do
36        setborder active $w
37    done
38    exit 0
39fi
40
41chwso -r $wid
42wtf $wid
43
44geom=$(wattr xywh $wid)
45set -- $geom
46x=$1; y=$2; w=$3; h=$4
47center_x=$((x + w/2))
48center_y=$((y + h/2))
49#wmp -a $center_x $center_y
50
51for w in $(lsw); do
52    if [ "$w" != "$wid" ]; then
53        setborder inactive $w
54    fi
55done
56
57sleep 0.01
58setborder active $wid