[xmonad] Managing Multiple Displays
mekeor.melire at gmail.com
mekeor.melire at gmail.com
Sun Jul 11 10:14:30 UTC 2021
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 at 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,
More information about the xmonad
mailing list