xglcomp

diff 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 diff
     1.1 --- a/src/cwin.cc	Thu Jan 21 08:45:31 2016 +0200
     1.2 +++ b/src/cwin.cc	Thu Jan 21 22:50:10 2016 +0200
     1.3 @@ -1,8 +1,9 @@
     1.4  #include <vector>
     1.5 +#include <algorithm>
     1.6  #include "cwin.h"
     1.7  #include "logger.h"
     1.8  
     1.9 -static std::vector<CompWindow> cwinlist;
    1.10 +static std::vector<CompWindow*> cwinlist;
    1.11  
    1.12  void add_window(CompWindow *cwin)
    1.13  {
    1.14 @@ -14,4 +15,54 @@
    1.15  	cwinlist.push_back(cwin);
    1.16  }
    1.17  
    1.18 -void delete_window(
    1.19 +bool delete_window(CompWindow *cwin)
    1.20 +{
    1.21 +	auto it = std::find(cwinlist.begin(), cwinlist.end(), cwin);
    1.22 +	if(it != cwinlist.end()) {
    1.23 +		cwinlist.erase(it);
    1.24 +		return true;
    1.25 +	}
    1.26 +	return false;
    1.27 +}
    1.28 +
    1.29 +bool have_window(CompWindow *cwin)
    1.30 +{
    1.31 +	return std::find(cwinlist.begin(), cwinlist.end(), cwin) != cwinlist.end();
    1.32 +}
    1.33 +
    1.34 +CompWindow *find_window_xid(Window xid)
    1.35 +{
    1.36 +	if(!xid) return 0;
    1.37 +
    1.38 +	for(size_t i=0; i<cwinlist.size(); i++) {
    1.39 +		if(cwinlist[i]->xwin == xid) {
    1.40 +			return cwinlist[i];
    1.41 +		}
    1.42 +	}
    1.43 +	return 0;
    1.44 +}
    1.45 +
    1.46 +CompWindow *find_window_pixmap(Pixmap pix)
    1.47 +{
    1.48 +	if(!pix) return 0;
    1.49 +
    1.50 +	for(size_t i=0; i<cwinlist.size(); i++) {
    1.51 +		if(cwinlist[i]->xpixmap == pix) {
    1.52 +			return cwinlist[i];
    1.53 +		}
    1.54 +	}
    1.55 +	return 0;
    1.56 +}
    1.57 +
    1.58 +int get_window_count()
    1.59 +{
    1.60 +	return (int)cwinlist.size();
    1.61 +}
    1.62 +
    1.63 +CompWindow *get_window(int idx)
    1.64 +{
    1.65 +	if(idx < 0 || idx >= (int)cwinlist.size()) {
    1.66 +		return 0;
    1.67 +	}
    1.68 +	return cwinlist[idx];
    1.69 +}