Hack72.Get the Big Picture with Multiple Displays


Hack 72. Get the Big Picture with Multiple Displays

Using two monitors with a single system gives you more room to work. The latest versions of the X Window System make this easier than ever before.

Many of the hacks in this book discuss how to better monitor system and process status, how to use the Web for basic computing infrastructure functions, and so on. This hack explains how to get enough display space so that you can actually see all of that information by attaching two video cards and two monitors to any Linux system and configuring the XFree86 or X.org X Window System for what is known as multi-head display.

Whenever possible, add a second graphics card of the same type as the one that is already in your system, or replace your existing graphics card with one that supports two monitors. This will enable you to use the same X server to control both graphics cards and their associated displays. Similarly, it's a good idea to add a second monitor of exactly the same size and with exactly the same maximum display resolution as your existing monitor. This will simplify synchronizing graphics modes across the two monitors (and in the X Window System configuration sections for each display).


This hack creates two separate displays, one on each of your monitors. An alternate approach would be to use the X Window System's Xinerama extension to create one single display that spans two monitors. (See http://www.tldp.org/HOWTO/Xinerama-HOWTO/ for more information about Xinerama.) With two separate displays you cannot move windows from one to the other, though you can create windows on a specific display by specifying the display that you want to use on an X application's command line. I find Xinerama disconcerting because windows can be split across the two displays, which makes them a tad hard to read because of the casing on my monitors. I find separate displays easier to use and cleaner looking. Your mileage may vary.

X Window System configuration information is stored in the file /etc/X11/xorg.conf if you are using the X11 server from X.org, or in /etc/X11/XF86Config if you are using an XFree86-based X11 server. After adding the hardware to your system and booting in a nongraphical, multi-user mode such as runlevel 3, the procedure for modifying this file to use a multi-head display is as simple as the following few steps.

First, you need to create two Monitor sections in your X server's configuration file. Make sure you use a unique Identifier name for each monitor:

 Section "Monitor" Identifier  "Monitor 0" VendorName  "Monitor Vendor" ModelName   "Model X" HorizSync   30.0 - 50.0 VertRefresh 60.0 - 60.0 EndSection Section "Monitor" Identifier   "Monitor 1" VendorName   "Monitor Vendor" ModelName    "Model Y" HorizSync    30.0 - 50.0 VertRefresh  60.0 - 60.0 EndSection 

Next, create a Device section for each graphics card in your system. As with the monitors, be sure to use a unique Identifier for each graphics card:

 Section "Device" Identifier "VideoCard 0" Driver "drivername" VendorName "Vendor" BusID "PCI:00:15:0" EndSection Section "Device" Identifier "VideoCard 1" Driver "drivername" VendorName "Vendor" BusID "PCI:1:0:0" EndSection 

The BusID enables the X server to correctly and uniquely define each display in your configuration file, and its value can be found from the output of the lspci command. The BusID can be found at the beginning of the first line of lspci output that identifies the graphics card. The format is slightly different than what you will need to put in your configuration file: lspci reports in hexadecimal, while you must use decimal notation in your configuration file. The output of the lspci command is also xx:yy.z, which you must express as xx:yy:z in your configuration filenote that the period in the lspci output must be replaced with a colon in your configuration file.

 # lspci | grep VGA 00:0f.0 VGA compatible controller: nVidia Corporation NV11 [GeForce2 MX/MX 400] (rev b2) 01:00.0 VGA compatible controller: nVidia Corporation NV15 [GeForce2 GTS/ Pro] (rev a4) 

My favorite tool for converting hex to decimal is the standard Linux bc utility. You can specify bc's input base using the ibase =base command and leave its output set to decimal (the default). For example, the following shows how to convert 10 hex to decimal (OK, that's not very hard, but this is an example, and a simple example does make things clear):

 $ bc q ibase=16 10 16 

After specifying the input base, you simply enter a hex value and press Return, and bc displays the decimal equivalent. Type Ctrl-D to exit bc.


The next thing to add to your X server's configuration file is two Screen sections. Each section will use one of the Monitor and Device stanzas that you defined previously. The resolution and color depth of the two can be different if you so desire but are usually the same:

 Section "Screen" Identifier "Screen 0" Device "VideoCard 0" Monitor "Monitor 0" DefaultDepth 24 SubSection "Display" Depth 24 Modes "800x600" "640x480" EndSubSection EndSection Section "Screen" Identifier "Screen 1" Device "VideoCard 1" Monitor "Monitor 1" DefaultDepth 24 SubSection "Display" Depth 24 Modes "1024x768" "800x600" "640x480" EndSubSection EndSection 

Now, you must tie all of these pieces together in the ServerLayout section (normally at the top of your configuration file:

 Section "ServerLayout" Identifier "Multihead layout" Screen 0 "Screen 0" 0 0 Screen 1 "Screen 1" RightOf "screen 0" InputDevice "Mouse0" "CorePointer" InputDevice "Keyboard0" "CoreKeyboard" InputDevice "DevInputMice" "AlwaysCore" EndSection 

The 0 0 next to Screen 0 means that this screen will start at position 0,0. Screen 1 will be located to the right of Screen 0.

Now that that's done, start the X Window System using your favorite startx or xinit command. If X does not start correctly, double-check the entries that you added to your configuration file for syntax errors, paying particular attention to the BusID values in the Device stanzas.

Redirecting the output of the startx or xinit command to a file can help capture error messages that you can use to debug your configuration files. Executing xinit> & x_startup.txt can be extremely useful, unless you can read much faster than I can.


Once X is working correctly, you can start a graphical application so that it starts on the screen of your choice by using the display option that is accepted by almost every X Window System command. For example, to start an xterm on Screen 1, you would execute the command xterm display :0.1. This display value specifies that the application use Screen 1 of the current display (display 0) on the current host. The general form of a display value is the following:

 hostname:displaynumber.screennumber 

Using a multi-head display may be a bit disconcerting at first, especially when your mouse pointer crosses from one monitor to the other, but you'll quickly find that the additional display real estate is well worth any amount of acclimation.

8.5.1. See Also

  • "Monitor Network Traffic with MRTG" [Hack #79]

Lance Tost



Linux Server Hacks (Vol. 2)
BSD Sockets Programming from a Multi-Language Perspective (Programming Series)
ISBN: N/A
EAN: 2147483647
Year: 2003
Pages: 162
Authors: M. Tim Jones

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net