]> Dogcows Code - chaz/openbox/blobdiff - obt/display.c
move the xerror handling into the libobt
[chaz/openbox] / obt / display.c
index 049b6aefed2eac4fb6338023e97cb83f000a2de5..b638f9cdf23c1305fef45860ce554c238aa8c9f0 100644 (file)
@@ -17,7 +17,6 @@
 */
 
 #include "obt/display.h"
-#include "obt/util.h"
 
 #ifdef HAVE_STRING_H
 #  include <string.h>
 #  include <unistd.h>
 #endif
 
+static gint xerror_handler(Display *d, XErrorEvent *e);
+
+static gboolean xerror_ignore = FALSE;
+static gboolean xerror_occured = FALSE;
+
 Display* obt_display_open(const char *display_name)
 {
     gchar *n;
@@ -39,6 +43,7 @@ Display* obt_display_open(const char *display_name)
     if (d) {
         if (fcntl(ConnectionNumber(d), F_SETFD, 1) == -1)
             g_message("Failed to set display as close-on-exec");
+        XSetErrorHandler(xerror_handler);
     }
     g_free(n);
 
@@ -49,3 +54,36 @@ void obt_display_close(Display *d)
 {
     if (d) XCloseDisplay(d);
 }
+
+static gint xerror_handler(Display *d, XErrorEvent *e)
+{
+#ifdef DEBUG
+    gchar errtxt[128];
+
+    XGetErrorText(d, e->error_code, errtxt, 127);
+    if (!xerror_ignore) {
+        if (e->error_code == BadWindow)
+            /*g_message(_("X Error: %s\n"), errtxt)*/;
+        else
+            g_error("X Error: %s", errtxt);
+    } else
+        g_message("XError code %d '%s'", e->error_code, errtxt);
+#else
+    (void)d; (void)e;
+#endif
+
+    xerror_occured = TRUE;
+    return 0;
+}
+
+void obt_display_ignore_errors(Display *d, gboolean ignore)
+{
+    XSync(d, FALSE);
+    xerror_ignore = ignore;
+    if (ignore) xerror_occured = FALSE;
+}
+
+gboolean obt_display_error_occured()
+{
+    return xerror_occured;
+}
This page took 0.021764 seconds and 4 git commands to generate.