New method to marshall and send a Startup Notification message. (from

* gdk/x11/gdkdisplay-x11.c
	(gdk_x11_display_broadcast_startup_message): New method to
	marshall and send a Startup Notification message. (from #415070)
	(gdk_notify_startup_complete_with_id): Use that

svn path=/trunk/; revision=17710
This commit is contained in:
Dan Winship
2007-04-29 18:13:42 +00:00
parent 99e8b92b6a
commit 0d2678417c
3 changed files with 83 additions and 44 deletions

View File

@ -930,33 +930,6 @@ _gdk_windowing_set_default_display (GdkDisplay *display)
}
}
static char*
escape_for_xmessage (const char *str)
{
GString *retval;
const char *p;
retval = g_string_new (NULL);
p = str;
while (*p)
{
switch (*p)
{
case ' ':
case '"':
case '\\':
g_string_append_c (retval, '\\');
break;
}
g_string_append_c (retval, *p);
++p;
}
return g_string_free (retval, FALSE);
}
static void
broadcast_xmessage (GdkDisplay *display,
const char *message_type,
@ -972,6 +945,9 @@ broadcast_xmessage (GdkDisplay *display,
Atom type_atom_begin;
Window xwindow;
if (!G_LIKELY (GDK_DISPLAY_X11 (display)->trusted_client))
return;
{
XSetWindowAttributes attrs;
@ -1045,6 +1021,72 @@ broadcast_xmessage (GdkDisplay *display,
XFlush (xdisplay);
}
/**
* gdk_x11_display_broadcast_startup_message:
* @display: a #GdkDisplay
* @message_type: startup notification message type ("new", "change",
* or "remove")
* @...: a list of key/value pairs (as strings), terminated by a
* %NULL key. (A %NULL value for a key will cause that key to be
* skipped in the output.)
*
* Sends a startup notification message of type @message_type to
* @display.
*
* This is a convenience function for use by code that implements the
* freedesktop startup notification specification. Applications should
* not normally need to call it directly. See the <ulink
* url="http://standards.freedesktop.org/startup-notification-spec/startup-notification-latest.txt">Startup
* Notification Protocol specification</ulink> for
* definitions of the message types and keys that can be used.
*
* Since: 2.12
**/
void
gdk_x11_display_broadcast_startup_message (GdkDisplay *display,
const char *message_type,
...)
{
GString *message;
va_list ap;
const char *key, *value, *p;
message = g_string_new (message_type);
g_string_append_c (message, ':');
va_start (ap, message_type);
while ((key = va_arg (ap, const char *)))
{
value = va_arg (ap, const char *);
if (!value)
continue;
g_string_append_printf (message, " %s=\"", key);
for (p = value; *p; p++)
{
switch (*p)
{
case ' ':
case '"':
case '\\':
g_string_append_c (message, '\\');
break;
}
g_string_append_c (message, *p);
}
g_string_append_c (message, '\"');
}
va_end (ap);
broadcast_xmessage (display,
"_NET_STARTUP_INFO",
"_NET_STARTUP_INFO_BEGIN",
message->str);
g_string_free (message, TRUE);
}
/**
* gdk_notify_startup_complete:
*
@ -1064,8 +1106,6 @@ gdk_notify_startup_complete (void)
{
GdkDisplay *display;
GdkDisplayX11 *display_x11;
gchar *escaped_id;
gchar *message;
display = gdk_display_get_default ();
if (!display)
@ -1076,9 +1116,6 @@ gdk_notify_startup_complete (void)
if (display_x11->startup_notification_id == NULL)
return;
if (!G_LIKELY (display_x11->trusted_client))
return;
gdk_notify_startup_complete_with_id (display_x11->startup_notification_id);
}
@ -1101,23 +1138,14 @@ void
gdk_notify_startup_complete_with_id (const gchar* startup_id)
{
GdkDisplay *display;
gchar *escaped_id;
gchar *message;
display = gdk_display_get_default ();
if (!display)
return;
escaped_id = escape_for_xmessage (startup_id);
message = g_strdup_printf ("remove: ID=%s", escaped_id);
g_free (escaped_id);
broadcast_xmessage (display,
"_NET_STARTUP_INFO",
"_NET_STARTUP_INFO_BEGIN",
message);
g_free (message);
gdk_x11_display_broadcast_startup_message (display, "remove",
"ID", startup_id,
NULL);
}
/**