Running X11 - 4. Starting X11
4.1 Starting the Display Server
There are basically three ways to start X11 under Mac OS X.
One is by running the application bundle, e.g. via double-clicking the app in the Finder.
This is typically /Applications/Utilities/X11(.app)
, if you are on
10.5-10.7, or /Applications/Utilities/XQuartz(.app)
if you're using
Xquartz (e.g. on 10.8).
Another way is via entering
the startx
command from a terminal window.
The third method is to attempt to run a program that needs X11 from a terminal window. on 10.5 and later this will automatically start an X11 server.
4.2 Customizing startup using the .xinitrc.d directory
The preferred method in current versions of X11 to customize your startup is to create a
directory named .xinitrc.d
at the top of your home directory, and to
fill that with executable scripts to run programs that you want to use at startup, including window
managers
Important: make sure to put an '&'; after the names of programs that
aren't window managers, or they will block other programs, including a window manager,
from being run. Also make sure that window managers do not have an
'&' after their names or they won't remain running, unless there is a session manager.
that is set to run after them. The xinit
program interprets such a condition that as "the session has ended, I should kill the X server
now, too".
Example: to run the WindowMaker
window manager on startup, start
with the following commands:
mkdir -p $HOME/.xinitrc.d nano $HOME/.xinitrc.d/94-wmaker.sh
(or use your favorite editor). Then put the following contents in
94-wmaker.sh
:
. /opt/sw/bin/init.sh quartz-wm --only-proxy & exec wmaker
Save the file, then use
chmod a+x 94-wmaker.sh
to make the script executable (quartz-wm --only-proxy
will be discussed in a
later section).
Example: to run the xlogo
program on startup, start
with the following commands:
mkdir -p $HOME/.xinitrc.d nano $HOME/.xinitrc.d/74-xlogo.sh
(again, feel free to use your favorite editor). Then put the following contents in
74-xlogo.sh
:
. /opt/sw/bin/init.sh xlogo &
Save the file, then use
chmod a+x 74-xlogo.sh
to make the script executable.
If you were to create both scripts above, the result would be that X11 would start up, run
xlogo
, and then the wmaker
window manager.
Example: full GNOME session. Create an executable 94-gnome-session.sh
with the following contents:
. /opt/sw/bin/init.sh quartz-wm --only-proxy & metacity & exec gnome-session
Example: rootless GNOME session. Create an executable 94-gnome-panel.sh
with the following contents:
. /opt/sw/bin/init.sh quartz-wm --only-proxy & metacity & exec gnome-panel
Example: KDE3. Create an executable 94-startkde.sh
with the following
contents:
. /opt/sw/bin/init.sh exec startkde
(startkde automatically starts a window manager and uses quartz-wm --only-proxy
)
Example: KDE4. Create an executable 94-startkde.sh
with the following
contents:
. /opt/sw/bin/init.sh exec /opt/sw/opt/kde4/x11/bin/startkde
Notes:
-
Starting each script with
. /opt/sw/bin/init.sh
ensures that programs which require other items from the Fink tree can find them. - The scripts are processed in ASCII order, so use prefixes to change that, as per the '74' and '94' above.
-
The scripts must be executable and have a
.sh
extension. Changing the execute permissions provides a method to alter which programs are run without deleting the scripts. -
Fink's
xinitrc
package, which is in the dependency chain for GNOME and KDE, overrides some of the default X11 lookup behavior, including that for user customization. We recommend that you restore it as discussed in the Fink 'xinitrc' package section.
4.3 The .xinitrc File
Note: the use of scripts in $HOME/.xinitrc.d is preferred.
If a file named .xinitrc
exists in your home
directory, it will be used to start some initial X clients, e.g. the
window manager and some xterms or a desktop environment like GNOME.
The .xinitrc
file is a /bin/sh
script that contains the commands to do this.
It is not necessary to put the usual #!/bin/sh
in the first line or to set the executable bit on the file;
xinit
will always run it through the /bin/sh
shell.
When there is no .xinitrc
file in your home
directory, and if $HOME/.xinitrc.d is not present, then
X11 will use its default file,
/usr/X11/lib/X11/xinit/xinitrc
.
You can use the default file as a starting point for your own
.xinitrc:
cp /usr/X11/lib/X11/xinit/xinitrc ~/.xinitrc
To ensure reliable operation of Fink programs in .xinitrc
, you should
put . /opt/sw/bin/init.sh
right at the beginning of the file to make sure the
environment is set up correctly.
You can put fairly arbitrary commands in an .xinitrc
,
but there are some caveats.
First, the shell that interprets the file will by default wait for
every program to finish before it starts the next one.
If you want several programs to run in parallel, you must tell the
shell to put them "in the background" by adding a &
at
the end of the line.
Second, xinit
waits for the .xinitrc
script to finish and interprets that as "the session has ended, I should
kill the X server now, too".
This means that the last command of your .xinitrc
must not be run in the background and it should be a long-living program.
Customarily, the window manager or session manager is used for this purpose.
In fact, most window managers or session managers assume that xinit
is
waiting for them to finish and use this to make the "Log out" entry in
their menus work.
(Note: To save some memory and CPU cycles, you can put an
exec
before the last line like in the examples below.)
Example: turn the X11 bell off, starts some clients and finally execute the Enlightenment window manager:
. /opt/sw/bin/init.sh xset b off xclock -geometry -0+0 & xterm & xterm & exec enlightenment
Example: start GNOME:
. /opt/sw/bin/init.sh quartz-wm --only-proxy & metacity & exec gnome-session
Finally, to start KDE3:
. /opt/sw/bin/init.sh exec startkde
4.4 The 'xinitrc' package
Certain Fink packages need to be able to perform actions upon X11 startup. To allow them to
do this, there is a package called xinitrc
(somewhat confusing, admittedly).
One side effect of installing this package, which is in the dependency chains of GNOME and KDE,
is to circumvent the default behavior of using scripts from
$HOME/.xinitrc.d
. There are currently a couple of methods available to
allow user customization of the X11 startup and allow Fink packages to do their
startup tasks:
-
The
xinitrc
package provides adminstrator entry points. Create the file/opt/sw/etc/xinitrc-last-hook
as a superuser, and give it the following contents:#!/bin/sh . /usr/X11/lib/X11/xinit/xinitrc.d/98-user.sh
This will restore the default behavior of looking in
$HOME/.xinitrc.d
for executable scripts. -
Create a
$HOME/.xinitrc
as per the .xinitrc section above. Fink'sxinitrc
package overwrites the system's default version with its own, and so you will be using Fink's version.The appropriate place to add additional programs that you want to run is immediately above the line that says
# start the window manager