diff --git a/display.sh b/display.sh index d641147..3463146 100755 --- a/display.sh +++ b/display.sh @@ -1,7 +1,6 @@ #!/bin/sh # stateful script to manage dual monitor setups -# c read_cfg() { if [ -f ~/.config/xrandr ]; then @@ -10,9 +9,6 @@ read_cfg() { if [ -z "${PRIMARY_MONITOR}" ]; then PRIMARY_MONITOR=$(get_default_monitor) fi - if [ -z "${SECONDARY_MONITOR}" ]; then - SECONDARY_MONITOR=$(get_default_monitor) - fi if [ -z "${MONITOR_RELATION}" ]; then MONITOR_RELATION="solo" fi @@ -30,13 +26,16 @@ get_default_monitor() { apply_monitor_cfg() { xrandr --output ${PRIMARY_MONITOR} --auto --primary - if [ ${PRIMARY_MONITOR} != ${SECONDARY_MONITOR} ]; then + if [ ! -z "${SECONDARY_MONITOR}" ] && [ "${SECONDARY_MONITOR}" != "${PRIMARY_MONITOR}" ]; then case ${MONITOR_RELATION} in solo) xrandr --output ${SECONDARY_MONITOR} --off ;; - left_of|right_of|above|below) - xrandr --output ${SECONDARY_MONITOR} --auto ${MONITOR_RELATION} ${PRIMARY_MONITOR} ;; + left-of|right-of|above|below) + xrandr --output ${SECONDARY_MONITOR} --auto --${MONITOR_RELATION} ${PRIMARY_MONITOR} ;; esac + else + echo "SECONDARY_MONITOR is not set, or same as PRIMARY_MONITOR:" + show_cfg fi } @@ -50,8 +49,8 @@ helpme() { printf " relation: set monitor relation\n" printf " reconfigure: set monitor config based on the relation\n" printf " relations:\n" - printf " solo: disable secondary monitor if different from primary\n" - printf " left_of,right_of,above,below: secondary monitor has named relation to primary\n" + printf " solo: disable secondary monitor\n" + printf " left-of,right-of,above,below: secondary monitor has named relation to primary\n" } read_cfg