XfceSessionClient

XfceSessionClient — Session management client

Stability Level

Stable, unless otherwise indicated

Functions

Properties

int auto-reconnect-interval Read / Write
char * client-id Read / Write / Construct Only
GStrv clone-command Read / Write
char * current-directory Read / Write
char * desktop-file Read / Write
guchar priority Read / Write / Construct
GStrv restart-command Read / Write
XfceSessionClientRestartStyle restart-style Read / Write / Construct
gboolean resumed Read

Signals

void quit Run Last
void quit-cancelled Run Last
gboolean quit-requested Run Last
gboolean replaced Run Last
void save-state Run Last
void save-state-extended Run Last

Types and Values

Object Hierarchy

    GEnum
    ├── XfceSessionClientErrorEnum
    ├── XfceSessionClientRestartStyle
    ╰── XfceSessionClientShutdownHint
    GObject
    ╰── XfceSessionClient

Includes

#include <libxfce4session-client/libxfce4session-client.h>

Description

XfceSessionClient is a session management client that supports both X11 and Wayland.

On X11 it speaks the X Session Management Protocol (XSMP), and on Wayland it uses a hybrid of xdg-session-management-v1 and xfce4-session's D-Bus protocol. It's designed to be easy to use and hide some of the more esoteric features of the session management protocols from the API user.

Functions

xfce_session_client_get_option_group ()

GOptionGroup *
xfce_session_client_get_option_group (gint argc,
                                      gchar **argv);

Constructs a GOptionGroup suitable for use with Glib's command-line option parser.

This function is a bit sneaky in that it will make a copy of the program's argc and argv before GTK+ etc. has a chance to mess around with it, so XfceSessionClient can later construct an accurate restart command. Instead of calling gtk_init() or gtk_init_with_args(), instead you'd do something like:

