Managing Multiple Displays

Hi, I often use multiple displays. Here are some configurations that I've used with my laptop: 1. Laptop monitor only 2. External monitor only (laptop lid closed) 3. External and laptop monitor at the same time. 4. Two external monitors (laptop lid closed). In order to show display correctly (which monitor is to the right/left of which and which is on/off) and shift trayer around to the right monitor and position, I've written a script that parses the output of xrandr, figures out if the laptop lid is open or not, then calls xrandr again to activate the right monitors and kills and relaunches trayer and places it in the correct position. I launch this script from a keybinding configured in xmonad.hs. This works, however, it has several disadvantages. The first is that adding a new configuration is a bit tedious -- this doesn't happen very often so it's not a huge deal. The other is that I can only activate the script if my screen is unlocked. This means that if my laptop is suspended and I want to disconnect the external monitor and put it in my bag for later use, I need to first wake it up, unlock it, launch the script to turn the laptop monitor on, and then put it away. Otherwise, I'll be staring at a blank screen when I turn it on and have to guess what to press to unlock and use the script. 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? Thank you, -- There are 10 types of people, those who know binary and those who don't.

Hello,
if you're using the git version of xmonad-contrib, you're in luck: the new
XMonad.Hooks.StatusBar module caters to that use case. It has built-in
functionality to make status bars (or anything, really) react to changes in
the screen configuration. This is achieved by defining a function that maps
a screen id to "IO StatusBarConfig", which then gets passed to dynamicSBs.
That takes care of appropriately setting the handleEventHook, startupHook
and logHook.
I hope it works!
Yecine
On Fri, 9 Jul 2021 at 16:16, Eyal Erez
Hi,
I often use multiple displays. Here are some configurations that I've used with my laptop: 1. Laptop monitor only 2. External monitor only (laptop lid closed) 3. External and laptop monitor at the same time. 4. Two external monitors (laptop lid closed).
In order to show display correctly (which monitor is to the right/left of which and which is on/off) and shift trayer around to the right monitor and position, I've written a script that parses the output of xrandr, figures out if the laptop lid is open or not, then calls xrandr again to activate the right monitors and kills and relaunches trayer and places it in the correct position. I launch this script from a keybinding configured in xmonad.hs.
This works, however, it has several disadvantages. The first is that adding a new configuration is a bit tedious -- this doesn't happen very often so it's not a huge deal. The other is that I can only activate the script if my screen is unlocked. This means that if my laptop is suspended and I want to disconnect the external monitor and put it in my bag for later use, I need to first wake it up, unlock it, launch the script to turn the laptop monitor on, and then put it away. Otherwise, I'll be staring at a blank screen when I turn it on and have to guess what to press to unlock and use the script.
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?
Thank you, -- There are 10 types of people, those who know binary and those who don't.
_______________________________________________ xmonad mailing list xmonad@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/xmonad

Dear Eyal,
For the "This means that if my laptop is suspended and I want to disconnect
the external monitor and put it in my bag for later use, I need to first
wake it up, unlock it, launch the script to turn the laptop monitor on, and
then put it away. "
why not have a script that, on resuming from suspension, calls your already
working script? This should work even if your screen is locked.
I have a very ugly kludge in a script that does that.
I no longer use more than one monitor at a time (my neck did not like it),
but I work either with the laptop connected to an external monitor or just
with the laptop monitor, and I can easily switch from one to another with
suspend events (and all suspend events include locking) in between. When I
resume from suspension, the script is called so that it uses the external
monitor if the laptop is plugged to it (and the monitor is on), or the
laptop otherwise.
My script is called by a service file I placed as
/etc/systemd/system/configure_monitors.service (I can send you the service
file and my script kludge, but the later is just a bunch of calls to xrandr to
figure out what is connected, and then configure the screens).
Best,
R.
On Fri, 09-July-2021, at 16:14:54, Eyal Erez
Hi,
I often use multiple displays. Here are some configurations that I've used with my laptop: 1. Laptop monitor only 2. External monitor only (laptop lid closed) 3. External and laptop monitor at the same time. 4. Two external monitors (laptop lid closed).
In order to show display correctly (which monitor is to the right/left of which and which is on/off) and shift trayer around to the right monitor and position, I've written a script that parses the output of xrandr, figures out if the laptop lid is open or not, then calls xrandr again to activate the right monitors and kills and relaunches trayer and places it in the correct position. I launch this script from a keybinding configured in xmonad.hs.
This works, however, it has several disadvantages. The first is that adding a new configuration is a bit tedious -- this doesn't happen very often so it's not a huge deal. The other is that I can only activate the script if my screen is unlocked. This means that if my laptop is suspended and I want to disconnect the external monitor and put it in my bag for later use, I need to first wake it up, unlock it, launch the script to turn the laptop monitor on, and then put it away. Otherwise, I'll be staring at a blank screen when I turn it on and have to guess what to press to unlock and use the script.
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?
Thank you,
-- Ramon Diaz-Uriarte Department of Biochemistry, Lab B-25 Facultad de Medicina Universidad Autónoma de Madrid Arzobispo Morcillo, 4 28029 Madrid Spain Phone: +34-91-497-2412 Email: rdiaz02@gmail.com ramon.diaz@iib.uam.es https://ligarto.org/rdiaz

