Editing my answer to make it simpler to setup.
Install autorandr to automate screen layout in xrandr, grab latest .deb from https://github.com/nalipaz/autorandr/releases and run:
dpkg -i [file]
Setup autorandr with stored screen layouts
autorandr --save [docked|mobile|home|etc]
As an example, on my laptop without any monitors plugged in, I setup arandr the way I want it, then ran:
autorandr --save mobile
Then plugged in my hdmi and reconfigured arandr, then ran:
autorandr --save docked
After setting up each of your layouts you can run (replace 'mobile' with previous favored name, I used mobile):
autorandr --default mobile
Now that autorandr is all setup you can automate the process by installing a package which will poll for connected displays and run autorandr --change
upon detection. Yes, I know about udev and you can set that up if it works for you, but in my testing udev didn't work for my hdmi consistently. It only worked 1 out of every 20 plugs/unplugs or so, and sometimes it just stopped altogether.
Download the latest .deb from here: https://github.com/nalipaz/poll-xrandr/releases/ then install with
dpkg -i [file]
It is most likely necessary that you run more tasks upon completion of autorandr --change
, autorandr allows for these commands to be inserted into a file called ~/.autorandr/postswitch. Do as follows:
cd ~/.autorandr/ && touch postswitch && chmod +x postswitch
Now edit the postswitch file to have something similar to the following:
#!/bin/bash
if pidof conky > /dev/null 2>&1; then
killall conky
fi
(sleep 2s && xrandr-adjust-brightness restore -q) &
(sleep 2s && nitrogen --restore) &
(sleep 3s && conky -q) &
Additionally you will likely want to add autorandr and poll-xrandr to your startups, something like the following two commands:
autorandr --change &
poll-xrandr &
Unplug or plug in a monitor and watch the magic!
udevadm monitor --property
from the terminal and plugging the monitor in. With my card, I see an event when it is plugged in. You may be able to use a +RUN rule in udev and some bash scripting to get what you want. However, I'm not sure how you would be able to implement this on a per user basis using udev.