Set up Linux Nvidia driver for multiple monitors

Q I'm attempting to set the propriety Nvidia driver up for single, dual and twin view, and after much searching, I've finally managed by creating the xorg.conf files directly (as the Nvidia GUI keeps complaining about overlapping meta modes and reporting wrong refresh rates). But though I now have the three xorg.conf files ready and working - one for each view that I need (dual, twin and single) - I can't seem to find any information on how to integrate these in a single environment where I can switch between them. I need to be able to switch between these three types of view on the fly, ideally with a keyboard combination.

As it is, I manually stop the X server, swap the xorg.conf file and restart X. I'd guess that I need to merge my three different xorg.conf files into one, but how? And how do I tie restarting the X server with an alternative view to a keyboard press (or any functionality, be it menu, file or whatever - as long as it's one-click or as near to as possible)? I'm using KDE on Fedora and would appreciate some guidance on this, but please be gentle - so far I've only been on the Linux wagon for a week.

A You can combine the various portions of the separate xorg.conf files into one, providing you give them different names. The Monitor sections can just be put one after the other, but you'll need to make sure that each of your Screen sections has a different name, with a separate section for each of the layouts. Most of the other entries in xorg.conf are the same for all; things like keyboard, mouse and font settings. Then you create a separate ServerLayout section for each layout, with a different name, so you'd have something like:

Section "ServerLayout"
Identifier "SingleScreen"
Screen        0 "SingleScreen" 0 0
InputDevice "Mouse0" "CorePointer"
InputDevice "Keyboard0" "CoreKeyboard"
Section "ServerLayout"
Identifier "TwinScreen"
Screen        0 "TwinScreen" 0 0
InputDevice "Mouse0" "CorePointer"
InputDevice "Keyboard0" "CoreKeyboard"

The first ServerLayout is the default, or you can specify it with:

Section "ServerFlags"
DefaultServerLayout "SingleScreen"

Now X will start up in single mode by default but can be started in twin mode with:

startx -- -layout TwinScreen

The '--' means 'end of startx options, pass anything else along to the server' In order to bind this switch to a hotkey, you need a short shell script. Save this script somewhere in your path, say as /usr/local/bin/restartx:

if  cut -c3)" == "5"
sudo /sbin/telinit 3
sudo killall X
sleep 2
startx -- -layout $1

and make it executable with chmod +x /usr/local/bin/restartx. As some of the script needs to run as root, you'll also have to edit /etc/sudoers, as root, and add this line:

yourusername ALL = NOPASSWD: /usr/bin/killall X,/sbin/telinit 3

Now you can switch layouts with:

nohup /usr/local/bin/restartx newlayoutname

The nohup is necessary or the script will be killed when the desktop closes. As you're using KDE, you can bind any commands you want to hotkeys in the Regional & Accessibility/Input Actions section of the Control Centre, so set up one to switch to each layout in your xorg.conf file. Finally, you'll probably want KDE to remember your open applications after switching. To do this, go to Control Centre > KDE Components > Session Manager and select Restore Manually Saved Session. This adds another option to enable you to save your session and you can get the script to do this automatically by inserting this as the second line:

dcop ksmserver ksmserver saveCurrentSession

This is the only KDE-specific part of this exercise, and you'll find that the rest will work with any desktop.

Follow us on or Twitter

Username:   Password:
Create Account | About TuxRadar