diff options
Diffstat (limited to 'local/bin/mxrandr')
-rwxr-xr-x | local/bin/mxrandr | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/local/bin/mxrandr b/local/bin/mxrandr new file mode 100755 index 0000000..7c51128 --- /dev/null +++ b/local/bin/mxrandr @@ -0,0 +1,119 @@ +#!/bin/bash + +# get info from xrandr +connectedOutputs=$(xrandr | grep " connected" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/") +activeOutput=$(xrandr | grep -E " connected (primary )?[1-9]+" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/") +disconnectedOutputs=$(xrandr | grep -E " disconnected (primary )?[1-9]+" | awk '{print $1}') + +cmd="xrandr " +cmd_def=$cmd + +INTERNAL=eDP1 +HDMI=HDMI1 +VGA=VGA1 + +for device in "$disconnectedOutputs"; do + if [ -n "$defice" ]; then + if [[ "$activeOutput" == *"$device"* ]]; then + cmd=$cmd" --output $device --off" + fi + fi +done + +function only_internal { + cmd=$cmd" --output $INTERNAL --auto --primary" + cmd=$cmd" --output $HDMI --off" + cmd=$cmd" --output $VGA --off" +} + +function internal_vga { + cmd=$cmd" --output $INTERNAL --auto --primary" + cmd=$cmd" --output $HDMI --off" + cmd=$cmd" --output $VGA --auto --right-of $INTERNAL" +} + +function internal_hdmi { + cmd=$cmd" --output $INTERNAL --auto --right-of $HDMI" + cmd=$cmd" --output $HDMI --auto --primary" + cmd=$cmd" --output $VGA --off" +} + +function internal_hdmi_vga { + cmd=$cmd" --output $INTERNAL --auto --right-of $HDMI" + cmd=$cmd" --output $HDMI --auto --primary" + cmd=$cmd" --output $VGA --auto --left-of $HDMI" +} + +function cmd_exec { + if [ "$cmd" != "$cmd_def" ]; then + echo $cmd + `$cmd` + fi +} + + +if [ $# -le 1 ]; then + if [[ "$connectedOutputs" == *"$HDMI"* ]]; then + if [[ "$connectedOutputs" == *"$VGA"* ]]; then + internal_hdmi_vga + else + internal_hdmi + fi + else + if [[ "$connectedOutputs" == *"$VGA"* ]]; then + internal_vga + else + only_internal + fi + fi + cmd_exec + exit +fi + +if [ "$2" != "mode" ]; then + if [[ "$connectedOutputs" != *"$2"* ]]; then + echo No $2 display known + exit + fi +fi + +case "$1" in + toggle) + case "$2" in + $INTERNAL) + if [[ "$activeOutput" == *"$INTERNAL"* ]]; then + cmd=$cmd" --output $INTERNAL --off" + else + if [[ "$activeOutput" == *"$HDMI"* ]]; then + cmd=$cmd" --output $INTERNAL --auto --right-of $HDMI" + else + cmd=$cmd" --output $INTERNAL --auto --primary" + fi + fi + ;; + $HDMI) + if [[ "$activeOutput" == *"$HDMI"* ]]; then + cmd=$cmd" --output $HDMI --off" + else + if [[ "$activeOutput" == *"$VGA"* ]]; then + cmd=$cmd" --output $HDMI --auto --primary" + else + cmd=$cmd" --output $HDMI --auto --right-of $INTERNAL" + fi + fi + ;; + $VGA) + if [[ "$activeOutput" == *"$VGA"* ]]; then + cmd=$cmd" --output $VGA --off" + else + if [[ "$activeOutput" == *"$HDMI"* ]]; then + cmd=$cmd" --output $VGA --auto --left-of $HDMI" + else + cmd=$cmd" --output $VGA --auto --right-of $INTERNAL" + fi + fi + ;; + esac + ;; +esac +cmd_exec |