Configuring Dual Monitors


The graphical display has a limited amount of screen real estate. As more windows are opened, space on the desktop becomes an issue. Using the Workplace Switcher (see Chapter 8) is a good start, but eventually you will find yourself rapidly switching back and forth between desktops as you try to use two applications at once. For serious power users, one monitor is usually not enough. Ubuntu offers a couple of different options for adding multiple monitors:

  • Two headed systems-One computer can have multiple graphics cards. This is an ideal solution for people with extra hardware. Alternately, some graphics cards are capable of driving more than one monitor.

  • Networked desktops-Two different computers combine to form one virtual desktop. This is a great option when you have spare computers lying around.

  • Shared desktops-There is no reason why all of the desktops need to run the same operating system. This is a must-have for anyone with a need to use Windows, Mac OS X, and Linux at the same time.

Using Two Heads

If your computer has multiple video ports, then you can frequently use them to drive two different monitors. Although most workstation computers don't have multiple video cards installed, you can always plug in an extra one. However, many laptops include two video sources: one for the LCD display and one for an external monitor. In some cases, these video ports can be configured to work together, forming one large display, while other laptops must display the same thing on both ports.

Note 

The computer display is commonly called a head. A computer with two displays is a dual-headed system. Many servers are headless, since they have no display attached.

There are two ways to have a dual-headed system. The first is to combine monitors using TwinView. However, TwinView is strictly limited to nVidia video cards. The more universal option is Xinerama.

Using Two Heads with TwinView

