From 03f30253179bfd3879eed7ee2c2b8e522efbb519 Mon Sep 17 00:00:00 2001 From: Thomas Ruoff Date: Mon, 28 Jul 2014 16:20:51 +0200 Subject: [PATCH] first approach --- swm.sh | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 swm.sh diff --git a/swm.sh b/swm.sh new file mode 100755 index 0000000..b6aa81e --- /dev/null +++ b/swm.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash +# +# Enable all connected montiors, disable all disconnected ones. +# Multiple monitors will be added to the right of previous ones. +# +# Author Thomas Ruoff + +set -e + +CONNECTED=$( xrandr | grep " connected" | awk '{print $1}') +DISCONNECTED=$( xrandr | grep "disconnected" | awk '{print $1}') + +POSTCMD="herbstclient reload" + + +# turn off all disconnected monitors +XRANDR_OFF_OPTIONS="" +for mon in $DISCONNECTED; do + XRANDR_OFF_OPTIONS+=" --output $mon --off" +done + +# turn on all connected monitors +XRANDR_ON_OPTIONS="" +LAST="" +for mon in $CONNECTED; do + XRANDR_ON_OPTIONS+=" --output $mon --auto" + if [ ! -z $LAST ]; then + XRANDR_ON_OPTIONS+=" --right-of $LAST" + fi + LAST=$mon +done + +xrandr $XRANDR_ON_OPTIONS $XRANDR_OFF_OPTIONS &&\ + echo Activated monitors: ${CONNECTED} &&\ + $POSTCMD + +exit $?