<!DOCTYPE html>
<html><head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
<meta charset="utf-8"/>
<meta content="width=device-width, initial-scale=1.0, user-scalable=yes" name="viewport"/>
<title>HTML E-Mail</title>
</head><body class="email">
<p>Hi,</p>
<p class="quotelead" style="font-style: italic; margin-bottom: -1em; color: #999; font-size: 80%">On Fri, Jul 09, 2021 at 05:14:54PM +0300, Eyal Erez wrote:</p>
<blockquote class="quote initial" style="padding: 0 0.5em; margin: 0; font-style: italic; border-left: 2px solid #ccc; color: #999; font-size: 80%">
<p>I often use multiple displays. Here are some configurations that I've used<br/>
{.quotelead}>with my laptop:</p>
</blockquote>
<blockquote class="quote initial" style="padding: 0 0.5em; margin: 0; font-style: italic; border-left: 2px solid #ccc; color: #999; font-size: 80%">
<p>[…]<br/>
I was wondering how others deal with this challenge? Are there other, more<br/>
well-built tools, than the script I have to do this more robustly and<br/>
automatically?</p>
</blockquote>
<p>There are many ways to do this. I'll describe my setup and then point to some alternatives.</p>
<hr/>
<p>I have <a href="https://work.lisk.in/2020/10/11/xrandr-ux.html">a script</a> that extends xrandr command-line usage so that I can just write a generic vertical layout like so:</p>
<pre style="line-height: 125%; margin: 0"><code> xrandr-smart --output 'eDP-*' --auto \
--output '!(eDP-*)' --auto --above 'eDP-*' </code></pre>
<p>Then I have <a href="https://github.com/liskin/dotfiles/blob/home/bin/layout-auto">another script</a> that lets me save layouts for <a href="https://github.com/liskin/dotfiles/tree/home/bin/.xlayout">specific configurations</a> of connected monitors. This one is invoked automatically whenever an output is connected/disconnected, using <a class="uri" href="https://xmonad.github.io/xmonad-docs/xmonad-contrib-0.16.999/XMonad-Hooks-Rescreen.html#v:addRandrChangeHook">https://xmonad.github.io/xmonad-docs/xmonad-contrib-0.16.999/XMonad-Hooks-Rescreen.html#v:addRandrChangeHook</a>.<br/>
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 <a href="https://github.com/davatorium/rofi">rofi</a> (I only need to type "ex" for it to know what I mean).</p>
<p>(Re)starting xmobars and trayers is handled by <a class="uri" href="https://xmonad.github.io/xmonad-docs/xmonad-contrib-0.16.999/XMonad-Hooks-StatusBar.html#v:dynamicSBs">https://xmonad.github.io/xmonad-docs/xmonad-contrib-0.16.999/XMonad-Hooks-StatusBar.html#v:dynamicSBs</a>, as mentioned by Yecine earlier.</p>
<p>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 <a class="uri" href="https://packages.debian.org/experimental/cryptsetup-suspend">https://packages.debian.org/experimental/cryptsetup-suspend</a> instead :-)). It's totally possible to let X.H.Rescreen invoke the script even if locked, and <a href="https://github.com/google/xsecurelock">xsecurelock</a> allows configuration of keybindings when the screen is locked.</p>
<hr/>
<p>Now for the alternatives:</p>
<p>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:</p>
<ul>
<li><a class="uri" href="https://xmonad.github.io/xmonad-docs/xmonad-contrib-0.16.999/XMonad-Hooks-Rescreen.html#v:addRandrChangeHook">https://xmonad.github.io/xmonad-docs/xmonad-contrib-0.16.999/XMonad-Hooks-Rescreen.html#v:addRandrChangeHook</a><br/>
</li>
<li><a class="uri" href="https://github.com/jceb/srandrd">https://github.com/jceb/srandrd</a><br/>
</li>
<li><a class="uri" href="https://github.com/phillipberndt/autorandr/blob/master/contrib/autorandr_launcher/autorandr_launcher.c">https://github.com/phillipberndt/autorandr/blob/master/contrib/autorandr_launcher/autorandr_launcher.c</a><br/>
</li>
<li><a class="uri" href="https://github.com/phillipberndt/autorandr/blob/master/contrib/listen_lid.sh">https://github.com/phillipberndt/autorandr/blob/master/contrib/listen_lid.sh</a><br/>
</li>
<li><a class="uri" href="https://github.com/phillipberndt/autorandr/blob/master/contrib/pm-utils/40autorandr">https://github.com/phillipberndt/autorandr/blob/master/contrib/pm-utils/40autorandr</a></li>
</ul>
<p>Also see <a class="uri" href="https://wiki.archlinux.org/title/xrandr">https://wiki.archlinux.org/title/xrandr</a> for other tools and tips.</p>
<div class="signature" style="color: #999; font-family: monospace; white-space: pre; margin: 1em 0 0 0; font-size: 80%"><span class="leader">-- </span><br/>Tomáš "liskin" ("Pivník") Janoušek, https://work.lisk.in/</div>
</body></html>