xglcomp
changeset 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 | 57050ca14de6 |
children | 3f908f812ec7 |
files | Makefile src/main.cc |
diffstat | 2 files changed, 64 insertions(+), 20 deletions(-) [+] |
line diff
1.1 --- a/Makefile Fri Jan 22 22:33:34 2016 +0200 1.2 +++ b/Makefile Fri Jan 29 10:22:58 2016 +0200 1.3 @@ -13,7 +13,7 @@ 1.4 1.5 CFLAGS = $(warn) $(dbg) $(opt) $(incpaths) 1.6 CXXFLAGS = -std=c++11 $(warn) $(dbg) $(opt) $(incpaths) 1.7 -LDFLAGS = -lGL -lGLEW -lX11 -lXext -lXcomposite -lXdamage -lm -lpthread 1.8 +LDFLAGS = -lGL -lGLEW -lX11 -lXext -lXcomposite -lXdamage -lXfixes -lm -lpthread 1.9 1.10 $(bin): $(obj) 1.11 $(CXX) -o $@ $(obj) $(LDFLAGS)
2.1 --- a/src/main.cc Fri Jan 22 22:33:34 2016 +0200 2.2 +++ b/src/main.cc Fri Jan 29 10:22:58 2016 +0200 2.3 @@ -6,10 +6,12 @@ 2.4 #include <X11/Xatom.h> 2.5 #include <X11/extensions/Xcomposite.h> 2.6 #include <X11/extensions/Xdamage.h> 2.7 +#include <X11/extensions/shape.h> 2.8 #include "cwin.h" 2.9 #include "opengl.h" 2.10 #include "logger.h" 2.11 2.12 +static bool query_extensions(); 2.13 static bool register_compositor(); 2.14 static void start_comp(); 2.15 static void manage_window(Window xwin); 2.16 @@ -23,6 +25,9 @@ 2.17 Window root_win, comp_win; 2.18 int root_width, root_height; 2.19 2.20 +static int xdmg_ev_base, xdmg_err_base; 2.21 +static int xshape_ev_base, xshape_err_base; 2.22 + 2.23 int main(int argc, char **argv) 2.24 { 2.25 if(!(dpy = XOpenDisplay(0))) { 2.26 @@ -35,26 +40,9 @@ 2.27 root_height = DisplayHeight(dpy, screen_num); 2.28 log_info("display size %dx%d\n", root_width, root_height); 2.29 2.30 - int xcomp_ev_base, xcomp_err_base; 2.31 - if(!XCompositeQueryExtension(dpy, &xcomp_ev_base, &xcomp_err_base)) { 2.32 - log_error("X server doesn't support the composite extension\n"); 2.33 + if(!query_extensions()) { 2.34 return 1; 2.35 } 2.36 - int xcomp_ver_major = 0, xcomp_ver_minor = 4; 2.37 - XCompositeQueryVersion(dpy, &xcomp_ver_major, &xcomp_ver_minor); 2.38 - log_info("Found composite extension version %d.%d\n", xcomp_ver_major, xcomp_ver_minor); 2.39 - if(xcomp_ver_major <= 0 && xcomp_ver_minor < 3) { 2.40 - // for NameWindowPixmap & CompositeGetoverlayWindow 2.41 - log_error("I need at least version 0.3\n"); 2.42 - return 1; 2.43 - } 2.44 - 2.45 - int xdmg_ev_base, xdmg_err_base; 2.46 - if(!XDamageQueryExtension(dpy, &xdmg_ev_base, &xdmg_err_base)) { 2.47 - log_error("X server doesn't support the damage extension\n"); 2.48 - return 1; 2.49 - } 2.50 - // TODO also XFixes ? 2.51 2.52 if(!register_compositor()) { 2.53 return 1; 2.54 @@ -80,6 +68,11 @@ 2.55 break; 2.56 2.57 case ConfigureNotify: 2.58 + // XXX is this right? 2.59 + if((cwin = find_window_xid(ev.xconfigure.window))) { 2.60 + log_debug("updating window attributes\n"); 2.61 + XGetWindowAttributes(dpy, cwin->xwin, &cwin->attr); 2.62 + } 2.63 break; 2.64 2.65 case DestroyNotify: 2.66 @@ -117,9 +110,54 @@ 2.67 if(ev.type == xdmg_ev_base + XDamageNotify) { 2.68 } 2.69 } 2.70 + 2.71 + redraw(); 2.72 } 2.73 } 2.74 2.75 +static bool query_extensions() 2.76 +{ 2.77 + int xcomp_ev_base, xcomp_err_base; 2.78 + if(!XCompositeQueryExtension(dpy, &xcomp_ev_base, &xcomp_err_base)) { 2.79 + log_error("X server doesn't support the composite extension\n"); 2.80 + return false; 2.81 + } 2.82 + int xcomp_ver_major, xcomp_ver_minor; 2.83 + XCompositeQueryVersion(dpy, &xcomp_ver_major, &xcomp_ver_minor); 2.84 + log_info("Found composite extension version %d.%d\n", xcomp_ver_major, xcomp_ver_minor); 2.85 + if(xcomp_ver_major <= 0 && xcomp_ver_minor < 3) { 2.86 + // for NameWindowPixmap & CompositeGetoverlayWindow 2.87 + log_error("I need at least version 0.3\n"); 2.88 + return false; 2.89 + } 2.90 + 2.91 + if(!XDamageQueryExtension(dpy, &xdmg_ev_base, &xdmg_err_base)) { 2.92 + log_error("X server doesn't support the damage extension\n"); 2.93 + return false; 2.94 + } 2.95 + 2.96 + if(!XShapeQueryExtension(dpy, &xshape_ev_base, &xshape_err_base)) { 2.97 + log_error("X server doesn't support the shape extension\n"); 2.98 + return false; 2.99 + } 2.100 + 2.101 + int xfix_ev_base, xfix_err_base; 2.102 + if(!XFixesQueryExtension(dpy, &xfix_ev_base, &xfix_err_base)) { 2.103 + log_error("X server doesn't support the Xfixes extension\n"); 2.104 + return false; 2.105 + } 2.106 + 2.107 + int xfix_ver_major, xfix_ver_minor; 2.108 + XFixesQueryVersion(dpy, &xfix_ver_major, &xfix_ver_minor); 2.109 + log_info("Found xfixes version %d.%d\n", xfix_ver_major, xfix_ver_minor); 2.110 + if(xfix_ver_major < 2) { 2.111 + // for SetWindowShapeRegion 2.112 + log_error("I need at least version 2.0\n"); 2.113 + return false; 2.114 + } 2.115 + return true; 2.116 +} 2.117 + 2.118 static bool register_compositor() 2.119 { 2.120 char atom_name[64]; 2.121 @@ -154,8 +192,14 @@ 2.122 } 2.123 log_info("starting compositor, managing %u top-level windows\n", num_children); 2.124 XFree(children); 2.125 + XUngrabServer(dpy); 2.126 2.127 - XUngrabServer(dpy); 2.128 + /* set a zero-area input-shape for the overlay window to let events 2.129 + * through to the windows under it 2.130 + */ 2.131 + XserverRegion region = XFixesCreateRegion(dpy, 0, 0); 2.132 + XFixesSetWindowShapeRegion(dpy, comp_win, ShapeInput, 0, 0, region); 2.133 + XFixesDestroyRegion(dpy, region); 2.134 } 2.135 2.136 static void manage_window(Window xwin)