X11 more details

From OS X Scientific Computing

Jump to: navigation, search


This page replaces my free-standing X11 on OS X page.

Quick Description of what you need to do

Go to X11 for the quick description.


The OS X version 10.3 and 10.4 installer CDs each gives you the (non-default) option of installing Apple's Xwindows. In 10.5, X-windows gets installed by default (a major improvement in my opinion). [10.4: Otherwise, you will need to manually install an X-windows system. There are several options, both free and commercial.] Probably the easiest option is to install Apple's version of X11, and it has the added advantage of having Quartz acceleration, which means that high-demand molecular graphics display programs like coot will behave better. Here's how to install Apple's X-windows and have it function as transparently as is if it were simply part of the operating system.

Why Do You Need to Do This?

In order to do anything scientifically useful, you will have to install X-windows on your Mac. You are probably used to Linux, SGI, etc, all of whose interfaces are X-windows based, so there is nothing to think about. However the Mac doesn't use this by default, so we have to install it. (Why they have you install support for 10 Languages, including Japanese, by default, but can't give you the option of installing this, is beyond my comprehension. But I digress...) The Mac Aqua interface essentially "replaces" the X-windows based interface on conventional unix machines, but it lacks the functionality required by all of the unix programs that are x-windows based. In addition, these programs expect you to have it by default, as well as all the libraries and stuff that comes with them. Hence you will have to install this even if you never compile anything but just import binaries from someone else. That is why I recommend that this be the very first thing you do.

On OS X, X11.app must be launched by the user, just like any other application. In 10.5, the launchd system does this for you, automatically, and on demand. On 10.4, if you use this frequently, you should make it one of the applications that you launch upon login (see System Preferences > Accounts > Login Items tab ). When the application is launched, it runs an "X11 server" that then permits unix programs requiring X11-based GUIs to run. By default, X11 will run in "rootless" mode, which means the "root" or parent (controlling) window never appears. This can create some confusion for people used to Linux and similar operating systems, but in practice it makes very little difference. (You can also run it in rooted or full-screen mode in 10.4, but I have no idea why you would want to do this.)

Summary of my recommended installation

Install Apple's X-windows programs. To do so, you must do BOTH of the following:

Install Apple's X11.app


It gets installed automatically by default.

However, a newer version with bug-fixes ought to be installed. This is in fact essential if you use my fink precompiled packages.

Go here: http://xquartz.macosforge.org/downloads/

Install X11- (or newer).

unless something more recent appears between now and when you read this.

10.4 and 10.3

