| Top |
| 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 |
| 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 |
GEnum ├── XfceSessionClientErrorEnum ├── XfceSessionClientRestartStyle ╰── XfceSessionClientShutdownHint GObject ╰── XfceSessionClient
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.
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.
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.
A new XfceSessionClient instance, or the singleton with its reference count incremented.
[transfer full][not nullable]
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.
argc |
The number of arguments passed to |
|
argv |
The argument vector passed to |
|
restart_style |
||
priority |
A restart priority |
A new XfceSessionClient instance, or the singleton with its reference count incremented.
[transfer full][not nullable]
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.
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 |
A new XfceSessionClient instance, or the singleton with its reference count incremented.
[transfer full][not nullable]
XfceSessionClient *
xfce_session_client_get (void);
Returns the singleton instance of XfceSessionClient, if one has been created.
gboolean xfce_session_client_connect (XfceSessionClient *session_client,GError **error);
Attempts to connect to the session manager.
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.
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.
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.
gboolean
xfce_session_client_is_connected (XfceSessionClient *session_client);
Determines whether or not the application has connected to the session manager.
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.
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.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.
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().
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.
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()).
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.
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.
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.
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.
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.
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).
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.
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).
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.
void xfce_session_client_set_restart_style (XfceSessionClient *session_client,XfceSessionClientRestartStyle restart_style);
Sets the restart style hint to restart_style
.
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
. If you wish to re-use xfce_session_client_restore_window()name
with cleared
state, you must call
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_remove_window()
instead.xfce_session_client_restore_window()
Depending on your needs, you can use descriptive titles for name
, such as
"settings-dialog", or you can use random strings or UUIDs.
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
was called. xfce_session_client_add_window()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
and then
xfce_session_client_remove_window()
were called), which will discard any
previous WM state for xfce_session_client_add_window()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
or xfce_session_client_add_window()
.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()
, or this function. If you wish to re-use
xfce_session_client_restore_window()new_name
, you must call
first.xfce_session_client_remove_window()
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.
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.
typedef struct _XfceSessionClient XfceSessionClient;
An opaque struct with only private fields.
Some sample priority values for use with xfce_session_client_set_priority().
|
A high priority value. You probably don't want to use this. |
||
|
A priority value for use by the window manager. |
||
|
A priority value for use by applications that place windows on the screen and possibly set window manager struts. |
||
|
A priority value for use by applications that draw on the desktop. |
||
|
A priority value for regular applications. |
||
|
The lowest possible priority value. |
An enumeration describing how the session manager should restart the application.
Hints to the session manager what kind of shutdown the session manager should perform.
#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.
“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
“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
“clone-command” property “clone-command” GStrv
A command used to start a new instance of this application.
Owner: XfceSessionClient
Flags: Read / Write
“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
“desktop-file” property “desktop-file” char *
The application's .desktop file.
Owner: XfceSessionClient
Flags: Read / Write
Default value: NULL
“priority” property “priority” guchar
Determines the ordering in which this client is restarted.
Owner: XfceSessionClient
Flags: Read / Write / Construct
Default value: 50
“restart-command” property “restart-command” GStrv
A command used to restart this application, preserving the current state.
Owner: XfceSessionClient
Flags: Read / Write
“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
“quit” signalvoid 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.
Flags: Run Last
“quit-cancelled” signalvoid 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.
Flags: Run Last
“quit-requested” signalgboolean 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.
Flags: Run Last
“replaced” signalgboolean 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.
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
“save-state” signalvoid 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.
Flags: Run Last
“save-state-extended” signalvoid 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.
Flags: Run Last