# HG changeset patch # User John Tsiombikas # Date 1454132931 -7200 # Node ID 03ca0fd499165a887a93eb213d25c6f5e8539958 # Parent 3f908f812ec79f061619d45c08d8fc9329d09a34 merged diff -r 3f908f812ec7 -r 03ca0fd49916 src/cwin.cc --- a/src/cwin.cc Fri Jan 29 10:23:08 2016 +0200 +++ b/src/cwin.cc Sat Jan 30 07:48:51 2016 +0200 @@ -1,9 +1,13 @@ #include #include #include +#include +#include #include "cwin.h" #include "logger.h" +extern Display *dpy; + static std::vector cwinlist; CompWindow::CompWindow(Window xid) @@ -12,6 +16,17 @@ xpixmap = 0; memset(&attr, 0, sizeof attr); mapped = false; + damage = 0; +} + +CompWindow::~CompWindow() +{ + if(xpixmap) { + XFreePixmap(dpy, xpixmap); + } + if(damage) { + XDamageDestroy(dpy, damage); + } } void add_window(CompWindow *cwin) @@ -21,6 +36,11 @@ return; } + // create the damage structure to track dirty regions in this window + if(!cwin->damage) { + cwin->damage = XDamageCreate(dpy, cwin->xwin, XDamageReportNonEmpty); + } + cwinlist.push_back(cwin); } diff -r 3f908f812ec7 -r 03ca0fd49916 src/cwin.h --- a/src/cwin.h Fri Jan 29 10:23:08 2016 +0200 +++ b/src/cwin.h Sat Jan 30 07:48:51 2016 +0200 @@ -2,6 +2,7 @@ #define COMP_WIN_H_ #include +#include #include "texture.h" class CompWindow { @@ -12,9 +13,13 @@ XWindowAttributes attr; bool mapped; + Damage damage; + XRectangle damage_rect; + Texture tex; CompWindow(Window xid = 0); + ~CompWindow(); }; void add_window(CompWindow *cwin); diff -r 3f908f812ec7 -r 03ca0fd49916 src/main.cc --- a/src/main.cc Fri Jan 29 10:23:08 2016 +0200 +++ b/src/main.cc Sat Jan 30 07:48:51 2016 +0200 @@ -16,6 +16,7 @@ static void start_comp(); static void manage_window(Window xwin); static void unmanage_window(Window xwin); +static void damage_window(XDamageNotifyEvent *ev); static void redraw(); static void draw_window(CompWindow *cwin); static void reshape(int x, int y); @@ -108,6 +109,7 @@ default: if(ev.type == xdmg_ev_base + XDamageNotify) { + damage_window((XDamageNotifyEvent*)&ev); } } @@ -217,14 +219,20 @@ CompWindow *cwin = find_window_xid(xwin); if(!cwin) return; - if(cwin->xpixmap) { - XFreePixmap(dpy, cwin->xpixmap); - } - remove_window(cwin); delete cwin; } +static void damage_window(XDamageNotifyEvent *ev) +{ + XserverRegion region; + CompWindow *cwin = find_window_xid(ev->drawable); + if(!cwin) return; + + region = XFixesCreateRegion(dpy, 0, 0); + XDamageSubtract(dpy, cwin->damage, None, region); +} + static void redraw() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);