Hi Eyal
For automating xrandr and making sure it configures the Monitors (not xmonad) right I use autorandr [1] not sure how that works with laptop lid close tho.
Regards Toni
[1] https://github.com/phillipberndt/autorandr
On 9 July 2021 21:31:04 CEST, Ramon Diaz-Uriarte
Dear Eyal,
For the "This means that if my laptop is suspended and I want to disconnect the external monitor and put it in my bag for later use, I need to first wake it up, unlock it, launch the script to turn the laptop monitor on, and then put it away. "
why not have a script that, on resuming from suspension, calls your already working script? This should work even if your screen is locked.
I have a very ugly kludge in a script that does that.
I no longer use more than one monitor at a time (my neck did not like it), but I work either with the laptop connected to an external monitor or just with the laptop monitor, and I can easily switch from one to another with suspend events (and all suspend events include locking) in between. When I resume from suspension, the script is called so that it uses the external monitor if the laptop is plugged to it (and the monitor is on), or the laptop otherwise.
My script is called by a service file I placed as /etc/systemd/system/configure_monitors.service (I can send you the service file and my script kludge, but the later is just a bunch of calls to xrandr to figure out what is connected, and then configure the screens).
Best,
R.
Hi,
I often use multiple displays. Here are some configurations that I've used with my laptop: 1. Laptop monitor only 2. External monitor only (laptop lid closed) 3. External and laptop monitor at the same time. 4. Two external monitors (laptop lid closed).
In order to show display correctly (which monitor is to the right/left of which and which is on/off) and shift trayer around to the right monitor and position, I've written a script that parses the output of xrandr,
out if the laptop lid is open or not, then calls xrandr again to activate the right monitors and kills and relaunches trayer and places it in
correct position. I launch this script from a keybinding configured in xmonad.hs.
This works, however, it has several disadvantages. The first is that adding a new configuration is a bit tedious -- this doesn't happen very often so it's not a huge deal. The other is that I can only activate
On Fri, 09-July-2021, at 16:14:54, Eyal Erez
wrote: figures the the script if my screen is unlocked. This means that if my laptop is suspended and I want to disconnect the external monitor and put it in my bag for later use, I need to first wake it up, unlock it, launch the script to turn the laptop monitor on, and then put it away. Otherwise, I'll be staring at a blank screen when I turn it on and have to guess what to press to unlock and use the script.
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?
Thank you,

