Fink

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:

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:

Next: 5. Other X11 Possibilities