xglcomp

diff 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
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/xerr.cc	Tue Feb 02 12:54:02 2016 +0200
     1.3 @@ -0,0 +1,35 @@
     1.4 +#include <stack>
     1.5 +#include "xerr.h"
     1.6 +#include "logger.h"
     1.7 +
     1.8 +static std::stack<xerr_handler_type> func_stack;
     1.9 +
    1.10 +void push_xerr_handler(xerr_handler_type func)
    1.11 +{
    1.12 +	func_stack.push(func);
    1.13 +	XSetErrorHandler(func);
    1.14 +}
    1.15 +
    1.16 +void pop_xerr_handler()
    1.17 +{
    1.18 +	if(func_stack.empty()) {
    1.19 +		log_error("attempt to pop_xerr_handler with an empty stack\n");
    1.20 +		return;
    1.21 +	}
    1.22 +	xerr_handler_type prev = func_stack.top();
    1.23 +	func_stack.pop();
    1.24 +	XSetErrorHandler(prev);
    1.25 +}
    1.26 +
    1.27 +int xerr_debug(Display *dpy, XErrorEvent *err)
    1.28 +{
    1.29 +	char errstr[512];
    1.30 +	XGetErrorText(dpy, err->error_code, errstr, sizeof errstr);
    1.31 +	printf("X error caught:\n%s\n", errstr);
    1.32 +	return 0;
    1.33 +}
    1.34 +
    1.35 +int xerr_ignore(Display *dpy, XErrorEvent *err)
    1.36 +{
    1.37 +	return 0;
    1.38 +}