Linux with 2 monitors and HD TV

From Urandom
Jump to: navigation, search

My Setup

I have a ATI Radeon HD 5870, that has 2 HD monitors and a HD TV connected. I usually have the two monitors in twinview/xinerama mode, and when i wach movies i turn one monitor off and the tv on. Later i switch back.

The problems

This is rather annoying to do with a GUI (amdcccle or KDE screen configure) so I prefer a command or key binding.
I have 2 panels on each monitor, when I turn one screen off and the other on, the panels jump on top of each other.
After playing some games eg(openarena) it changes the screens to clone, i need a easy way to restore the old settings.

Solutions

Screen switching

I created 2 commands for changing the screens

Edit /usr/bin/ch_monitors.sh

#!/bin/bash
xrandr --output DFP2 --off --size 3840x1080 #turn off TV, the --size is not important, it keeps the virtual screen size consistent.
xrandr --output DFP3 --auto --rotate normal --pos 0x0 --output DFP4  --auto --rotate normal --right-of DFP3 #turn on the other screen
/usr/bin/panels2screens.sh #this moves the KDE panels back in place, will discuss it later.

Edit /usr/bin/ch_television.sh

#!/bin/bash
xrandr --output DFP4 --off --size 3840x1080 #turn off monitor, the --size is not important, it keeps the virtual screen size consistent.
xrandr --output DFP3 --auto --rotate normal --pos 0x0 --output DFP2  --auto --rotate normal --right-of DFP3 #turn on the TV
/usr/bin/panels2screens.sh #this moves the KDE panels back in place, will discuss it later.
Don't forget to chmod +x the files, so they are executable.
If you run ch_monitors.sh then the two monitors should be besides each other and when you run ch_television.sh then one monitor should turn off and TV should turn on.

KDE panel problem

Here i solve the panel problem, so that after the change the panels go to both screens.

Edit /usr/bin/panels2screens.sh

#!/bin/bash

# path to the javascript file
JS_FILE="/usr/bin/PutPanels.js" 

# Plasma javascript console title
JS_CONSOLE_TITLE="Console de scriptage"

# set this to false if you don't want to use the xdotool hack
USE_XDOTOOL_HACK=true

qdbus org.kde.plasma-desktop /MainApplication loadScriptInInteractiveConsole $JS_FILE

if $USE_XDOTOOL_HACK
then
    WIN=$(xdotool search "$JS_CONSOLE_TITLE")
    xdotool key --window $WIN --clearmodifiers ctrl+e
    xdotool key --window $WIN --clearmodifiers Escape
fi

exit 0
This script is needs to run the next script from console. You bneed to hace xtool program. Please see http://sidux.com/index.php?name=PNphpBB2&file=viewtopic&p=157373&sid=e8565943e21fdee9dd2c27a6fd0e7c96#157373

Edit /usr/bin/panels2screens.sh

var mypanels=panelIds #get all the panels
var psa = panelById(mypanels[0]) #get the first panel
psa.screen=0 #put it to sceen 0
var psb = panelById(mypanels[1]) #get the second panel
psb.screen=1 #put it to sceen 1
You might need to adjust this script to your needs, you could have 4 panels too if you wanted. If you have one panel then you don't need this anyway.

Urban terror or other games

It is distracting to have 2 screens running cloned and trying to play, so to automatically turn off one monitor to play and after that restore old seting i use this script.
#!/bin/bash
xrandr --output DFP4 --off
cd /home/mardicas/.UrbanTerror/
./ioUrbanTerror.x86_64 
/usr/bin/ch_monitors.sh