I move my laptop (ThinkPad T570, Ubuntu Xenial, Unity/Compiz) between different work environments, and I find that using Unity Control Center "Display" applet doesn't reliably (ever?!) retain the arrangements I specify.
To work around this, I've written a bash/xrandr script which arranges things as I want them. (Available here as a gist, but the details aren't really essential to my question so not including in full). If the screens don't appear correctly then I execute this script to arrange them.
What I'd like to do is have this script trigger on monitor connection. Unity/Compiz do this for the settings stored in Display prefs, so I'd like to know the correct way to take my preferred settings as expressed in bash/xrandr, and have that be delivered by Ubuntu as part of the "native" experience.
UPDATE: I found ~/.config/monitors.xml
which seems to be where Unity stores the settings. Here's mine, with new revisions as I swap locations.
I've thought about triggering the rearrangement via /etc/udev/rules.d
, but that would require permitting scripts run by root to talk to my WM, which presumably means opening xhost permissions. Since the default OS seems to arrange displays without that (just not to an arrangement I want), I'd prefer to find as "native" a solution as possible.
I ended up handling this in a bash script which tests the output of
xrandr
for connected devices, then sets appropriate per-environment layouts.Below is a simplified version which demonstrates how to do it.
My actual script is available at https://gist.github.com/e1892192ea8dd03a210d2890f8f966e7