user3597931
user3597931

Reputation:

Xmonad with two monitors

how can I setup XMonad to work with two monitors? I have a laptop and when at my desk I plug a second monitor on the HDMI port.

With the monitor plugged and activated, XMonad thinks I have a single very wide screen. I3 works good; I have different workspaces for different monitors.

import System.IO
import XMonad
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.ManageDocks
import XMonad.Util.EZConfig (additionalKeys)
import XMonad.Util.Run (spawnPipe)

import qualified Data.Map as M

main =
  xmonad =<<
  xmobar
    defaultConfig
    { terminal = "alacritty"
    , manageHook = manageDocks <+> manageHook defaultConfig
    , layoutHook = avoidStruts $ layoutHook defaultConfig
    , handleEventHook = mconcat [docksEventHook, handleEventHook defaultConfig]
    , borderWidth = 2
    , modMask = mod4Mask
    , keys = mykeys
    }

mykeys :: XConfig Layout -> M.Map (KeyMask, KeySym) (X ())
mykeys c = (myKeys c) `M.union` (XMonad.keys defaultConfig c)
  where
    myKeys (XConfig {modMask = modm}) = myKeyBindings modm

myKeyBindings modm = M.fromList $ []

This is my xmonad.hs

My xorg.conf is:

➜ X11 cat xorg.conf

Section "ServerLayout"
    Identifier "layout"
    Screen 0 "nvidia"
    Inactive "intel"
EndSection

Section "Device"
    Identifier "intel"
    Driver "modesetting"
    BusID "PCI:0@0:2:0"
    Option "AccelMethod" "None"
EndSection

Section "Screen"
    Identifier "intel"
    Device "intel"
EndSection

Section "Device"
    Identifier "nvidia"
    Driver "nvidia"
    BusID "PCI:1@0:0:0"
    Option "ConstrainCursor" "off"
EndSection

Section "Screen"
    Identifier "nvidia"
    Device "nvidia"
    Option "AllowEmptyInitialConfiguration" "on"
    Option "IgnoreDisplayDevices" "CRT"
EndSection

Upvotes: 2

Views: 5223

Answers (2)

shovan rai
shovan rai

Reputation: 62

You can have it set up like this on your .profile.

xrandr --output name_of_primary_display --mode ResxRes --left/right/top/bottom-of secondary-display --auto &

Upvotes: 0

Oh Fiveight
Oh Fiveight

Reputation: 475

I run XMonad as my display manager on a multi-monitor setup, so I can help.

#1

XMonad is not what controls how the monitors are laid out / oriented; that is the job of X itself. You can play around with xrandr to get them laid out how you want. Just make sure both monitors can be detected, and then run this from the command line:

xrandr

That will give you all of your monitor info, like resolution and where it is plugged in.

(https://www.x.org/releases/X11R7.5/doc/man/man1/xrandr.1.html)

This is what I run in my .xinitrc before XMonad launches to configure my monitors:

xrandr --dpi 192
xrandr --output HDMI-0 --mode 1920x1080 --pos 0x0 --scale 1.5x1.5
xrandr --output HDMI-1 --mode 3840x2160 --pos 3840x0 

Just make sure you switch out the output name, resolution, and position with how yours are laid out, and only configure the DPI / scale if the monitors have different resolutions.

#2

As far as configuring XMonad to have additional functionality regarding the two-monitor setup, you may want to check out XMonad.Actions.OnScreen from xmonad-contrib.

(https://xmonad.github.io/xmonad-docs/xmonad-contrib/XMonad-Actions-OnScreen.html)

Personally I use focusOnMouseMove from XMonad.Actions.UpdateFocus too, to switch the focus monitor when I move the cursor to the other monitor.

(https://hackage.haskell.org/package/xmonad-contrib-0.17.1/docs/XMonad-Actions-UpdateFocus.html#v:focusOnMouseMove)

Upvotes: 1

Related Questions