gtk: Add GtkWindow property for session identifiers
This identifier will be used for session management purposes, and is meant to be stable across executions.
This commit is contained in:
committed by
Matthias Clasen
parent
adfc69d501
commit
f79c181c56
@@ -284,6 +284,8 @@ typedef struct
|
||||
|
||||
GdkCursor *resize_cursor;
|
||||
|
||||
char *session_id;
|
||||
|
||||
GtkEventController *menubar_controller;
|
||||
} GtkWindowPrivate;
|
||||
|
||||
@@ -333,6 +335,8 @@ enum {
|
||||
PROP_MAXIMIZED,
|
||||
PROP_FULLSCREENED,
|
||||
|
||||
PROP_SESSION_ID,
|
||||
|
||||
LAST_ARG
|
||||
};
|
||||
|
||||
@@ -1076,6 +1080,24 @@ gtk_window_class_init (GtkWindowClass *klass)
|
||||
TRUE,
|
||||
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
||||
|
||||
/**
|
||||
* GtkWindow:session-id: (attributes org.gtk.Property.get=gtk_window_get_session_id org.gtk.Property.set=gtk_window_set_session_id)
|
||||
*
|
||||
* The identifier of this toplevel in the session.
|
||||
*
|
||||
* In windowing environments that allow it, this identifier will be
|
||||
* used to identify windows in a persistent manner across runs, and
|
||||
* restore window state (e.g. position, size) for them.
|
||||
*
|
||||
* Currently, this is only implemented for the Wayland backend.
|
||||
*
|
||||
* Since: 4.16
|
||||
*/
|
||||
window_props[PROP_SESSION_ID] =
|
||||
g_param_spec_string ("session-id", NULL, NULL,
|
||||
NULL,
|
||||
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
||||
|
||||
g_object_class_install_properties (gobject_class, LAST_ARG, window_props);
|
||||
|
||||
/**
|
||||
@@ -1895,6 +1917,9 @@ gtk_window_set_property (GObject *object,
|
||||
case PROP_HANDLE_MENUBAR_ACCEL:
|
||||
gtk_window_set_handle_menubar_accel (window, g_value_get_boolean (value));
|
||||
break;
|
||||
case PROP_SESSION_ID:
|
||||
gtk_window_set_session_id (window, g_value_get_string (value));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
@@ -1984,6 +2009,9 @@ gtk_window_get_property (GObject *object,
|
||||
case PROP_HANDLE_MENUBAR_ACCEL:
|
||||
g_value_set_boolean (value, gtk_window_get_handle_menubar_accel (window));
|
||||
break;
|
||||
case PROP_SESSION_ID:
|
||||
g_value_set_string (value, gtk_window_get_session_id (window));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
@@ -6987,3 +7015,52 @@ gtk_window_get_handle_menubar_accel (GtkWindow *window)
|
||||
|
||||
return phase == GTK_PHASE_CAPTURE;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_window_set_session_id:
|
||||
* @window: a `GtkWindow`
|
||||
* @session_id: (nullable): A persistent identifier for this window
|
||||
*
|
||||
* Sets the identifier to be used for session management purposes.
|
||||
*
|
||||
* State of this window may be restored from prior executions, by using this
|
||||
* identifier to match the related state. This identifier should be constant,
|
||||
* or at least stable between executions, and unique among the windows of the
|
||||
* application.
|
||||
*
|
||||
* Different backends may have different requirements for this string, therefore
|
||||
* it is best to be conservative and keep the string relatively short and stick
|
||||
* to ASCII without leading or trailing whitespace.
|
||||
*
|
||||
* Since: 4.16
|
||||
**/
|
||||
void
|
||||
gtk_window_set_session_id (GtkWindow *window,
|
||||
const char *session_id)
|
||||
{
|
||||
GtkWindowPrivate *priv = gtk_window_get_instance_private (window);
|
||||
|
||||
if (g_set_str (&priv->session_id, session_id))
|
||||
g_object_notify_by_pspec (G_OBJECT (window), window_props[PROP_SESSION_ID]);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_window_get_session_id:
|
||||
* @window: a `GtkWindow`
|
||||
*
|
||||
* Gets the window identifier to be used for session management purposes.
|
||||
*
|
||||
* See [method@Gtk.Window.set_session_id] for more details about window
|
||||
* identifiers for session management.
|
||||
*
|
||||
* Returns: (nullable): the session identifier
|
||||
*
|
||||
* Since: 4.16
|
||||
*/
|
||||
const char *
|
||||
gtk_window_get_session_id (GtkWindow *window)
|
||||
{
|
||||
GtkWindowPrivate *priv = gtk_window_get_instance_private (window);
|
||||
|
||||
return priv->session_id;
|
||||
}
|
||||
|
||||
@@ -259,6 +259,13 @@ void gtk_window_set_handle_menubar_accel (GtkWindow *window,
|
||||
GDK_AVAILABLE_IN_4_2
|
||||
gboolean gtk_window_get_handle_menubar_accel (GtkWindow *window);
|
||||
|
||||
GDK_AVAILABLE_IN_4_16
|
||||
void gtk_window_set_session_id (GtkWindow *window,
|
||||
const char *session_id);
|
||||
|
||||
GDK_AVAILABLE_IN_4_16
|
||||
const char * gtk_window_get_session_id (GtkWindow *window);
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkWindow, g_object_unref)
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkWindowGroup, g_object_unref)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user