Leopard and X11

Introduction


19 Nov 2007

Most of the following content has been extracted from Ben Byer's posts in the last couple of months to Apple's X11-users Mailing List.

X11 in Leopard syncs up with Xorg 7.2. The developers switched from the XFree86 codebase (based on IIRC, X11R6.8) to the X.org codebase (X11R7.2). It now installs by default. You can choose not to install it by clicking customize during the Leopard installation process and deselect it before installing. Unfortunately, Apple shipped X11 in Leopard as a work in progress and with many painful bugs. But, as clearly stated by Apple's "Jordan K. Hubbard" at the "X11-users" list:

...X.org is the keeper and primary owner of these bits, not Apple.....Apple does not own or exert significant control over the X.org bits and I doubt that anyone would wish to change that fact....Apple bundles X11, Apple contributes what engineering resources it can to the X.org project, that's the long and short of it...

The good thing is that it's based on a much more modern codebase, and once the bugs are ironed out, I'm confident that X11 in Leopard will be great to use (porting will become easier, we will see a more "Mac-like" behaviour, a better window manager, and a more up-to-date code base).

Ben Byer (CoreOS / BSD Technology Group, XDarwin maintainer) is the main Apple developer working to resolve all the issues with X11 in Leopard. Originally, he started posting at the XDarwin Wiki non official binary and source releases of Xquartz with fixes to issues that have been discovered in X11.app since it was released. But recently, he moved the Wiki to the Xquartz Project and there you will find now the latest information and releases.

Thanks to his work and the involvement of the X11 community, X11 is already becoming usable again. With the latest release of the Xquartz binaries via open source, now you can use the X server to get some real work done. I want to thank Ben Byer and his group for solving so many different issues in X11 so quickly. A great effort!

Some time ago, Jeremy Huddleston, one of the major open source contributors to the Xquartz Project, was employed by Apple to continue the development of X11. Thanks to his work, there have been several updated X11 releases by the Xquartz Project.

Apple included some of the work done in the Xquartz Project in their 10.5.2 update and will likely include further changes in possible future updates of 10.5.x. It is suggested that you install the latest XQuartz release after updating to 10.5.2 (and any future 10.5.x or security updates).

10.5.2's version of X11 is somewhere between the 2.1.1 and 2.1.2 packages released through the Xquartz Project. The launchd mechanism to start X11 in 10.5.2 is unique to Apple's 10.5.2 and never appeared in a release from the Xquartz Project in its current form (though it was essentially integrated into xinit for 2.1.2).

The 2008-002 Security Update version of X11 is the same as 10.5.2 with some security fixes applied. Installing versions prior to X11 2.1.2 onto OS-X 10.5.2 may work but is not supported.

Updated Xquartz binaries


Updated Xquartz binaries are available now at the Xquartz project

Direct link to the Releases page at the project.

Your best bet for staying current with bugfixes is to install the latest X11 package which at the moment is X11 2.2.1 (contains Xquartz-1.3.0-apple20), and it includes fixes outside of just Xquartz. Afterwards, just install the latest binary versions of Xquartz released periodically as fixes are being made.

Note: Mac OS X 10.5.0 or later is required to install this package.

As of 2.2.0, you do not need to have Leopard's X11 package installed (but it is alright if you do).

Mac OS-X Updates: You will need to re-install this package after future OS and Security Updates delivered through Apple's Software Update.

Logout Notice: Because they have changed the way launchd starts the server, you will need to logout after installation.

To see the complete list of changes in release X11-2.2.1 relative to version 2.0 shipped with Leopard, please go here

The updates available on the Xquartz Project site are not official Apple releases. They are a convenient way for users to stay up to date with progress made in the open source community (in which Apple is participating). Official Apple releases will come from Apple (most likely through Apple Update).

If you'd like to help out with development, please join the xquartz-dev mailing list

Question:

What do I need to do to go from my box stock Leopard X11 installation to the lastest/greatest bump?

Answer:

Download and install the updated X11-2.2.1 package (this release contains Xquartz-1.3.0-apple20) from here . Because they have changed the way launchd starts the server, you will need to logout after installation.


For more information about X11 in Leopard:

Changes in the X11 2.2.1 package


To see the complete list of changes in release X11-2.2.1 relative to version 2.0 shipped with Leopard, please go here

Note: Mac OS X 10.5.0 or later is required to install this package.

As of 2.2.0, you do not need to have Leopard's X11 package installed (but it is alright if you do).

Mac OS-X Updates: You will need to re-install this package after future OS and Security Updates delivered through Apple's Software Update.

Logout Notice: Because they have changed the way launchd starts the server, you will need to logout after installation.

Working with launchd


Before Leopard you could control X11 with a series of customizations in your configuration files to make sure everything worked automatically. And now you're shocked because the first time you use a vanilla X11 in Leopard nothing seems to work.

Starting X11.app from the dock will get you two icons, setting it to auto-launch is also a no-no, and if you have set DISPLAY in any of your configuration files you get a disaster.

And, you also realize that they changed the location of the system xinitrc (to match other X.org distributions on other platforms), and they removed xterm from that file. The reason is because in Leopard, the X11.app in /Applications/Utilities is just a little wrapper around the command "/usr/bin/login -fp $USER /usr/X11/bin/xterm". So it's a "launcher" that launches xterm by default. And the starting of xterm then triggers the startup of the real server, which is now located at /usr/X11/X11.app.

Take a deep breath and relax... there's light at the end of the tunnel...

Biggest user-visible change in Leopard X11 is a new launch-on-demand support, courtesy of launchd. If you start a program that tries to open your X $DISPLAY, launchd will check to see if X11.app is running. If not, it will automatically start it for you. So on Leopard, just run a command like xterm or start an application that needs X11, and X11 will start up automatically. This means that now you can just run X apps like you would any other app. But this launch-on-demand functionality only works correctly if X11.app is launched on demand.

So don't run X11.app from the Dock. Or, at all, manually. Ensure that you are not explicitly setting $DISPLAY in any configuration files as it will throw away the location of the launchd socket that X clients need to know how to use, verify that 'echo $DISPLAY' in Terminal.app reports something that starts with '/tmp/launchd', and then just run 'xterm &' from Terminal. This will work with any X11 client application that links with the standard libX11.dylib.

In a few words, you no longer start /Applications/Utilities/X11.app at login or launch the X11.app. You make sure the DISPLAY environment variable is NOT set, and then you simply issue the command, or click on the icon, or whatever, and the rest happens automatically.

Working without launchd


If you don't like launchd you can do the following:

  • Run /usr/X11/X11.app instead of /Applications/Utilities/X11.app. That will give you a simple, normal X server. You might even move the former to the latter.

The next two steps are optional:

  • Add an xterm back to /usr/X11/lib/X11/xinit/xinitrc or add it to ~/.xinitrc
    That will give you an xterm when you open /usr/X11/X11.app.

  • To prevent launchd from setting $DISPLAY run:
sudo launchctl unload -w /System/Library/LaunchAgents/org.x.X11.plist

To bring back Tiger's X11


So you decided to wait to install X11 in Leopard until most bugs are fixed and Apple releases an official update. Meantime, you could work with Tiger's X11 in Leopard.

Please read, Aaron Iba's:

Bring Back Tiger's X11 to Leopard in 3 Steps

or Ben Byer's :

Easier instructions to install Tiger's X11.app

You can download Tiger's X11 Update 2006 from here

ssh tunnelling


Assuming you have not set DISPLAY anywhere, you should be able to connect using SSH tunnelling without any special steps:

1.Open Terminal.app
2.run "echo $DISPLAY" -- verify the result is of the form "/tmp/ launchd-xxxxx/:0"
3.run "ssh -Y user@host"
4.after you log in, X11.app should start on your Mac
5.run "echo $DISPLAY"(on the remote host)-verify result is of the form localhost:10
6.run xterm & (on the remote host)-xterm should appear on your Mac

"ssh -Y" works well between Macs running Leopard or Tiger either way, or from a Mac/Leopard to Linux. No difference to Tiger, except that you don't need to set DISPLAY (your DISPLAY will automatically be set on the remote host) or start X11.app.

