2018-08-01 19:50:05 -05:00
|
|
|
#! /bin/bash
|
|
|
|
#
|
|
|
|
# monitorset.sh
|
|
|
|
# Copyright (C) 2018 salt <salt@dsk-cstm-0>
|
|
|
|
#
|
|
|
|
# Distributed under terms of the MIT license.
|
|
|
|
#
|
|
|
|
|
|
|
|
printf "[INFO] Setting up monitors\n"
|
|
|
|
# Get the primary first, to ensure it's the first element
|
2018-08-01 21:21:35 -05:00
|
|
|
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)
|
|
|
|
|
2018-08-01 21:35:56 -05:00
|
|
|
# Sanity checks
|
|
|
|
if ! [[ "$desktops_total" -ge 1 ]]; then
|
|
|
|
printf " [ERROR] desktops_total cannot be $desktops_total, defaulting\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
|
|
|
|
desktops_primary=6
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Setup
|
2018-08-01 21:21:35 -05:00
|
|
|
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
|
2018-08-01 21:35:56 -05:00
|
|
|
deskpermon=$(expr $desktops_secondary / ${#monitors_secondary[@]})
|
2018-08-01 21:21:35 -05:00
|
|
|
# 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[@]}
|
2018-08-01 21:35:56 -05:00
|
|
|
desktops_total=$(expr $desktops_secondary + $desktops_primary)
|
2018-08-01 21:21:35 -05:00
|
|
|
deskpermon=1
|
2018-08-01 21:35:56 -05:00
|
|
|
printf " [INFO] Remaining workspaces set to $desktops_secondary, highest workspace is now $desktops_total\n"
|
2018-08-01 21:21:35 -05:00
|
|
|
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
|
2018-08-01 19:50:05 -05:00
|
|
|
|