Skip to content

Instantly share code, notes, and snippets.

@hh
Created August 27, 2014 22:02
Show Gist options
  • Save hh/55eed67c5c5a27f555cc to your computer and use it in GitHub Desktop.
Save hh/55eed67c5c5a27f555cc to your computer and use it in GitHub Desktop.
Detecting external monitor changes and reconfiguring X Displays and reloading Window manager on Arch MacBookAir5,2
# put this in /etc/udev/rules.d
# It's important that it starts with 99 or something high
# If this file is 10-local.rules it will fail to run the scripts
ACTION=="change", SUBSYSTEM=="drm", RUN+="/etc/udev/monitor.change.sh"
#!/bin/bash
status="$(cat /sys/class/drm/card0-HDMI-A-1/status)"
enabled="$(cat /sys/class/drm/card0-HDMI-A-1/enabled)"
export DISPLAY=:0
export XAUTHORITY=/home/hh/.Xauthority
if [ "${status}" = disconnected ]; then
if [ "${enabled}" = enabled ]; then
/usr/bin/xrandr --auto
killall awesome -SIGHUP
fi
elif [ "${status}" = connected ]; then
if [ "${enabled}" = disabled ]; then
/usr/bin/xrandr --output HDMI1 --auto --left-of eDP1
killall awesome -SIGHUP
fi
else
/usr/bin/xrandr --auto
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment