xglcomp

annotate src/xerr.cc @ 9:245dd960f0b3

added xerror handling helpers
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 02 Feb 2016 12:54:02 +0200
parents
children be18500d76d1
rev   line source
nuclear@9 1 #include <stack>
nuclear@9 2 #include "xerr.h"
nuclear@9 3 #include "logger.h"
nuclear@9 4
nuclear@9 5 static std::stack<xerr_handler_type> func_stack;
nuclear@9 6
nuclear@9 7 void push_xerr_handler(xerr_handler_type func)
nuclear@9 8 {
nuclear@9 9 func_stack.push(func);
nuclear@9 10 XSetErrorHandler(func);
nuclear@9 11 }
nuclear@9 12
nuclear@9 13 void pop_xerr_handler()
nuclear@9 14 {
nuclear@9 15 if(func_stack.empty()) {
nuclear@9 16 log_error("attempt to pop_xerr_handler with an empty stack\n");
nuclear@9 17 return;
nuclear@9 18 }
nuclear@9 19 xerr_handler_type prev = func_stack.top();
nuclear@9 20 func_stack.pop();
nuclear@9 21 XSetErrorHandler(prev);
nuclear@9 22 }
nuclear@9 23
nuclear@9 24 int xerr_debug(Display *dpy, XErrorEvent *err)
nuclear@9 25 {
nuclear@9 26 char errstr[512];
nuclear@9 27 XGetErrorText(dpy, err->error_code, errstr, sizeof errstr);
nuclear@9 28 printf("X error caught:\n%s\n", errstr);
nuclear@9 29 return 0;
nuclear@9 30 }
nuclear@9 31
nuclear@9 32 int xerr_ignore(Display *dpy, XErrorEvent *err)
nuclear@9 33 {
nuclear@9 34 return 0;
nuclear@9 35 }