diff finch/plugins/gntgf.c @ 16320:94843d812e69

Gracefully do nothing if the WINDOWID is invalid. And plug a leak, thanks to deryni.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Mon, 23 Apr 2007 06:28:18 +0000
parents 4c707efebc0c
children 30829e806dae
line wrap: on
line diff
--- a/finch/plugins/gntgf.c	Sun Apr 22 23:56:41 2007 +0000
+++ b/finch/plugins/gntgf.c	Mon Apr 23 06:28:18 2007 +0000
@@ -111,6 +111,15 @@
 }
 
 #ifdef HAVE_X11
+static int
+error_handler(Display *dpy, XErrorEvent *error)
+{
+	char buffer[1024];
+	XGetErrorText(dpy, error->error_code, buffer, sizeof(buffer));
+	purple_debug_error("gntgf", "Could not set urgent to the window: %s.\n", buffer);
+	return 0;
+}
+
 static void
 urgent()
 {
@@ -130,9 +139,14 @@
 	if (dpy == NULL)
 		return;
 
+	XSetErrorHandler(error_handler);
 	hints = XGetWMHints(dpy, id);
-	hints->flags|=XUrgencyHint;
-	XSetWMHints(dpy, id, hints);
+	if (hints) {
+		hints->flags|=XUrgencyHint;
+		XSetWMHints(dpy, id, hints);
+		XFree(hints);
+	}
+	XSetErrorHandler(NULL);
 
 	XFlush(dpy);
 	XCloseDisplay(dpy);