Re: startup-notification support for nautilus as a launchee



Replying to my own email kind of sucks, but while writing the same
patch for gnome-terminal, I noticed that the commented out error in
nautilus can now be removed.  So, here's a new patch...
Index: src/nautilus-application.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-application.c,v
retrieving revision 1.231
diff -p -u -r1.231 nautilus-application.c
--- src/nautilus-application.c	22 Feb 2005 08:46:38 -0000	1.231
+++ src/nautilus-application.c	28 Feb 2005 19:47:26 -0000
@@ -1034,8 +1034,14 @@ end_startup_notification (GtkWidget  *wi
 					   gdk_screen_get_number (screen),
 					   startup_id);
 
-	sn_launchee_context_setup_window (context,
-					  GDK_WINDOW_XWINDOW (widget->window));
+	/* Handle the setup for the window if the startup_id is valid;
+	 * I don't think it can hurt to do this even if it was
+	 * invalid, but why do the extra work...
+	 */
+	if (strncmp (sn_launchee_context_get_startup_id (context), "_TIME", 5) != 0) {
+		sn_launchee_context_setup_window (context,
+						  GDK_WINDOW_XWINDOW (widget->window));
+	}
 
 	/* Now, set the _NET_WM_USER_TIME for the new window to the timestamp
 	 * that caused the window to be launched.
@@ -1044,14 +1050,6 @@ end_startup_notification (GtkWidget  *wi
 		gulong startup_id_timestamp;
 		startup_id_timestamp = sn_launchee_context_get_timestamp (context);
 		gdk_x11_window_set_user_time (widget->window, startup_id_timestamp);
-	} else {
-		/* Comment this out for now, as it warns way to often.
-		 * like when launching nautilus from the terminal.
-		 
-		g_warning ("Launched by a non-compliant or obsolete startup "
-			   "notification launcher.  Focus-stealing-prevention "
-			   "may fail.\n");
-		*/
 	}
   
 	sn_launchee_context_complete (context);
Index: src/nautilus-main.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-main.c,v
retrieving revision 1.144
diff -p -u -r1.144 nautilus-main.c
--- src/nautilus-main.c	14 Feb 2005 10:59:23 -0000	1.144
+++ src/nautilus-main.c	28 Feb 2005 19:47:26 -0000
@@ -54,6 +54,7 @@
 #include <libxml/parser.h>
 #include <popt.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 
 /* Keeps track of everyone who wants the main event loop kept active */
@@ -188,6 +189,59 @@ register_icons (void)
 	
 }
 
+/* Copied from libnautilus/nautilus-program-choosing.c; In this case,
+ * though, it's really needed because we have no real alternative when
+ * no DESKTOP_STARTUP_ID (with its accompanying timestamp) is
+ * provided...
+ */
+static Time
+slowly_and_stupidly_obtain_timestamp (Display *xdisplay)
+{
+	Window xwindow;
+	XEvent event;
+	
+	{
+		XSetWindowAttributes attrs;
+		Atom atom_name;
+		Atom atom_type;
+		char* 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[])
 {
@@ -276,6 +330,15 @@ main (int argc, char *argv[])
 				      GNOME_PARAM_POPT_TABLE, options,
 				      GNOME_PARAM_HUMAN_READABLE_NAME, _("Nautilus"),
 				      NULL);
+
+	/* Do this here so that gdk_display is initialized */
+	if (startup_id_copy == NULL) {
+		/* Create a fake one containing a timestamp that we can use */
+		Time timestamp;
+		timestamp = slowly_and_stupidly_obtain_timestamp (gdk_display);
+		startup_id_copy = g_strdup_printf ("_TIME%lu",
+						   timestamp);
+	}
 
 	register_icons ();
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]