If you have an NVIDIA graphics card and it supports two monitors, then you can use TwinView to combine both monitors into one desktop. TwinView is an NVIDIA-specific graphics extension for managing multiple monitors.

  1. Create a backup of your working xorg.conf file.

     sudo cp /etc/X11/xorg.conf /etc/X11/xorg.conf.orig 
  2. Tell X-Windows about the second monitor. In the file /etc/X11/xorg.conf is a section titled "Device". This contains the video card attributes. Add in TwinView options for the second monitor. For example:

     Section "Device"     Identifier  "NVIDIA Corporation NV18 [GeForce4 MX 4000 AGP 8x]"     Driver      "nvidia"     BusID       "PCI:1:0:0"     Option      "TwinView"     Option      "MetaModes"  "1280x1024,1280x1024; 1024x768,1024x768"     Option      "TwinViewOrientation"    "RightOf"     Option      "ConnectedMonitor"       "CRT,CRT"     Option      "SecondMonitorHorizSync"         "UseEdidFreqs"     Option      "SecondMonitorVertRefresh"       "UseEdidFreqs" #   Option      "SecondMonitorHorizSync"         "24-80" #   Option      "SecondMonitorVertRefresh"       "50-75" EndSection 

    These options include pairs of video resolutions (one for each monitor), the location of the second monitor (right of the first), and the monitor scan rates (either using defaults or specifying range).

  3. Save your new xorg.conf file and restart the X-server. Log out and use Ctrl+Alt+ Backspace to restart the server. If it does not come up, then refer to the section "Debugging X-Windows" earlier in this chapter. (If it does come up, then you're done and you should have two working displays.)

Using Two Heads with Xinerama

If your system has two different video ports, then you can use Xinerama to link them into one virtual display. Before you can use two monitors, you will need to make sure the computer actually has two video devices. Use the lspci command to list all display devices:

 lspci -X | grep -i -e VGA -e DISPLAY 

If only one display controller is listed, then you won't be able to use this option. However, if you see multiple video cards, then you can configure your X-server to use both cards. This requires editing the /etc/X11/xorg.conf file.

  1. Create a backup of your working xorg.conf file.

     sudo cp /etc/X11/xorg.conf /etc/X11/xorg.conf.orig 
  2. Tell X-Windows about the second monitor. In the file /etc/X11/xorg.conf is a section titled "Monitor". This contains a unique identifier and monitor attributes. Create a second one for your second monitor. For example:

     Section "Monitor"         # Default monitor         Identifier       "LCD"         Option           "DPMS" EndSection Section "Monitor"         # Second monitor that I added         Identifier       "CRT"         Option           "DPMS"         HorizSync       31.5 - 57.0         VertRefresh      50-100         # You may want to add ModeLine items later EndSection 
  3. Each monitor in the xorg.conf file may display different desktop screens. You need to tell X-Windows about the second screen. In the file /etc/X11/xorg.conf is a section titled "Screen". This contains a unique identifier and information about the graphics modes. Create a second screen section with a different identifier for the second monitor. For example:

     Section "Screen"   # Define the first screen   Identifier    "Default Screen"   Device        "NVIDIA Corporation NV18 [GeForce4 MX 4000 AGP 8x]"   Monitor "LCD"   DefaultDepth  24   BusID         "PCI:1:0:0" # optional for distinguishing cards   SubSection "Display"     Depth       24     Modes       "1024x768"   EndSubSection EndSection Section "Screen"   # Define the second screen   Identifier    "Second Screen"   Device "ATI Technologies, Inc. M9+ 5C63 [Radeon Mobility 9000 (AGP)]"   Monitor       "CRT"   DefaultDepth  24   SubSection "Display"     Depth       24     Modes       "1280x1024"   EndSubSection EndSection 

    Note 

    Be sure the labels in your Screen section's "Monitor" lines match the unique identifiers from the Monitor sections. The Device name and option BusID value should match the results from the lspci -X command.

    Tip 

    Use the BusID option when you have two of the same type of video card in one computer. This distinguishes one card from the other.

  4. In the /etc/X11/xorg.conf file is a section titled "ServerLayout". This is where you will specify the geometry of the desktop. Using the screen identifiers, you need to specify the X-display number (for example, 0 for DISPLAY=:0, 1 for DISPLAY=:1, and so on) and their relationship in forming the desktop: Above, Below, LeftOf, or RightOf. For example, if my CRT monitor is located to the right of the LCD monitor, then I can use:

     Section "ServerLayout"         Identifier "Default Layout"         Screen 0 "Default Screen"         Screen 1 "Second Screen" RightOf "Default Screen"         InputDevice "Generic Keyboard"         InputDevice "Configured Mouse"         InputDevice "stylus" "SendCoreEvents"         InputDevice "cursor" "SendCoreEvents"         InputDevice "eraser" "SendCoreEvents"         InputDevice "Synaptics Touchpad" EndSection 
  5. (Optional) If you want to have the displays linked as one desktop, rather than being treated as individual displays, then you will need to add a Xinerama option. This can be done by creating a section titled "ServerFlags" and setting the Xinerama option to true.

     Section "ServerFlags"         Option "Xinerama" "true" EndSection 

    Alternately, you can add the Option line to the "ServerLayout" section.

  6. If you have everything in place, then you should be able to save your new xorg.conf file and restart the X-server. Logout and use Ctrl+Alt+Backspace to restart the server. If it does not come up, then you'll need to go to the section in this chapter titled "Debugging X-Windows." (If it does come up, then you're done and you should have two working displays.)

image from book
Xinerama

The big trick to making a multi-display desktop is the Xinerama extensions to X- Windows. This library is installed by default and allows you to chain multiple X- Windows displays into one large, virtual desktop. Without the flag, multiple displays can be used, but they do not appear as one coherent desktop.

How can you tell if you need the flag?

  • If you cannot drag a window across the desktop, from one monitor to the other, then you need the Xinerama flag.

  • If your graphical desktop (Gnome or KDE) replicates the background image and panels in every window, then you need the Xinerama flag. Without the flag, each display is treated independently. With the flag, they are linked into one large desktop. However, as one large desktop all panels will only appear in the first display. This allows the secondary displays to be used for presentation projectors and not be cluttered with panels and widgets.

image from book

Using Two Computers and One Desktop

If you have a high-end computer or two high-end video cards in one system, then connecting two monitors to one computer is definitely the way to go. However, there are some situations where it is more desirable to use a second computer to run the second display. For example:

  • You do not have a second video card to put into your system. In my case, I have no spare video cards available, but I have plenty of spare computers that have video cards built into their motherboards.

  • Your computer does not have available expansion slots for a second video card. Some low-end PCs are not expandable. Many times, motherboards have only one high-bandwidth slot for a high-end video card. You may have extra expansion slots, but may be unable to use them for graphics.

  • Your second monitor is built into a stand-alone computer (for example, My grape iMac has a monitor built into the computer housing.)

