summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDon Scorgie <dscorgie@src.gnome.org>2006-01-16 17:55:50 +0000
committerDon Scorgie <dscorgie@src.gnome.org>2006-01-16 17:55:50 +0000
commita7a4c2f69ad140ea5b7e2befc7283ab377d5d10d (patch)
treea5d74ab58bd0e51d5509a204af40392656cb03af
parenta3f0dbb615e69cc81f80d2436e7a42b484c4bfcf (diff)
downloadyelp-a7a4c2f69ad140ea5b7e2befc7283ab377d5d10d.tar.gz
Add startup notification stuff, fixes #310237
* configure.in: * src/yelp-base.h: * idl/GNOME_Yelp.idl: * src/yelp-main.c: * src/yelp-base.c: Add startup notification stuff, fixes #310237
-rw-r--r--ChangeLog9
-rw-r--r--configure.in1
-rw-r--r--idl/GNOME_Yelp.idl2
-rw-r--r--src/yelp-base.c67
-rw-r--r--src/yelp-base.h3
-rw-r--r--src/yelp-main.c73
6 files changed, 144 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index f34cf9e2..9b24fd7b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2006-01-16 Don Scorgie <dscorgie@cvs.gnome.org>
+
+ * configure.in:
+ * src/yelp-base.h:
+ * idl/GNOME_Yelp.idl:
+ * src/yelp-main.c:
+ * src/yelp-base.c:
+ Add startup notification stuff, fixes #310237
+
2006-01-15 Christian Persch <chpe@cvs.gnome.org>
* m4/gecko.m4:
diff --git a/configure.in b/configure.in
index d8030961..ad163aab 100644
--- a/configure.in
+++ b/configure.in
@@ -76,6 +76,7 @@ PKG_CHECK_MODULES(YELP,
libxml-2.0 >= 2.6.5
libxslt >= 1.1.4
libexslt >= 0.8.1
+ libstartup-notification-1.0 >= 0.8
])
AC_SUBST([YELP_CFLAGS])
AC_SUBST([YELP_LIBS])
diff --git a/idl/GNOME_Yelp.idl b/idl/GNOME_Yelp.idl
index b45b53f1..00281f02 100644
--- a/idl/GNOME_Yelp.idl
+++ b/idl/GNOME_Yelp.idl
@@ -10,7 +10,7 @@ module GNOME {
interface Yelp : Bonobo::Unknown {
typedef sequence<string> WindowList;
- void newWindow (in string url);
+ void newWindow (in string url, in string time);
WindowList getWindows ();
};
};
diff --git a/src/yelp-base.c b/src/yelp-base.c
index f91f67d7..680b78b9 100644
--- a/src/yelp-base.c
+++ b/src/yelp-base.c
@@ -24,6 +24,9 @@
#include <bonobo/bonobo-main.h>
#include <libgnomevfs/gnome-vfs.h>
+#include <gdk/gdkx.h>
+#define SN_API_NOT_YET_FROZEN
+#include <libsn/sn-launchee.h>
#include <string.h>
@@ -60,13 +63,13 @@ static BonoboObjectClass *parent_class;
static void
impl_Yelp_newWindow (PortableServer_Servant servant,
const CORBA_char *url,
+ const CORBA_char *time,
CORBA_Environment *ev)
{
YelpBase *yelp_base;
-
- yelp_base = YELP_BASE (bonobo_object (servant));
- yelp_base_new_window (yelp_base, url);
+ yelp_base = YELP_BASE (bonobo_object (servant));
+ yelp_base_new_window (yelp_base, url, time);
}
static GNOME_Yelp_WindowList *
@@ -141,8 +144,8 @@ yelp_base_new_window_cb (YelpWindow *window, const gchar *uri,
g_return_if_fail (YELP_IS_WINDOW (window));
g_return_if_fail (YELP_IS_BASE (base));
- new_window = yelp_base_new_window (base, uri);
-
+ new_window = yelp_base_new_window (base, uri, NULL);
+
gtk_widget_show (new_window);
}
@@ -185,18 +188,60 @@ yelp_base_new (void)
return base;
}
+static void
+sn_error_trap_push (SnDisplay *display,
+ Display *xdisplay)
+{
+ gdk_error_trap_push ();
+}
+
+static void
+sn_error_trap_pop (SnDisplay *display,
+ Display *xdisplay)
+{
+ gdk_error_trap_pop ();
+}
+
GtkWidget *
-yelp_base_new_window (YelpBase *base, const gchar *uri)
+yelp_base_new_window (YelpBase *base, const gchar *uri, const gchar *startup_id)
{
YelpBasePriv *priv;
GtkWidget *window;
-
+ SnDisplay *sn_display = NULL;
+ GdkScreen *screen = NULL;
+ GdkDisplay *display = NULL;
+ SnLauncheeContext *context = NULL;
+
g_return_val_if_fail (YELP_IS_BASE (base), NULL);
priv = base->priv;
window = yelp_window_new (priv->toc_tree, priv->index);
-
+ gtk_widget_realize (GTK_WIDGET (window));
+
+ if (startup_id) {
+ screen = gtk_window_get_screen (GTK_WINDOW (window));
+ display = gdk_screen_get_display (screen);
+
+ sn_display =
+ sn_display_new (gdk_x11_display_get_xdisplay (display),
+ sn_error_trap_push, sn_error_trap_pop);
+ context = sn_launchee_context_new (sn_display,
+ gdk_screen_get_number (screen),
+ startup_id);
+ if (strncmp (sn_launchee_context_get_startup_id (context),
+ "_TIME", 5) != 0)
+ sn_launchee_context_setup_window (context,
+ GDK_WINDOW_XWINDOW (window->window));
+
+ if (sn_launchee_context_get_id_has_timestamp (context)) {
+ gulong time;
+
+ time = sn_launchee_context_get_timestamp (context);
+ gdk_x11_window_set_user_time (window->window, time);
+ }
+ }
+
priv->windows = g_slist_prepend (priv->windows, window);
g_object_weak_ref (G_OBJECT (window),
@@ -214,6 +259,12 @@ yelp_base_new_window (YelpBase *base, const gchar *uri)
else
yelp_window_load (YELP_WINDOW (window), "x-yelp-toc:");
+ if (context) {
+ sn_launchee_context_complete (context);
+ sn_launchee_context_unref (context);
+ sn_display_unref (sn_display);
+ }
+
return window;
}
diff --git a/src/yelp-base.h b/src/yelp-base.h
index 49eec80f..091b88a3 100644
--- a/src/yelp-base.h
+++ b/src/yelp-base.h
@@ -54,6 +54,7 @@ GType yelp_base_get_type (void);
YelpBase * yelp_base_new (void);
GtkWidget * yelp_base_new_window (YelpBase *base,
- const gchar *uri);
+ const gchar *uri,
+ const gchar *timestamp);
#endif /* __YELP_BASE_H__ */
diff --git a/src/yelp-main.c b/src/yelp-main.c
index a72936a6..d40777b5 100644
--- a/src/yelp-main.c
+++ b/src/yelp-main.c
@@ -27,6 +27,7 @@
#include <glib/gi18n.h>
#include <gtk/gtkmain.h>
#include <gtk/gtkwidget.h>
+#include <gdk/gdkx.h>
#include <bonobo/bonobo-context.h>
#include <bonobo/bonobo-exception.h>
#include <bonobo/bonobo-generic-factory.h>
@@ -49,6 +50,7 @@ static poptContext poptCon;
/* static gint next_opt; */
static gchar *cache_dir;
static gchar *open_urls;
+static gchar *startup_id;
/*structure defining command line option.*/
enum {
@@ -76,6 +78,8 @@ static void main_client_die (GnomeClient *client,
gpointer cdata);
static gboolean main_restore_session (void);
+static Time slowly_and_stupidly_obtain_timestamp (Display *xdisplay);
+
static struct poptOption options[] = {
{
@@ -142,12 +146,13 @@ main_open_new_window (CORBA_Object yelp_base, const gchar *url)
CORBA_exception_init (&ev);
- GNOME_Yelp_newWindow (yelp_base, url, &ev);
+ GNOME_Yelp_newWindow (yelp_base, url, startup_id, &ev);
if (BONOBO_EX (&ev)) {
g_error (_("Could not open new window."));
}
+ g_free (startup_id);
CORBA_exception_free (&ev);
}
@@ -303,6 +308,57 @@ main_restore_session (void)
return FALSE;
}
+/* Copied from libnautilus/nautilus-program-choosing.c; Needed in case
+ * we have no DESKTOP_STARTUP_ID (with its accompanying timestamp).
+ */
+static Time
+slowly_and_stupidly_obtain_timestamp (Display *xdisplay)
+{
+ Window xwindow;
+ XEvent event;
+
+ {
+ XSetWindowAttributes attrs;
+ Atom atom_name;
+ Atom atom_type;
+ gchar* name;
+
+ attrs.override_redirect = True;
+ attrs.event_mask = PropertyChangeMask | StructureNotifyMask;
+
+ xwindow =
+ XCreateWindow (xdisplay,
+ RootWindow (xdisplay, 0),
+ -100, -100, 1, 1,
+ 0,
+ CopyFromParent,
+ CopyFromParent,
+ CopyFromParent,
+ CWOverrideRedirect | CWEventMask,
+ &attrs);
+
+ atom_name = XInternAtom (xdisplay, "WM_NAME", TRUE);
+ g_assert (atom_name != None);
+ atom_type = XInternAtom (xdisplay, "STRING", TRUE);
+ g_assert (atom_type != None);
+
+ name = "Fake Window";
+ XChangeProperty (xdisplay,
+ xwindow, atom_name,
+ atom_type,
+ 8, PropModeReplace, name, strlen (name));
+ }
+
+ XWindowEvent (xdisplay,
+ xwindow,
+ PropertyChangeMask,
+ &event);
+
+ XDestroyWindow(xdisplay, xwindow);
+
+ return event.xproperty.time;
+}
+
int
main (int argc, char **argv)
{
@@ -312,16 +368,31 @@ main (int argc, char **argv)
GnomeClient *client;
gboolean session_started = FALSE;
const gchar **args;
+ gchar *startup_id;
bindtextdomain(GETTEXT_PACKAGE, GNOMELOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain(GETTEXT_PACKAGE);
+ startup_id = (gchar *) g_getenv ("DESKTOP_STARTUP_ID");
+
+ if (startup_id != NULL && *startup_id != '\0') {
+ startup_id = g_strdup (startup_id);
+ putenv ("DESKTOP_STARTUP_ID=");
+ }
+
+ gtk_window_set_auto_startup_notification(FALSE);
+
program = gnome_program_init (PACKAGE, VERSION,
LIBGNOMEUI_MODULE, argc, argv,
GNOME_PARAM_POPT_TABLE, options,
GNOME_PROGRAM_STANDARD_PROPERTIES,
NULL);
+ if (!startup_id) {
+ Time tmp;
+ tmp = slowly_and_stupidly_obtain_timestamp (gdk_display);
+ startup_id = g_strdup_printf ("_TIME%lu", tmp);
+ }
g_set_application_name (_("Help"));
gtk_window_set_default_icon_name ("gnome-help");