[Linux] Dualscreen : XBMC on secondary screen AND normal Ubuntu on primary screen
#1
Rainbow 
I wanted to use see if XBMC could be powered by my PC, while letting me use it normally. Most PCs have enough power for video decoding and web surfing at the same time... My PC is most often on when I want to watch a movie, and it is close enough to the TV to plug it with HDMI.

So I investigated on making it work on dualscreen : XBMC running on secondary screen (through HDMI), and Ubuntu still usable on primary screen (through DVI or VGA).
My PC has an Intel HD Graphic card (Core i5 650), and runs Ubuntu 10.04 (64-bit). I use XBMC 10.1 (Dharma).

I now have something useable and wanted to share my little experience :

XBMC on secondary screen (with Intel graphics card)
I read some posts talking of DISPLAY=:0.1 commands, but it does not seem to work this way on a single Intel Graphic card.
I had to configure XBMC to run in windowed mode (that must configured inside the GUI of XBMC), and make a script to move it to secondary screen.
It uses xrandr to activate HDMI2 (this is the name of my HDMI output. HDMI1 is in fact the DVI output that I use for my main screen).
My TV only handles 720p, so I also chose this resolution instead of 1080p
You might adjust all these settings depending on your hardware/configuration (run xrandr on command-line to see which outputs you have)
After activating HDMI2, the script launches xbmc in the background, wait for its window to appear, then moves it to the secondary screen (my main screen has a resolution of 1600x1200, that's why I need to move it with 1600 pixels on the right). I also resize it to 800x600 so that it fits inside the TV screen.
Then I change it to fullscreen. These window movements are made with wmctrl, which should be installed first :
Code:
sudo apt-get install wmctrl

Use HDMI sound
The HDMI sound does not work with the standard kernel of ubuntu 10.04 (2.6.32.x), but it works with the one of ubuntu 10.10 (2.6.35.x). I installed a version backported for lucid : 2.6.35-25.44~lucid1
For more info, see http://doityourselfhtpc.wordpress.com/20...-and-xbmc/
I did not try to make hardware acceleration work on 10.04 : I'll wait until my next ubuntu upgrade.
For XBMC to use the HDMI output for sound, I had to set the following values :
sound output : HDMI
custom hardware : plughw:0,3
passthrough : hdmi
This way, the sound from XBMC goes to the TV (except for the navigation sounds, but it's not a big problem), and all the other sound of the system goes to the standard sound output of the PC.

Use XBMC and Ubuntu at the same time
With only one X session, the keyboard and mouse are shared between the two screens.
My solution was to use a wiimote to control XBMC : it does not emulate keyboard keys but directly XBMC events. This way, it does not interact with the main screen, and it still works if the XBMC window does not have the focus.
Unfortunately, the xbmc-wiiremote tool currently has issues on a 64-bit (multiple deconnections, and events sent too fast). So I had to recompile it from git : running make in that directory https://github.com/xbmc/xbmc/tree/master.../WiiRemote should give you an executable called "WiiUse_WiiRemote" that you can use instead of xbmc-wiiremote

Disable Compiz
XBMC works with Compiz (at least for my config), but I noticed that it slows down XBMC videos. Even on my Core i5, it makes them jerky : it's really annoying. So the script disables it before launching XBMC

Disable screensaver/powersaving/standby mode
The script tries to disable all the things that can disturb XBMC.
For that to work, it has to save the values of these settings, change them while XBMC is running, and put it back after XBMC is stopped.
For that to work, I also use wmctrl to check if XBMC is still running or not. I poll it every second.
There is a drawback of this method : in some cases (if the computer hangs, in particular), the values will not be put back and the powersaving parameters will be kept disabled. So you should keep these values somewhere in case of you have to set them manually

Put BOINC in standby mode
The script tests if BOINC is installed, and put in standby mode if it is. After XBMC is shut down, it makes it compute again.
That saves some CPU for XBMC


I'm pretty sure this script can be improved : suggestions are welcome.
It is really customized to my context (hardware & software) : you'll probably want to modify it to suit your own needs (consider it as GPL if you want to improve it)
I did not test it on any version of ubuntu, and on any other computer : please give your feedback if necessary

Code:
#! /bin/bash
# Pass -c as a parameter to disable Compiz while XBMC is running
while getopts "c" optname
  do
    case "$optname" in
      "c")
        DISABLECOMPIZ=1
        ;;
      *)
        echo "Invalid option: -$optname"
        ;;
    esac
  done
