xglcomp

view src/cwin.cc @ 1:b2b7cb950c28

window list and compositor registration
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 21 Jan 2016 22:50:10 +0200
parents d9b3fba68705
children 876efea9424c
line source
1 #include <vector>
2 #include <algorithm>
3 #include "cwin.h"
4 #include "logger.h"
6 static std::vector<CompWindow*> cwinlist;
8 void add_window(CompWindow *cwin)
9 {
10 if(have_window(cwin)) {
11 log_warning("add_window trying to add duplicate, ignoring\n");
12 return;
13 }
15 cwinlist.push_back(cwin);
16 }
18 bool delete_window(CompWindow *cwin)
19 {
20 auto it = std::find(cwinlist.begin(), cwinlist.end(), cwin);
21 if(it != cwinlist.end()) {
22 cwinlist.erase(it);
23 return true;
24 }
25 return false;
26 }
28 bool have_window(CompWindow *cwin)
29 {
30 return std::find(cwinlist.begin(), cwinlist.end(), cwin) != cwinlist.end();
31 }
33 CompWindow *find_window_xid(Window xid)
34 {
35 if(!xid) return 0;
37 for(size_t i=0; i<cwinlist.size(); i++) {
38 if(cwinlist[i]->xwin == xid) {
39 return cwinlist[i];
40 }
41 }
42 return 0;
43 }
45 CompWindow *find_window_pixmap(Pixmap pix)
46 {
47 if(!pix) return 0;
49 for(size_t i=0; i<cwinlist.size(); i++) {
50 if(cwinlist[i]->xpixmap == pix) {
51 return cwinlist[i];
52 }
53 }
54 return 0;
55 }
57 int get_window_count()
58 {
59 return (int)cwinlist.size();
60 }
62 CompWindow *get_window(int idx)
63 {
64 if(idx < 0 || idx >= (int)cwinlist.size()) {
65 return 0;
66 }
67 return cwinlist[idx];
68 }