1
2
3
4
GOptionContext *context = g_option_context_new("");
g_option_context_add_group(context, gtk_get_option_group(TRUE));
g_option_context_add_group(context, xfce_session_client_get_option_group(argc, argv);
g_option_context_parse(context, &argc, &argv, NULL);

Error checking is omitted here for brevity, and of course you could add your app's own options with g_option_context_add_main_entries() or similar.

Parameters

argc

The application's argument count

 

argv

The application's argument vector

 

Returns

A new GOptionGroup


xfce_session_client_new ()

XfceSessionClient *
xfce_session_client_new (void);

Creates the application's SM client instance. This is best used with xfce_session_client_get_option_group() above (and using the returned GOptionGroup with g_option_context_parse()), as the command line parsing will figure out many of the SM client's required property values for you.

If you have already created an XfceSessionClient instance using any of the "new" functions, this will return a new reference to the same instance.

Returns

A new XfceSessionClient instance, or the singleton with its reference count incremented.

[transfer full][not nullable]


xfce_session_client_new_with_argv ()

XfceSessionClient *
xfce_session_client_new_with_argv (gint argc,
                                   gchar **argv,
                                   XfceSessionClientRestartStyle restart_style,
                                   guchar priority);

Creates a new XfceSessionClient instance. It attempts to set all required properties using the app's command line. Note that this function does not actually connect to the session manager, so other actions can be taken (such as setting custom properties or connecting signals) before calling xfce_session_client_connect().

If you have already created an XfceSessionClient instance using any of the "new" functions, this will return a new reference to the same instance, ignoring any arguments passed.

If you are using Gtk or Glib's command-line option parser, it is recommended that you use xfce_session_client_get_option_group() and xfce_session_client_new() instead.

Parameters

argc

The number of arguments passed to main()

 

argv

The argument vector passed to main()

 

restart_style

An XfceSessionClientRestartStyle

 

priority

A restart priority

 

Returns

A new XfceSessionClient instance, or the singleton with its reference count incremented.

[transfer full][not nullable]


xfce_session_client_new_full ()

XfceSessionClient *
xfce_session_client_new_full (XfceSessionClientRestartStyle restart_style,
                              guchar priority,
                              const gchar *resumed_client_id,
                              const gchar *current_directory,
                              const gchar **restart_command,
                              const gchar *desktop_file);

Creates a new SM client instance, allowing the application fine-grained control over the initial properties set. Note that this function does not actually connect to the session manager, so other actions can be taken (such as setting custom properties or connecting signals) before calling xfce_session_client_connect().

If you have already created an XfceSessionClient instance using any of the "new" functions, this will return a new reference to the same instance, ignoring any arguments passed.

It is recommended to use xfce_session_client_new_with_argv(), or, if you are using Gtk or Glib's command-line option parser, xfce_session_client_get_option_group() and xfce_session_client_new() instead.

Parameters

restart_style

An XfceSessionClientRestartStyle

 

priority

A restart priority

 

resumed_client_id

The client id used in the previous session

 

current_directory

The application's working directory

 

restart_command

A command that can resume the application's saved state

 

desktop_file

The application's .desktop file

 

Returns

A new XfceSessionClient instance, or the singleton with its reference count incremented.

[transfer full][not nullable]


xfce_session_client_get ()

XfceSessionClient *
xfce_session_client_get (void);

Returns the singleton instance of XfceSessionClient, if one has been created.

Returns

A XfceSessionClient instance.

[transfer none][nullable]


xfce_session_client_connect ()

gboolean
xfce_session_client_connect (XfceSessionClient *session_client,
                             GError **error);

Attempts to connect to the session manager.

Parameters

session_client

An XfceSessionClient

 

error

A GError location.

[out][nullable][transfer full]

Returns

TRUE on success, FALSE otherwise. If an error occurs, error will be set.


xfce_session_client_discard ()

void
xfce_session_client_discard (XfceSessionClient *session_client);

Asks the session manager to discard all stored data about this session, and then disconnects the application from the session manager.

If your application calls this on graceful exit, you may wish to ensure that it does not call it when exiting in response to the “quit” signal.

This may not remove the application from the saved session (if any) if the user later does not choose to save the session when logging out.

Parameters

session_client

An XfceSessionClient

 

xfce_session_client_disconnect ()

void
xfce_session_client_disconnect (XfceSessionClient *session_client);

Disconnects the application from the session manager.

This may not remove the application from the saved session (if any) if the user later does not choose to save the session when logging out.

Parameters

session_client

An XfceSessionClient

 

xfce_session_client_set_auto_reconnect_interval ()

void
xfce_session_client_set_auto_reconnect_interval
                               (XfceSessionClient *session_client,
                                gint auto_reconnect_interval_ms);

Sets the non-zero interval at which session_client will automatically attempt to reconnect to the session manager if the connection is lost.

Pass -1 to disable auto-reconnect entirely.

Note that this value (whether it is enabled or disabled) determines the default behavior of “replaced” when there is no signal handler connected to it; see its docs for more information.

Parameters

session_client

An XfceSessionClient

 

auto_reconnect_interval_ms

Timeout in milliseconds, or -1 to disable auto-reconnect

 

xfce_session_client_is_connected ()

gboolean
xfce_session_client_is_connected (XfceSessionClient *session_client);

Determines whether or not the application has connected to the session manager.

Parameters

session_client

An XfceSessionClient

 

Returns

TRUE if connected to the session manager, FALSE otherwise


xfce_session_client_is_resumed ()

gboolean
xfce_session_client_is_resumed (XfceSessionClient *session_client);

Determines whether the application was resumed from a previous session, or if the application has been started fresh with no state information associated with it.

Parameters

session_client

An XfceSessionClient

 

Returns

TRUE if resumed from a previous session, FALSE otherwise


xfce_session_client_set_desktop_file ()

void
xfce_session_client_set_desktop_file (XfceSessionClient *session_client,
                                      const gchar *desktop_file);

Sets the application's .desktop file. In addition to informing the session manager of the .desktop file so it can present localized names and an icon in session listings and the splash screen, this also calls g_set_application_name() and gtk_window_set_default_icon_name() (or gtk_window_set_default_icon_from_file()) if the Name and Icon keys are present, respectively.

If a relative path to the file is provided, this function will search the standard application directories as specified by the

XDG Desktop Menu Specification.

Parameters

session_client

An XfceSessionClient

 

desktop_file

The path to the application's .desktop file

 

xfce_session_client_request_shutdown ()

void
xfce_session_client_request_shutdown (XfceSessionClient *session_client,
                                      XfceSessionClientShutdownHint shutdown_hint);

Sends a request to the session manager to end the session. Depending on hint , the session manager may prompt for a certain action (log out, halt, reboot, etc.) or may take the requested action without user intervention.

The session manager may or may not support all requested actions, and is also free to ignore the requested action.

Parameters

session_client

An XfceSessionClient

 

shutdown_hint

The type of shutdown requested

 

xfce_session_client_get_client_id ()

const gchar *
xfce_session_client_get_client_id (XfceSessionClient *session_client);

Retrieves the session client's unique ID. This ID can be used to construct a filename used to restore the application's state. Note that this value is only guaranteed to be valid if connected to the session manager.

Instead of constructing a state filename, it is recommended to use xfce_session_client_get_state_file().

Parameters

session_client

An XfceSessionClient

 

Returns

an opaque object-owned string


xfce_session_client_set_client_id ()

void
xfce_session_client_set_client_id (XfceSessionClient *session_client,
                                   const gchar *client_id);

Resets session_client 's client ID to client_id , or clears it if NULL is passed.

It is an error to call this function while session_client is connected to the session manager.

Note that you usually won't need to call this; the constructor functions will either take the client ID as a parameter, or parse the app's argv to try to find it.

Parameters

session_client

An XfceSessionClient

 

client_id

A client ID string.

[nullable]

xfce_session_client_get_state_file ()

const gchar *
xfce_session_client_get_state_file (XfceSessionClient *session_client);

Constructs a filename that can be used to restore or save state information.

When saving state, note that this file may already exist (and may have been used for saving previous state for the application), so the application should first remove or empty the file if it requires a fresh state file.

On the next application start, this function can be used to check to see if there is any previous saved state, and, if so, the state can be restored from the file.

This function will use a standard location and naming scheme and handle state cleanup (setting of the discard command) for you.

Before calling this function, the application must have a valid client ID (see xfce_session_client_get_client_id()).

Parameters

session_client

An XfceSessionClient

 

Returns

a file name string, owned by the object or NULL if the session client is disabled.


xfce_session_client_get_current_directory ()

const gchar *
xfce_session_client_get_current_directory
                               (XfceSessionClient *session_client);

Retrieves the session client's working directory. See xfce_session_client_set_current_directory() for more information.

Parameters

session_client

An XfceSessionClient

 

Returns

an object-owned string


xfce_session_client_set_current_directory ()

void
xfce_session_client_set_current_directory
                               (XfceSessionClient *session_client,
                                const gchar *current_directory);

Sets the startup working directory of session_client to current_directory . If unset, defaults to the user's home directory.

Parameters

session_client

An XfceSessionClient

 

current_directory

A valid path name

 

xfce_session_client_get_priority ()

guint8
xfce_session_client_get_priority (XfceSessionClient *session_client);

Retrieves the session client's restart priority. See xfce_session_client_set_priority() for more information.

Parameters

session_client

An XfceSessionClient

 

Returns

a value from G_MININT8 to G_MAXINT8


xfce_session_client_set_priority ()

void
xfce_session_client_set_priority (XfceSessionClient *session_client,
                                  guint8 priority);

Sets the startup priority for session_client to priority . Note that the default priority for applications is 50; lower values should be reserved for components of the desktop environment.

Parameters

session_client

An XfceSessionClient

 

priority

A 8-bit signed priority value

 

xfce_session_client_get_clone_command ()

const gchar *const *
xfce_session_client_get_clone_command (XfceSessionClient *session_client);

Retrieves the session client's clone command. See xfce_session_client_set_clone_command() for more information.

Parameters

session_client

An XfceSessionClient

 

Returns

an object-owned string vector


xfce_session_client_set_clone_command ()

void
xfce_session_client_set_clone_command (XfceSessionClient *session_client,
                                       const gchar *const *clone_command);

Sets the application's "clone" command, which is used to start a fresh instance of the application without restoring any state.

If unset, defaults to the command used to start this instance of the application, with session management related arguments removed (if present).

Parameters

session_client

An XfceSessionClient

 

clone_command

An argument vector

 

xfce_session_client_get_restart_command ()

const gchar *const *
xfce_session_client_get_restart_command
                               (XfceSessionClient *session_client);

Retrieves the session client's restart command. See xfce_session_client_set_restart_command() for more information.

Parameters

session_client

An XfceSessionClient

 

Returns

an object-owned string vector


xfce_session_client_set_restart_command ()

void
xfce_session_client_set_restart_command
                               (XfceSessionClient *session_client,
                                const gchar *const *restart_command);

Sets the application's "restart" command, which is used to restart the application and restore any saved state from the previous run.

If unset, defaults to the command used to start this instance of the application, with session management related arguments added (if not already present).

Parameters

session_client

An XfceSessionClient

 

restart_command

An argument vector

 

xfce_session_client_get_restart_style ()

XfceSessionClientRestartStyle
xfce_session_client_get_restart_style (XfceSessionClient *session_client);

Retrieves the session client's restart style. See xfce_session_client_set_restart_style() for more information.

Parameters

session_client

An XfceSessionClient

 

Returns

a value from the XfceSessionClientRestartStyle enum


xfce_session_client_set_restart_style ()

void
xfce_session_client_set_restart_style (XfceSessionClient *session_client,
                                       XfceSessionClientRestartStyle restart_style);

Sets the restart style hint to restart_style .

Parameters

session_client

An XfceSessionClient

 

restart_style

An XfceSessionClientRestartStyle value

 

xfce_session_client_add_window ()

void
xfce_session_client_add_window (XfceSessionClient *session_client,
                                GtkWindow *window,
                                const gchar *name);

Asks the session manager to keep track of window so its WM state can be restored later. window must not have already been added to the session.

name must be unique, and cannot be a string that has previously been sent to the session manager using this function or xfce_session_client_restore_window() . If you wish to re-use name with cleared state, you must call xfce_session_client_remove_window() first. If you wish to add a window with a name that has been previously used (without being removed), you must use xfce_session_client_restore_window() instead.

Depending on your needs, you can use descriptive titles for name , such as "settings-dialog", or you can use random strings or UUIDs.

Parameters

session_client

An XfceSessionClient

 

window

A GtkWindow

 

name

A unique name

 

xfce_session_client_restore_window ()

void
xfce_session_client_restore_window (XfceSessionClient *session_client,
                                    GtkWindow *window,
                                    const gchar *name);

Asks the session manager to restore WM state for name and associate it with window . If name is not known in the session, the session manager will act as if xfce_session_client_add_window() was called. window must not have already been added to the session, and there must be no other window currently registered with the session manager using name .

This must be called before window is mapped.

While this may be called at any time, note that the window restore will not take place until window is mapped. If window becomes mapped while session_client is not connected to the session manager, it cannot be restored. When client is eventually connected, window will instead be removed and re-added (as if xfce_session_client_remove_window() and then xfce_session_client_add_window() were called), which will discard any previous WM state for window .

Parameters

session_client

An XfceSessionClient

 

window

A GtkWindow

 

name

A unique name

 

xfce_session_client_rename_window ()

void
xfce_session_client_rename_window (XfceSessionClient *session_client,
                                   GtkWindow *window,
                                   const gchar *new_name);

Asks the session manager to rename window 's stored state name to new_name .

window must be registered with the compositor via a previous call to xfce_session_client_add_window() or xfce_session_client_restore_window() .

new_name must be unique, and cannot be a string that has previously been sent to the session manager using xfce_session_client_add_window() , xfce_session_client_restore_window() , or this function. If you wish to re-use new_name , you must call xfce_session_client_remove_window() first.

Note that if this function is called while window is not mapped or client is not connected, the actual rename operation will be deferred until the next time it is mapped when client is connected.

If another window is named new_name , but is unmapped with a pending rename to another name, it is an error to call this function with new_name on window . You must first map the other window so the rename away from new_name can complete.

Parameters

session_client

An XfceSessionClient

 

window

A GtkWindow

 

new_name

A unique name

 

xfce_session_client_remove_window ()

void
xfce_session_client_remove_window (XfceSessionClient *session_client,
                                   const gchar *name);

Asks the session manager to forget all state about the window identified by name .

This will make name available for use with other windows.

If you just want to close/destroy the window while the session manager keeps state for it (possibly to be restored later), destroy the window without calling this function.

Parameters

session_client

An XfceSessionClient

 

name

Name of the window

 

Types and Values

XfceSessionClient

typedef struct _XfceSessionClient XfceSessionClient;

An opaque struct with only private fields.


enum XfceSessionClientPriority

Some sample priority values for use with xfce_session_client_set_priority().

Members

XFCE_SESSION_CLIENT_PRIORITY_HIGHEST

A high priority value. You probably don't want to use this.

 

XFCE_SESSION_CLIENT_PRIORITY_WM

A priority value for use by the window manager.

 

XFCE_SESSION_CLIENT_PRIORITY_CORE

A priority value for use by applications that place windows on the screen and possibly set window manager struts.

 

XFCE_SESSION_CLIENT_PRIORITY_DESKTOP

A priority value for use by applications that draw on the desktop.

 

XFCE_SESSION_CLIENT_PRIORITY_DEFAULT

A priority value for regular applications.

 

XFCE_SESSION_CLIENT_PRIORITY_LOWEST

The lowest possible priority value.

 

enum XfceSessionClientRestartStyle

An enumeration describing how the session manager should restart the application.

Members

XFCE_SESSION_CLIENT_RESTART_NORMAL

Only restart the application if it is still running when the session is next saved.

 

XFCE_SESSION_CLIENT_RESTART_IMMEDIATELY

Immediately restart the application if it ever quits.

 

enum XfceSessionClientShutdownHint

Hints to the session manager what kind of shutdown the session manager should perform.

Members

XFCE_SESSION_CLIENT_SHUTDOWN_HINT_ASK

Prompt the user for a choice,

 

XFCE_SESSION_CLIENT_SHUTDOWN_HINT_LOGOUT

End the current session,

 

XFCE_SESSION_CLIENT_SHUTDOWN_HINT_HALT

Shut down the computer.

 

XFCE_SESSION_CLIENT_SHUTDOWN_HINT_REBOOT

Restart the computer.

 

enum XfceSessionClientErrorEnum

Error codes returned by XfceSessionClient functions.

Members

XFCE_SESSION_CLIENT_ERROR_FAILED

Failed to connect to the session manager.

 

XFCE_SESSION_CLIENT_ERROR_INVALID_CLIENT

Session does not have a valid client id.

 

XFCE_SESSION_CLIENT_ERROR

#define XFCE_SESSION_CLIENT_ERROR xfce_session_client_error_quark ()

Error domain for XfceSessionClient.

Errors in this domain will be from the XfceSessionClientErrorEnum enumeration.

See GError for more information on error domains.

Property Details

The “auto-reconnect-interval” property

  “auto-reconnect-interval”  int

Auto-reconnect interval in milliseconds (-1 to disable).

Owner: XfceSessionClient

Flags: Read / Write

Allowed values: >= -1

Default value: 30000


The “client-id” property

  “client-id”                char *

A string uniquely identifying the current instance of this client.

Owner: XfceSessionClient

Flags: Read / Write / Construct Only

Default value: NULL


The “clone-command” property

  “clone-command”            GStrv

A command used to start a new instance of this application.

Owner: XfceSessionClient

Flags: Read / Write


The “current-directory” property

  “current-directory”        char *

The directory that should be used as the working directory the next time this client is restarted.

Owner: XfceSessionClient

Flags: Read / Write

Default value: NULL


The “desktop-file” property

  “desktop-file”             char *

The application's .desktop file.

Owner: XfceSessionClient

Flags: Read / Write

Default value: NULL


The “priority” property

  “priority”                 guchar

Determines the ordering in which this client is restarted.

Owner: XfceSessionClient

Flags: Read / Write / Construct

Default value: 50


The “restart-command” property

  “restart-command”          GStrv

A command used to restart this application, preserving the current state.

Owner: XfceSessionClient

Flags: Read / Write


The “restart-style” property

  “restart-style”            XfceSessionClientRestartStyle

Specifies how the client should be restarted by the session manager.

Owner: XfceSessionClient

Flags: Read / Write / Construct

Default value: XFCE_SESSION_CLIENT_RESTART_NORMAL


The “resumed” property

  “resumed”                  gboolean

Whether or not the client was resumed with previous state.

Owner: XfceSessionClient

Flags: Read

Default value: FALSE

Signal Details

The “quit” signal

void
user_function (XfceSessionClient *session_client,
               gpointer           user_data)

Emitted when the application is required to quit. This is not optional: if the client does not quit a short time after receiving this signal, it will likely be terminated in some other way. While not required, the application will usually receive quit-requested before receiving quit. If the application does not connect to this signal, XfceSessionClient will call exit(3) with an exit code of zero on behalf of the application.

Parameters

session_client

An XfceSessionClient

 

user_data

user data set when the signal handler was connected.

 

Flags: Run Last


The “quit-cancelled” signal

void
user_function (XfceSessionClient *session_client,
               gpointer           user_data)

Informs the application that it will not need to quit. In most cases, quit-cancelled will be emitted a short time after quit-requested.

Parameters

session_client

An XfceSessionClient

 

user_data

user data set when the signal handler was connected.

 

Flags: Run Last


The “quit-requested” signal

gboolean
user_function (XfceSessionClient *session_client,
               gpointer           user_data)

Signals the client that the session manager will soon want the application to quit, perhaps as a part of ending the session (but this should not be assumed). The application can take this opportunity to prompt the user to save any unsaved work to disk.

This signal also expects a return value from the handler. If the application wishes to cancel the quit request (perhaps because the user selected "Cancel" in prompts to save unsaved work), it should return TRUE from the handler. If the application is satisfied with possibly needing to quit soon, the handler should return FALSE.

Parameters

session_client

An XfceSessionClient

 

user_data

user data set when the signal handler was connected.

 

Flags: Run Last


The “replaced” signal

gboolean
user_function (XfceSessionClient *session_client,
               gpointer           user_data)

Informs the application that another instance of the app has taken over the session ID.

If no handler is connected to this signal, the behavior follows the “auto-reconnect-interval” property: if auto-reconnect is enabled, session replacement will trigger a re-registration with the session manager, but if it is disabled, no action will be taken, and session_client will remain disconnected.

Parameters

session_client

An XfceSessionClient

 

user_data

user data set when the signal handler was connected.

 

Returns

TRUE if session_client should clear its client ID and reconnect with a fresh session, or FALSE to disconnect and do nothing.

Flags: Run Last


The “save-state” signal

void
user_function (XfceSessionClient *session_client,
               gpointer           user_data)

Signals the client that it should save a copy of its current state such that it could be restarted later in exactly the same state as it is at the time of signal emission.

If the state is simple enough to be encoded in the application's command line, xfce_session_client_set_restart_command() can be used to set that command line. For more complex state data, xfce_session_client_get_state_file() should be used.

The application should attempt to save its state as quickly as possible, and MUST NOT interact with the user as a part of saving state.

Parameters

session_client

An XfceSessionClient

 

user_data

user data set when the signal handler was connected.

 

Flags: Run Last


The “save-state-extended” signal

void
user_function (XfceSessionClient *session_client,
               gpointer           user_data)

Allows the application to save extra state information after all other applications in the session have had a chance to save their state. This is mainly used by an X11 window manager to save window positions. Most applications should not need to connect to this signal.

Parameters

session_client

An XfceSessionClient

 

user_data

user data set when the signal handler was connected.

 

Flags: Run Last