diff --git a/screen.sh b/screen.sh new file mode 100755 index 0000000..657154c --- /dev/null +++ b/screen.sh @@ -0,0 +1,81 @@ +#!/bin/ksh +# +# Copyright (c) 2020 Uwe Werler +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# +# This is a small script to set my monitors when plugged into the docking +# station. It starts from left to right in the order of detection. It can be +# used in cwm with e.g.: +# +# bind-key C4-r '/home/uwerler/bin/screen.sh' +# bind-key C4-R '/home/uwerler/bin/screen.sh --off' +# + +[[ -n ${1} ]] && _eDP="--off" + +xrandr --verbose | { while read _line; do + + case $_line in + *\ connected*) + set -A CDEVS ${CDEVS[@]} ${_line%% connected*} + ;; + *\ disconnected*) + set -A DDEVS ${DDEVS[@]} ${_line%% disconnected*} + ;; + esac + + done + + _pos=0 + _prim="--primary" + + for _dev in ${CDEVS[*]}; do + + if [[ ${#CDEVS[*]} -gt 1 ]]; then + + case ${_dev} in + + eDP*) if [[ ${_eDP} == "--off" ]]; then + + set -A XRANDR -- "--output ${_dev} ${_eDP}" + + else + + set -A XRANDR -- "--output ${_dev} --mode 1920x1080 --pos $(( (${#CDEVS[*]}-1)*1920 ))x0 --rotate normal" + fi + + ;; + + *) set -A XRANDR -- "${XRANDR[@]} --output ${_dev} ${_prim} --mode 1920x1080 --pos ${_pos}x0 --rotate normal" + (( _pos += 1920 )) + unset _prim + ;; + esac + + else + + set -A XRANDR -- "${XRANDR[@]} --output ${_dev} --primary --mode 1920x1080 --pos 0x0 --rotate normal" + fi + + done + + for _dev in ${DDEVS[*]}; do + + set -A XRANDR -- "${XRANDR[@]} --output ${_dev} --off" + done + + xrandr ${XRANDR[@]} +} + +#vim: set ai:ts=2:et:sw=2