ExoXsessionClient

## ExoXsessionClient ExoXsessionClient — Lightweight session management support |

## Synopsis

    #include <exo/exo.h>

                        ExoXsessionClient;
    ExoXsessionClient * exo_xsession_client_new_with_group  (GdkWindow *leader);
    GdkWindow *         exo_xsession_client_get_group       (ExoXsessionClient *client);
    void                exo_xsession_client_set_group       (ExoXsessionClient *client,
                                                             GdkWindow *leader);
    gboolean            exo_xsession_client_get_restart_command
                                                            (ExoXsessionClient *client,
                                                             gchar ***argv,
                                                             gint *argc);
    void                exo_xsession_client_set_restart_command
                                                            (ExoXsessionClient *client,
                                                             gchar **argv,
                                                             gint argc);

## Object Hierarchy

      GObject
       +----ExoXsessionClient

## Properties

      "group"                    GdkWindow*            : Read / Write
      "restart-command"          GStrv                 : Read / Write

## Signals

      "save-yourself"                                  : Run First

## Description

This module provides application developers with lightweight session management functions, based on the X11R5 session management protocol. The X11R5 session management protocol is very limited in its functionality and flexibility compared to the newer X11R6 session management protocol (XSMP), but - on the other hand - offers several advantages for applications that do not need the complicated features of the XSMP. Most importantly, the setup is much easier and faster than with XSMP, because no special actions must be taken.

So, in case your application is simple in its session management requirements, e.g. it only needs to tell the session manager its restart command, you may want to use the ExoXsessionClient instead of a full featured XSMP client.

Lets say, for example, you are developing a text editor, which should provide basic session management support, limited to proper restarting all editor windows that where left open when you logged off the X session. In case the user was editing a file when logging off, the same file should be opened in the window on next startup.

Example 4. Texteditor with ExoXsessionClient

    static gchar *open_file_name = NULL;

    static void
    save_yourself (ExoXsessionClient *client)
    {
      gchar *argv[2];

      if (open_file_name != NULL)
        {
          argv[0] = "myeditor";
          argv[1] = open_file_name;

          exo_xsession_client_set_restart_command (client, argv, 2);
        }
      else
        {
          argv[0] = "myeditor";

          exo_xsession_client_set_restart_command (client, argv, 1);
        }
    }

    // ...

    int
    main (int argc, char **argv)
    {
      ExoXsessionClient *client;
      GdkDisplay        *display;
      GdkWindow         *leader;
      GtkWidget         *window;

      gtk_init (&argc, &argv);

      if (argc > 1)
        open_file_name = argv[1];

      // create the main window
      window = create_window ();

      // setup the session client
      display = gtk_widget_get_display (window);
      leader = gdk_display_get_default_group (display);
      client = exo_xsession_client_new_with_group (leader);
      g_signal_connect (G_OBJECT (client), "save-yourself",
                        G_CALLBACK (save_yourself), NULL);

      // ...
    }

This example demonstrates the basic handling of ExoXsessionClient. It is oversimplified, but we hope you get the point. The rule of thumb is, use ExoXsessionClient if you can store all session data in the restart command, else use a full-featured XSMP client.

## Details

### ExoXsessionClient

    typedef struct _ExoXsessionClient ExoXsessionClient;

The ExoXsessionClient struct contains only private fields and should not be directly accessed.

### exo_xsession_client_new_with_group ()

    ExoXsessionClient * exo_xsession_client_new_with_group  (GdkWindow *leader);

Creates a new ExoXsessionClient and associates it with the group, which is lead by `leader`.

`leader` : | The client leader window of the group.
Returns : | A newly allocated ExoXsessionClient.

### exo_xsession_client_get_group ()

    GdkWindow *         exo_xsession_client_get_group       (ExoXsessionClient *client);

Returns the client leader window of the group with which the `client` is associated or `NULL` if `client` is not associated with any group.

`client` : | An ExoXsessionClient.
Returns : | The client leader window of the group with which `client` is associated or `NULL`.

### exo_xsession_client_set_group ()

    void                exo_xsession_client_set_group       (ExoXsessionClient *client,
                                                             GdkWindow *leader);

Sets the group according to the specified `leader`.

`client` : | An ExoXsessionClient.
`leader` : | The client leader window of a group or `NULL`.

### exo_xsession_client_get_restart_command ()

    gboolean            exo_xsession_client_get_restart_command
                                                            (ExoXsessionClient *client,
                                                             gchar ***argv,
                                                             gint *argc);

Retrieves the restart command previously set on `client`. The result is stored in `argv` and should be freed using `g_strfreev()` when no longer needed.

See `exo_xsession_client_set_restart_command()` for further explanation.

`client` : | An ExoXsessionClient.
`argv` : | Pointer to the location where the pointer to the argument vector should be stored to.
`argc` : | Pointer to the location where the number of arguments should be stored to or `NULL`.
Returns : | `TRUE` on success, else `FALSE`.

### exo_xsession_client_set_restart_command ()

    void                exo_xsession_client_set_restart_command
                                                            (ExoXsessionClient *client,
                                                             gchar **argv,
                                                             gint argc);

Sets the `WM_COMMAND` property on the client leader window, which instructs the session manager (or session-enabled window manager) how to restart the application on next login.

This function can only be used if `client` is associated with a client leader window.

If `argc` is specify as -1, the argument vector `argv` is expected to be `NULL`-terminated and `argc` will be automatically calculated from `argv`.

Please take note, that `gtk_init()` automatically sets the `WM_COMMAND` property on all client leader windows that are implicitly created by Gtk+. So, you may only need to call this function in response to the ::save-yourself signal.

`client` : | An ExoXsessionClient.
`argv` : | The argument vector.
`argc` : | The number of arguments in `argv` or -1.

## Property Details

### The `"group"` property

      "group"                    GdkWindow*            : Read / Write

Window group leader.

### The `"restart-command"` property

      "restart-command"          GStrv                 : Read / Write

Session restart command.

## Signal Details

### The `"save-yourself"` signal

    void                user_function                      (ExoXsessionClient *client,
                                                            gpointer           user_data)      : Run First

This signal is emitted when `client` receives a `WM_SAVE_YOURSELF` message from the session manager or the window manager on the specified client leader window.

`client` : | An ExoXsessionClient.
`user_data` : | user data set when the signal handler was connected.