See also http://live.gnome.org/SessionManagement/NewGnomeSession

Startup
-------

main() creates the GsmSession object representing the session (either
failsafe or normal). gsm_session_new() reads the appropriate autostart
and session files to create a list of GsmApps to be started.
(GsmAppAutostart represents an autostarted app, and GsmAppResumed
represents an app resumed from the previous saved session.)

Startup is divided into 7 phases (GsmManagerPhase):

    * GSM_MANAGER_PHASE_STARTUP covers gnome-session's internal
      startup, which also includes starting gconfd and dbus-daemon (if
      it's not already running). Gnome-session starts up those
      explicitly because it needs them for its own purposes.

    * GSM_MANAGER_PHASE_EARLY_INITIALIZATION is the first phase of
      "normal" startup (ie, startup controlled by .desktop files
      rather than hardcoding). It covers the possible installation of
      files in $HOME by gnome-initial-setup and must be done before
      other components such as gnome-keyring use those files.

    * GSM_MANAGER_PHASE_INITIALIZATION covers low-level stuff like
      gnome-settings-daemon and at-spi-registryd, that need to be
      running very early (before any windows are displayed).

      Apps in this phase can make use of a D-Bus interface
      (org.gnome.SessionManager.Setenv) to set environment variables
      in gnome-session's environment. This can be used for things like
      $GTK_MODULES, $GNOME_KEYRING_SOCKET, etc

    * GSM_MANAGER_PHASE_WINDOW_MANAGER includes window managers and
      compositing managers, and anything else that has to be running
      before any windows are mapped

    * GSM_MANAGER_PHASE_PANEL includes anything that permanently takes
      up screen real estate (via EWMH struts). This is the first phase
      where things actually appear on the screen.

    * GSM_MANAGER_PHASE_DESKTOP includes anything that draws directly
      on the desktop (eg, nautilus).

    * GSM_MANAGER_PHASE_APPLICATION is everything else (normal apps,
      tray icons, etc)

For each startup phase, GsmSession launches the appropriate GsmApps.
When apps connect to the XSMP or D-Bus servers, GsmClients are created
and added to the session. The session tries to map these clients to
GsmApps. GsmApps signal when they register (via XSMP or SN) or exit,
and GsmSession uses this to decide when the phase is complete.

FIXME: after starting the session, we need to run the DiscardCommands
of resumed apps.


Running/Shutdown
----------------

GSM_MANAGER_PHASE_RUNNING is pretty similar to the old gnome-session;
mostly it just tracks XSMP clients, and watches for
SmRestartImmediately clients exiting (NOTE: THIS DOESN'T HAPPEN YET).

GsmClient is in theory not XSMP-specific, but it's very very
XSMP-like, and the shutdown procedure is also very XSMP-like. This is
just because there's no way to do XSMP shutdown correctly otherwise.
However, GsmClientDBus will still be able to present a more sane
protocol to its clients than GsmClient presents to it.