Note that some people have seen problems with step 4, where X11.app can hang while launching.

ssh X forwarding debugging


Try these SSH troubleshooting steps. This list shows the expected behavior of the system.

local $ -----> refers to commands run on my local Mac running Leopard.
remote $ --> refers to commands run on a remote Unix machine, of any type.

Step 1 - Run:

local $ echo $DISPLAY /tmp/launch-Bh0fLm/:0

If step 1 returns ':0', 'localhost:0' or anything similar, you have a configuration file that is overriding the system's DISPLAY variable.


Step 2 - Run:

local $ grep DISPLAY ~/.*rc ~/.login ~/.*profile ~/.MacOSX/ environment.plist 2>/dev/null

If step 2 outputs anything, it indicates that a configuration file in your home directory may be the culprit; try creating a new user and repeating the steps with that user.


Step 3 - Run:

local $ grep -r DISPLAY /opt/local/etc /sw/etc /etc 2>/dev/null

If step 3 outputs anything, it indicates that a system-wide change was made that is overriding your environment. If it begins with /opt/ local, it is MacPorts; if it begins with /sw, it is Fink. Otherwise, it is probably a commercial program that uses X11; contact your vendor for an updated version.


Step 4 - Run:

local $ ssh -Y remote Warning: No xauth data; using fake authentication data for X11 forwarding.

The warning message in step 4 is harmless.


Step 5 - Run:

remote $ echo $DISPLAY localhost:10.0

If step 5 does not output anything, then step 6 will say "X11Forwarding no". In this case, you must fix the configuration on the remote side.


Step 6 - Run:

