xglcomp

view src/cwin.cc @ 2:876efea9424c

OpenGL
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 22 Jan 2016 06:31:03 +0200
parents b2b7cb950c28
children e831d38e6faa
line source
1 #include <vector>
2 #include <algorithm>
3 #include "cwin.h"
4 #include "logger.h"
6 static std::vector<CompWindow*> cwinlist;
8 CompWindow::CompWindow(Window xid)
9 {
10 xwin = xid;
11 xpixmap = 0;
12 }
14 void add_window(CompWindow *cwin)
15 {
16 if(have_window(cwin)) {
17 log_warning("add_window trying to add duplicate, ignoring\n");
18 return;
19 }
21 cwinlist.push_back(cwin);
22 }
24 bool remove_window(CompWindow *cwin)
25 {
26 auto it = std::find(cwinlist.begin(), cwinlist.end(), cwin);
27 if(it != cwinlist.end()) {
28 cwinlist.erase(it);
29 return true;
30 }
31 return false;
32 }
34 bool have_window(CompWindow *cwin)
35 {
36 return std::find(cwinlist.begin(), cwinlist.end(), cwin) != cwinlist.end();
37 }
39 CompWindow *find_window_xid(Window xid)
40 {
41 if(!xid) return 0;
43 for(size_t i=0; i<cwinlist.size(); i++) {
44 if(cwinlist[i]->xwin == xid) {
45 return cwinlist[i];
46 }
47 }
48 return 0;
49 }
51 CompWindow *find_window_pixmap(Pixmap pix)
52 {
53 if(!pix) return 0;
55 for(size_t i=0; i<cwinlist.size(); i++) {
56 if(cwinlist[i]->xpixmap == pix) {
57 return cwinlist[i];
58 }
59 }
60 return 0;
61 }
63 int get_window_count()
64 {
65 return (int)cwinlist.size();
66 }
68 CompWindow *get_window(int idx)
69 {
70 if(idx < 0 || idx >= (int)cwinlist.size()) {
71 return 0;
72 }
73 return cwinlist[idx];
74 }