|
| 1 | +Display Supervisor |
| 2 | +================== |
| 3 | + |
| 4 | +i3 does not manage displays and I move my laptop around a lot. This little script fills a much needed gap in my tiling window manager setup. |
| 5 | + |
| 6 | +How it works |
| 7 | +------------ |
| 8 | + Usage: display-supervisor [-f] [-i] [-l [switch]] |
| 9 | + |
| 10 | + -f, --feh Run feh bg script. |
| 11 | + Executes ~/.fehbg upon completion. |
| 12 | + -i, --i3 Test for i3wm instance. |
| 13 | + For avoiding conflict with multiple environments. |
| 14 | + -l, --lid Check laptop lid status. |
| 15 | + It is possible to specify switch. Defaults to 'LID0' |
| 16 | + If unsure, look under /proc/acpi/button/lid/... |
| 17 | + -v, --version Print version info. |
| 18 | + |
| 19 | +When executed, it checks the available and connected display outputs and sets the optimal resolution for each (as determined by xrandr). It can then also reset the wallpaper. |
| 20 | +At the moment I have three outputs defined: `LVDS1`, `HDMI1` and `VGA1`. For now, layout configuration is hard-coded. I am hoping to make this more dynamic. |
| 21 | + |
| 22 | +When lid is open: LVDS (Primary) on left with HDMI or VGA on right. |
| 23 | +My laptop can only handle two displays at a time, so if both HDMI and VGA are present, or lid is closed: HDMI (Primary) on left with VGA on right. |
| 24 | + |
| 25 | +You could of course use `arandr` to generate layout scripts and replace my xrandr lines with those. |
| 26 | + |
| 27 | +How I use it |
| 28 | +------------ |
| 29 | + |
| 30 | +##### User Login: |
| 31 | +Added as `exec` to i3 config. |
| 32 | + |
| 33 | +##### Monitor hotplug: |
| 34 | +Created the following udev rule in `/etc/udev/rules.d/20-display-supervisor.conf`: |
| 35 | + |
| 36 | + ACTION=="change", SUBSYSTEM=="drm", ENV{HOTPLUG}=="1", RUN+="/path/to/display-supervisor.sh -f -l" |
| 37 | + |
| 38 | +##### Laptop lid open/close: |
| 39 | +Using acpid with the following rules in `/etc/acpi/handler.sh`: |
| 40 | + |
| 41 | + ... |
| 42 | + button/lid) |
| 43 | + case "$3" in |
| 44 | + close) |
| 45 | + logger 'LID closed' |
| 46 | + /path/to/display-supervisor.sh -f -l |
| 47 | + ;; |
| 48 | + open) |
| 49 | + logger 'LID opened' |
| 50 | + /path/to/display-supervisor.sh -f -l |
| 51 | + ;; |
| 52 | + *) |
| 53 | + logger "ACPI action undefined: $3" |
| 54 | + ;; |
| 55 | + esac |
| 56 | + ;; |
| 57 | + ... |
| 58 | + |
| 59 | +##### System resume: |
| 60 | +Create a wake-up script `/usr/lib/systemd/system-sleep/initiate-display-supervisor.sh`: |
| 61 | + |
| 62 | + #!/bin/sh |
| 63 | + case $1/$2 in |
| 64 | + pre/*) |
| 65 | + exit 0 |
| 66 | + ;; |
| 67 | + post/*) |
| 68 | + echo "Waking up from $2... Refreshing displays." |
| 69 | + $(/path/to/display-supervisor.sh·-f·-l) |
| 70 | + ;; |
| 71 | + esac |
| 72 | + |
| 73 | +Remember to mark as executable. |
| 74 | + |
| 75 | +Dependencies |
| 76 | +------------ |
| 77 | +* xorg-xrandr |
| 78 | +* acpid (for lid events) |
| 79 | + |
| 80 | +Notes |
| 81 | +----- |
| 82 | +In all of the above usages, besides user login, the script is run as root user by the system. This requires the use of a `getXuser()` function to find `$DISPLAY` and `$XAUTHORITY` needed by `xrandr`. Running as user (upon login) then only works when launching sessions with `startx` instead of a display manager. I am looking into a better method. |
| 83 | + |
| 84 | +To-do |
| 85 | +---- |
| 86 | +- [ ] Add an option for custom bg script. |
| 87 | +- [ ] Daemonize script and use real-time signals instead. |
| 88 | +- [ ] Layout flexibility. |
| 89 | +- [ ] OSD? |
| 90 | + |
| 91 | +---- |
| 92 | +####Credits |
| 93 | +I shamelessly stole some base functionality from [codingtony](https://github.com/codingtony/udev-monitor-hotplug). Thank you, kind sir. |
0 commit comments