2023-03-06 19:08:25 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
2023-03-15 05:40:44 +01:00
|
|
|
## sort windows by herds/flock ##
|
2023-03-07 14:01:29 +01:00
|
|
|
|
2023-08-08 04:42:24 +02:00
|
|
|
. /tmp/wms_var
|
2023-03-06 19:08:25 +01:00
|
|
|
|
2023-04-01 05:27:27 +02:00
|
|
|
FLAG=$1 # input
|
|
|
|
FW=$(pfw) # focused window id
|
|
|
|
AMW=$(lsw) # all maped windows
|
2023-08-07 04:23:00 +02:00
|
|
|
NAMES="$HOME/.config/wms/wms_names"
|
2023-03-06 19:08:25 +01:00
|
|
|
|
|
|
|
usage() {
|
2023-07-24 08:08:48 +02:00
|
|
|
cat<<EOF
|
|
|
|
usage:
|
2023-03-20 02:46:41 +01:00
|
|
|
wms_shepperd.sh [ -a, -r, -t ]
|
2023-03-06 19:08:25 +01:00
|
|
|
-a) add
|
|
|
|
-A) add all
|
|
|
|
-d) delete
|
|
|
|
-D) delete all
|
2023-07-24 08:08:48 +02:00
|
|
|
-t) togle
|
|
|
|
EOF
|
2023-03-06 19:08:25 +01:00
|
|
|
}
|
|
|
|
|
2023-03-09 05:41:12 +01:00
|
|
|
# create atom in focused window
|
|
|
|
add_focused() {
|
2023-06-29 06:45:55 +02:00
|
|
|
name="$($XMENU < $NAMES)"
|
2023-08-07 04:23:00 +02:00
|
|
|
if [ -n "$name" ]; then
|
2023-04-06 07:05:22 +02:00
|
|
|
atomx WM_HERD="$name $FW" $FW
|
2023-04-01 05:27:27 +02:00
|
|
|
else
|
|
|
|
exit 0
|
2023-03-15 05:40:44 +01:00
|
|
|
fi
|
2023-03-09 05:41:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# create atom in all maped windows
|
|
|
|
add_all() {
|
2023-06-29 06:45:55 +02:00
|
|
|
name="$($XMENU < $NAMES)"
|
2023-09-26 06:47:29 +02:00
|
|
|
for wid in $AMW; do
|
2023-03-31 15:44:07 +02:00
|
|
|
if [ -n "$name" ]; then
|
|
|
|
atomx WM_HERD="$name $wid" $wid
|
|
|
|
else
|
2023-04-01 05:27:27 +02:00
|
|
|
exit 0
|
2023-03-31 15:44:07 +02:00
|
|
|
fi
|
|
|
|
done
|
2023-03-09 05:41:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# delete atom from focused window
|
|
|
|
del_focused() {
|
2023-03-15 05:40:44 +01:00
|
|
|
atomx -d WM_HERD $FW
|
2023-03-09 05:41:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
del_all() {
|
2023-03-15 05:40:44 +01:00
|
|
|
atomx -d WM_HERD $AMW
|
2023-03-09 05:41:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# togle groups
|
|
|
|
togle() {
|
2023-03-31 15:44:07 +02:00
|
|
|
herds=$(atomx WM_HERD $(lsw -a) | cut -d ' ' -f1 | sort -u) # herds
|
2023-03-15 05:40:44 +01:00
|
|
|
if [ -n "$herds" ]; then # check if any herd exist
|
|
|
|
h_target=$(printf "$herds" | $XMENU) # select herd target
|
2023-03-31 15:44:07 +02:00
|
|
|
wind_to_map=$(atomx WM_HERD $(lsw -u) | grep $h_target | cut -d ' ' -f2) # windows to map
|
|
|
|
wind_to_unmap=$(atomx WM_HERD $(lsw) | grep -v $h_target | cut -d ' ' -f2) # windows to unmap
|
|
|
|
mapw -m $wind_to_map & mapw -u $wind_to_unmap
|
2023-03-09 05:41:12 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case $FLAG in
|
|
|
|
-a)
|
|
|
|
add_focused
|
|
|
|
;;
|
|
|
|
-A)
|
|
|
|
add_all
|
|
|
|
;;
|
|
|
|
-d)
|
|
|
|
del_focused
|
|
|
|
;;
|
|
|
|
-D)
|
2023-05-12 06:03:45 +02:00
|
|
|
del_all
|
2023-03-09 05:41:12 +01:00
|
|
|
;;
|
|
|
|
-t)
|
|
|
|
togle
|
2023-03-06 19:08:25 +01:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage # self-explained
|
|
|
|
;;
|
|
|
|
esac
|
2023-06-29 06:47:19 +02:00
|
|
|
|