This is the eventual solution I have come to. There is no need to use anything so complex as dbus, and xrandr is the needed command. Time has passed and though I don't use KDE currently (using XFCE4 at the moment), I use the following script to set my second monitor up whenever I connect it:
Quote:
#Used for laptop. Puts HDMI screen to the right of the laptop screen.
#Pass the xrandr name of the display device.
function checkOTHERMONITOR {
if [ -n $1 ]; then
local OTHERMONITOR="${1}"
echo "the variable OTHERMONITOR is $OTHERMONITOR"
if [ $OTHERMONITOR = "$( xrandr | grep '\<connected' | cut -d' ' -f1 | grep ${OTHERMONITOR} )" ]; then
return 0
else
return 1
fi
fi
}
checkOTHERMONITOR HDMI1 && xrandr --output LVDS1 --auto --output HDMI1 --auto --right-of LVDS1
|
The above should work for KDE, xfce4, any, as well as for most window managers. Suppose that you run a video game that changes all your monitor settings...then you may run a script like the above to put them back to their automatic settings. Copying the above script will not work for everyone, and you will need to find out what the command xrandr (included with all xwindows variants) names your monitors and modify your script accordingly. The window managers should all respect the underlying xwindow settings.
This script places my external monitor HDMI1 to the right of the laptop monitor LDVS1. There is no need for me to check for LDVS, because its the built-in. For that reason it doesn't appear in the short script. Once the script works right you can add it to your session start-up, and so when you log in your duel monitors will be set up for you. It can also be tacked on to scripts that run video games or scripts that monitor game processes, so that after they exit the monitors will be set up properly again. (This seems to be less of a problem lately, but certain games still fail to set monitors back up after they run.)