xglcomp

view src/xerr.cc @ 10:be18500d76d1

better error message in xerr_debug
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 03 Feb 2016 03:55:52 +0200
parents 245dd960f0b3
children cb636a23f4f2
line source
1 #include <stack>
2 #include "xerr.h"
3 #include "logger.h"
5 static std::stack<xerr_handler_type> func_stack;
7 void push_xerr_handler(xerr_handler_type func)
8 {
9 func_stack.push(func);
10 XSetErrorHandler(func);
11 }
13 void pop_xerr_handler()
14 {
15 if(func_stack.empty()) {
16 log_error("attempt to pop_xerr_handler with an empty stack\n");
17 return;
18 }
19 xerr_handler_type prev = func_stack.top();
20 func_stack.pop();
21 XSetErrorHandler(prev);
22 }
24 int xerr_debug(Display *dpy, XErrorEvent *err)
25 {
26 char errstr[512];
27 XGetErrorText(dpy, err->error_code, errstr, sizeof errstr);
28 printf("X error caught: \n%s (code: %u)\n", errstr, err->error_code);
29 printf(" Failed request number: %lu (%u,%u)\n", err->serial,
30 (unsigned int)err->request_code, (unsigned int)err->minor_code);
31 printf(" Resource: %lx\n", err->resourceid);
32 return 0;
33 }
35 int xerr_ignore(Display *dpy, XErrorEvent *err)
36 {
37 return 0;
38 }