Friday, September 3, 2010

Xrandr + Xmonad Session

For my 'xmonad-session' I use a bunch of scripts to easilly get needed monitor setup for my dual head laptop graphic card.

$ l bin/xrandr-*
bin/xrandr-bigdesktop -> xrandr-bigdesktop-LVDS_DVI

$ cat bin/xrandr-bigdesktop-VGA_DVI 

xrandr --output LVDS --off
xrandr --output HDMI-0 --off
xrandr --output VGA-0 --auto \
       --output DVI-0 --auto --primary --right-of VGA-0

Symlink 'xrandr-bigdesktop' is my default ... that is my laptop display is turned on and it is primary one and if something is connected to DVI-0 it would be used as secondary monitor. This symlink is called from my 'xmonad-session' startup script called by CDM in my case, so after boot I got LVDS_DVI setup (if there is nothing physically connected to DVI-0 I got properly just one monitor laptop LVDS setup, xrandr command will not fail and xmonad later starts correctly in 'one monitor' layout).

In office I've got 2 external LCD monitors so my preffered layout there is 'bin/xrandr-bigdesktop-VGA_DVI'. After I start my default LVDS_DVI session I just run in the terminal:

$ xrandr-bigdesktop-VGA_DVI && xmonad-session-repair

xsetroot -solid black

#nitrogen --restore

killall trayer
trayer --edge top --align right \
       --width 10 --widthtype request --height 19 --heighttype pixel \
       --SetDockType true --SetPartialStrut true \
       --transparent true --alpha 0 --tint 0x000000 \
       --expand true &

xmonad --restart

When I need to move e.g. to meeting room I usually just grab my laptop and run :). So after that I have just dead laptop screen. What I do? I switch to some tty let's say first one Ctrl+Alt+F1 and then after I login and not forget to put myself into console in CDM menu I do:

# to be able to communicate with X server
$ export DISPLAY=:0.0

# because CDM doesn't load profile
$ . .profile

$ xrandr-bigdesktop-LVDS_DVI
xrandr: Configure crtc 0 failed
xrandr: cannot find crtc for output LVDS

# let's try sleep first for couple of seconds
# in meantime switch to xtty (usually it would be 7th = Alt+f7 but depends how you're starting X server)
# and wait... until your LVDS is back
$ sleep 5 && xrandr-bigdesktop-LVDS_DVI

I've configured some xmonad key bindings so I don't have to do anything above manually.

-- xrandr
((myModMask, xK_F10), spawn "xrandr-bigdesktop-LVDS_DVI && xmonad-session-repair"),
((myModMask, xK_F11), spawn "xrandr-bigdesktop-LVDS_VGA && xmonad-session-repair"),
((myModMask, xK_F12), spawn "xrandr-bigdesktop-VGA_DVI && xmonad-session-repair")