Make gdk_set_sm_client_id X11-specific

This is really not a cross-platform API
This commit is contained in:
Matthias Clasen
2010-12-13 13:45:38 -05:00
parent ccb6edeb8b
commit 4a74060d63
5 changed files with 55 additions and 73 deletions

View File

@ -321,7 +321,6 @@ gdk_set_locale
gdk_set_pointer_hooks gdk_set_pointer_hooks
gdk_set_program_class gdk_set_program_class
gdk_set_show_events gdk_set_show_events
gdk_set_sm_client_id
gdk_setting_action_get_type G_GNUC_CONST gdk_setting_action_get_type G_GNUC_CONST
gdk_setting_get gdk_setting_get
gdk_spawn_command_line_on_screen gdk_spawn_command_line_on_screen
@ -566,6 +565,7 @@ gdk_x11_screen_get_window_manager_name
gdk_x11_screen_get_xscreen gdk_x11_screen_get_xscreen
gdk_x11_screen_lookup_visual gdk_x11_screen_lookup_visual
gdk_x11_screen_supports_net_wm_hint gdk_x11_screen_supports_net_wm_hint
gdk_x11_set_sm_client_id
gdk_x11_ungrab_server gdk_x11_ungrab_server
gdk_x11_visual_get_xvisual gdk_x11_visual_get_xvisual
gdk_x11_window_get_xid gdk_x11_window_get_xid

View File

