Handling Multiple Displays with x2x

By: Rob Reilly
Tuesday, September 27, 2005 02:30:52 PM EST
URL: http://www.linuxplanet.com/linuxplanet/tutorials/6020/1/

Two Displays, One Problem

My desk is the shape of a big L and my 17-inch monitor sits on a little elevated rack in the corner. The display works with a desktop that I use for hardware and software testing. With tons of desktop real estate, my HP laptop sits comfortably in front of the monitor. I like to watch news on my desktop screen (via a Hauppauge TV card) while computing on the laptop, so it's easy to just move my eyes up and down to see the two screens.

But, it's a huge pain to close the lid on the laptop every time I have to type something on the desktop keyboard or fish around for the desktop connected mouse.

I needed a way to operate the desktop using my laptop keyboard and mouse.

x2x turned out to be the solution and here's how it works.

Putting x2x To Work

x2x is a standard application on the SUSE Linux 9.2 Professional DVD. Since my notebook is an AMD Athlon 64 the version I use is 1.30-beta-2x86_64. Versions are also available under Red Hat, Debian, Gentoo, and BSD. I installed the program with YAST.

The desktop is an old Pentium II machine with SUSE Linux 9.3 Professional installed. It's hooked up to the router using a CAT 5 cable. The notebook talks via a 802.11b link.

x2x can be executed at the command line or from a script. You can use any combination of laptops or desktops and don't necessarily have to mirror my example.

Starting and running x2x is pretty painless. In my case I used my laptop (192.168.2.23) to control my desktop (192.168.2.26). Here's how to make it happen.

The first task is to ssh into the desktop machine from the notebook. I created an rreilly account on each machine, with the same password, for convenience.

Next, I ran the following commands over the ssh login.

    rreilly-desktop> X -ac :0 &
    rreilly-desktop> /usr/X11R6/bin/kde
    rreilly-desktop> set DISPLAY 192.168.2.26:0
    rreilly-desktop> DISPLAY=192.168.2.26:0; export DISPLAY

In this case, KDE then appeared on the desktop display and sat there waiting for input. GNOME, FVWM2, or xfce could just as well.

Then, it was an easy matter to start x2x in a laptop xterm:

	
    rreilly-laptop> x2x -west -to 192.168.2.23:0

Like magic, the mouse cursor could then be rolled back and forth between the laptop and the desktop screens. The "west" switch arranges the screens so that if you move off the laptop screen to the left, you'll see the cursor appear on the desktop monitor. Move back to the right (on the desktop screen) and the cursor will pop back to the laptop. The laptop keyboard and mouse controls both screens. The desktop mouse and keyboard are still usable.

To simplify startup, I put the desktop machine commands into a little script file called "headless." I probably should have called it "mousekeyboardless" or something. The file permissions were changed on the headless file to 744. Back at the first step, the file can then be executed in an xterm:

    rreilly-desktop> ./headless

Try Some Options

Some people may have three machines to control. You can copy the headless script over to the third machine. Since the laptop will be controlling the three screens, no changes need to be made to the script. Naturally, the user accounts need to be synced and I assume machine three will run KDE. You don't necessarily need to keep KDE though. Change the second line and give another window manager a try, if you are adventurous.

One difference is that x2x will need to be started with the -east option. This will make the cursor switch to machine three when you roll the mouse off the right side of the laptop screen. Don't forget that you'll also be starting x2x for both remote machines, in their own xterms on the laptop.

A couple of other options that you might try are the "label" and "wait" switches. Label overrides the title of the control window, which might be helpful to keep of your screens over ssh.

The wait option lets x2x sit there and poll until the from or to machines become available. This might be useful if you run x2x from a script.

Another useful switch is for "north" and "south" machines. Conceivably, you could then control up to four machines from your laptop. Sadly, these options apparently aren't implemented in my version. Take a look at the x2x man page for a complete list.

I also wanted to mention that the commands that I used to set up X on the desktop machine is not very secure. So, you'll probably want to look at using MIT-Magic-Cookie authentication or tunneling through ssh. Both are mentioned on the x2x home page. The method outlined works fine for my little lab network where I can keep an eye on who's logged in.

x2x is a nice little program to use for controlling multiple Linux machines from one keyboard and mouse.

I'm happy because I don't have to close my laptop lid any more.

Rob Reilly is a consultant, writer, and commentator who advises clients on business & technology projects. He is also a Contributing Editor for Linux Today. Send him a note or visit his Web site at http://home.earthlink.net/~robreilly.

Copyright Jupitermedia Corp. All Rights Reserved.