remote $ grep X11 /etc/ssh/sshd_config ~/.ssh/* X11Forwarding yes X11DisplayOffset 10

If step 6 outputs anything other than "localhost:xx.0", then your remote configuration is overriding the DISPLAY variable set by sshd on the remote side.


Tips and workarounds


  • You found a bug in X11
    Send your bug reports to Apple


  • A brief history of Apple's X11.app by Ben Byer.


  • 8-bit color mode doesn't work.
    Workaround: use Xephyr


  • Fullscreen mode doesn't work.
    Workaround: use Xephyr


  • To fake fullscreen support with Xephyr:
$ Xephyr -ac -fullscreen :9 & $ DISPLAY=:9 twm& $ DISPLAY=:9 xterm &

Hit F8, drag to a different Space to get a fullscreen X server on one of your Spaces.


  • XDMCP now works in the new released X11-2.1.1.pkg
    (it also includes Xephyr, Xfake, Xvfb, and Xnest.


  • To open an xterm without starting X11.app first:
    a. Open a Terminal.app window and type "xterm" at the command prompt or
    b. Open /usr/X11/bin in the Finder and double-click on the xterm icon.


  • To run another window manager:
    Replace the call to quartz-wm in /usr/X11/lib/X11/xinit/xinitrc to change this for all users, or set up a custom ~/.xinitrc.


  • Fink initial support for 10.5:
    To update Fink to 10.5 just follow the instructions at their Homepage.

    Fink Note:
    Fink users who want to update their Leopard X11 installation can download and install the latest "X11-2.1.1 package" released by the Xquartz Project. Those users who previously have applied the X11-2.1.0.1.pkg and/or the patched "Xquartz-1.3.0-apple-fink" file from the Xquartz Project, should upgrade to the "X11-2.1.1 package or greater" for Fink to work properly. This release supercedes all previous releases, including the fink-specific Xquartz.


  • man pages missing
    no manual entry for man X
$ man X No manual entry for X

The X11-2.1.1.pkg includes man pages for Xquartz and other Xservers.


  • X11.app remains running after all sub-processes are terminated. X11.app is started by launchd. After X11.app starts it remains running even after all the triggers that launched it are closed. Some users may prefer X11.app to remain running so it is immediately available for re-use, some may prefer it to close to conserve system resources.


  • For more information on launchd:
    See the following man pages: launchd(8), launchctl(1) and launchd.plist(5)
    Example of launchctl list:
[sao @ Heaven: ~] % launchctl list org.x.X11 { "Label" = "org.x.X11"; "LimitLoadToSessionType" = "Aqua"; "OnDemand" = true; "LastExitStatus" = 0; "PID" = 262; "TimeOut" = 30; "Program" = "/usr/X11/X11.app/Contents/MacOS/X11"; "Sockets" = { ":0" = ( file-descriptor-object; ); }; };

It will will spit out a plist data structure that describes that LaunchAgent and if it is currently running for the current user, it will list the pid of the process along with the other attributes of the launchd plist.


  • Setting the DPI
    A quick fix to make it always use 75 dpi fonts:
cd /usr/X11/lib/X11/fonts sudo mv 100dpi{,.hide} sudo ln -s 75dpi 100 dpi

Do the reverse to always use 100 dpi fonts. Somewhere they mention to edit xorg.conf -- AFAIK, if you place an xorg.conf in /usr/X11/lib/X11 (instead of /etc/X11), Xquartz will read it, but I haven't heard of anyone who tested this yet.


  • Console Logs
    It appears that Leopard no longer keeps track of console messages in an independent text file. The Console application is actually doing a database query in order to come up with the "Console Messages" contents. But, have a look at the command "syslog" . When invoked with the -C option, syslog fetches and prints console messages. Read "man syslog" for more information.


  • Patch for the gsi enabled version of ssh
    You can find it here . It applies cleanly to both gsi-openssh-4.1 and gsi-openssh-4.0 included with globus-4.0.5.

Installing Gimp in Leopard


From Wilber loves Apple

  • The Gimp for MacOS 10.5 Leopard (Intel)
  • current version 2.4.5 - Screenshot
  • Build by Christoph Schröder
  • It requires:
  • Intel CPU
  • MacOS 10.5
  • Download Gimp for MacOS 10.5 Leopard (Intel) from here
  • Download the X11 Package (2.2.1) from Xquartz Project Releases
  • Note: Mac OS X 10.5.0 is required to install the X11 2.2.1 package

Open it to install with Leopard's Installer. As of 2.2.0, you do not need to have Leopard's X11 package installed (but it is alright if you do). This release contains Xquartz-1.3.0-apple20.

  • The Gimp for MacOS 10.5 Leopard (PowerPC)
  • current version 2.4.5_1
  • Package by Chachi
  • It requires:
  • G4 or G5 CPU
  • MacOS 10.5
  • Updated Xquartz from the Xquartz project

  • Download Gimp for MacOS 10.5 Leopard (PowerPC) from here
  • Download the X11 Package (2.2.1) from Xquartz Project Releases
  • Note: Mac OS X 10.5.0 is required to install the X11 2.2.1 package

Open it to install with Leopard's Installer. As of 2.2.0, you do not need to have Leopard's X11 package installed (but it is alright if you do). This release contains Xquartz-1.3.0-apple20.

You can also install Gimp version 2.4.2 with MacPorts or version 2.0.6 with Fink

Gimp Tip - To make Gimp recognise a slower double click,
add the following line at the end of the:
/Applications/Gimp.app/Contents/Resources/share/gimp/2.0/themes/Default/gtkrc

gtk-double-click-time = 500

You can do that for all themes.


To make a droplet using Automator


For making an Nedit.app that allows dropping files on its icons, open Automator, choose "Utilities" and drag "Run Shell Script" to the workflow area. In the text area, you basically just need to write "nedit $*". In my case, since I have nedit installed via Fink, I wrote 2 lines:

source /sw/bin/init.sh nedit $*

In the drop-down menus, chose:

Shell: /bin/bash and Pass input: as arguments.

Save as Application.

OpenOffice and Quick-Look


In Leopard you can double-click an OpenOffice word processing document and it will open up in TextEdit, fully formatted. Even if OpenOffice is not installed you can Quick-Look an OpenOffice word processing document (with the .odt format).

If you define the following shell function:

ql(){ qlmanage -p $1 2>/dev/null }

You can use the qlmanage command to see the Quick-Look preview of a file from the command line. You can invoke it as ql FILENAME when needed. Use C-c to exit.


Quick Look Plugins

Plugin to view the contents of .tar.gz Archive Files.
Plugin to view the contents of .zip Archive Files.
Plugin to view the contents of a folder.
Plugin to see XML files with indentation and syntax coloring.
Plugin to preview a chm(compiled html) archive.
Plugin to view source code with syntax highlighting.
Plugin to render previews (certain filetypes) using the TextMate syntax highlighter.
Plugin to view scr files.
Plugin for medical images in the MINC1, MINC2, DICOM and NIfTI file formats.
Plugin to display previews and thumbnails for eps files.
Plugin that produces colorized output for the following languages:

  • Objective-C/C++
  • C/C++
  • Perl
  • Python
  • Java
  • Shell scripts
  • Assembly language

Screenshots

Leopard has new support for "flat packages"


These new one-file pkgs are xar archives. The Leopard system DVD uses them, too.

To list their contents:

xar -tf X11-2.1.0.pkg

To extract into the current directory:

xar -xf X11-2.1.0.pkg

After this, you have a structure like inside a traditional *.pkg bundle. The files "Payload" and "Scripts" are gzipped pax archives, like the traditional "Archive.pax.gz".

Useful Commands


To check if you have the launchd plist required to launch X11 in Leopard:

launchctl list | grep org.x

To load the .plist file:

sudo launchctl load -w /System/Library/LaunchAgents/org.x.X11.plist

The receipts are now in /Library/Receipts/boms/, and there is a command "pkgutil" to manage them, including removing the receipt or even the installed files. The pkg's themselves are no longer directories, but /usr/bin/xar archives:

pkgutil --verify com.apple.pkg.update.os.10.5.1

Is X running and you don't see it? Check it by running:

ps aux | grep X

To get seven lines worth of Console messages:

syslog -C | tail -n 7

To supress xterm running by default. Note: starting with the X11-2.1.1 package "org.x.X11_launcher" is now "org.x.X11"

If you want to launch the X server by hand and don't want any application to start, then set app_to_run to /usr/bin/true.

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

Versions and more versions...

pkg-config xorg-server --modversion X -version Xquartz -version

Let's talk X11 fonts commands...

fc-cache -v fc-list fc-cat fc-match mkfontdir mkfontscale xlsfonts xlsfonts | wc -l xfontsel xset q xset fp strings /usr/X11/lib/libfontconfig.dylib | grep -C 1 FONTCONFIG_PATH cat /usr/X11/lib/X11/fonts/OTF/fonts.dir

XDMCP - Xnest - Xephyr...

Xquartz -query Xnest -query 10.0.10.1 -geometry 1024x768 :1 Xephyr -ac -fullscreen :9 & Xephyr -fullscreen -query -once (mylinuxserverIP) :9 Xephyr -screen 1024x768 -query -once (mylinuxserverIP) :9

Generate a text file "installed-pkgs" with a list of your Fink installed packages:

fink list -i | grep -v " p " | cut -f 2 > installed-pkgs

Messed up your X11 installation?


Messed it up, got confused, want to start over?

Before you start deleting anything, make sure you have a Leopard's installation DVD available and downloaded the latest X11 package from the Xquartz Project.

  • Delete pretty much all X11 from you system, and let it forget its receipts:
sudo rm -rf /usr/X11 /usr/X11R6 sudo pkgutil --forget com.apple.pkg.X11DocumentationLeo sudo pkgutil --forget com.apple.pkg.X11User sudo pkgutil --forget com.apple.pkg.X11SDKLeo sudo pkgutil --forget org.x.X11.pkg
  • Install X11User.pkg from Leopard's installation DVD, which is in
    /Volumes/Mac OS X Install DVD/Optional Install/Optional Installs.mpkg

  • Install X11SDK.pkg from Leopard's installation DVD, which is in
    /Volumes/Mac OS X Install DVD/Optional Installs/Xcode Tools/Packages/

  • Install the latest X11 package release.