@ -136,8 +136,6 @@ static GdkAppLaunchContext *gdk_display_real_get_app_launch_context (GdkDisplay
static guint signals[LAST_SIGNAL] = { 0 }; static guint signals[LAST_SIGNAL] = { 0 };
static char *gdk_sm_client_id;
static const GdkDisplayDeviceHooks default_device_hooks = { static const GdkDisplayDeviceHooks default_device_hooks = {
_gdk_windowing_get_device_state, _gdk_windowing_get_device_state,
gdk_window_real_window_get_device_position, gdk_window_real_window_get_device_position,
@ -661,49 +659,6 @@ gdk_event_send_clientmessage_toall (GdkEvent *event)
gdk_screen_broadcast_client_message (gdk_screen_get_default (), event); gdk_screen_broadcast_client_message (gdk_screen_get_default (), event);
} }
/**
* gdk_set_sm_client_id:
* @sm_client_id: the client id assigned by the session manager when the
* connection was opened, or %NULL to remove the property.
*
* Sets the <literal>SM_CLIENT_ID</literal> property on the application's leader window so that
* the window manager can save the application's state using the X11R6 ICCCM
* session management protocol.
*
* See the X Session Management Library documentation for more information on
* session management and the Inter-Client Communication Conventions Manual
* (ICCCM) for information on the <literal>WM_CLIENT_LEADER</literal> property.
* (Both documents are part of the X Window System distribution.)
**/
void
gdk_set_sm_client_id (const gchar* sm_client_id)
{
GSList *displays, *tmp_list;
g_free (gdk_sm_client_id);
gdk_sm_client_id = g_strdup (sm_client_id);
displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
for (tmp_list = displays; tmp_list; tmp_list = tmp_list->next)
_gdk_windowing_display_set_sm_client_id (tmp_list->data, sm_client_id);
g_slist_free (displays);
}
/**
* _gdk_get_sm_client_id:
*
* Gets the client ID set with gdk_set_sm_client_id(), if any.
*
* Return value: Session ID, or %NULL if gdk_set_sm_client_id()
* has never been called.
**/
const char *
_gdk_get_sm_client_id (void)
{
return gdk_sm_client_id;
}
void void
_gdk_display_enable_motion_hints (GdkDisplay *display, _gdk_display_enable_motion_hints (GdkDisplay *display,
GdkDevice *device) GdkDevice *device)

View File

@ -157,6 +157,8 @@ static const char *const precache_atoms[] = {
"_NET_VIRTUAL_ROOTS" "_NET_VIRTUAL_ROOTS"
}; };
static char *gdk_sm_client_id;
G_DEFINE_TYPE_WITH_CODE (GdkDisplayX11, _gdk_display_x11, GDK_TYPE_DISPLAY, G_DEFINE_TYPE_WITH_CODE (GdkDisplayX11, _gdk_display_x11, GDK_TYPE_DISPLAY,
G_IMPLEMENT_INTERFACE (GDK_TYPE_EVENT_TRANSLATOR, G_IMPLEMENT_INTERFACE (GDK_TYPE_EVENT_TRANSLATOR,
gdk_display_x11_event_translator_init)) gdk_display_x11_event_translator_init))
@ -1165,6 +1167,25 @@ gdk_input_init (GdkDisplay *display)
g_list_free (list); g_list_free (list);
} }
static void
set_sm_client_id (GdkDisplay *display,
const gchar *sm_client_id)
{
GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
if (gdk_display_is_closed (display))
return;
if (sm_client_id && strcmp (sm_client_id, ""))
XChangeProperty (display_x11->xdisplay, display_x11->leader_window,
gdk_x11_get_xatom_by_name_for_display (display, "SM_CLIENT_ID"),
XA_STRING, 8, PropModeReplace, (guchar *)sm_client_id,
strlen (sm_client_id));
else
XDeleteProperty (display_x11->xdisplay, display_x11->leader_window,
gdk_x11_get_xatom_by_name_for_display (display, "SM_CLIENT_ID"));
}
/** /**
* gdk_display_open: * gdk_display_open:
* @display_name: the name of the display to open * @display_name: the name of the display to open
@ -1185,8 +1206,7 @@ _gdk_x11_display_open (const gchar *display_name)
GdkWindowAttr attr; GdkWindowAttr attr;
gint argc; gint argc;
gchar *argv[1]; gchar *argv[1];
const char *sm_client_id;
XClassHint *class_hint; XClassHint *class_hint;
gulong pid; gulong pid;
gint i; gint i;
@ -1357,9 +1377,8 @@ _gdk_x11_display_open (const gchar *display_name)
class_hint); class_hint);
XFree (class_hint); XFree (class_hint);
sm_client_id = _gdk_get_sm_client_id (); if (gdk_sm_client_id)
if (sm_client_id) set_sm_client_id (display, gdk_sm_client_id);
_gdk_windowing_display_set_sm_client_id (display, sm_client_id);
pid = getpid (); pid = getpid ();
XChangeProperty (display_x11->xdisplay, XChangeProperty (display_x11->xdisplay,
@ -2665,6 +2684,34 @@ extern GdkNativeWindow _gdk_x11_display_get_drag_protocol (GdkDisplay
GdkDragProtocol *protocol, GdkDragProtocol *protocol,
guint *version); guint *version);
/**
* gdk_x11_set_sm_client_id:
* @sm_client_id: the client id assigned by the session manager when the
* connection was opened, or %NULL to remove the property.
*
* Sets the <literal>SM_CLIENT_ID</literal> property on the application's leader window so that
* the window manager can save the application's state using the X11R6 ICCCM
* session management protocol.
*
* See the X Session Management Library documentation for more information on
* session management and the Inter-Client Communication Conventions Manual
*/
void
gdk_x11_set_sm_client_id (const gchar *sm_client_id)
{
GSList *displays, *l;
g_free (gdk_sm_client_id);
gdk_sm_client_id = g_strdup (sm_client_id);
displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
for (l = displays; l; l = l->next)
set_sm_client_id (l->data, sm_client_id);
g_slist_free (displays);
}
static void static void
_gdk_display_x11_class_init (GdkDisplayX11Class * class) _gdk_display_x11_class_init (GdkDisplayX11Class * class)
{ {

View File

@ -49,7 +49,6 @@
#include <X11/XKBlib.h> #include <X11/XKBlib.h>
#endif #endif
typedef struct _GdkPredicate GdkPredicate; typedef struct _GdkPredicate GdkPredicate;
typedef struct _GdkGlobalErrorTrap GdkGlobalErrorTrap; typedef struct _GdkGlobalErrorTrap GdkGlobalErrorTrap;
@ -203,27 +202,6 @@ _gdk_xgrab_check_destroy (GdkWindow *window)
g_list_free (devices); g_list_free (devices);
} }
void
_gdk_windowing_display_set_sm_client_id (GdkDisplay *display,
const gchar *sm_client_id)
{
GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
if (gdk_display_is_closed (display))
return;
if (sm_client_id && strcmp (sm_client_id, ""))
{
XChangeProperty (display_x11->xdisplay, display_x11->leader_window,
gdk_x11_get_xatom_by_name_for_display (display, "SM_CLIENT_ID"),
XA_STRING, 8, PropModeReplace, (guchar *)sm_client_id,
strlen (sm_client_id));
}
else
XDeleteProperty (display_x11->xdisplay, display_x11->leader_window,
gdk_x11_get_xatom_by_name_for_display (display, "SM_CLIENT_ID"));
}
/* /*
*-------------------------------------------------------------- *--------------------------------------------------------------
* gdk_x_io_error * gdk_x_io_error

View File

@ -248,6 +248,8 @@ void gdk_x11_register_standard_event_type (GdkDisplay *display,
gint n_events); gint n_events);
void gdk_x11_set_sm_client_id (const gchar *sm_client_id);
G_END_DECLS G_END_DECLS
#endif /* __GDK_X_H__ */ #endif /* __GDK_X_H__ */