xglcomp

changeset 9:245dd960f0b3

added xerror handling helpers
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 02 Feb 2016 12:54:02 +0200
parents b0081a0c211f
children be18500d76d1
files src/main.cc src/xerr.cc src/xerr.h
diffstat 3 files changed, 58 insertions(+), 2 deletions(-) [+]
line diff
     1.1 --- a/src/main.cc	Sat Jan 30 07:58:07 2016 +0200
     1.2 +++ b/src/main.cc	Tue Feb 02 12:54:02 2016 +0200
     1.3 @@ -10,6 +10,8 @@
     1.4  #include "cwin.h"
     1.5  #include "opengl.h"
     1.6  #include "logger.h"
     1.7 +#include "xerr.h"
     1.8 +
     1.9  
    1.10  static bool query_extensions();
    1.11  static bool register_compositor();
    1.12 @@ -65,18 +67,20 @@
    1.13  		CompWindow *cwin;
    1.14  		switch(ev.type) {
    1.15  		case CreateNotify:
    1.16 +			log_debug("CreateNotify: %x\n", ev.xcreatewindow.window);
    1.17  			manage_window(ev.xcreatewindow.window);
    1.18  			break;
    1.19  
    1.20  		case ConfigureNotify:
    1.21  			// XXX is this right?
    1.22  			if((cwin = find_window_xid(ev.xconfigure.window))) {
    1.23 -				log_debug("updating window attributes\n");
    1.24 +				log_debug("updating window attributes for: %x\n", cwin->xwin);
    1.25  				XGetWindowAttributes(dpy, cwin->xwin, &cwin->attr);
    1.26  			}
    1.27  			break;
    1.28  
    1.29  		case DestroyNotify:
    1.30 +			log_debug("DestroyNotify: %x\n", ev.xdestroywindow.window);
    1.31  			unmanage_window(ev.xdestroywindow.window);
    1.32  			break;
    1.33  
    1.34 @@ -226,10 +230,13 @@
    1.35  {
    1.36  	XserverRegion region;
    1.37  	CompWindow *cwin = find_window_xid(ev->drawable);
    1.38 -	if(!cwin) return;
    1.39 +	if(!cwin || !cwin->damage) return;
    1.40  
    1.41  	region = XFixesCreateRegion(dpy, 0, 0);
    1.42 +
    1.43 +	push_xerr_handler(xerr_debug);
    1.44  	XDamageSubtract(dpy, cwin->damage, None, region);
    1.45 +	pop_xerr_handler();
    1.46  }
    1.47  
    1.48  static void redraw()
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/xerr.cc	Tue Feb 02 12:54:02 2016 +0200
     2.3 @@ -0,0 +1,35 @@
     2.4 +#include <stack>
     2.5 +#include "xerr.h"
     2.6 +#include "logger.h"
     2.7 +
     2.8 +static std::stack<xerr_handler_type> func_stack;
     2.9 +
    2.10 +void push_xerr_handler(xerr_handler_type func)
    2.11 +{
    2.12 +	func_stack.push(func);
    2.13 +	XSetErrorHandler(func);
    2.14 +}
    2.15 +
    2.16 +void pop_xerr_handler()
    2.17 +{
    2.18 +	if(func_stack.empty()) {
    2.19 +		log_error("attempt to pop_xerr_handler with an empty stack\n");
    2.20 +		return;
    2.21 +	}
    2.22 +	xerr_handler_type prev = func_stack.top();
    2.23 +	func_stack.pop();
    2.24 +	XSetErrorHandler(prev);
    2.25 +}
    2.26 +
    2.27 +int xerr_debug(Display *dpy, XErrorEvent *err)
    2.28 +{
    2.29 +	char errstr[512];
    2.30 +	XGetErrorText(dpy, err->error_code, errstr, sizeof errstr);
    2.31 +	printf("X error caught:\n%s\n", errstr);
    2.32 +	return 0;
    2.33 +}
    2.34 +
    2.35 +int xerr_ignore(Display *dpy, XErrorEvent *err)
    2.36 +{
    2.37 +	return 0;
    2.38 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/xerr.h	Tue Feb 02 12:54:02 2016 +0200
     3.3 @@ -0,0 +1,14 @@
     3.4 +#ifndef XERR_H_
     3.5 +#define XERR_H_
     3.6 +
     3.7 +#include <X11/Xlib.h>
     3.8 +
     3.9 +typedef int (*xerr_handler_type)(Display*, XErrorEvent*);
    3.10 +
    3.11 +void push_xerr_handler(xerr_handler_type func);
    3.12 +void pop_xerr_handler();
    3.13 +
    3.14 +int xerr_debug(Display *dpy, XErrorEvent *err);
    3.15 +int xerr_ignore(Display *dpy, XErrorEvent *err);
    3.16 +
    3.17 +#endif	/* XERR_H_ */