Hello :) My solution: I have a keybinding which rotates through monitor-configurations. When plug-in a new monitor, or unplug a monitor or so, I keep pressing that keybinding until it fits the new monitor setup. It's not beautiful code, but here it is: This is the keybinding: ``` ("M-S-s" , do ownState <- XS.get let newMonitorLayoutIndex = (monitorLayoutIndex ownState + 1) `mod` (length Host.monitorLayouts) spawn (monitorLayouts !! newMonitorLayoutIndex) XS.put (ownState { monitorLayoutIndex = newMonitorLayoutIndex }) refresh) ``` The `monitorLayouts` variable is just a list of xrandr-commands as strings. (I generate those via `arandr`.) The monitor-state is a state-property: ``` data OwnState = OwnState { monitorLayoutIndex :: Int } deriving Typeable instance ExtensionClass OwnState where initialValue = OwnState { orientation = OrientB , keyboardLayout = De , monitorLayoutIndex = 0 } ``` I show the monitor-state in my dock, dzen2: ``` ownPPConfig statusbar = def { ppExtras = [ Just . show . monitorLayoutIndex <$> XS.get ] } ``` Kind regards Mekeor 2021-07-09 / 17:14 / oneself@gmail.com:
Hi,
I often use multiple displays. Here are some configurations that I've used with my laptop: 1. Laptop monitor only 2. External monitor only (laptop lid closed) 3. External and laptop monitor at the same time. 4. Two external monitors (laptop lid closed).
In order to show display correctly (which monitor is to the right/left of which and which is on/off) and shift trayer around to the right monitor and position, I've written a script that parses the output of xrandr, figures out if the laptop lid is open or not, then calls xrandr again to activate the right monitors and kills and relaunches trayer and places it in the correct position. I launch this script from a keybinding configured in xmonad.hs.
This works, however, it has several disadvantages. The first is that adding a new configuration is a bit tedious -- this doesn't happen very often so it's not a huge deal. The other is that I can only activate the script if my screen is unlocked. This means that if my laptop is suspended and I want to disconnect the external monitor and put it in my bag for later use, I need to first wake it up, unlock it, launch the script to turn the laptop monitor on, and then put it away. Otherwise, I'll be staring at a blank screen when I turn it on and have to guess what to press to unlock and use the script.
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?
Thank you,

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-Re.... 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-St..., 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-Re... * https://github.com/jceb/srandrd * https://github.com/phillipberndt/autorandr/blob/master/contrib/autorandr_lau... * https://github.com/phillipberndt/autorandr/blob/master/contrib/listen_lid.sh * https://github.com/phillipberndt/autorandr/blob/master/contrib/pm-utils/40au... Also see https://wiki.archlinux.org/title/xrandr for other tools and tips. -- Tomáš "liskin" ("Pivník") Janoušek, https://work.lisk.in/

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
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 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-Re... . 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-St..., 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-Re... - https://github.com/jceb/srandrd - https://github.com/phillipberndt/autorandr/blob/master/contrib/autorandr_lau... - https://github.com/phillipberndt/autorandr/blob/master/contrib/listen_lid.sh - https://github.com/phillipberndt/autorandr/blob/master/contrib/pm-utils/40au...
Also see https://wiki.archlinux.org/title/xrandr for other tools and tips. -- Tomáš "liskin" ("Pivník") Janoušek, https://work.lisk.in/
--
*Eyal Erez <**oneself@gmail.com*

Not sure if this is out of place, but do you know grobi? It works great for me!
Dominik
GitHub - fd0/grobi: Automatically configure monitors/outputs for Xorg via RANDR – https://github.com/fd0/grobi
On July 20, 2021 2:23:21 PM GMT+02:00, Eyal Erez
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
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 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-Re...
. 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
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
https://xmonad.github.io/xmonad-docs/xmonad-contrib-0.16.999/XMonad-Hooks-St..., 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-Re...
https://github.com/phillipberndt/autorandr/blob/master/contrib/autorandr_lau...
-
https://github.com/phillipberndt/autorandr/blob/master/contrib/listen_lid.sh
-
https://github.com/phillipberndt/autorandr/blob/master/contrib/pm-utils/40au...
Also see https://wiki.archlinux.org/title/xrandr for other tools and
tips.
-- Tomáš "liskin" ("Pivník") Janoušek, https://work.lisk.in/
-- *Eyal Erez <**oneself@gmail.com*
*>* There are 10 types of people, those who know binary and those who don't.
participants (7)
-
Dominik Schrempf
-
Eyal Erez
-
eye
-
mekeor.melire@gmail.com
-
Ramon Diaz-Uriarte
-
Tomas Janousek
-
Yecine Megdiche