This comes as a non-default component on the OS X installation DVD or CD, so you have to do a "custom install." If you bought a new Mac, such as a new Intel-iMac, put in the first install DVD and find the optional packages installer, open it, check the X11 box, and install from that. If you didn't do this and can't locate it, you can grab the backup copies I made for my PPC X11.app components (look to the right column of this page). The startup utility (the double-clickable X icon) now winds up in /Applications/Utilities (Discard any old ones in /Applications; they don't work.)

Install Apple's X11 SDK

On 10.4 and above, this gets installed by default when you install the Xcode developer tools. On 10.3, it does not get installed by default, so if you didn't remember to do it, grab the download from the column on the right. On 10.2, you have to install everything by default. These put header files in /usr/X11R6/include that you will need to compile X11 programs. If fink doesn't find these, it goes nuts.

Please note

Sometimes Apple's X11SDK and X11 installers mess up and don't install everything. This will wreak havoc on your attempts to get fink to recognize X11.app. To avoid this pain, download Gary Kerbaugh's pkgdiff script and run it according to the description linked here.

10.5: DON'T set the $DISPLAY variable

In 10.5, X11 is more integrated with OS X, and it sets $DISPLAY on its own. If you try to do it, you will mess everything up. So don't do it, and take it out of your startup scripts. (The new zsh-templates now handles this properly.)

10.4 and earlier only: Set the $DISPLAY variable


To run X11 programs from the command line within Terminal.app or iTerm.app, you need to set the DISPLAY environment variable. (If you launch them from an xterm, you shouldn't have to do this, as it is set automatically.)

The simplest way (if no one else is logged in)


You can simply type

export DISPLAY=:0.0

if you are a bash or zsh shell user, or

setenv DISPLAY :0.0

if you are a tcsh user.

You can add the appropriate line to your appropriate shell startup script. However, Apple's Fast User Switching permits multiple users to run X11.app simultaneously, in which case this trick won't work if more than one person is logged in. The first person gets display 0, the second gets display 1, and if the first person then logs out, and a third user logs in, she will get display 0 again, not display 2. So this approach won't work under those circumstances. You need a general way to set the right value of this variable. In what follows, I will give you examples of how to do this, manually, or automatically (I wrote a little GUI program called Xterminator (see below) to help you deal with this painlessly.)

Add the shell script commands appropriate for your default unix shell:


You can set the DISPLAY environment variable to let you run X-windows applications from your non-X terminal windows by putting commands in your login file file (eg: ~/.cshrc for tcsh; or ~/.bash_profile and ~/.bashrc for bash; or ~/.zshrc for zsh. This table has links to examples for each of these shell startup files. The commands are written to handle the case of multiple simultaneous X11.app users, which occurs when Fast User Switching is enabled.

Use my automated customization program:


You might instead want to try a cheesy little program I wrote called Xterminator to assist you in configuring X11.app the way you want it, including setting up the $DISPLAY variable for each of the shells.

Screen shot

Unlike "native" Aqua OS X applications, X11 applications use GUIs that are platform-independent. They tend to be rather drab, like the CCP4i tk-based GUI in the upper-right hand corner of the screenshot below. Other more modern GUI systems, like GTK+2, permit the user to apply "themes," including ones that better match the native aqua appearance (which is what is going on in those other windows).


Screenshot depicting several X11 applications running in "rootless" mode within OS X.
Note the use of the aqua-like gtk+2 theme.

Additional Tips and Tricks

To get rid of the annoying lobotomized xterm that appears when you start X11

In 10.5

In an open terminal session, issue the command

defaults write org.x.X11_launcher app_to_run /usr/X11/bin/xlsclients


defaults write org.x.X11_launcher app_to_run /usr/bin/true

and to put it back,

defaults write org.x.X11_launcher app_to_run /usr/X11/bin/xterm

In 10.4

cp /etc/X11/xinit/xinitrc  ~/.xinitrc

Then, edit ~/.xinitrc and comment out the line

xterm &

so it reads

# xterm &

Of course, you can add whatever you want to this file as well, but make sure you use the "&" to make the command run in the background.

Here is one possible, sensible alternative:

xterm -bg black -fg white -cr grey -geometry 80X25 -sb -rightbar -ls &

That gives it a black background, white foreground, grey carriage return, and a scollbar on the right. In addition, it ensures the xterm will run as a "login" shell (-ls), which is a good idea when running in rootless mode.

However, there is really no need to use xterm on OS X. You can use Terminal.app or iTerm.app. All you have to do is set the $DISPLAY environment variable, as described above.

To use stereographics display

Enter the following command:

defaults write com.apple.x11 enable_stereo -bool true

or with the most recent versions of X11 on 10.5

 defaults write org.x.X11 nable_stereo -bool true

You of course also need to have the appropriate hardware (CRT, stereo glasses, etc).

To get traditional X11 focus-follows-mouse behavior

Enter the commands:

defaults write com.apple.x11 wm_ffm true
defaults write com.apple.x11 wm_click_through -bool true

or, on the most recent versions of X11 for 10.5,

 defaults write org.x.X11 wm_ffm true
 defaults write org.x.X11 click_through -bool true

To get rid of the annoying quit alert that sabotages your logouts

Enter the following command:

defaults write com.apple.x11 no_quit_alert true

or, on the most recent versions of X11 on 10.5, use

 defaults write org.x.X11 no_quit_alert true

To get rid of the X11 dock icon

Here's how to get rid of the dock icon (it also removes the menu bar):

Dockless in 10.5

This doesn't work with the updated X11, which also moves X11.app (back) to /Applications/Utilities

  • Edit /usr/X11/X11.app/Contents/Info.plist
  • Put in the lines just above the penultimate line that reads </dict>:

  • Save the changes. Then issue the following (1 line) command:
/System/Library/Frameworks/ApplicationServices.framework/Versions/A\ /Frameworks/LaunchServices.framework/Versions/A/Support/lsregister \
-f /usr/X11/X11.app 
  • Enjoy the illusion of a fully integrated X11 display.

Dockless in 10.4

  • Edit the Info.plist file in /Applications/Utilities/X11.app/Contents
  • Put in the lines just above the penultimate line that reads </dict>:


  • Save the changes. Then issue the following (1 line) command:
/System/Library/Frameworks/ApplicationServices.framework/Versions/A\ /Frameworks/LaunchServices.framework/Versions/A/Support/lsregister \
-f /Applications/Utilities/X11.app
  • Enjoy the illusion of a fully integrated X11 display.

Some comments on X11 window size and handling within Quartz

At least in Tiger's Quartz/X11, its not obvious how to open windows (e.g. an xterm) beyond the resolution of the window manager - instead, the windows seem constrained to open only to the limit of your display. cf. Gnome, where you can open it to any size you want, e.g. well beyond the display resolution (e.g. if you have a really-really large number of columns in a file). Setting `--geometry n X n` will not help either. it remains to be seen if Leopard and friends will allow this, or if this author is simply missing something.

Also, in Gnome you can use alt-[left click] to 'grab' a window and slide it around, even to move the menu bar "out of sight" ; however, with Quartz, it is not obvious how to do anything like that.

(contrib. by BWL, 19apr08)

Running X11 programs that require 256 colors or 8-bit display

Occasionally you might be faced with an X11 program that requires the old-style 8-bit display. Here is a somewhat involved way to get this to work:

X11 and 10.5.X

Updates to Leopard's X11

Using Tiger's X11 on Leopard

It is possible to Install the 10.4 X11 on 10.5, although you may want to think twice, as it may break some 3rd-party applications, especially fink.

(FWIW, W. G. Scott has not tried this, does not recommend this, and cannot guarantee things will work if you do this. Proceed at your own risk)

You should try upgrading before you try downgrading.

Third-Party X11 Alternatives

I'm almost certain none of these work on 10.5:

Apple's X11 should do everything you need, and with its Xquartz acceleration, it is likely to be better than the alternatives. But you may have reasons for installing an alternative that I am not aware of. Here is a (probably incomplete) list of other options, with links.

  • XTools if you prefer to spend $100
  • OroborOSX A rootless aqua window manager for X11

Other Sites, Downloads, and Useful Links (External)

  • Gary Kerbaugh's pkgdiff allows you to check if the X11.app installation is incomplete.
Personal tools