Sunday, January 9, 2011

XBMC and NVidia's TwinView

I was looking for a decent media center - mostly to watch movies with an overhead projector connected to a PC. The PC is running Linux and I would like to be able to select a movie, change the volume, pause etc with my Medion (read: cheap, RF, USB connected) remote. One day I stumbled upon XBMC. It turned out to be a decent piece of software. Configuring the remote was easy. But...

I must mention here that my display setup uses the NVidia's TwinView, which serves me well. My main LCD monitor is connected through a D-Sub while the beamer via HDMI. They form a dual-screen setup with the beamer on the right of the LCD.

But there is always a catch... Actually two of them.
  1. XBMC's fullscreen ignores TwinView, so it spans both displays, or the other display is turned off. 
  2. There is video tearing visible while XBMC is running on the beamber, there is no tearing if it runs on the LCD.
The first issue can be fixed by making XBMC use so-called windowed mode. It appears as a window then. Having a window and using wmctrl it is possible to make it look like fullscreen.
The second issue regard configuring the NVdia in a proper way which makes OpenGL sync to the specified display instead of the first one. It can be achieved by exporting two environment variables __GL_SYNC_TO_VBLANK=1 and __GL_SYNC_DISPLAY=name_of_the_display_to_sync_to.

So here comes my magical bash script which launches the XBMC with a proper syncing enabled and shifts it to the beamer making the window fullscreen (mind that the beamer is on the right of the LCD, and the LCD is 1280x1024).

Enjoy.
#!/bin/bash

move_and_fullscreen(){
  NAME='XBMC Media Center'

  while [ -z "`wmctrl -l | grep \"$NAME\"`" ]
  do
      sleep 1
  done

  wmctrl -r "$NAME" -e '0,1280,-1,-1,-1'
  wmctrl -r "$NAME" -b toggle,fullscreen
}

move_and_fullscreen &
__GL_SYNC_TO_VBLANK=1 __GL_SYNC_DISPLAY_DEVICE=DFP-0 SDL_VIDEO_ALLOW_SCREENSAVER=0 exec xbmc

Update: As of XBMC 10.1 I had to add SDL_VIDEO_ALLOW_SCREENSAVER=0 to disable screensaver while running XBMC. The above approach uses the windowed mode of XBMC which enables system screensaver now - it kicks in while watching movies :( (the screensaver is disabled in the fullscreen mode only).