shift $((OPTIND-1))

if $(xrandr --prop |grep -q "HDMI2 connected")
then

    if [ "$DISABLECOMPIZ" != "" ]
    then
        echo "Disable Compiz"
        metacity --replace &
        sleep 3
    fi

    echo "Activate HDMI2"
    # The following two lines can be uncommented if the 1280x720 resolution is not proposed (which seems to be the case for Ubuntu 11.04)
    #xrandr --newmode "1280x720" 60.47  1280 1328 1456 1632  720 721 724 741  -HSync +Vsync
    #xrandr --addmode HDMI2 1280x720
    xrandr --output HDMI1 --auto --primary --output HDMI2 --right-of HDMI1 --mode 1280x720

    echo "Prepare wiimote connexion"
    killall xbmc-wiiremote
    xbmc-wiiremote &
    # If you use 64-bit version of Ubuntu, you need to use a recompiled version from git because of a bug in amd64 version
    #killall -q WiiUse_WiiRemote
    #cd ~/dev/xbmc_wiimote/xbmc/tools/EventClients/Clients/WiiRemote/
    #./WiiUse_WiiRemote &
    #cd ~

    if which boinccmd>/dev/null
    then
        echo "Put BOINC in standby mode"
        # (for 8 hours maximum)
        boinccmd --set_run_mode never 28800
    fi

    echo "Start XBMC in background"
    killall -s9 -q xbmc.bin
    xbmc &

    echo "Wait for the XBMC window to appear"
    status=0
    while [ $status -eq 0 ]
    do
        sleep 1
        status=`wmctrl -x -l | grep "XBMC Media Center" | wc -l | awk '{print $1}'`
    done

    echo "Move XBMC to secondary screen"
    wmctrl -x -r XBMC Media Center.XBMC Media Center -e 0,1600,0,800,600

    sleep 1
    
    echo "Force XBMC window to fullscreen"
    wmctrl -x -r XBMC Media Center.XBMC Media Center -b toggle,fullscreen

    echo "Disable Screensaver"
    gconftool-2 --set /apps/gnome-screensaver/idle_activation_enabled --type bool FALSE

    echo "Disable PowerManager"
    SLEEPDISPLAY=`gconftool-2 --get /apps/gnome-power-manager/timeout/sleep_display_ac`
    gconftool-2 --set /apps/gnome-power-manager/timeout/sleep_display_ac --type int 0
    SLEEPCOMPUTER=`gconftool-2 --get /apps/gnome-power-manager/timeout/sleep_computer_ac`
    gconftool-2 --set /apps/gnome-power-manager/timeout/sleep_computer_ac --type int 0
    xset -dpms

    # Wait for the XBMC window to disappear
    status=1
    while [ $status -eq 1 ]
    do
        sleep 1
        status=`wmctrl -x -l | grep "XBMC Media Center" | wc -l | awk '{print $1}'`
    done

    echo "Disable HDMI2"
    xrandr --output HDMI2 --off

    echo "Kill the process that handles the wiimote"
    killall xbmc-wiiremote
    #killall WiiUse_WiiRemote

    if which boinccmd>/dev/null
    then
        echo "Re-enable BOINC"
        boinccmd --set_run_mode auto
    fi

    echo "Wait 2 seconds for xrandr to complete"
    sleep 2

    echo "Re-enable ScreenSaver"
    gconftool-2 --set /apps/gnome-screensaver/idle_activation_enabled --type bool TRUE

    echo "Re-enable PowerManager"
    gconftool-2 --set /apps/gnome-power-manager/timeout/sleep_display_ac --type int $SLEEPDISPLAY
    gconftool-2 --set /apps/gnome-power-manager/timeout/sleep_computer_ac --type int $SLEEPCOMPUTER
    xset +dpms

    if [ "$DISABLECOMPIZ" != "" ]
    then
        echo "Re-enable Compiz"
        compiz --replace &
    fi

    read -p "Press enter to exit..."

else
    echo -e "HDMI2 is not connected"
fi

Update April 2012 :
For those who would be interested, I updated the script for Ubuntu 12.04 and Unity, on XBMC 11 Eden.
See post #8 below
Reply
#2
Hi,

