wms/wms_backgroundize.sh

56 lines
1.2 KiB
Bash
Raw Normal View History

2023-03-07 02:55:30 +01:00
#!/bin/sh
2023-03-07 14:01:29 +01:00
## send windows to desktop background ##
2023-03-20 02:46:41 +01:00
. $HOME/.config/wms/wms_var
2023-03-07 02:55:30 +01:00
FLAG=$1
2023-03-07 14:01:29 +01:00
FW=$(pfw) # focused window
RID=$(lsw -r) # root widnow id
RW=$(wattr w $RID) # root width
RH=$(wattr h $RID) # root height
SW=$((RW - 2*BW)) # usable screen width
SH=$((RH - 2*BW)) # usable screen height
2023-03-07 02:55:30 +01:00
usage() {
echo "usage:
2023-03-20 02:46:41 +01:00
wms_backgroundize.sh [ -b, -r ]
2023-03-14 04:51:11 +01:00
-b) backgroundize focused window
-r) open menu and choose the window/s to restore"
2023-03-07 02:55:30 +01:00
}
2023-03-09 05:41:12 +01:00
# send windows to background
2023-03-14 04:51:11 +01:00
background() {
2023-03-09 05:41:12 +01:00
if [ ! "$(wattr o $FW && echo 1)" ]; then # if override is not set
wtp 0 0 $SW $SH $FW
ignw -s $FW # ignore focused window
chwb -c 000000 $FW # change border color to ignore
2023-03-07 02:55:30 +01:00
2023-03-09 05:41:12 +01:00
else
ignw -r $FW # unignore focused window
chwb -c $FG $FW # change border color to active
fi
}
2023-03-07 02:55:30 +01:00
2023-03-09 05:41:12 +01:00
# restore windows from background
2023-03-14 04:51:11 +01:00
restore() {
2023-03-09 05:41:12 +01:00
if [ -n "$(lsw -o)" ]; then
2023-03-07 02:55:30 +01:00
otarget=$(for wid in $(lsw -o); do # override target
printf '%s\n' "$wid | $(atomx WM_CLASS $wid) | $(wname $wid)"
done | cut -c 1-100 | $XMENU | cut -d ' ' -f 1)
ignw -r $otarget # unignore otarget
2023-03-09 05:41:12 +01:00
fi
}
case $FLAG in
2023-03-14 04:51:11 +01:00
-b)
background
2023-03-09 05:41:12 +01:00
;;
2023-03-14 04:51:11 +01:00
-r)
restore
2023-03-07 02:55:30 +01:00
;;
*)
usage
;;
esac