The all new Nisus Writer Express is here. Join the celebration for only $59.95
Xs! They’re everywhere!
July 15, 2003
Want to dig even deeper? Post to the new MacEdition Forums (beta)!
X is everywhere. There is Mac OS X and now Apple is releasing a version of X11 for Mac OS X. What is X11, and how is it related to Mac OS X? X and X! What is X!
In short, X11 is a way of running a graphical program on a computer somewhere on a network and being able to interact with it (see what it draws, click on buttons, drag stuff around) on the computer you’re seated in front of. Programs running remotely act exactly the same as programs you’re running locally, it’s just that they’re running on a different machine.
The X11 technology is pretty old, at least in terms of the computer industry. The Graphical User Interface (GUI) was coming into its own in the early 80s. Many workstation vendors (a lot of which used unix in some form) had their own proprietary graphics systems such as EnvironV on Intergraph CAD workstations and SunView on Sun machines. The problems with these environments is that if a program wanted to show any graphics or provide any interaction with the user, the program had to be run on the same machine that had the screen, just like today with normal Mac OS and Windows applications. Powerful workstations in those days were really expensive and wimpy workstations were less expensive (I wouldn’t say “cheap”). Organizations were stuck having to have a few powerful machines to run the graphical programs (CAD, scientific visualization, etc), or a bunch of weaker machines that might not be able to run the programs the users need.
X11 was born out of this need, specifically, MIT wanting to use cheap graphic workstations to access more powerful computers that were shared amongst a lot of folks. 1984 was when MIT started the X project, which eventually grew into The X Window System, version 11, release 6 (which explains the X11R6 acronym you may have seen around).
“Network Based” is a term associated with X11. That means that an application runs on one machine and sends drawing commands to another. This other machine draws the stuff, looks for events like mouse and keyboard activity, and then sends events back to the application, who then updates its state and then sends back some more drawing commands.
In X11 terminology, the application running on the remote machine is called the “client”, and the machine displaying the graphics is the “server”. This is backwards from most uses of client/server, where the remote machine is a server and your local machine is a client. The reasoning behind this is that the graphics system is providing a service (showing stuff to the user), of which the applications (word processors, scientific visualizers) are making use.
So, the stuff that Apple’s X11 package gives you is an X server that you can run on your Mac, and it will draw stuff other programs tell it to. (Old timers might also remember another X11 Server running on the Mac platform – MacX.)
The design of X11 is based on a “functionality, not policy” philosophy. It provides a lot of tools that applications can use (draw a line in red, fill in a rectangle with a checkerboard pattern, display some text using Courier), but gives no guidance as far as user interface or behavior standards. This is the opposite of the Mac landscape where there are strict UI guidelines and the underlying technology enforces a lot of the guidelines. This “hands-off” approach to the use of the toolkit was intentional and allowed the X project to avoid getting bogged down in the politics surrounding the different looks and feels available (such as OSF’s Motif and Sun’s OpenLook).
This flexibility has lead to User Interface freedom (or “chaos” as some would call it). Custom interfaces and user control over minutiae are both common. “Skinning” and similar customization is a popular pastime. themes.org has a ton of different UI configurations for X11.
One aspect of your environment that you typically have control over in X11 and not on the Mac is the “window manager”. This is a program that handles all the window stuff that applications don’t do, such as drawing the window control gadgets (resize box, close box). The window manager controls window placement, stacking and tiling, showing and hiding, and iconifying them so they don’t eat up any screen real-estate (much like sending a window to the Dock). Applications can ask the window manager to position window, but the window manager has the final say where the windows actually go. The window manager frequently has other features like customizable pop-up menus which lets the user start new programs. Because window managers are independent programs, you can choose amongst a bunch of different window managers that suits your work style and your desire/tolerance for eye candy. (If you think about it, due to X11’s network design you can have a program on one machine display a window on your local machine, and have the window placement being controlled by a window manager running on yet a different machine. Your X11 configuration can be made arbitrarily complex if you so desire.)
Apple’s X11 comes with a window manager that behaves exactly like the Aqua, so you won’t see any difference of behavior between “native” OS X windows and X11 windows. You can change the window manager Apple’s X11 uses, if you want, though.
Given the UI “flexibility”, it’s inevitable that even on the Mac with Apple’s Aqua Window manager, many X11 applications won’t have the familiar Mac look and feel. It’ll be the look and feel of the toolkit the programmer used, or perhaps something completely alien depending on the programmer’s whim. Frequently it’s just a prettied-up version of whatever the Windows UI was when the program was written.
Additionally, X11 programs love multiple button mice. If you’re going to be running a lot of X11 applications, you’ll want to pick up a three button USB mouse and use that. Unfortunately there’s not a lot of continuity across programs in how they use multiple buttons. You’ll need to check the documentation for the program (or else click around randomly and see what the buttons do). For instance, one popular style guide has button 1 for selecting, shift-button-1 to toggle selected items, button 2 for dragging items around, and 3 for popping up a menu. Another popular style guide has button 1 for selecting, button 2 for adjusting the selection, and 3 for a pop-up menu. If you don’t have a multi-button mouse, you can use modifier keys to simulate the additional buttons.
Reach out and app someone
So, what sort of applications are actually available? OpenOffice (a MS Office clone) requires X11. There are also popular X11 applications like The GIMP (photoshop clone) and LyX (TeX-based document processor) that you can use to enhance your personal productivity (void where prohibited).
One frequent use (at least among the folks I’ve interviewed), is running GUI programs on their Linux boxes, like administrative programs, having multiple shells open, running xload (system activity monitor), xeyes, etc. That way they can run their Linux box headless (without a monitor) and still run GUI applications.
There’s a couple of ways to set things up so that remote machines can display stuff on your X server. The first is using the xset program. This tells X11 to accept incoming connections from other computers. You can control whether to accept incoming connections from particular computers, or from everybody. In today’s paranoid security conscious world, letting random computers connect to your machine and open windows isn’t necessarily a great idea.
You can use ssh, the secure shell, which is a program you can run from the terminal to establish an encrypted communications channel from your machine to another computer over the network. All communications is encrypted (even the sending of your password over the network), which leads to a measure of protection for the data that passes back and forth. If you run ssh from an X11 session, the X11 communication will automatically “tunnel” in the ssh connection. This lets you run remote X11 programs and have them show up locally, and it also increases your local security by not allowing anyone else to connect to your computer.
There’s some configuration that needs to be done on the remote machine
for it to work. The sshd (Secure Shell Daemon) needs to have
X11Forwarding yes set in the sshd_config
file. (On Mac OS X, this file lives in
/private/etc/sshd_config) If that’s not set, the
remote machine will refuse any attempts at X11 tunneling.
To set up X11 tunneling, run the ssh program with the -X flag. Here I’m logging into my linux box at 192.168.0.174 on my local network. (note you’ll need to run this from an xterm under X11. The shells from the Terminal program won’t let you do this)
my-mac% ssh -X 192.168.0.174
Last login: Thu Jun 19 10:07:36 2003 from borkopolis Welcome to SuSE Linux. Have a lot of fun.
Directory: /home/markd Thu Jun 19 14:05:49 EDT 2003 % xclock
and then a clock appears on my Mac. If you don’t want to specify the
-Xflag every time you run a remote program, you can edit
/private/etc/ssh_config and make sure there is a
yes line in there.
Programming X11 (the condensed version)
X11 has been around a long time, and there’s a number of ways to write programs using it. Why would you want to write an X11 program rather than a Carbon or Cocoa program? You can target multiple platforms, particularly Unix platforms. You also get X11’s remote execution behavior. In many cases it can be easier to write a single X11 program that runs on a big powerful machine than it is to write a back-end computational engine and then talk to it via the network from a Cocoa or Carbon front-end.
The lowest-level toolkit is one called XLib. This provides all the drawing functions, visual attributes, and event handling. It’s very low level, and doing programming at this level can be a real world of hurt. If you don’t need absolute control over every aspect of your program’s interaction, stick to a higher level toolkit.
There are a number of free toolkits available that provide features you’d expected in a graphical toolkit, like pushbuttons and scrolling lists. GTK+, originally was built for The GIMP, is a C-based procedural API. This is the foundation toolkit for the Gnome project. There’s also Qt a C++ object-based toolkit. Qt is used for the KDE project. (Both KDE and Gnome are integrated desktop environments like the Mac) Qt lets you produce native Windows and Mac programs as well. For Linux and and the Mac, Qt has a dual licensing scheme: free distribution rights for free programs, and a for-fee license for commercial applications.
If you don’t want to program at the C level, many scripting languages (like Perl, Python, and Tcl) support the Tk toolkit. Tk was originally developed by the creators of the Tcl scripting language, but it has been ported to the other major scripting languages. Tk lets you create windows with a user interface in them, and you can attach behavior to buttons and other UI objects by using scripts. There is also a canvas item that lets you do arbitrary drawing for implementing custom controls. A Tk interface won’t necessarily be the most beautiful program you’ve ever seen, but it can be quite functional.
X11 is a venerable graphics display system that’s also quite functional. By giving us an X Server we can run on OS X, we can take advantage of even more unix software, whether we run it locally on our AlBooks at 10,000 feet on an airplane, or we run it on our Xserv cluster in some refrigerated room. Happiness is having more tools at our disposal.
Mark Dalrymple (email@example.com) has been wrangling Mac and Unix systems for entirely too many years. In addition to random consulting and custom app development at Borkware, he also teaches the Core Mac OS X and Unix Programming class for the Big Nerd Ranch.