]> git.donarmstrong.com Git - don.git/blob - posts/autorandr.mdwn
change the inline code bits
[don.git] / posts / autorandr.mdwn
1 [[!meta title="Autorandr: automatically adjust screen layout"]]
2
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.
7
8 Recently, I ran
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,
14 the
15 [deb is here](https://www.donarmstrong.com/autorandr_1.2-1_all.deb)
16 and
17 the
18 [git repo is here](https://git.donarmstrong.com/deb_pkgs/autorandr.git).
19
20 To use it, simply install the package, and create your initial
21 configuration (in my case, undocked):
22
23      autorandr --save undocked
24
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):
28
29     autorandr --save workstation
30
31 repeat for any additional configurations you have (or as you find new
32 configurations).
33
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
40 looks like this:
41
42      #!/bin/bash
43      
44      xrandr --dpi 92
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;'
49
50
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
54 profile directory.
55
56 Check it out if you change your monitor configuration regularly!
57
58
59 [[!tag debian tech]]