xglcomp

annotate src/cwin.cc @ 8:b0081a0c211f

damage issues
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 30 Jan 2016 07:58:07 +0200
parents 03ca0fd49916
children 1c0d056ec360
rev   line source
nuclear@3 1 #include <string.h>
nuclear@0 2 #include <vector>
nuclear@1 3 #include <algorithm>
nuclear@7 4 #include <X11/Xlib.h>
nuclear@7 5 #include <X11/extensions/Xdamage.h>
nuclear@0 6 #include "cwin.h"
nuclear@0 7 #include "logger.h"
nuclear@0 8
nuclear@7 9 extern Display *dpy;
nuclear@7 10
nuclear@1 11 static std::vector<CompWindow*> cwinlist;
nuclear@0 12
nuclear@2 13 CompWindow::CompWindow(Window xid)
nuclear@2 14 {
nuclear@2 15 xwin = xid;
nuclear@2 16 xpixmap = 0;
nuclear@3 17 memset(&attr, 0, sizeof attr);
nuclear@3 18 mapped = false;
nuclear@7 19 damage = 0;
nuclear@7 20 }
nuclear@7 21
nuclear@7 22 CompWindow::~CompWindow()
nuclear@7 23 {
nuclear@7 24 if(xpixmap) {
nuclear@7 25 XFreePixmap(dpy, xpixmap);
nuclear@7 26 }
nuclear@7 27 if(damage) {
nuclear@7 28 XDamageDestroy(dpy, damage);
nuclear@7 29 }
nuclear@2 30 }
nuclear@2 31
nuclear@0 32 void add_window(CompWindow *cwin)
nuclear@0 33 {
nuclear@0 34 if(have_window(cwin)) {
nuclear@0 35 log_warning("add_window trying to add duplicate, ignoring\n");
nuclear@0 36 return;
nuclear@0 37 }
nuclear@0 38
nuclear@8 39 XGetWindowAttributes(dpy, cwin->xwin, &cwin->attr);
nuclear@8 40
nuclear@7 41 // create the damage structure to track dirty regions in this window
nuclear@8 42 if(!cwin->damage && cwin->attr.c_class != InputOnly) {
nuclear@7 43 cwin->damage = XDamageCreate(dpy, cwin->xwin, XDamageReportNonEmpty);
nuclear@7 44 }
nuclear@7 45
nuclear@0 46 cwinlist.push_back(cwin);
nuclear@0 47 }
nuclear@0 48
nuclear@2 49 bool remove_window(CompWindow *cwin)
nuclear@1 50 {
nuclear@1 51 auto it = std::find(cwinlist.begin(), cwinlist.end(), cwin);
nuclear@1 52 if(it != cwinlist.end()) {
nuclear@1 53 cwinlist.erase(it);
nuclear@1 54 return true;
nuclear@1 55 }
nuclear@1 56 return false;
nuclear@1 57 }
nuclear@1 58
nuclear@1 59 bool have_window(CompWindow *cwin)
nuclear@1 60 {
nuclear@1 61 return std::find(cwinlist.begin(), cwinlist.end(), cwin) != cwinlist.end();
nuclear@1 62 }
nuclear@1 63
nuclear@1 64 CompWindow *find_window_xid(Window xid)
nuclear@1 65 {
nuclear@1 66 if(!xid) return 0;
nuclear@1 67
nuclear@1 68 for(size_t i=0; i<cwinlist.size(); i++) {
nuclear@1 69 if(cwinlist[i]->xwin == xid) {
nuclear@1 70 return cwinlist[i];
nuclear@1 71 }
nuclear@1 72 }
nuclear@1 73 return 0;
nuclear@1 74 }
nuclear@1 75
nuclear@1 76 CompWindow *find_window_pixmap(Pixmap pix)
nuclear@1 77 {
nuclear@1 78 if(!pix) return 0;
nuclear@1 79
nuclear@1 80 for(size_t i=0; i<cwinlist.size(); i++) {
nuclear@1 81 if(cwinlist[i]->xpixmap == pix) {
nuclear@1 82 return cwinlist[i];
nuclear@1 83 }
nuclear@1 84 }
nuclear@1 85 return 0;
nuclear@1 86 }
nuclear@1 87
nuclear@1 88 int get_window_count()
nuclear@1 89 {
nuclear@1 90 return (int)cwinlist.size();
nuclear@1 91 }
nuclear@1 92
nuclear@1 93 CompWindow *get_window(int idx)
nuclear@1 94 {
nuclear@1 95 if(idx < 0 || idx >= (int)cwinlist.size()) {
nuclear@1 96 return 0;
nuclear@1 97 }
nuclear@1 98 return cwinlist[idx];
nuclear@1 99 }