From a2f5a826a1ed79102cd59a9ef17724fb90afe86b Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Mon, 23 Jul 2007 20:55:19 -0400 Subject: move the xerror handling into the libobt --- obt/display.c | 40 +++++++++++++++++++++++++++++++++++++++- obt/display.h | 3 +++ 2 files changed, 42 insertions(+), 1 deletion(-) (limited to 'obt') diff --git a/obt/display.c b/obt/display.c index 049b6aef..b638f9cd 100644 --- a/obt/display.c +++ b/obt/display.c @@ -17,7 +17,6 @@ */ #include "obt/display.h" -#include "obt/util.h" #ifdef HAVE_STRING_H # include @@ -29,6 +28,11 @@ # include #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; +} diff --git a/obt/display.h b/obt/display.h index a42630e1..aafa0fcd 100644 --- a/obt/display.h +++ b/obt/display.h @@ -27,6 +27,9 @@ G_BEGIN_DECLS Display* obt_display_open(const char *display_name); void obt_display_close(Display *d); +void obt_display_ignore_errors(Display *d, gboolean ignore); +gboolean obt_display_error_occured(); + G_END_DECLS #endif /*__obt_instance_h*/ -- cgit v1.2.3