Hot plugging monitors in XFCE
Ever since Debian Wheezy has been released, I've been putting off the upgrade of my non-server machines because I don't want to switch from my cozy GNOME 2 desktop. As kind of a test trial, I've been using Wheezy with XFCE on my work laptop since mid-July. With some work I managed to get it pretty close to GNOME 2 functionality I am used to. However it still feels like a significant step backwards in usability and it has several annoying features that I was so far unable to work around.
I might post a list of tweaks I did later on in another post. For now, here is a somewhat ugly hack to work around the fact that XFCE never fails to do exactly the wrong thing when a monitor has been added or removed from the system. As I often move between a docking station, external monitor and an occasional projector, it's extremely annoying to have to drop into a terminal all the time to poke around xrandr.
This is based on this post I found. The original solution didn't work for me and was a bit more convoluted than it strictly needed to be. Plus having some error checking is always nice.
Any way, put the following into /etc/udev/rules.d/20-monitor.rules to tell udev to call a shell script on a monitor hot plug event:
ACTION=="change", SUBSYSTEM=="drm", ENV{HOTPLUG}=="1", ENV{DEVNAME}=="dri/card0", RUN+="/etc/udev/monitors.sh"
The corresponding script in my case looks like this:
#!/bin/bash set -e XUSER=`w -h -s|awk '$3~"^:0"{print $1; exit 0}'` if [ -z "$XUSER" ]; then echo "No one logged in, exiting." exit 0; fi XHOMEDIR=`getent passwd $XUSER|cut -d: -f6` export DISPLAY=":0" export XAUTHORITY="$XHOMEDIR/.Xauthority" # Adjust the following to fit your needs function dock { xrandr --output DisplayPort-2 --left-of LVDS --primary --auto } function undock { xrandr --auto } if xrandr|grep -q 'DisplayPort-2 connected'; then dock else undock fi
By the way, to debug scripts called from udev, use:
# udevadm control --log-priority=debug
This causes udev to log standard output and error streams emitted by scripts to syslog and is pretty useful when a script mysteriously doesn't seem to do what is supposed to.
The original warnings still apply. This solution only works when there is one graphical log in. It also doesn't work when you first turn on the computer or when the configuration of monitors change while the laptop was suspended.
For these cases I have a shortcut to monitors.sh on my desktop which I can click in anger when my high-DPI 24" flat panel starts pretending it has resolution of a Game Boy LCD.
Although a few years old, this article helped me. But I had to change the line in rules.d to this:
<pre>ACTION=="change", SUBSYSTEM=="drm", ENV{HOTPLUG}=="1", ENV{DEVNAME}=="dri/card0", RUN+="/etc/udev/monitors.sh"</pre>
source: https://bbs.archlinux.org/viewtopic.php?id=170294