xglcomp

annotate src/cwin.cc @ 7:03ca0fd49916

merged
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 30 Jan 2016 07:48:51 +0200
parents e831d38e6faa
children b0081a0c211f
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@7 39 // create the damage structure to track dirty regions in this window
nuclear@7 40 if(!cwin->damage) {
nuclear@7 41 cwin->damage = XDamageCreate(dpy, cwin->xwin, XDamageReportNonEmpty);
nuclear@7 42 }
nuclear@7 43
nuclear@0 44 cwinlist.push_back(cwin);
nuclear@0 45 }
nuclear@0 46
nuclear@2 47 bool remove_window(CompWindow *cwin)
nuclear@1 48 {
nuclear@1 49 auto it = std::find(cwinlist.begin(), cwinlist.end(), cwin);
nuclear@1 50 if(it != cwinlist.end()) {
nuclear@1 51 cwinlist.erase(it);
nuclear@1 52 return true;
nuclear@1 53 }
nuclear@1 54 return false;
nuclear@1 55 }
nuclear@1 56
nuclear@1 57 bool have_window(CompWindow *cwin)
nuclear@1 58 {
nuclear@1 59 return std::find(cwinlist.begin(), cwinlist.end(), cwin) != cwinlist.end();
nuclear@1 60 }
nuclear@1 61
nuclear@1 62 CompWindow *find_window_xid(Window xid)
nuclear@1 63 {
nuclear@1 64 if(!xid) return 0;
nuclear@1 65
nuclear@1 66 for(size_t i=0; i<cwinlist.size(); i++) {
nuclear@1 67 if(cwinlist[i]->xwin == xid) {
nuclear@1 68 return cwinlist[i];
nuclear@1 69 }
nuclear@1 70 }
nuclear@1 71 return 0;
nuclear@1 72 }
nuclear@1 73
nuclear@1 74 CompWindow *find_window_pixmap(Pixmap pix)
nuclear@1 75 {
nuclear@1 76 if(!pix) return 0;
nuclear@1 77
nuclear@1 78 for(size_t i=0; i<cwinlist.size(); i++) {
nuclear@1 79 if(cwinlist[i]->xpixmap == pix) {
nuclear@1 80 return cwinlist[i];
nuclear@1 81 }
nuclear@1 82 }
nuclear@1 83 return 0;
nuclear@1 84 }
nuclear@1 85
nuclear@1 86 int get_window_count()
nuclear@1 87 {
nuclear@1 88 return (int)cwinlist.size();
nuclear@1 89 }
nuclear@1 90
nuclear@1 91 CompWindow *get_window(int idx)
nuclear@1 92 {
nuclear@1 93 if(idx < 0 || idx >= (int)cwinlist.size()) {
nuclear@1 94 return 0;
nuclear@1 95 }
nuclear@1 96 return cwinlist[idx];
nuclear@1 97 }