Whatever your situation might be, you can extend your virtual display such that it spreads across computers. All you need are two or more networked computers running X-Windows.

Tip 

Ideally you'll want the network to be fast. In some corporate environments, physically adjacent computers may actually be on different subnets. Since transmitting video consumes bandwidth, consider investing in a cheap router and putting all of the display computers on the same subnet. Latency across a slow network can be very noticeable.

  1. Your virtual display will have one primary display (for the mouse and keyboard) and one or more secondary displays that will provide the desktop. Install the Distributed Multihead X Project server (Xdmx) on the primary computer. This will be used to bridge different X-Windows systems.

     sudo apt-get install xdmx 
  2. Each of the machines that will be part of the virtual desktop will need to allow remote access to their X-Windows system. The problem is, the default Ubuntu installation disables all remote access. Thus, you will need to enable it. How you enable it depends on your desktop.

    • For Ubuntu's default window manager, Gnome, you must edit

       /etc/gdm/gdm.conf. Change DisallowTCP=true to DisallowTCP=false. 

    • For the Kubuntu KDE window manager, you must edit /etc/kde3/kdb/kdbrc and change ServerArgsLocal=-nolisten tcp to ServerArgsLocal= (no parameters).

    • For other window managers, such as TWM, you will need to edit

       /etc/X11/xinit/xserverrc and change exec /usr/bin/X11/X -dpi 100 -nolisten tcp to exec /usr/bin/X11/X -dpi 100. 

    After making this change, you will need to restart the X-server. Pressing Ctrl+Alt+ Backspace won't cut it (that only re-reads configuration files). Instead, you will need to either reboot the system or restart the display. For example, to restart Gnome you can use:

    • Stop Gnome using: sudo /etc/init.d/gdm stop.

    • At the text screen, press Alt+F2 to get to a text login screen.

    • Log in.

    • At the command-line prompt, run: sudo /etc/init.d/gdm start.

  3. Use xhost +hostname to enable remote access for the display server. For example, if my primary server is named alpha, then I would use xhost +alpha. You can also specify an IP address such as xhost +10.1.2.15.

  4. On the primary display server, enable local access.

     xhost +local: 
  5. Now you can use Xdmx to link all of the displays together. For example, if my secondary display is on the computer named bravo, then on the primary system I would run:

     Xdmx :1 -display :0 -display bravo:0 

    This assigns the virtual desktop as display :1. The virtual desktop spans :0 on the primary system (the normal display) and bravo:0 is located to the right. If I had a third system (for example, charlie), then I could use:

     Xdmx :1 -display :0 -display bravo:0 -display charlie:0 

Xdmx takes a variety of different options. For example, the primary display does not need to be on the left. However, if it is not on the left, then you will need to specify which display will provide the keyboard and mouse input.

 Xdmx :1 -input :0 -display bravo:0 -display :0 -display charlie:0 

Other useful options include:

  • +xinerama-If you need to enable to Xinerama flag, then use Xdmx +xinerama.

  • -ignorebadfontpaths-It's not uncommon to have default font paths in the X configuration when they don't actually exist. This flag tells Xdmx to ignore bad font paths.

  • -configfile and -config-The virtual display does not need to be horizontal. You can also specify vertical alignment. The -configfile option identifies the configuration file, while the -config option allows you to choose which virtual display layout you would like. Listing 9-3 shows an example configuration file with different layouts.

Listing 9-3: A Sample Xdmx Configuration File (xdmx.conf)

image from book
 # A basic horizontal (left to right) alignment. Use -config l2r virtual l2r   {   display :0 @0x0;          # the top corner will be at 0x0   display bravo:0 @1024x0;  # place it 1024 pixels to the right   } # A vertical alignment using a 1x2 grid. Use -config virtual_stack virtual vertical_stack { wall 1x2 bravo:0 :0; } # A huge 3x3 display. Use -config grid3x3. virtual grid3x3   {   wall 3x3   bravo:0 charlie:0 delta:0   echo:0  :0        foxtrot:0   golf:0  hotel:0   india:0;   } # Specify two displays with absolute position 200x200 # This will overlay the displays (good for projection systems) virtual overlay { display alpha:0 @200x200; display :0 @0x0; } 
