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.
|
|
|
|
#
|
|
|
|
|
2018-08-27 20:28:58 -05:00
|
|
|
if ! pgrep bspwm > /dev/null 2>&1; then
|
|
|
|
tsk_log "Not running in bspwm"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
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}
|
2018-08-22 11:10:32 -05:00
|
|
|
desktops_secondary=$(($desktops_total - $desktops_primary))
|
2018-08-01 21:21:35 -05:00
|
|
|
|
2018-08-01 21:35:56 -05:00
|
|
|
# Sanity checks
|
|
|
|
if ! [[ "$desktops_total" -ge 1 ]]; then
|
2018-08-27 20:28:58 -05:00
|
|
|
tsk_log "desktops_total cannot be $desktops_total, defaulting to 8"
|
2018-08-01 21:35:56 -05:00
|
|
|
desktops_total=8
|
|
|
|
fi
|
|
|
|
if ! [[ "$desktops_primary" -ge 1 ]]; then
|
2018-08-27 20:28:58 -05:00
|
|
|
tsk_log "desktops_primary cannot be $desktops_primary, defaulting to 6"
|
2018-08-01 21:35:56 -05:00
|
|
|
desktops_primary=6
|
|
|
|
fi
|
|
|
|
|
2018-08-02 21:13:57 -05:00
|
|
|
# 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
|
2018-08-27 20:28:58 -05:00
|
|
|
tsk_log "Configuration would leave some monitors without desktops; adding more"
|
2018-08-02 21:13:57 -05:00
|
|
|
desktops_secondary=${#monitors_secondary[@]}
|
2018-08-22 11:10:32 -05:00
|
|
|
desktops_total=$(($desktops_secondary + $desktops_primary))
|
2018-08-02 21:13:57 -05:00
|
|
|
deskpermon=1
|
2018-08-27 20:28:58 -05:00
|
|
|
tsk_log "Remaining desktops set to $desktops_secondary, highest desktop is now $desktops_total"
|
2018-08-02 21:13:57 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Can we actually reach all of these desktops via keybinds?
|
|
|
|
if [[ $desktops_total -gt 10 ]]; then
|
2018-08-27 20:28:58 -05:00
|
|
|
tsk_log "More than ten desktops were allocated! Not all of these can be reached via keybinds!"
|
2018-08-22 11:10:32 -05:00
|
|
|
if [[ $(($desktops_total - $desktops_secondary)) -gt 0 ]]; then
|
2018-08-27 20:28:58 -05:00
|
|
|
tsk_log "Adjusting primary desktop reservation"
|
2018-08-22 11:10:32 -05:00
|
|
|
desktops_primary=$(($desktops_total - $desktops_secondary))
|
2018-08-27 20:28:58 -05:00
|
|
|
tsk_log "Set reserved desktops to $desktops_primary"
|
2018-08-02 21:13:57 -05:00
|
|
|
else
|
2018-08-27 20:28:58 -05:00
|
|
|
tsk_log "Cannot resolve this situation without starving the primary monitor of desktops!"
|
|
|
|
tsk_log "This may result in desktops being allocated that cannot be easily accessed!"
|
2018-08-02 21:13:57 -05:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# The code that actually sets the monitors up
|
|
|
|
# First, do we actually have any secondaries?
|
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)
|
2018-08-27 20:28:58 -05:00
|
|
|
tsk_log "Found one monitor: $monitor_primary, so giving it layout \"$layout\""
|
2018-08-01 21:21:35 -05:00
|
|
|
bspc monitor $monitor_primary -d $layout
|
|
|
|
else
|
2018-08-22 11:10:32 -05:00
|
|
|
deskpermon=$(($desktops_secondary / ${#monitors_secondary[@]}))
|
2018-08-01 21:21:35 -05:00
|
|
|
layout=$(seq --separator=" " 1 $desktops_primary)
|
2018-08-27 20:28:58 -05:00
|
|
|
tsk_log "Giving primary monitor $monitor_primary layout \"$layout\""
|
2018-08-01 21:21:35 -05:00
|
|
|
bspc monitor $monitor_primary -d $layout
|
|
|
|
unset layout
|
2018-08-27 20:28:58 -05:00
|
|
|
tsk_log "Attempting to put $desktops_secondary desktops across ${#monitors_secondary[@]} monitors, $deskpermon each"
|
2018-08-22 11:10:32 -05:00
|
|
|
for m in $(seq 0 $((${#monitors_secondary[@]} - 1))); do
|
|
|
|
layout=$(seq --separator=" " $((1 + $m + $desktops_primary)) ${#monitors_secondary[@]} "$desktops_total")
|
2018-08-27 20:28:58 -05:00
|
|
|
tsk_log "Giving monitor $m (${monitors_secondary[$m]}) layout \"$layout\""
|
2018-08-01 21:21:35 -05:00
|
|
|
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
|
|
|
|