I have very similar requirements and ended up with almost the same setup. Minor differences of mine:

* I disabled compiz only on the second screen (TV), running openbox there instead.

* To prevent mouse incidentally moving to the TV and toggling the OSD, the two screens are a few pixels apart. Switching via switchscreen mapped to a multimedia key on my keyboard

I followed the description at http://forums.boxee.tv/showthread.php?t=16249
Reply
#3
That's interesting : could you explain a bit further what you did?
Regarding compiz, do you mean that you managed to keep compiz running on the primary screen.
What do you mean by switching between screens?
Reply
#4
mossroy Wrote:Regarding compiz, do you mean that you managed to keep compiz running on the primary screen.
Yes, this worked fine: http://forum.xbmc.org/showthread.php?tid=50500&page=2

If you look at that script for running xbmc, it is am using wmctrl to put xbmc to fullscreen (while it is configured in windowed mode, no borders itself, windows size 1920x1080). wmctrl needs a window manager running. If you disable compiz, you have to run some other WM on the second screen. I chose openbox for its simplicity.

This is my modified script (I am using the xbmc-pvr branch, thus the waiting for tvheadend):

Code:
#! /bin/bash
# Launch XBMC in windowed mode, then use wmctrl to remove the titlebar

pgrep xbmc.bin && exit 0

# Select display 1
DISPLAY=:0.1
export DISPLAY

pgrep openbox || nohup openbox --replace &

export LC_ALL="cs_CZ.UTF-8"
export LANG="cs_CZ.UTF-8"


# waiting for tvheadend startup
while pgrep tvheadend && ! netcat -z 127.0.0.1 9982; do
        sleep 0.5s
done

# Start XBMC
xbmc --debug -l /var/run/lirc/lircd  &

# Wait for the XBMC window to appear
status=0
while [ $status -eq 0 ]
do
        sleep 0.2s
        status=`wmctrl -x -l | grep "XBMC Media Center" | wc -l | awk '{print $1}'`
done

# Force XBMC window to fullscreen
wmctrl -x -r XBMC Media Center.XBMC Media Center -b toggle,fullscreen

Quote:What do you mean by switching between screens?
If you "jail" your mouse (and thus keyboard) by setting the two screens a few pixels apart in xorg.conf, you cannot move the mouse to the second screen anymore. To do that I am running the switchscreen utility, mapped to one of multimedia keys on my keyboard. I push the key, mouse/keyboard get switched to TV with xbmc. Upon pushing again the mouse/keyboard return to the primary LCD monitor.
Reply
#5
Thanks phofman for your answer.

Which graphic card do you use? Does it use the open-source Intel driver (included in the kernel) or another one?

In my case, it's an Intel HD Graphics (integrated in my Core i5 650), with the kernel driver.
At least on my config (Ubuntu 10.04, 64 bits), it does not seem to handle the secondary screen as another display (accessible with DISPLAY environment variable).
If I install openbox and run your script, xbmc fails to launch with the following error message :
Code:
/usr/lib/pymodules/python2.6/gtk-2.0/gtk/__init__.py:57: GtkWarning: could not open display
  warnings.warn(str(e), _gtk.Warning)
Error: unable to open display :0.1
FEH.py: cannot connect to X server :0.1

