[xmonad] Managing Multiple Displays

Tomas Janousek tomi at nomi.cz
Tue Jul 13 11:22:42 UTC 2021


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
>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](https://work.lisk.in/2020/10/11/xrandr-ux.html) 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](https://github.com/liskin/dotfiles/blob/home/bin/layout-auto) 
that lets me save layouts for [specific configurations](https://github.com/liskin/dotfiles/tree/home/bin/.xlayout) 
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](https://github.com/davatorium/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](https://github.com/google/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.

-- 
Tomáš "liskin" ("Pivník") Janoušek, https://work.lisk.in/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/xmonad/attachments/20210713/2ced4d89/attachment.html>


More information about the xmonad mailing list