1 [[!meta title="Autorandr: automatically adjust screen layout"]]
3 Like many laptop users, I often plug my laptop into different monitor
4 setups (multiple monitors at my desk, projector when presenting, etc.)
5 Running xrandr commands or clicking through interfaces gets tedious,
6 and writing scripts isn't much better.
9 across [autorandr](https://github.com/phillipberndt/autorandr), which
10 detects attached monitors using EDID (and other settings), saves
11 xrandr configurations, and restores them. It can also run arbitrary
12 scripts when a particular configuration is loaded. I've packed it, and
13 it is currently waiting in NEW. If you can't wait,
15 [deb is here](https://www.donarmstrong.com/autorandr_1.2-1_all.deb)
18 [git repo is here](https://git.donarmstrong.com/deb_pkgs/autorandr.git).
20 To use it, simply install the package, and create your initial
21 configuration (in my case, undocked):
23 autorandr --save undocked
25 then, dock your laptop (or plug in your external monitor(s)), change
26 the configuration using xrandr (or whatever you use), and save your
27 new configuration (in my case, workstation):
29 autorandr --save workstation
31 repeat for any additional configurations you have (or as you find new
34 Autorandr has `udev`, `systemd`, and `pm-utils` hooks, and `autorandr
35 --change` should be run any time that new displays appear. You can
36 also run `autorandr --change` or `autorandr --load workstation`
37 manually too if you need to. You can also add your own
38 `~/.config/autorandr/$PROFILE/postswitch` script to run after a
39 configuration is loaded. Since I run i3, my workstation configuration
45 xrandr --output DP2-2 --primary
46 i3-msg '[workspace="^(1|4|6)"] move workspace to output DP2-2;'
47 i3-msg '[workspace="^(2|5|9)"] move workspace to output DP2-3;'
48 i3-msg '[workspace="^(3|8)"] move workspace to output DP2-1;'
51 which fixes the dpi appropriately, sets the primary screen (possibly
52 not needed?), and moves the i3 workspaces about. You can also arrange
53 for configurations to never be run by adding a `block` hook in the
56 Check it out if you change your monitor configuration regularly!