xglcomp

diff src/main.cc @ 5:86e57e56a454

passing events through the overlay window
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 29 Jan 2016 10:22:58 +0200
parents e831d38e6faa
children 03ca0fd49916
line diff
     1.1 --- a/src/main.cc	Fri Jan 22 22:33:34 2016 +0200
     1.2 +++ b/src/main.cc	Fri Jan 29 10:22:58 2016 +0200
     1.3 @@ -6,10 +6,12 @@
     1.4  #include <X11/Xatom.h>
     1.5  #include <X11/extensions/Xcomposite.h>
     1.6  #include <X11/extensions/Xdamage.h>
     1.7 +#include <X11/extensions/shape.h>
     1.8  #include "cwin.h"
     1.9  #include "opengl.h"
    1.10  #include "logger.h"
    1.11  
    1.12 +static bool query_extensions();
    1.13  static bool register_compositor();
    1.14  static void start_comp();
    1.15  static void manage_window(Window xwin);
    1.16 @@ -23,6 +25,9 @@
    1.17  Window root_win, comp_win;
    1.18  int root_width, root_height;
    1.19  
    1.20 +static int xdmg_ev_base, xdmg_err_base;
    1.21 +static int xshape_ev_base, xshape_err_base;
    1.22 +
    1.23  int main(int argc, char **argv)
    1.24  {
    1.25  	if(!(dpy = XOpenDisplay(0))) {
    1.26 @@ -35,26 +40,9 @@
    1.27  	root_height = DisplayHeight(dpy, screen_num);
    1.28  	log_info("display size %dx%d\n", root_width, root_height);
    1.29  
    1.30 -	int xcomp_ev_base, xcomp_err_base;
    1.31 -	if(!XCompositeQueryExtension(dpy, &xcomp_ev_base, &xcomp_err_base)) {
    1.32 -		log_error("X server doesn't support the composite extension\n");
    1.33 +	if(!query_extensions()) {
    1.34  		return 1;
    1.35  	}
    1.36 -	int xcomp_ver_major = 0, xcomp_ver_minor = 4;
    1.37 -	XCompositeQueryVersion(dpy, &xcomp_ver_major, &xcomp_ver_minor);
    1.38 -	log_info("Found composite extension version %d.%d\n", xcomp_ver_major, xcomp_ver_minor);
    1.39 -	if(xcomp_ver_major <= 0 && xcomp_ver_minor < 3) {
    1.40 -		// for NameWindowPixmap & CompositeGetoverlayWindow
    1.41 -		log_error("I need at least version 0.3\n");
    1.42 -		return 1;
    1.43 -	}
    1.44 -
    1.45 -	int xdmg_ev_base, xdmg_err_base;
    1.46 -	if(!XDamageQueryExtension(dpy, &xdmg_ev_base, &xdmg_err_base)) {
    1.47 -		log_error("X server doesn't support the damage extension\n");
    1.48 -		return 1;
    1.49 -	}
    1.50 -	// TODO also XFixes ?
    1.51  
    1.52  	if(!register_compositor()) {
    1.53  		return 1;
    1.54 @@ -80,6 +68,11 @@
    1.55  			break;
    1.56  
    1.57  		case ConfigureNotify:
    1.58 +			// XXX is this right?
    1.59 +			if((cwin = find_window_xid(ev.xconfigure.window))) {
    1.60 +				log_debug("updating window attributes\n");
    1.61 +				XGetWindowAttributes(dpy, cwin->xwin, &cwin->attr);
    1.62 +			}
    1.63  			break;
    1.64  
    1.65  		case DestroyNotify:
    1.66 @@ -117,9 +110,54 @@
    1.67  			if(ev.type == xdmg_ev_base + XDamageNotify) {
    1.68  			}
    1.69  		}
    1.70 +
    1.71 +		redraw();
    1.72  	}
    1.73  }
    1.74  
    1.75 +static bool query_extensions()
    1.76 +{
    1.77 +	int xcomp_ev_base, xcomp_err_base;
    1.78 +	if(!XCompositeQueryExtension(dpy, &xcomp_ev_base, &xcomp_err_base)) {
    1.79 +		log_error("X server doesn't support the composite extension\n");
    1.80 +		return false;
    1.81 +	}
    1.82 +	int xcomp_ver_major, xcomp_ver_minor;
    1.83 +	XCompositeQueryVersion(dpy, &xcomp_ver_major, &xcomp_ver_minor);
    1.84 +	log_info("Found composite extension version %d.%d\n", xcomp_ver_major, xcomp_ver_minor);
    1.85 +	if(xcomp_ver_major <= 0 && xcomp_ver_minor < 3) {
    1.86 +		// for NameWindowPixmap & CompositeGetoverlayWindow
    1.87 +		log_error("I need at least version 0.3\n");
    1.88 +		return false;
    1.89 +	}
    1.90 +
    1.91 +	if(!XDamageQueryExtension(dpy, &xdmg_ev_base, &xdmg_err_base)) {
    1.92 +		log_error("X server doesn't support the damage extension\n");
    1.93 +		return false;
    1.94 +	}
    1.95 +
    1.96 +	if(!XShapeQueryExtension(dpy, &xshape_ev_base, &xshape_err_base)) {
    1.97 +		log_error("X server doesn't support the shape extension\n");
    1.98 +		return false;
    1.99 +	}
   1.100 +
   1.101 +	int xfix_ev_base, xfix_err_base;
   1.102 +	if(!XFixesQueryExtension(dpy, &xfix_ev_base, &xfix_err_base)) {
   1.103 +		log_error("X server doesn't support the Xfixes extension\n");
   1.104 +		return false;
   1.105 +	}
   1.106 +
   1.107 +	int xfix_ver_major, xfix_ver_minor;
   1.108 +	XFixesQueryVersion(dpy, &xfix_ver_major, &xfix_ver_minor);
   1.109 +	log_info("Found xfixes version %d.%d\n", xfix_ver_major, xfix_ver_minor);
   1.110 +	if(xfix_ver_major < 2) {
   1.111 +		// for SetWindowShapeRegion
   1.112 +		log_error("I need at least version 2.0\n");
   1.113 +		return false;
   1.114 +	}
   1.115 +	return true;
   1.116 +}
   1.117 +
   1.118  static bool register_compositor()
   1.119  {
   1.120  	char atom_name[64];
   1.121 @@ -154,8 +192,14 @@
   1.122  	}
   1.123  	log_info("starting compositor, managing %u top-level windows\n", num_children);
   1.124  	XFree(children);
   1.125 +	XUngrabServer(dpy);
   1.126  
   1.127 -	XUngrabServer(dpy);
   1.128 +	/* set a zero-area input-shape for the overlay window to let events
   1.129 +	 * through to the windows under it
   1.130 +	 */
   1.131 +	XserverRegion region = XFixesCreateRegion(dpy, 0, 0);
   1.132 +	XFixesSetWindowShapeRegion(dpy, comp_win, ShapeInput, 0, 0, region);
   1.133 +	XFixesDestroyRegion(dpy, region);
   1.134  }
   1.135  
   1.136  static void manage_window(Window xwin)