[nautilus/gnome-3-6] shell-provider: get a timestamp from X when activating the file



commit 714250d9d8701c8b3cd01df73e0d6308d9e58744
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Fri Sep 28 19:49:58 2012 -0400

    shell-provider: get a timestamp from X when activating the file
    
    Since the WM itself spawns us, I think the API should pass the timestamp
    down; since it doesn't, get a timestamp ourselves.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=674816

 src/nautilus-shell-search-provider.c |   59 +++++++++++++++++++++++++++++++++-
 1 files changed, 58 insertions(+), 1 deletions(-)
---
diff --git a/src/nautilus-shell-search-provider.c b/src/nautilus-shell-search-provider.c
index 08dc096..cf1cced 100644
--- a/src/nautilus-shell-search-provider.c
+++ b/src/nautilus-shell-search-provider.c
@@ -27,6 +27,7 @@
 #include <gio/gio.h>
 #include <string.h>
 #include <glib/gi18n.h>
+#include <gdk/gdkx.h>
 
 #include <libnautilus-private/nautilus-file.h>
 #include <libnautilus-private/nautilus-file-utilities.h>
@@ -686,6 +687,55 @@ handle_get_result_metas (NautilusShellSearchProvider  *skeleton,
   nautilus_file_list_free (missing_files);
 }
 
+/* taken from Epiphany's ephy-main.c */
+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, (unsigned char *)name, strlen (name));
+  }
+
+  XWindowEvent (xdisplay,
+                xwindow,
+                PropertyChangeMask,
+                &event);
+
+  XDestroyWindow(xdisplay, xwindow);
+
+  return event.xproperty.time;
+}
+
 static void
 handle_activate_result (NautilusShellSearchProvider *skeleton,
                         GDBusMethodInvocation       *invocation,
@@ -693,8 +743,15 @@ handle_activate_result (NautilusShellSearchProvider *skeleton,
                         gpointer                     user_data)
 {
   GError *error = NULL;
+  guint32 timestamp;
+
+  /* We need a timestamp here to get the correct WM focus.
+   * Ideally this would be given to us by the caller, but since it
+   * is not, get it ourselves.
+   */
+  timestamp = slowly_and_stupidly_obtain_timestamp (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()));
+  gtk_show_uri (NULL, result, timestamp, &error);
 
-  gtk_show_uri (NULL, result, GDK_CURRENT_TIME, &error);
   if (error != NULL) {
     g_warning ("Unable to activate %s: %s", result, error->message);
     g_error_free (error);



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