image from book

The Xdmx command creates the X-Windows desktop, but does not start any window managers. This means that every display will have the plain X-Windows gray color. For a more usable desktop, you will need to start a window manager. Listing 9-4 is an example startup script that runs Xdmx and starts the Gnome window manager. You can extend this script to start specific applications like a terminal or graphical monitor.

Tip 

To quickly shut down Xdmx, press Ctrl+Alt+Q. This will kill the Xdmx system and immediately close all windows.

Listing 9-4: Sample Startup Script for Xdmx with a Window Manager

image from book
 #!/bin/sh # Give permission to open an X application. xhost +local: unset XAUTHORITY # Save the displays export REALDISPLAY=$DISPLAY export NEWDISPLAY=:1 # Start Xdmx (use -configfile or -display to specify the virtual display) Xdmx $NEWDISPLAY +xinerama -ignorebadfontpaths \   -input $REALDISPLAY -configfile xdmx.conf -config l2r & export DISPLAY=$NEWDISPLAY sleep 2  # give it time to come up # Select your window manager # Gnome should not have a SESSION_MANAGER variable set. unset SESSION_MANAGER gnome-session --sm-disabled & #startkde & # run KDE as the window manager #twm &      # run TWM as the window manager #xterm &    # run a plain terminal 
image from book

Tip 

If you always want to run the virtual display, then you can add the startup script to your $HOME/.xinitrc. This way, it will always start up after you log in to a graphical desktop.

The Xdmx command has two significant limitations. First, if the network goes down or one of the virtual desktop computers crashes, then the program will abruptly exit. If you lose one of the desktops, then you will lose all of them. Second, creating a virtual desktop between two very different hardware platforms (for example, PC and Mac) can result in screwed up colors- even if all of the platforms are running Ubuntu with true 24-bit color. For best results, stick with the same hardware platforms.

Using Two Computers with Different Desktops

In the corporate world, few Linux users work strictly with other Linux users. Usually you need to interact with a wide variety of Windows, Linux, and Unix users (and the rare OS/2 fanatic). I know plenty of people who run two computers, one Linux and one Windows, for full compatibility. The problem is, they spend a lot of time either transferring files or using shared hard drives. Taking output from a Linux program and pasting it into a Microsoft Outlook e-mail is definitely a multi-step solution. While Part II of this book (and Chapter 6 in particular) covered many of the ways to share information between different operating systems, there is another option.

Using a tool called Synergy, you can connect the desktops from completely different operating systems. Although you cannot drag applications off desktops, you can use one mouse and keyboard to navigate the linked desktops. And most importantly: you can share the clipboard. This way, you can copy text from a Linux application and paste it into a Windows program without a dozen steps.

