xglcomp

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