<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook V4.2//EN" [
<!ENTITY % defs SYSTEM "X11/defs.ent"> %defs;
]>

<article>

<articleinfo>

<title>X.Org X on Darwin and Mac OS X</title>
<author><firstname>Torrey</firstname><surname>T. Lyons</surname></author>
<pubdate>15 December 2003</pubdate>

</articleinfo>

<sect1>
<title>Introduction</title>

<para>
<ulink
url="http://www.freedesktop.org/Software/xorg">Xorg</ulink>, a freely
redistributable open-source implementation of the 
<ulink url="http://www.x.org/">X Window System</ulink>, 
has been ported to <ulink url="http://www.opensource.apple.com/projects/darwin/"
>Darwin</ulink>
and <ulink
url="http://www.apple.com/macosx/">Mac OS X</ulink>. This
document is a collection of information for anyone
running Xorg's X server on Apple's next generation operating system.
</para>

<para>
Most of the current work on X for Darwin and Mac OS&nbsp;X is centered
around the <ulink
url="http://sourceforge.net/projects/xonx/"
>XonX project</ulink
> at <ulink
url="http://sourceforge.net"
>SourceForge</ULink
>. If you are interested in up-to-date status, want to
report a bug, or are interested in working on Xorg for Darwin, stop by the
<ulink
url="http://sourceforge.net/projects/xonx/"
>XonX project</ULink
>.
</para>

</sect1>

<sect1>
<title>Hardware Support and Configuration</title>

<Para>
The X window server for Darwin and Mac OS&nbsp;X provided by the <ulink
url="http://www.X.Org/">X.Org Foundation.</ulink> is called
XDarwin. XDarwin can run in three different modes. On Mac OS&nbsp;X,
XDarwin runs in parallel with Aqua in full screen or rootless modes.
These modes are called Quartz modes, named after the Quartz 2D compositing
engine used by Aqua. XDarwin can also be run from the Darwin console in
IOKit mode.
</para>

<para>
In full screen Quartz mode, when the X Window System is active, it takes
over the entire screen. You can switch back to the Mac OS&nbsp;X desktop
by holding down Command-Option-A. This key combination can be changed in
the user preferences. From the Mac OS&nbsp;X desktop, click on the XDarwin
icon in the Dock to switch back to the X window system. (You can change
this behavior in the user preferences so that you must click the XDarwin
icon in the floating switch window instead.)
</para>

<para>
In rootless mode, the X window system and Aqua share your display.
The root window of the X11 display is the size of the screen and contains
all the other windows. The X11 root window is not displayed in rootless
mode as Aqua handles the desktop background.
</para>

<para>
From the console, the Darwin port of X11R&relvers; uses the IOKit for device
driver loading and discovery, rather than the X11R&relvers; module loader.
Because of this, the X11R&relvers; configuration file is not used on Darwin
or Mac OS&nbsp;X systems. The descriptions found elsewhere of devices
supported by X11R&relvers; for other operating systems also do not apply.
</para>

<para>
X11R&relvers; for Darwin or Mac OS&nbsp;X will work with any video card that
you have an IOKit driver for. If you are running Mac OS&nbsp;X, this
typically means any card that has been shipped by Apple. If a card works
for you with the Mac OS&nbsp;X GUI, it will work on the same machine with
X11R&relvers;. If you have a pure Darwin installation, you may need to download
additional third-party drivers from
<ulink
url="http://developer.apple.com/darwin/"
>Apple's Darwin site</ULink
>. IOKit drivers are typically installed in
<literal remap="tt">/System/Library/Extensions/</literal> or <literal remap="tt">/Library/Extensions/</literal>.
</para>

<para>
Multi-button and scroll wheel mouse support works well with all
USB mice that I have tested. I have done no testing with ADB
mice, but without a special driver, only a single mouse button
will work on an ADB mouse.
</para>

</sect1>

<sect1>
<title>Getting Started</title>

<para>
Following are instructions for building and running your own copy of
X11R&relvers;. The procedure for getting your X server up and running on
Darwin and Mac OS&nbsp;X are very similar. Where there are differences
I have noted them below. Note that to build X11R&relvers; for yourself on
Mac OS&nbsp;X, you need to install the Developers' Tools.
</para>

<para>
<literal remap="tt">/Applications</literal>.
</para>

<para>
If you get the precompiled binaries you can skip ahead to the section
on <xref linkend="running"> On the other hand,
if you want to build things yourself from scratch, follow the directions
below.
</para>

<sect2>
<title>Get the Code </title>

<para>
The first thing you need to do is to get the source code from the
X.Org Foundation project.
</para>

<para>

<itemizedlist>
<listitem>

<para>
 Setup CVS: Both Darwin and Mac OS&nbsp;X include CVS (Concurrent
Versions System), which is an easy way to download and keep up to date
with open source code released by the X.Org Foundation and others. You do have to
setup CVS properly, however, to tell it where to look. Follow the
<ulink
url="http://x.org/">X.Org CVS instructions</ulink> on
how to do this either via ssh or via the cvs pserver.

</para>
</listItem>
<listItem>

<para>
 Now make a directory in some convenient place which will serve
as your top level directory for you open source development efforts. I
am going to call this directory <literal remap="tt">sandbox/</literal> in the following discussions
and you could put this directory, for example, in <literal remap="tt">&tilde;/sandbox/</literal>.

</para>
</listitem>
<listitem>

<para>
From the command line type:

<screen>
cd sandbox
cvs checkout xc
</screen>

Wait for all the files to complete downloading. 

</para>
</listitem>

</itemizedlist>

</para>

</sect2>

<sect2>
<title>Build X11R&relvers;</title>

