From f8e05a9f3004b5d6cb135512785283e003f0c16e Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 11 Dec 2015 18:35:20 +0200 Subject: [PATCH] Ignore errors from the X server Events don't provide enough information to perform all necessary operations atomically, so some errors are unavoidable. --- source/main.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/source/main.c b/source/main.c index 561159d..ae9bc4f 100644 --- a/source/main.c +++ b/source/main.c @@ -87,6 +87,13 @@ static const float vertices[] = 1.0f, 0.0f }; +int x_error_handler(Display *display, XErrorEvent *event) +{ + printf("Ignoring X error %d on resource %lx\n", event->error_code, event->resourceid); + (void)display; + return 0; +} + int with_error(const char *message) { fprintf(stderr, "%s\n", message); @@ -258,7 +265,11 @@ void add_window(Compositor *compositor, CompositedScreen *screen, Window w) if(w==screen->root || w==screen->overlay) return; - XGetWindowAttributes(compositor->display, w, &win_attr); + if(!XGetWindowAttributes(compositor->display, w, &win_attr)) + { + printf("XGetWindowAttributes failed; probably the window was already destroyed\n"); + return; + } if(win_attr.class==InputOnly) return; @@ -379,6 +390,8 @@ int initialize_compositor(Compositor *compositor) if(!compositor->display) return with_error("Could not open X display"); + XSetErrorHandler(&x_error_handler); + if(!XCompositeQueryExtension(compositor->display, &event_base, &error_base)) return with_error("XComposite is required but was not found"); else if(!XCompositeQueryVersion(compositor->display, &major_ver, &minor_ver)) -- 2.45.2