# HG changeset patch # User John Tsiombikas # Date 1453441607 -7200 # Node ID e831d38e6faa2e47b5ab87eb4207aa664d69428a # Parent 876efea9424c209e85d2f1c74c72d93eac063d0b textures diff -r 876efea9424c -r e831d38e6faa src/cwin.cc --- a/src/cwin.cc Fri Jan 22 06:31:03 2016 +0200 +++ b/src/cwin.cc Fri Jan 22 07:46:47 2016 +0200 @@ -1,3 +1,4 @@ +#include #include #include #include "cwin.h" @@ -9,6 +10,8 @@ { xwin = xid; xpixmap = 0; + memset(&attr, 0, sizeof attr); + mapped = false; } void add_window(CompWindow *cwin) diff -r 876efea9424c -r e831d38e6faa src/cwin.h --- a/src/cwin.h Fri Jan 22 06:31:03 2016 +0200 +++ b/src/cwin.h Fri Jan 22 07:46:47 2016 +0200 @@ -2,6 +2,7 @@ #define COMP_WIN_H_ #include +#include "texture.h" class CompWindow { public: @@ -9,6 +10,9 @@ Pixmap xpixmap; XWindowAttributes attr; + bool mapped; + + Texture tex; CompWindow(Window xid = 0); }; diff -r 876efea9424c -r e831d38e6faa src/main.cc --- a/src/main.cc Fri Jan 22 06:31:03 2016 +0200 +++ b/src/main.cc Fri Jan 22 07:46:47 2016 +0200 @@ -15,6 +15,7 @@ static void manage_window(Window xwin); static void unmanage_window(Window xwin); static void redraw(); +static void draw_window(CompWindow *cwin); static void reshape(int x, int y); Display *dpy; @@ -72,6 +73,7 @@ XEvent ev; XNextEvent(dpy, &ev); + CompWindow *cwin; switch(ev.type) { case CreateNotify: manage_window(ev.xcreatewindow.window); @@ -85,8 +87,15 @@ break; case MapNotify: + if((cwin = find_window_xid(ev.xmap.window))) { + cwin->mapped = true; + } break; + case UnmapNotify: + if((cwin = find_window_xid(ev.xunmap.window))) { + cwin->mapped = false; + } break; case ReparentNotify: @@ -101,10 +110,7 @@ break; case Expose: - if(ev.xexpose.window == root_win) { - log_debug("expose\n"); - // TODO - } + // TODO? break; default: @@ -157,6 +163,7 @@ //log_debug("manage_window %u\n", xwin); CompWindow *cwin = new CompWindow(xwin); XGetWindowAttributes(dpy, xwin, &cwin->attr); + cwin->mapped = cwin->attr.map_state != IsUnmapped; add_window(cwin); } @@ -164,16 +171,22 @@ { //log_debug("unmanage_window %u\n", xwin); CompWindow *cwin = find_window_xid(xwin); - if(cwin) { - remove_window(cwin); - delete cwin; + if(!cwin) return; + + if(cwin->xpixmap) { + XFreePixmap(dpy, cwin->xpixmap); } + + remove_window(cwin); + delete cwin; } static void redraw() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glPushAttrib(GL_ENABLE_BIT); + glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_ONE); @@ -181,20 +194,48 @@ for(int i=0; iattr.x, cwin->attr.y); - glVertex2f(cwin->attr.x + cwin->attr.width, cwin->attr.y); - glVertex2f(cwin->attr.x + cwin->attr.width, cwin->attr.y + cwin->attr.height); - glVertex2f(cwin->attr.x, cwin->attr.y + cwin->attr.height); - glEnd(); + if(!cwin->mapped) continue; + + if(cwin->attr.x + cwin->attr.width <= 0 || + cwin->attr.y + cwin->attr.height <= 0 || + cwin->attr.x >= root_width || cwin->attr.y >= root_height) { + continue; + } + + draw_window(cwin); } - glDisable(GL_BLEND); + glPopAttrib(); glXSwapBuffers(dpy, comp_win); } +static void draw_window(CompWindow *cwin) +{ + if(!cwin->xpixmap) { + cwin->xpixmap = XCompositeNameWindowPixmap(dpy, cwin->xwin); + if(!cwin->xpixmap) { + log_warning("failed to get pixmap\n"); + return; + } + cwin->tex.set_image(dpy, cwin->xpixmap); + } + + glBindTexture(GL_TEXTURE_2D, cwin->tex.get_id()); + + glBegin(GL_QUADS); + glColor3f(0.3, 0.3, 0.3); + glTexCoord2f(0, 0); + glVertex2f(cwin->attr.x, cwin->attr.y); + glTexCoord2f(1, 0); + glVertex2f(cwin->attr.x + cwin->attr.width, cwin->attr.y); + glTexCoord2f(1, 1); + glVertex2f(cwin->attr.x + cwin->attr.width, cwin->attr.y + cwin->attr.height); + glTexCoord2f(0, 1); + glVertex2f(cwin->attr.x, cwin->attr.y + cwin->attr.height); + glEnd(); +} + static void reshape(int x, int y) { glViewport(0, 0, x, y);