mirror of
https://github.com/tomru/switchmon.git
synced 2026-03-03 06:27:23 +01:00
can pass a single device now
This commit is contained in:
60
swm
60
swm
@@ -7,31 +7,61 @@
|
|||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
CONNECTED=$( xrandr | grep " connected" | awk '{print $1}')
|
usage() {
|
||||||
DISCONNECTED=$( xrandr | grep "disconnected" | awk '{print $1}')
|
echo "swm - a helper to switch connected monitors";
|
||||||
|
echo;
|
||||||
|
echo "usage: swm [monitor]";
|
||||||
|
echo;
|
||||||
|
echo "If monitor is not passed it turns on all connected devices";
|
||||||
|
echo "and lays them out next to each other in the order detected.";
|
||||||
|
echo;
|
||||||
|
echo "monitor: The string as reported by the script. If provided only";
|
||||||
|
echo "this monitor will be turned on.";
|
||||||
|
}
|
||||||
|
|
||||||
POSTCMD="herbstclient reload"
|
echoerr() { echo "$@" 1>&2; }
|
||||||
|
|
||||||
|
if [[ $1 == "-h" ]] || [[ $1 == "--help" ]] ; then
|
||||||
|
usage
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
TARGET=$1;
|
||||||
|
CONNECTED=$( xrandr | grep " connected" | awk 'BEGIN{ORS=" "} {print $1}');
|
||||||
|
DISCONNECTED=$( xrandr | grep "disconnected" | awk 'BEGIN{ORS=" "} {print $1}');
|
||||||
|
|
||||||
|
POSTCMD="herbstclient reload";
|
||||||
|
|
||||||
|
|
||||||
|
echo connected devices: $CONNECTED;
|
||||||
|
echo disconnected devices: $DISCONNECTED;
|
||||||
|
|
||||||
|
if [[ -n "$TARGET" ]] && [[ ! "$CONNECTED" =~ "$TARGET" ]] ; then
|
||||||
|
echoerr "error: device $1 is not connected";
|
||||||
|
exit 1;
|
||||||
|
fi
|
||||||
|
|
||||||
|
FORON=${1-$CONNECTED};
|
||||||
|
FOROFF="$DISCONNECTED ${CONNECTED//$TARGET/}";
|
||||||
|
|
||||||
# turn off all disconnected monitors
|
# turn off all disconnected monitors
|
||||||
XRANDR_OFF_OPTIONS=""
|
XRANDR_OFF_OPTIONS="";
|
||||||
for mon in $DISCONNECTED; do
|
for mon in $FOROFF; do
|
||||||
XRANDR_OFF_OPTIONS+=" --output $mon --off"
|
XRANDR_OFF_OPTIONS+=" --output $mon --off";
|
||||||
done
|
done
|
||||||
|
|
||||||
# turn on all connected monitors
|
# turn on all connected monitors
|
||||||
XRANDR_ON_OPTIONS=""
|
XRANDR_ON_OPTIONS="";
|
||||||
LAST=""
|
LAST="";
|
||||||
for mon in $CONNECTED; do
|
for mon in $FORON; do
|
||||||
XRANDR_ON_OPTIONS+=" --output $mon --auto"
|
XRANDR_ON_OPTIONS+=" --output $mon --auto";
|
||||||
if [ ! -z $LAST ]; then
|
if [ ! -z $LAST ]; then
|
||||||
XRANDR_ON_OPTIONS+=" --right-of $LAST"
|
XRANDR_ON_OPTIONS+=" --right-of $LAST";
|
||||||
fi
|
fi
|
||||||
LAST=$mon
|
LAST=$mon;
|
||||||
done
|
done
|
||||||
|
|
||||||
xrandr $XRANDR_ON_OPTIONS $XRANDR_OFF_OPTIONS &&\
|
xrandr $XRANDR_ON_OPTIONS $XRANDR_OFF_OPTIONS &&\
|
||||||
echo Activated monitors: ${CONNECTED} &&\
|
echo Activated monitors: ${FORON} &&\
|
||||||
$POSTCMD
|
$POSTCMD;
|
||||||
|
|
||||||
exit $?
|
|
||||||
|
|||||||
Reference in New Issue
Block a user