# HG changeset patch # User John Tsiombikas # Date 1454410442 -7200 # Node ID 245dd960f0b347724ed755d72ad0ddb8da1c2458 # Parent b0081a0c211f12204f629e6c9ea2bd2db08dbc7d added xerror handling helpers diff -r b0081a0c211f -r 245dd960f0b3 src/main.cc --- a/src/main.cc Sat Jan 30 07:58:07 2016 +0200 +++ b/src/main.cc Tue Feb 02 12:54:02 2016 +0200 @@ -10,6 +10,8 @@ #include "cwin.h" #include "opengl.h" #include "logger.h" +#include "xerr.h" + static bool query_extensions(); static bool register_compositor(); @@ -65,18 +67,20 @@ CompWindow *cwin; switch(ev.type) { case CreateNotify: + log_debug("CreateNotify: %x\n", ev.xcreatewindow.window); manage_window(ev.xcreatewindow.window); break; case ConfigureNotify: // XXX is this right? if((cwin = find_window_xid(ev.xconfigure.window))) { - log_debug("updating window attributes\n"); + log_debug("updating window attributes for: %x\n", cwin->xwin); XGetWindowAttributes(dpy, cwin->xwin, &cwin->attr); } break; case DestroyNotify: + log_debug("DestroyNotify: %x\n", ev.xdestroywindow.window); unmanage_window(ev.xdestroywindow.window); break; @@ -226,10 +230,13 @@ { XserverRegion region; CompWindow *cwin = find_window_xid(ev->drawable); - if(!cwin) return; + if(!cwin || !cwin->damage) return; region = XFixesCreateRegion(dpy, 0, 0); + + push_xerr_handler(xerr_debug); XDamageSubtract(dpy, cwin->damage, None, region); + pop_xerr_handler(); } static void redraw() diff -r b0081a0c211f -r 245dd960f0b3 src/xerr.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/xerr.cc Tue Feb 02 12:54:02 2016 +0200 @@ -0,0 +1,35 @@ +#include +#include "xerr.h" +#include "logger.h" + +static std::stack func_stack; + +void push_xerr_handler(xerr_handler_type func) +{ + func_stack.push(func); + XSetErrorHandler(func); +} + +void pop_xerr_handler() +{ + if(func_stack.empty()) { + log_error("attempt to pop_xerr_handler with an empty stack\n"); + return; + } + xerr_handler_type prev = func_stack.top(); + func_stack.pop(); + XSetErrorHandler(prev); +} + +int xerr_debug(Display *dpy, XErrorEvent *err) +{ + char errstr[512]; + XGetErrorText(dpy, err->error_code, errstr, sizeof errstr); + printf("X error caught:\n%s\n", errstr); + return 0; +} + +int xerr_ignore(Display *dpy, XErrorEvent *err) +{ + return 0; +} diff -r b0081a0c211f -r 245dd960f0b3 src/xerr.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/xerr.h Tue Feb 02 12:54:02 2016 +0200 @@ -0,0 +1,14 @@ +#ifndef XERR_H_ +#define XERR_H_ + +#include + +typedef int (*xerr_handler_type)(Display*, XErrorEvent*); + +void push_xerr_handler(xerr_handler_type func); +void pop_xerr_handler(); + +int xerr_debug(Display *dpy, XErrorEvent *err); +int xerr_ignore(Display *dpy, XErrorEvent *err); + +#endif /* XERR_H_ */