Skip to content

Commit

Permalink
Standalone compositor 2. #1
Browse files Browse the repository at this point in the history
  • Loading branch information
jaelpark committed Jan 30, 2021
1 parent cde9ace commit d5dde9b
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 8 deletions.
5 changes: 4 additions & 1 deletion config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@ def OnKeyRelease(self, keyId):
self.shiftFocus = None;

def OnTimer(self):
#NOTE: OnTimer() calls currently disabled.
battery = psutil.sensors_battery();
try:
if not battery.power_plugged:
Expand All @@ -677,7 +678,9 @@ def OnTimer(self):
self.batteryAlarmLevel = 0;

class Compositor(chamfer.Compositor):
pass
def OnRedirectExternal(self, title, className):
#Used only in standalone compositor mode. Return False to filter out incompatible WM/UI components.
return True;

backend = Backend();
chamfer.BindBackend(backend);
Expand Down
13 changes: 7 additions & 6 deletions src/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1359,19 +1359,20 @@ sint Default::HandleEvent(bool forcePoll){
if(!standaloneComp){
const WManager::Container *proot = pclient->pcontainer->GetRoot();
StackClients(proot);
}else{

netClientList.clear();
for(auto &p : clients)
netClientList.push_back(p.first->window);
xcb_change_property(pcon,XCB_PROP_MODE_REPLACE,pscr->root,ewmh._NET_CLIENT_LIST,XCB_ATOM_WINDOW,32,netClientList.size(),netClientList.data());
}else
if(ApproveExternal(&wmName,&wmClass)){
//clientStack won't get cleared in standalone compositor mode
if(std::get<2>(*mrect) != 0){ //!= XCB_NONE
auto m = std::find_if(clientStack.begin(),clientStack.end(),[&](auto &p)->bool{
return static_cast<X11Client *>(p)->window == std::get<2>(*mrect);
});
clientStack.insert(m+1,pclient);
}else clientStack.push_front(pclient);

netClientList.clear();
for(auto &p : clients)
netClientList.push_back(p.first->window);
xcb_change_property(pcon,XCB_PROP_MODE_REPLACE,pscr->root,ewmh._NET_CLIENT_LIST,XCB_ATOM_WINDOW,32,netClientList.size(),netClientList.data());
}
}

Expand Down
1 change: 1 addition & 0 deletions src/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ friend class Compositor::TexturePixmap;
};
virtual X11Client * FindClient(xcb_window_t, MODE) const = 0;
virtual void TimerEvent() = 0;
virtual bool ApproveExternal(const BackendStringProperty *, const BackendStringProperty *) = 0;
//void * GetProperty(xcb_atom_t, xcb_atom_t) const;
//void FreeProperty(...) const;
protected:
Expand Down
20 changes: 20 additions & 0 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,10 @@ CompositorInterface::~CompositorInterface(){
//
}

bool CompositorInterface::OnRedirectExternal(std::string title, std::string className){
return true;
}

void CompositorInterface::Bind(boost::python::object obj){
CompositorInterface &compositorInt = boost::python::extract<CompositorInterface&>(obj)();
pcompositorInt = &compositorInt;
Expand All @@ -724,6 +728,21 @@ CompositorProxy::~CompositorProxy(){
//
}

bool CompositorProxy::OnRedirectExternal(std::string title, std::string className){
boost::python::override ovr = this->get_override("OnRedirectExternal");
if(ovr){
try{
return ovr(title,className);
}catch(boost::python::error_already_set &){
PyErr_Print();
//
boost::python::handle_exception();
PyErr_Clear();
}
}
return CompositorInterface::OnRedirectExternal(title,className);
}

CompositorConfig::CompositorConfig(CompositorInterface *_pcompositorInt) : pcompositorInt(_pcompositorInt){
pcompositorInt->pcompositor = this;
}
Expand Down Expand Up @@ -1126,6 +1145,7 @@ BOOST_PYTHON_MODULE(chamfer){
.value("USER_BIT",Compositor::ClientFrame::SHADER_FLAG_USER_BIT);

boost::python::class_<CompositorProxy,boost::noncopyable>("Compositor")
.def("OnRedirectExternal",&CompositorInterface::OnRedirectExternal)
.def_readwrite("deviceIndex",&CompositorInterface::deviceIndex)
.def_readwrite("debugLayers",&CompositorInterface::debugLayers)
.def_readwrite("scissoring",&CompositorInterface::scissoring)
Expand Down
4 changes: 3 additions & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ class BackendConfig{
class CompositorInterface{
public:
CompositorInterface();
~CompositorInterface();
virtual ~CompositorInterface();
virtual bool OnRedirectExternal(std::string, std::string);

sint deviceIndex;
bool debugLayers;
Expand All @@ -204,6 +205,7 @@ class CompositorProxy : public CompositorInterface, public boost::python::wrappe
public:
CompositorProxy();
~CompositorProxy();
bool OnRedirectExternal(std::string, std::string);
};

class CompositorConfig{
Expand Down
8 changes: 8 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,10 @@ class DefaultBackend : public Backend::Default, public RunBackend{
//
Config::BackendInterface::pbackendInt->OnTimer();
}

bool ApproveExternal(const Backend::BackendStringProperty *pwmName, const Backend::BackendStringProperty *pwmClass){
return Config::CompositorInterface::pcompositorInt->OnRedirectExternal(pwmName->pstr,pwmClass->pstr);
}
};

//TODO: some of these functions can be templated and shared with the DefaultBackend
Expand Down Expand Up @@ -785,6 +789,10 @@ class DebugBackend : public Backend::Debug, public RunBackend{
void TimerEvent(){
//
}

bool ApproveExternal(const Backend::BackendStringProperty *pwmName, const Backend::BackendStringProperty *pwmClass){
return true;
}
};

class DefaultCompositor : public Compositor::X11Compositor, public RunCompositor{
Expand Down

0 comments on commit d5dde9b

Please sign in to comment.