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