Maybe I did something wrong, but I can't manage to have 2 different window-managers on the 2 screens.
That also prevents from using your switchscreen utility (I suppose you're talking about http://sampo.kapsi.fi/switchscreen/ ?), because it's also based on different displays.
I also can't have a space between primary and secondary screens when I use the screen preferences of Ubuntu : they have to be stuck to each other.

Maybe it's because I don't have a xorg.conf?
Reply
#6
Hi mossroy,

sorry for the delay. For the script to work you have to have two separate screens configured so that DISPLAY=:0.1 makes sense. I would be surprised if the dual-head intel graphics did not support this standard mode. There is ubuntu gui tool for monitor setup, or you can set it up in xorg.conf, or using the xrandr tool.
Reply
#7
Well, it surprised me too. Maybe I did not find the right way to do it.
I used the gui and xrandr, but not xorg.conf (because I don't want the dual-screen to be permanent : I want to easily switch the secondary screen on and off)

Using the DISPLAY=:0.1 feature would make things much more simple for me. If anyone has a hint to make this work on an intel graphic card...
Reply
#8
I updated the script for Ubuntu 12.04 and Unity, on XBMC 11 Eden.
I switch from Unity-3D to Unity-2D (see https://answers.launchpad.net/unity-2d/+question/189486 )

Code:
#! /bin/bash
# Pass -c as a parameter to disable Compiz while XBMC is running
while getopts "c" optname
  do
    case "$optname" in
      "c")
        DISABLECOMPIZ=1
        ;;
      *)
        echo "Invalid option: -$optname"
        ;;
    esac
  done
shift $((OPTIND-1))

if $(xrandr --prop |grep -q "HDMI2 connected")
then

    if [ "$DISABLECOMPIZ" != "" ]
    then
        if ps ax | grep -v grep | grep compiz > /dev/null
        then
            COMPIZWASRUNNING=1
            echo "Disable Compiz"
            killall -q compiz
            metacity --replace &
            killall -q compiz
            sleep 2
            

            #gnome-panel &

                killall -q unity-2d-shell
            killall -q unity-2d-panel
            sleep 1
            unity-2d-panel &
            sleep 1
            unity-2d-shell &
        fi
    fi

    echo "Activate HDMI2"
    # The following two lines can be needed if the 1280x720 resolution is not proposed (which seems to be the case for Ubuntu 11.04 and +)
    xrandr --newmode "1280x720" 60.47  1280 1328 1456 1632  720 721 724 741  -HSync +Vsync
    #xrandr --delmode "1280x720"
    #xrandr --newmode "1280x720" 74.50  1280 1344 1472 1664  720 723 728 748 -hsync +vsync
    xrandr --addmode HDMI2 1280x720
    xrandr --output HDMI1 --auto --primary --output HDMI2 --right-of HDMI1 --mode 1280x720
    #xrandr --output HDMI1 --auto --primary --output HDMI2 --right-of HDMI1 --mode 1920x1080

    echo "Prepare wiimote connexion"
    killall -q xbmc-wiiremote
    xbmc-wiiremote &
    cd ~

    if which boinccmd>/dev/null
    then
        echo "Put BOINC in standby mode"
        # (for 8 hours maximum)
        boinccmd --set_run_mode never 28800
    fi

    echo "Re-enable standard sound output instead of HDMI"
    pacmd "set-card-profile 0 output:analog-stereo+input:analog-stereo"

    echo "Start XBMC in background"
    killall -s9 -q xbmc.bin
    xbmc &

    echo "Wait for the XBMC window to appear"
    status=0
    while [ $status -eq 0 ]
    do
        sleep 1
        status=`wmctrl -x -l | grep "XBMC Media Center" | wc -l | awk '{print $1}'`
    done

    echo "Move XBMC to secondary screen"
    # Resize so that it will fit in the secondary screen
    wmctrl -x -r XBMC Media Center.XBMC Media Center -e 0,0,0,800,600
    # Move to secondary screen
    wmctrl -x -r XBMC Media Center.XBMC Media Center -e 0,1600,0,800,600

    sleep 1
    
    echo "Force XBMC window to fullscreen"
    wmctrl -x -r XBMC Media Center.XBMC Media Center -b toggle,fullscreen

    echo "Disable DPMS power saving"
    xset -dpms
    xset s off
    # The sessionmanager is inhibited in the following python script

    echo "Wait for XBMC window to close"
    python ~/disable_screensaver_and_wait_for_xbmc_exit.py

    echo "Disable HDMI2"
    xrandr --output HDMI2 --off

    echo "Kill the process that handles the wiimote"
    killall xbmc-wiiremote

    if which boinccmd>/dev/null
    then
        echo "Re-enable BOINC"
        boinccmd --set_run_mode auto
    fi

    echo "Wait 2 seconds for xrandr to complete"
    sleep 2

    echo "Re-enable DPMS power saving"
    xset +dpms
    xset s on

    if [ "$DISABLECOMPIZ" != "" ]
    then
        if [ "$COMPIZWASRUNNING" != "" ]
        then
            echo "Re-enable Compiz"
                killall -q unity-2d-shell
            killall -q unity-2d-panel
            killall -q gnome-panel
            killall -q compiz
            compiz --replace &
        fi
    fi

    #read -p "Press enter to exit..."

else
    echo -e "HDMI2 is not connected"
fi

It also needs the following disable_screensaver_and_wait_for_xbmc_exit.py Python script :
Code:
#!/usr/bin/env python
import dbus
import commands
from time import sleep

# Inhibit SessionManager
# NB : this can't be done from a shell because the inhibition is "hold" by the
# process that asked for it. In shell, a dbus-send exits just after the inhibition
# So it would uninhibit automatically.
# See http://www.lucidelectricdreams.com/2011/06/disabling-screensaverlock-screen-on.html
print "Inhibit SessionManager"
bus = dbus.SessionBus()
proxy = bus.get_object('org.gnome.SessionManager', '/org/gnome/SessionManager')
screenSaverCookie = proxy.Inhibit("XBMC",dbus.UInt32(0),"XBMC temporarily inhibits the screen saver",dbus.UInt32(8))

# Wait for XBMC window to disappear
status = "1"
while status == "1":
    status = commands.getoutput('wmctrl -x -l | grep "XBMC Media Center" | wc -l | awk "{print $1}"')
    sleep(1)

# Un-inhibit SessionManager
print "Un-inhibit SessionManager"
proxy.Uninhibit(screenSaverCookie)

This works pretty well, but I still have some tearing problems under Unity 2D. See https://bugs.launchpad.net/ubuntu/+sourc...bug/792315
If I keep Compiz, the videos stutter
If I switch to metacity (including Ubuntu-2D) without Compiz, the videos do not stutter any more, but I have tearing...

In the end, I gave up trying to do everything on the same computer. I found an old notebook (Dell Inspiron 1525 : Intel graphics with HDMI output) and installed it with XBMC on Xubuntu 12.04 : after disabling compositing in xfce, no stuttering and no tearing
Reply
#9
Hi mossroy & phofman!

I have almost the same setup as you guys, but whatever I do i can't get xbmc to load in full screen on my TV. When I'm running the script it now loads xbmc in full screen on HDMI1, without the script it stretches across the two screens.

Some specs info:
HDMI1: Samsung SyncMaster245B connected with DVI (1920x1200)
HDMI2: LG plasma TV (1280x768)
Intel HD Graphic card (Core i3-530)
Arch Linux 12.01 with XBMC Eden

I don't use compiz, wiiremote etc. so all I need the script to do is to load on the TV. which seems to be impossible (I spent the last 2 days trying to figure it out).

Here's the script:

Code:
#! /bin/bash

    echo "Activate HDMI2"
    #The following two lines can be needed if the 1280x720 resolution is not proposed (which seems to be the case for U$
    #xrandr --newmode "1280x768" 80.14  1280 1344 1480 16680  768 769 772 795  -HSync +Vsync
    #xrandr --delmode "1280x720"
    #xrandr --newmode "1280x720" 74.50  1280 1344 1472 1664  720 723 728 748 -hsync +vsync
    #xrandr --addmode HDMI2 1280x768
    xrandr --output HDMI1 --auto --primary --output HDMI2 --right-of HDMI1 --mode 1280x768
    #xrandr --output HDMI1 --auto --primary --output HDMI2 --right-of HDMI1 --mode 1920x1080

    echo "Start XBMC in background"
    killall -s9 -q xbmc.bin
    xbmc &

    echo "Wait for the XBMC window to appear"
    status=0
    while [ $status -eq 0 ]
    do
        sleep 1
        status=`wmctrl -x -l | grep "XBMC Media Center" | wc -l | awk '{print $1}'`
    done

    echo "Move XBMC to secondary screen"
    # Resize so that it will fit in the secondary screen
    wmctrl -x -r XBMC Media Center.XBMC Media Center -e 0,0,0,800,600
    # Move to secondary screen
    wmctrl -x -r XBMC Media Center.XBMC Media Center -e 0,1920,0,800,600

    sleep 1

    echo "Force XBMC window to fullscreen"
    wmctrl -x -r XBMC Media Center.XBMC Media Center -b toggle,fullscreen

    #echo "Wait 2 seconds for xrandr to complete"
    #sleep 2

Code:
[ove@arch ~]$ xrandr -q
Screen 0: minimum 320 x 200, current 3200 x 1200, maximum 8192 x 8192
VGA1 disconnected (normal left inverted right x axis y axis)
HDMI1 connected 1920x1200+0+0 (normal left inverted right x axis y axis) 518mm x 324mm
   1920x1200      60.0*+
   1600x1200      60.0  
   1680x1050      59.9  
   1680x945       60.0  
   1400x1050      59.9  
   1600x900       60.0  
   1280x1024      75.0     60.0  
   1440x900       75.0     59.9  
   1280x960       60.0  
   1366x768       60.0  
   1360x768       60.0  
   1280x800       74.9     59.9  
   1152x864       75.0  
   1280x768       74.9     60.0  
   1024x768       75.1     70.1     60.0  
   1024x576       60.0  
   832x624        74.6  
   800x600        72.2     75.0     60.3     56.2  
   848x480        60.0  
   640x480        72.8     75.0     66.7     60.0  
   720x400        70.1  
DP1 disconnected (normal left inverted right x axis y axis)
HDMI2 connected 1280x768+1920+0 (normal left inverted right x axis y axis) 1000mm x 550mm
   1280x768       60.0*+   74.9     60.4  
   1920x1080      60.0     50.0     30.0     24.0     30.0     25.0  
   1680x1050      59.9  
   1680x945       60.0  
   1400x1050      74.9     59.9  
   1600x900       60.0  
   1280x1024      75.0     60.0  
   1440x900       75.0     59.9  
   1280x960       60.0  
   1366x768       60.0  
   1360x768       59.8  
   1280x800       74.9     59.9  
   1152x864       75.0  
   1280x720       60.0     50.0     59.7  
   1440x576       25.0  
   1024x768       75.0     70.1     60.0  
   1024x576       60.0  
   800x600        72.2     75.0     60.3  
   720x576        50.0  
   848x480        60.0  
   720x480        59.9  
   640x480        75.0     72.8     60.0     59.9     59.9  
   720x400        70.1  
HDMI3 disconnected (normal left inverted right x axis y axis)
DP2 disconnected (normal left inverted right x axis y axis)
DP3 disconnected (normal left inverted right x axis y axis)

I hope you guys can help, it seems like wmctrl don't move xbmc at all ...
Reply
#10
Hi zalaam,

Inside XBMC, did you configure it to window mode (instead of fullscreen, which is the default) ?
This is necessary for the script to work
Reply
#11
Try this: http://forum.xbmc.org/showthread.php?tid=116996

We have fixed multi-head setups post-Frodo.
Reply
#12
Thanx for the fast reply guys!

(2012-12-30, 20:42)mossroy Wrote: Hi zalaam,

Inside XBMC, did you configure it to window mode (instead of fullscreen, which is the default) ?
This is necessary for the script to work

Yes it's configured to window mode.

(2012-12-31, 10:12)FernetMenta Wrote: Try this: http://forum.xbmc.org/showthread.php?tid=116996

We have fixed multi-head setups post-Frodo.

Are you sure you posted the correct link FernetMenta? I don't even have AMD ...
Reply
#13
wsnipex created the repo originally for AMD but I thought for a test it should do. Reading this thread more carefully I noticed that your distr is Arch and an Ubuntu ppa won't help anyway. In case you want to compile from source:
https://github.com/FernetMenta/xbmc
Reply
#14
(2012-12-31, 10:12)FernetMenta Wrote: We have fixed multi-head setups post-Frodo.

Fresh install of Frodo RC2 and it still doesn't work. I can only choose between windowed and fullscreen #1 (which bring back the same old center across both screens)
Everything else works perfectly in Frodo.

Tried your script mossroy (my modified version) and still no luck.

Hope someone can help on this. I'm considering buying an new dedicated HTPC just to fix this, but I'm hoping that's unnecessary step.
Reply
#15
@zalaam:
You can install it freshly as often as you want. This functionality is not in the xbmc version of xbmc.org - use the git tree fernetmenta gave you. As it contains a whole rewrite of those sections responsible for multi monitor output.

You don't have to buy a new htpc, but you should read more carefully :-)
First decide what functions / features you expect from a system. Then decide for the hardware. Don't waste your money on crap.
Reply

Logout Mark Read Team Forum Stats Members Help
[Linux] Dualscreen : XBMC on secondary screen AND normal Ubuntu on primary screen0
This forum uses Lukasz Tkacz MyBB addons.