From d253c3daf1e77a7b4932c1c71965d6873afa326d Mon Sep 17 00:00:00 2001 From: Salt Date: Wed, 1 Aug 2018 21:21:35 -0500 Subject: [PATCH] bspwm: Change behavior of workspace layout setter It now gives the primary monitor the first few workspaces, then distributes the rest over the remaining secondary monitors --- .config/bspwm/monitorset.sh | 50 +++++++++++++++++++++++++++------ .config/dtfscripts/wmstartup.sh | 4 +++ 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/.config/bspwm/monitorset.sh b/.config/bspwm/monitorset.sh index 8c76f3e1..439fe33d 100755 --- a/.config/bspwm/monitorset.sh +++ b/.config/bspwm/monitorset.sh @@ -8,13 +8,45 @@ printf "[INFO] Setting up monitors\n" # Get the primary first, to ensure it's the first element -monitors=($(xrandr -q | awk '/primary/{print $1}' && xrandr -q | grep ' connected' | grep -v 'primary' | awk '{print $1}')) -desktops=8 -deskpermon=$(expr $desktops / ${#monitors[@]}) -printf " [INFO] Putting $desktops desktops across ${#monitors[@]} monitors, $deskpermon each\n" -for m in $(seq 0 $(expr ${#monitors[@]} - 1)); do - layout=$(seq --separator=" " $(expr 1 + $m) ${#monitors[@]} $(expr $desktops )) - printf " [INFO] Giving monitor $m (${monitors[$m]}) layout \"$layout\"\n" - bspc monitor ${monitors[$m]} -d $layout -done +monitor_primary=$(xrandr -q | awk '/primary/{print $1}') +monitors_secondary=($(xrandr -q | grep ' connected' | grep -v 'primary' | awk '{print $1}')) + +desktops_total=${BSPWM_DESKTOPS_TOTAL:-8} +desktops_primary=${BSPWM_DESKTOPS_PRIMARY:-6} +desktops_secondary=$(expr $desktops_total - $desktops_primary) + +deskpermon=$(expr $desktops_secondary / ${#monitors_secondary[@]}) +printf " [INFO] Distributing $desktops_total desktops, $desktops_primary for primary and $desktops_secondary across all secondaries\n" +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" + bspc monitor $monitor_primary -d $layout +else + # Give the first monitor the first few workspaces + layout=$(seq --separator=" " 1 $desktops_primary) + 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[@]} + deskpermon=1 + printf " [INFO] Remaining workspaces set to $desktops_secondary\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" + bspc monitor ${monitors_secondary[$m]} -d $layout + done +fi +unset monitor_primary +unset monitors_secondary +unset desktops_total +unset desktops_primary +unset desktops_secondary +unset deskpermon diff --git a/.config/dtfscripts/wmstartup.sh b/.config/dtfscripts/wmstartup.sh index 4bd9827b..aaa42e7d 100755 --- a/.config/dtfscripts/wmstartup.sh +++ b/.config/dtfscripts/wmstartup.sh @@ -21,6 +21,7 @@ # SOFTWARE. ## Clean up some variables that I use in device-specific scripts +# Polybar unset PB_MONITOR unset PB_WM_RESTACK unset PB_BAR_WIDTH @@ -30,6 +31,9 @@ unset PB_BAR_SECONDARY_MODULES_LEFT PB_BAR_SECONDARY_MODULES_CENTER PB_BAR_SECON unset PB_BAR_SECONDARY_2_MODULES_LEFT PB_BAR_SECONDARY_2_MODULES_CENTER PB_BAR_SECONDARY_2_MODULES_RIGHT unset PB_MODULE_BAR_WIDTH unset PB_MODULE_WLAN_INTERFACE +# bspwm monitorset.sh +unset BSPWM_DESKTOPS_TOTAL +unset BSPWM_DESKTOPS_PRIMARY ## Patch path, if not already done if [[ "$PATH" != "*$HOME/.local/bin*" ]]; then