Thank you all for the wonderful suggestions. There are definitely many good options available that I was not aware of.I've tried a few and autorandr seems like a good addition into my already (more or less) working workflow. It solves the specific problem that I've described. In the future, I might try and replace my custom script with a different end-to-end solution.On Tue, Jul 13, 2021 at 2:22 PM Tomas Janousek <tomi@nomi.cz> wrote:Hi,
On Fri, Jul 09, 2021 at 05:14:54PM +0300, Eyal Erez wrote:
I often use multiple displays. Here are some configurations that I've used
{.quotelead}>with my laptop:[…]
I was wondering how others deal with this challenge? Are there other, more
well-built tools, than the script I have to do this more robustly and
automatically?There are many ways to do this. I'll describe my setup and then point to some alternatives.
I have a script that extends xrandr command-line usage so that I can just write a generic vertical layout like so:
xrandr-smart --output 'eDP-*' --auto \ --output '!(eDP-*)' --auto --above 'eDP-*'
Then I have another script that lets me save layouts for specific configurations of connected monitors. This one is invoked automatically whenever an output is connected/disconnected, using https://xmonad.github.io/xmonad-docs/xmonad-contrib-0.16.999/XMonad-Hooks-Rescreen.html#v:addRandrChangeHook.
I can also invoke it manually via a keybinding to force a laptop-only layout, or to force an automatic multi-head layout in an unknown setup. If I need something extra (like external monitor only for games), I just invoke a "layout-extonly" script via rofi (I only need to type "ex" for it to know what I mean).(Re)starting xmobars and trayers is handled by https://xmonad.github.io/xmonad-docs/xmonad-contrib-0.16.999/XMonad-Hooks-StatusBar.html#v:dynamicSBs, as mentioned by Yecine earlier.
In my setup, the automatic switching doesn't happen when the screen is locked, and neither do the keybindings work, but that is just my paranoia (and yeah, I should just use https://packages.debian.org/experimental/cryptsetup-suspend instead :-)). It's totally possible to let X.H.Rescreen invoke the script even if locked, and xsecurelock allows configuration of keybindings when the screen is locked.
Now for the alternatives:
Others have mentioned autorandr. That is probably what most minimalist window manager users use. Autorandr can be invoked on output (dis)connect, lid open/close and suspend/resume in various ways:
- https://xmonad.github.io/xmonad-docs/xmonad-contrib-0.16.999/XMonad-Hooks-Rescreen.html#v:addRandrChangeHook
- https://github.com/jceb/srandrd
- https://github.com/phillipberndt/autorandr/blob/master/contrib/autorandr_launcher/autorandr_launcher.c
- https://github.com/phillipberndt/autorandr/blob/master/contrib/listen_lid.sh
- https://github.com/phillipberndt/autorandr/blob/master/contrib/pm-utils/40autorandr
Also see https://wiki.archlinux.org/title/xrandr for other tools and tips.
--Eyal Erez <oneself@gmail.com>There are 10 types of people, those who know binary and those who don't.