xglcomp

view src/cwin.cc @ 6:3f908f812ec7

added docs
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 29 Jan 2016 10:23:08 +0200
parents 876efea9424c
children 03ca0fd49916
line source
1 #include <string.h>
2 #include <vector>
3 #include <algorithm>
4 #include "cwin.h"
5 #include "logger.h"
7 static std::vector<CompWindow*> cwinlist;
9 CompWindow::CompWindow(Window xid)
10 {
11 xwin = xid;
12 xpixmap = 0;
13 memset(&attr, 0, sizeof attr);
14 mapped = false;
15 }
17 void add_window(CompWindow *cwin)
18 {
19 if(have_window(cwin)) {
20 log_warning("add_window trying to add duplicate, ignoring\n");
21 return;
22 }
24 cwinlist.push_back(cwin);
25 }
27 bool remove_window(CompWindow *cwin)
28 {
29 auto it = std::find(cwinlist.begin(), cwinlist.end(), cwin);
30 if(it != cwinlist.end()) {
31 cwinlist.erase(it);
32 return true;
33 }
34 return false;
35 }
37 bool have_window(CompWindow *cwin)
38 {
39 return std::find(cwinlist.begin(), cwinlist.end(), cwin) != cwinlist.end();
40 }
42 CompWindow *find_window_xid(Window xid)
43 {
44 if(!xid) return 0;
46 for(size_t i=0; i<cwinlist.size(); i++) {
47 if(cwinlist[i]->xwin == xid) {
48 return cwinlist[i];
49 }
50 }
51 return 0;
52 }
54 CompWindow *find_window_pixmap(Pixmap pix)
55 {
56 if(!pix) return 0;
58 for(size_t i=0; i<cwinlist.size(); i++) {
59 if(cwinlist[i]->xpixmap == pix) {
60 return cwinlist[i];
61 }
62 }
63 return 0;
64 }
66 int get_window_count()
67 {
68 return (int)cwinlist.size();
69 }
71 CompWindow *get_window(int idx)
72 {
73 if(idx < 0 || idx >= (int)cwinlist.size()) {
74 return 0;
75 }
76 return cwinlist[idx];
77 }