Installing and configuring Synergy is much simpler than using Xdmx.

  1. Install Synergy on each of the virtual desktop systems. Under Ubuntu, this is simply sudo apt-get install synergy. For other operating systems, you will need to visit http://synergy2.sourceforge.net/. They have precompiled binaries available for Windows (from Windows 95 to Windows XP and Windows ME), Linux, and Mac OS X. If you need other platforms, then you can download and compile the source code.

  2. Synergy uses a central server as the primary system, and one or more clients for the shared desktops. The server is the system that has the mouse and keyboard, and this system uses a configuration file to manage the screen relationships. Unlike Xdmx, Synergy can handle non-rectangular relationships and loops where, for example, moving off the far left takes you to the far right.

    • For an Ubuntu Synergy server (and Mac OS X server), the configuration file is a text file that contains hostnames and relationships. My configuration file (Listing 9-5) has three hosts: a Windows client named willy, a Mac OS X named matt, and an Ubuntu system named udo. The computers are arranged with the Windows box (willy) sitting above the Ubuntu system (udo), and the Mac (matt) is to the right of the Ubuntu system.

    • For Windows systems, the Synergy server uses an application for specifying systems and relational positions (see Figure 9-7).

      image from book
      Figure 9-7: The Microsoft Windows Synergy server configuration window showing the same relationships as Listing 9-5

    Regardless of the server's platform, the configuration has three main components. First, all of the possible clients are listed. Second, the links between the displays are defined. Finally, any special options can be listed. The links form the most complicated part; they define what happens when the mouse goes off the edge of a screen. You can specify left, right, above, and below relationships. Only defined relationships exist--nothing is assumed.

    Tip 

    Synergy links do not have to be symmetrical. For example, my system named matt may be located to the right of udo, but udo may not be left of matt. You can also create loops. For example, moving right from udo goes to matt, and continuing to the right can cycle back to udo.

    Warning 

    Be sure to define both directions of a link. If I only define matt as being right of udo without specifying the return link (for example, udo is left of matt) then I will not be able to move the cursor back.

    Listing 9-5: A Sample Synergy Configuration File (synergy.conf) with Three Systems

    image from book
     # The layout: #    willy         -- is above udo #     udo    matt  -- matt is right of udo section: screens   # List every known client by name, and any special mappings   udo:   matt:     meta = super  # this is a Mac and uses the command/super key   willy: end section: links   # Define every link relationship.   # It does not need to by symmetrical!   udo:     right = matt     left = matt # make a horizontal loop     up = willy   matt:     left = udo     right = udo # make a horizontal loop   willy:     down = udo end section: options   # Make all screensavers turn on at the same time   screenSaverSync = true end 
    image from book

  3. Check your client configuration. Synergy supports pretty much any Windows, Mac OS X, Linux, and Unix system. For X-Windows systems, be sure to have the XTEST extension enabled. You can check this with xdpyinfo | grep XTEST. This should display the word XTEST. For Windows and Mac systems, no special configurations are needed.

  4. Start the client. Each client requires two elements. First, it needs to know the host name of the server. Second, it needs a unique name that is listed in the server's configuration (in the screens section). By default, the name is the client's host name. However, you can specify an alternate client name.

    • Under Linux, Unix, and Mac OS X, the client is synergyc. The server's name is specified on the command line. You can also include an optional name for the client. Following the example above, I used this command to connect my Mac (matt) to my Ubuntu server (udo).

       synergyc --name matt udo 
    • Under Windows, use the Synergy client to specify the server's name and optional client's name (see Figure 9-8).

      image from book
      Figure 9-8: The Microsoft Windows client configuration for Synergy

  5. Start the server. On Ubuntu, Mac OS X, and other Unix and Linux systems, the command is synergys. You specify the configuration file using:

     synergys --config synergy.conf 

    On Windows systems, open the Synergy application, select Share this computer's keyboard and mouse (server) and click Start.

Tip 

By default, syngergys and synergyc detach from the console and run in the background. To prevent the process from becoming a daemon, use -f. For example, synergys -f –config synergy.conf.

Although the server and clients all need to be started, the order does not really matter. Clients regularly poll the server until a connection is achieved. As each system connects, the rules for the links are applied. Following the example, the cursor will be unable to move off the right side of udo until matt connects. When matt connects, the movement to the right will follow the established link.

Note 

Under Synergy, systems are either clients or a server. You do not need to run a server on the client.

When all of the clients connect to the server, you can start sharing desktops. Moving the mouse between windows allows you to set the focus for the keyboard. And most importantly: if you copy text from any desktop then you can paste it into application on any other desktop.

Tip 

With Xdmx, if any system disconnects for any reason, the entire Xdmx session aborts. In contrast, Synergy allows all clients to connect and disconnect without notice. If you have systems that crash or reboot often, Synergy is definitely a good productivity solution since you can continue working while one part of the desktop is down.

Dual heads, Xdmx, and Synergy are not independent solutions. You can actually run two displays on one computer (a dual head solution) and use Xdmx to link it to more displays and use Synergy to link in desktops from other operating systems. The only limitation to your virtual desktop size becomes your physical desktop. Just how many monitors can your desk hold?

Tip 

Consider installing a Synergy client in a virtual machine, such as Qemu (see Chapter 6). This enables you to cut and paste between the virtual computer and the real desktop. In many cases, this is much more convenient than transferring data across a network or through a shared partition.



Hacking Ubuntu
Hacking Ubuntu: Serious Hacks Mods and Customizations (ExtremeTech)
ISBN: 047010872X
EAN: 2147483647
Year: 2004
Pages: 124
Authors: Neal Krawetz

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