]> git.0d.be Git - empathy.git/commitdiff
empathy_window_present: use X server time if there is no event
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Thu, 18 Mar 2010 15:41:38 +0000 (16:41 +0100)
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Mon, 22 Mar 2010 09:34:26 +0000 (10:34 +0100)
libempathy-gtk/empathy-ui-utils.c

index 4503a39cc22f67f12cb613e3d1be4f55df183d46..ef7ff78b28a73971f02758ad939184bbc674b80b 100644 (file)
@@ -1383,6 +1383,55 @@ empathy_window_iconify (GtkWindow *window, GtkStatusIcon *status_icon)
        gtk_window_iconify (window);
 }
 
+/* Code from Thomas Thurman
+ * http://people.collabora.co.uk/~tthurman/pingwindow.c.txt
+ */
+static guint32
+get_server_time (void)
+{
+  Display *display;
+  Window pingingWindow;
+  XEvent propertyEvent;
+  XSetWindowAttributes attrs;
+
+  display = XOpenDisplay (NULL);
+
+  attrs.override_redirect = True;
+  attrs.event_mask = PropertyChangeMask;
+
+  pingingWindow = XCreateWindow (display,
+      XRootWindow (display, 0), /* parent */
+      -100, -100, 1, 1, /* off-screen */
+      0,
+      CopyFromParent,
+      CopyFromParent,
+      (Visual *)CopyFromParent,
+      CWOverrideRedirect | CWEventMask,
+      &attrs);
+
+  /* Change a property. XA_PRIMARY is never really
+   * used for properties, so it's safe.
+   */
+  XChangeProperty (display,
+      pingingWindow,
+      XA_PRIMARY, XA_STRING, 8,
+      PropModeAppend, NULL, 0);
+
+  /* Pick up the event. */
+  XWindowEvent (display,
+      pingingWindow,
+      PropertyChangeMask,
+      &propertyEvent);
+
+  /* If you want to do this often,
+   * just keep the window around and
+   * don't destroy it.
+   */
+  XDestroyWindow (display, pingingWindow);
+
+  return ((XPropertyEvent*)&propertyEvent)->time;
+}
+
 /* Takes care of moving the window to the current workspace. */
 void
 empathy_window_present (GtkWindow *window)
@@ -1412,8 +1461,8 @@ empathy_window_present (GtkWindow *window)
 
        timestamp = gtk_get_current_event_time ();
        if (timestamp == 0)
-               /* No event, fallback to _NET_WM_USER_TIME */
-               timestamp = gdk_x11_display_get_user_time (gdk_display_get_default ());
+               /* No event, fallback to X server time */
+               timestamp = get_server_time ();
 
        gtk_window_present_with_time (window, timestamp);
        gtk_window_set_skip_taskbar_hint (window, FALSE);