diff --git a/bin/auto-display b/bin/auto-display new file mode 100755 index 0000000..241a53d --- /dev/null +++ b/bin/auto-display @@ -0,0 +1,29 @@ +#! /bin/bash + +# Needed exports and vars +#export DISPLAY=$(w -h -s | grep ":[0-9]\W" | head -1 | awk '{print $3}') +X_USER=$(w -h -s | grep ":[0-9]\W" | head -1 | awk '{print $1}') +X_UID=$(id -u ${X_USER}) +export XAUTHORITY=/home/${X_USER}/.Xauthority + +# Grep connected/disconnected monitors from xrandr +EXTRA_DISPLAY=$(xrandr | grep " connected" | grep -v "eDP1" | awk '{print $1}') +DISCONNECTED_DISPLAY=$(xrandr | grep " disconnected" | awk '{print $1}') + +xrandr --auto + +# Make sure disconnected display are off +for display in ${DISCONNECTED_DISPLAY}; do + xrandr --output ${display} --off +done + +if [ $(wc -l <<< ${EXTRA_DISPLAY}) -eq 0 ]; then + xrandr --output eDP1 --primary +elif [ $(wc -l <<< ${EXTRA_DISPLAY}) -eq 1 ]; then + xrandr --output ${EXTRA_DISPLAY} --primary --output eDP1 --right-of ${EXTRA_DISPLAY} +else + xrandr --output eDP1 --off + FIRST_DISPLAY=$(head -n1 <<< ${EXTRA_DISPLAY}) + SECOND_DISPLAY=$(head -n2 <<< ${EXTRA_DISPLAY} | tail -n1) + xrandr --output ${FIRST_DISPLAY} --primary --output ${SECOND_DISPLAY} --right-of ${FIRST_DISPLAY} +fi diff --git a/bin/auto-outputs b/bin/auto-outputs deleted file mode 100755 index 4736ae2..0000000 --- a/bin/auto-outputs +++ /dev/null @@ -1,20 +0,0 @@ -#! /bin/bash - -. ~/.config/i3/env - -usage() { - echo "usage: auto-outputs" -} - -if [ $# -ne 0 ]; then - usage; exit 1 -fi - -xrandr --auto -if [ -n "${PRIMARY_OUTPUT}" ] && [ -n "${SECONDARY_OUTPUT}" ]; then - if [ -n "${SECONDARY_OUTPUT_POSITION}" ]; then - xrandr --output ${PRIMARY_OUTPUT} --primary --output ${SECONDARY_OUTPUT} ${SECONDARY_OUTPUT_POSITION} HDMI-1 - else - xrandr --output ${PRIMARY_OUTPUT} --primary --output ${SECONDARY_OUTPUT} --right-of HDMI-1 - fi -fi diff --git a/config b/config index 7c202ef..29f1419 100644 --- a/config +++ b/config @@ -1,7 +1,7 @@ set $mod Mod4 floating_modifier $mod -exec --no-startup-id ~/.config/i3/bin/auto-outputs +exec --no-startup-id ~/.config/i3/bin/auto-display ########## # Visual # @@ -31,6 +31,7 @@ bindsym $mod+Shift+c kill bindsym $mod+Shift+r reload bindsym $mod+Control+r restart bindsym $mod+Control+q exit +bindsym $mod+Control+d exec ~/.config/i3/bin/auto-display bindsym --release $mod+z exec slock # basic softs bindsym $mod+Return exec kitty