Last active
March 26, 2019 07:32
-
-
Save jamesmcdonald/66e03e6ea2d50b51c300def03a382c54 to your computer and use it in GitHub Desktop.
Monitor plug autodetection for i3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This should go in /etc/udev/rules.d | |
KERNEL=="card0", SUBSYSTEM=="drm", ACTION=="change", RUN+="/usr/local/bin/monitorswitch.sh" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# You will have to customise the device names and layout to whatever xrandr | |
# setup is appropriate for your machine. udev will run this script as root, | |
# which works fine for calling xrandr. | |
# /etc/udev/rules.d/98-monitorswitch.rules: | |
# KERNEL=="card0", SUBSYSTEM=="drm", ACTION=="change", RUN+="/usr/local/bin/monitorswitch.sh" | |
#exec >>/tmp/monitorswitch.log 2>&1 | |
read user dn <<EOF | |
$(who | perl -lane 'if (/\(:([0-9])+\)/) {print "$F[0] $1"; exit}') | |
EOF | |
userhome=$(getent passwd $user | cut -f6 -d:) | |
export XAUTHORITY=$userhome/.Xauthority | |
export DISPLAY=:$dn | |
displays=$(xrandr | perl -lane '/ connected/ && print $F[0]') | |
echo "connected displays:" $displays | |
if echo $displays | grep -q DP-2 && echo $displays | grep -q DP-3; then | |
xrandr --output DP-2 --auto --right-of LVDS-1 --verbose | |
xrandr --output DP-3 --auto --right-of DP-2 --verbose | |
else | |
xrandr --output DP-2 --off | |
xrandr --output DP-3 --off | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment