diff --git a/.config/bspwm/monitorset.sh b/.config/bspwm/monitorset.sh index c03d1fa1..e8a9536f 100755 --- a/.config/bspwm/monitorset.sh +++ b/.config/bspwm/monitorset.sh @@ -17,37 +17,53 @@ desktops_secondary=$(expr $desktops_total - $desktops_primary) # Sanity checks if ! [[ "$desktops_total" -ge 1 ]]; then - printf " [ERROR] desktops_total cannot be $desktops_total, defaulting\n" 1>&2 + printf " [ERROR] desktops_total cannot be $desktops_total, defaulting to 8\n" 1>&2 desktops_total=8 fi if ! [[ "$desktops_primary" -ge 1 ]]; then - printf " [ERROR] desktops_primary cannot be $desktops_primary, defaulting\n" 1>&2 + printf " [ERROR] desktops_primary cannot be $desktops_primary, defaulting to 6\n" 1>&2 desktops_primary=6 fi -# Setup +# Do we have enough desktops for all monitors? +# We can correct this without defaulting, so don't error +if [[ $desktops_secondary -lt ${#monitors_secondary[@]} ]]; then + printf " [WARN] Configuration would leave some monitors without desktops!\n" 1>&2 + printf " [INFO] Adding more desktops\n" + desktops_secondary=${#monitors_secondary[@]} + desktops_total=$(expr $desktops_secondary + $desktops_primary) + deskpermon=1 + printf " [INFO] Remaining desktops set to $desktops_secondary, highest desktop is now $desktops_total\n" +fi + +# Can we actually reach all of these desktops via keybinds? +if [[ $desktops_total -gt 10 ]]; then + printf " [WARN] More than ten desktops were allocated! Not all of these can be reached via keybinds!\n" 1>&2 + if [[ $(expr $desktops_total - $desktops_secondary) -gt 0 ]]; then + printf " [INFO] Adjusting primary desktop reservation\n" + desktops_primary=$(expr $desktops_total - $desktops_secondary) + printf " [INFO] Set reserved desktops to $desktops_primary\n" + else + printf " [WARN] Cannot resolve this situation without starving the primary monitor of desktops!\n" + printf " [WARN] This may result in desktops being allocated that cannot be easily accessed!\n" + fi +fi + + +# The code that actually sets the monitors up +# First, do we actually have any secondaries? if [[ $(echo ${monitors_secondary:-0}) == "0" ]]; then # We only have one monitor, so give it everything layout=$(seq --separator=" " 1 $desktops_total) - printf " [INFO] Found one monitor: $monitor_primary, so giving it layout "$layout"\n" + printf " [INFO] Found one monitor: $monitor_primary, so giving it layout \"$layout\"\n" bspc monitor $monitor_primary -d $layout else deskpermon=$(expr $desktops_secondary / ${#monitors_secondary[@]}) - # Give the first monitor the first few workspaces layout=$(seq --separator=" " 1 $desktops_primary) - printf " [INFO] Giving primary monitor $monitor_primary layout "$layout"\n" + printf " [INFO] Giving primary monitor $monitor_primary layout \"$layout\"\n" bspc monitor $monitor_primary -d $layout unset layout printf " [INFO] Attempting to put $desktops_secondary desktops across ${#monitors_secondary[@]} monitors, $deskpermon each\n" - # Ensure we have enough remaining workspaces for the secondary monitors - if [ $desktops_secondary -lt ${#monitors_secondary[@]} ]; then - printf " [WARN] Configuration would leave some monitors without workspaces! Adding more\n" - desktops_secondary=${#monitors_secondary[@]} - desktops_total=$(expr $desktops_secondary + $desktops_primary) - deskpermon=1 - printf " [INFO] Remaining workspaces set to $desktops_secondary, highest workspace is now $desktops_total\n" - fi - # And distribute the rest to the secondaries for m in $(seq 0 $(expr ${#monitors_secondary[@]} - 1)); do layout=$(seq --separator=" " $(expr 1 + $m + $desktops_primary) ${#monitors_secondary[@]} $(expr $desktops_total )) printf " [INFO] Giving monitor $m (${monitors_secondary[$m]}) layout \"$layout\"\n"