<para>
Once you have everything ready it is easy to build and install
X11R&relvers;. From the command line: 
</para>

<para>

<screen>
cd sandbox/xc
make World &#62;&#38; world.log

(wait for several hours)

sudo make install &#62;&#38; install.log
sudo make install.man &#62;&#38; man.log
</screen>

</para>

</sect2>

</sect1>

<sect1 id="running" xreflabel="running the X window System">
<title>Run the X Window System</title>

<sect2>
<title>Setting Your Path</title>

<para>
You need to add the X Window System executables to your path. Your path
is the list of directories to be searched for executable commands. 
The X11 commands are located in <literal remap="tt">/usr/X11R6/bin</literal>, which needs to be
added to your path. In Quartz mode, the XDarwin application does this for
you automatically. It can also be configured to add additional directories
where you have installed command line applications. When running from the
Darwin console, you will need to set the path correctly for your shell as
XDarwin will not do this for you.
</para>

<para>
More experienced users will have already set their path correctly using the
initialization files for their shell. In this case, you can inform XDarwin
not to modify your path in the preferences. XDarwin launches the initial
X11 clients in the user's default login shell. (An alternate shell can also
be specified in the preferences.) The way to set the path depends on the
shell you are using. This is described in the man page documentation for
the shell.
</para>

<para>
In addition you may also want to add the man pages from X11R&relvers; to the list
of pages to be searched when you are looking for documentation. The X11 man
pages are located in <literal remap="tt">/usr/X11R6/man</literal> and the <literal remap="tt">MANPATH</literal>
environment variable contains the list of directories to search.
</para>

</sect2>

<sect2>
<title>Starting the X Server</title>

<para>
On Mac OS&nbsp;X, you can run X11R&relvers; from the Darwin
text console or in parallel with Aqua. To get to the text
console in Mac OS&nbsp;X you need to logout and type ``&gt;console'' as
the user name. This will shutdown Core Graphics and
bring up the console login prompt. Login again as your user.
From the text console you can start the X Window System by typing
``exec startx''.
</para>

<para>
When you are ready to quit X11R&relvers; type ``exit'' in the main
terminal window or quit with the window manager if you have one
running. Unfortunately in IOKit mode, the X server does not shutdown
correctly and if you did not start with ``exec startx'', you 
will get an apparently frozen screen with only a spinning beachball
cursor on it. Nothing you type shows up on the screen, but in fact
your keystrokes are being received by the console. Type
``logout'' to return to normalcy after a brief delay. With
Darwin, this should put you back at the text console login prompt. With
Mac OS&nbsp;X, Core Graphics will restart and you should be given a login
window.
</para>

<para>
To start X11R&relvers; in Quartz mode you can launch the XDarwin application
in the <literal remap="tt">/Applications</literal> folder, or from the command line type
``startx -- -quartz''. By default this will give you a mode picker to
choose between full screen or rootless mode. You can change the default
to always use a particular mode in the preferences, or you can specify
the ``-fullscreen'' or ``-rootless'' options on the command line instead
of ``-quartz''.
</para>

</sect2>

<sect2>
<title>Double-clickable X11 Executables</title>

<para>
Mac OS&nbsp;X 10.3 can be configured to automatically launch XDarwin when
you double-click an X11 executable in the Finder. When an executable file
is double-clicked Launch Services checks to see if it is linked against
the X11 libraries. If it is, Launch Services opens the default X server.
To set the default X server, do the following:
</para>

<para>

<itemizedlist>
<listitem><para>Create a simple file which ends in ''.x11app''.</para>
</listitem>

<listitem><para>Open the file with Get Info in the Finder.</para>
</listItem>

<listItem><Para>Under ''Open with:'' select the XDarwin application.</Para>
</ListItem>

<ListItem><Para>Select ''Change All...'' to set XDarwin as the default.</Para>
</ListItem>

</ItemizedList>

</Para>

<Para>
On Mac OS&nbsp;X 10.3 the default X server is started when an X11
executable is double-clicked, whether or not its extension is
''.x11app''. On previous versions of Mac OS&nbsp;X, an X11 executable must
have a ''.x11app'' extension for this to work.
</Para>

</Sect2>

<Sect2>
<Title>Customize the X Window System</Title>

<Para>
The X Window System is very customizable and you will certainly want to
change some things. There is a lot you can do to control how your windows
look, how the windows are moved, resized, etc. You will likely want to
get a fancier window manager than twm, which is included with
X11R&relvers;. The <Literal remap="tt">.xinitrc</Literal> file in your home directory controls what
programs are run when you start the X Window System. You can find a sample
<Literal remap="tt">.xinitrc</Literal> file in <Literal remap="tt">/etc/X11/xinit/xinitrc</Literal>.  
</Para>

<Para>
There are many window managers that have been ported to Darwin. The
following pages contain collections of window managers and other X
window system clients:
</Para>

<Para>

<ItemizedList>
<ListItem>

<Para>
 <ULink
URL="http://darwinports.opendarwin.org/"
>DarwinPorts</ULink
>: An easy way to install various open-source software
products on Darwin and Mac OS&nbsp;X.

</Para>
</ListItem>
<ListItem>

<Para>
 <ULink
URL="http://fink.sourceforge.net/"
>Fink</ULink
>: A
package manager that will easily download, compile, and install lots
of open source software from the Internet.

</Para>
</ListItem>
<ListItem>

<Para>
 <ULink
URL="http://gnu-darwin.sourceforge.net/"
>GNU-Darwin</ULink
>:
A source for tons of software ported to Darwin.

</Para>
</ListItem>

</ItemizedList>

</Para>

<Para>
Good luck!
</Para>

</Sect2>

</Sect1>

</Article>
