xglcomp

annotate 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
rev   line source
nuclear@0 1 #include <vector>
nuclear@1 2 #include <algorithm>
nuclear@0 3 #include "cwin.h"
nuclear@0 4 #include "logger.h"
nuclear@0 5
nuclear@1 6 static std::vector<CompWindow*> cwinlist;
nuclear@0 7
nuclear@0 8 void add_window(CompWindow *cwin)
nuclear@0 9 {
nuclear@0 10 if(have_window(cwin)) {
nuclear@0 11 log_warning("add_window trying to add duplicate, ignoring\n");
nuclear@0 12 return;
nuclear@0 13 }
nuclear@0 14
nuclear@0 15 cwinlist.push_back(cwin);
nuclear@0 16 }
nuclear@0 17
nuclear@1 18 bool delete_window(CompWindow *cwin)
nuclear@1 19 {
nuclear@1 20 auto it = std::find(cwinlist.begin(), cwinlist.end(), cwin);
nuclear@1 21 if(it != cwinlist.end()) {
nuclear@1 22 cwinlist.erase(it);
nuclear@1 23 return true;
nuclear@1 24 }
nuclear@1 25 return false;
nuclear@1 26 }
nuclear@1 27
nuclear@1 28 bool have_window(CompWindow *cwin)
nuclear@1 29 {
nuclear@1 30 return std::find(cwinlist.begin(), cwinlist.end(), cwin) != cwinlist.end();
nuclear@1 31 }
nuclear@1 32
nuclear@1 33 CompWindow *find_window_xid(Window xid)
nuclear@1 34 {
nuclear@1 35 if(!xid) return 0;
nuclear@1 36
nuclear@1 37 for(size_t i=0; i<cwinlist.size(); i++) {
nuclear@1 38 if(cwinlist[i]->xwin == xid) {
nuclear@1 39 return cwinlist[i];
nuclear@1 40 }
nuclear@1 41 }
nuclear@1 42 return 0;
nuclear@1 43 }
nuclear@1 44
nuclear@1 45 CompWindow *find_window_pixmap(Pixmap pix)
nuclear@1 46 {
nuclear@1 47 if(!pix) return 0;
nuclear@1 48
nuclear@1 49 for(size_t i=0; i<cwinlist.size(); i++) {
nuclear@1 50 if(cwinlist[i]->xpixmap == pix) {
nuclear@1 51 return cwinlist[i];
nuclear@1 52 }
nuclear@1 53 }
nuclear@1 54 return 0;
nuclear@1 55 }
nuclear@1 56
nuclear@1 57 int get_window_count()
nuclear@1 58 {
nuclear@1 59 return (int)cwinlist.size();
nuclear@1 60 }
nuclear@1 61
nuclear@1 62 CompWindow *get_window(int idx)
nuclear@1 63 {
nuclear@1 64 if(idx < 0 || idx >= (int)cwinlist.size()) {
nuclear@1 65 return 0;
nuclear@1 66 }
nuclear@1 67 return cwinlist[idx];
nuclear@1 68 }