aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy-gtk/empathy-ui-utils.c
diff options
context:
space:
mode:
authorSjoerd Simons <sjoerd.simons@collabora.co.uk>2010-04-24 23:13:50 +0800
committerSjoerd Simons <sjoerd.simons@collabora.co.uk>2010-04-24 23:15:38 +0800
commit97dd1e1301eb2c0e2cfc25c4cda6cd9a8bc447d5 (patch)
tree48743af2e4b7f071f77816672164de88ed000229 /libempathy-gtk/empathy-ui-utils.c
parent694d330bc1eda0fd5bfeb60496378e0843bfd1a6 (diff)
downloadgsoc2013-empathy-97dd1e1301eb2c0e2cfc25c4cda6cd9a8bc447d5.tar
gsoc2013-empathy-97dd1e1301eb2c0e2cfc25c4cda6cd9a8bc447d5.tar.gz
gsoc2013-empathy-97dd1e1301eb2c0e2cfc25c4cda6cd9a8bc447d5.tar.bz2
gsoc2013-empathy-97dd1e1301eb2c0e2cfc25c4cda6cd9a8bc447d5.tar.lz
gsoc2013-empathy-97dd1e1301eb2c0e2cfc25c4cda6cd9a8bc447d5.tar.xz
gsoc2013-empathy-97dd1e1301eb2c0e2cfc25c4cda6cd9a8bc447d5.tar.zst
gsoc2013-empathy-97dd1e1301eb2c0e2cfc25c4cda6cd9a8bc447d5.zip
Fix X display connection leak
Use gdk_x11_get_server_time instead our own function for getting the X server time. This also fixes a leak of one X connection each time empathy_window_present is used without a timestamp.
Diffstat (limited to 'libempathy-gtk/empathy-ui-utils.c')
-rw-r--r--libempathy-gtk/empathy-ui-utils.c64
1 files changed, 12 insertions, 52 deletions
diff --git a/libempathy-gtk/empathy-ui-utils.c b/libempathy-gtk/empathy-ui-utils.c
index 24f22166b..3f37ea2db 100644
--- a/libempathy-gtk/empathy-ui-utils.c
+++ b/libempathy-gtk/empathy-ui-utils.c
@@ -1390,55 +1390,6 @@ 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)
@@ -1467,9 +1418,18 @@ empathy_window_present (GtkWindow *window)
}
timestamp = gtk_get_current_event_time ();
- if (timestamp == 0)
- /* No event, fallback to X server time */
- timestamp = get_server_time ();
+ if (timestamp == 0 && gdk_window != NULL) {
+ GdkEventMask mask;
+
+ /* According to the documentation of gdk_x11_get_server_time
+ * GDK_PROPERTY_CHANGE_MASK needs to be set in its events otherwise a hang
+ * can occur. Be sure to at least temporarily set this mask */
+ mask = gdk_window_get_events (gdk_window);
+ gdk_window_set_events (gdk_window,
+ mask | GDK_PROPERTY_CHANGE_MASK);
+ timestamp = gdk_x11_get_server_time (gdk_window);
+ gdk_window_set_events (gdk_window, mask);
+ }
gtk_window_present_with_time (window, timestamp);
gtk_window_set_skip_taskbar_hint (window, FALSE);