-
-
Notifications
You must be signed in to change notification settings - Fork 950
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
153 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include "IdleInhibit.hpp" | ||
|
||
CIdleInhibitor::CIdleInhibitor(SP<CIdleInhibitorResource> resource_, wlr_surface* surf_) : resource(resource_), surface(surf_) { | ||
; | ||
} | ||
|
||
CIdleInhibitorResource::CIdleInhibitorResource(SP<CZwpIdleInhibitorV1> resource_, wlr_surface* surface_) : resource(resource_), surface(surface_) { | ||
hyprListener_surfaceDestroy.initCallback( | ||
&surface->events.destroy, [this](void* owner, void* data) { PROTO::idleInhibit->removeInhibitor(this); }, this, "CIdleInhibitorResource"); | ||
|
||
resource->setOnDestroy([this](CZwpIdleInhibitorV1* p) { PROTO::idleInhibit->removeInhibitor(this); }); | ||
resource->setDestroy([this](CZwpIdleInhibitorV1* p) { PROTO::idleInhibit->removeInhibitor(this); }); | ||
} | ||
|
||
CIdleInhibitorResource::~CIdleInhibitorResource() { | ||
hyprListener_surfaceDestroy.removeCallback(); | ||
events.destroy.emit(); | ||
} | ||
|
||
CIdleInhibitProtocol::CIdleInhibitProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) { | ||
; | ||
} | ||
|
||
void CIdleInhibitProtocol::onManagerResourceDestroy(wl_resource* res) { | ||
std::erase_if(m_vManagers, [res](const auto& other) { return other->resource() == res; }); | ||
} | ||
|
||
void CIdleInhibitProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) { | ||
const auto RESOURCE = m_vManagers.emplace_back(std::make_unique<CZwpIdleInhibitManagerV1>(client, ver, id)).get(); | ||
RESOURCE->setOnDestroy([this](CZwpIdleInhibitManagerV1* p) { this->onManagerResourceDestroy(p->resource()); }); | ||
|
||
RESOURCE->setDestroy([this](CZwpIdleInhibitManagerV1* pMgr) { this->onManagerResourceDestroy(pMgr->resource()); }); | ||
RESOURCE->setCreateInhibitor( | ||
[this](CZwpIdleInhibitManagerV1* pMgr, uint32_t id, wl_resource* surface) { this->onCreateInhibitor(pMgr, id, wlr_surface_from_resource(surface)); }); | ||
} | ||
|
||
void CIdleInhibitProtocol::removeInhibitor(CIdleInhibitorResource* resource) { | ||
std::erase_if(m_vInhibitors, [resource](const auto& el) { return el.get() == resource; }); | ||
} | ||
|
||
void CIdleInhibitProtocol::onCreateInhibitor(CZwpIdleInhibitManagerV1* pMgr, uint32_t id, wlr_surface* surface) { | ||
const auto CLIENT = wl_resource_get_client(pMgr->resource()); | ||
const auto RESOURCE = | ||
m_vInhibitors.emplace_back(std::make_shared<CIdleInhibitorResource>(std::make_shared<CZwpIdleInhibitorV1>(CLIENT, wl_resource_get_version(pMgr->resource()), id), surface)); | ||
|
||
RESOURCE->inhibitor = std::make_shared<CIdleInhibitor>(RESOURCE, surface); | ||
events.newIdleInhibitor.emit(RESOURCE->inhibitor); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
#include <unordered_map> | ||
#include "WaylandProtocol.hpp" | ||
#include "idle-inhibit-unstable-v1.hpp" | ||
#include "../helpers/signal/Signal.hpp" | ||
|
||
class CIdleInhibitorResource; | ||
|
||
class CIdleInhibitor { | ||
public: | ||
CIdleInhibitor(SP<CIdleInhibitorResource> resource_, wlr_surface* surf_); | ||
|
||
struct { | ||
CHyprSignalListener destroy; | ||
} listeners; | ||
|
||
WP<CIdleInhibitorResource> resource; | ||
wlr_surface* surface = nullptr; | ||
}; | ||
|
||
class CIdleInhibitorResource { | ||
public: | ||
CIdleInhibitorResource(SP<CZwpIdleInhibitorV1> resource_, wlr_surface* surface_); | ||
~CIdleInhibitorResource(); | ||
|
||
SP<CIdleInhibitor> inhibitor; | ||
|
||
struct { | ||
CSignal destroy; | ||
} events; | ||
|
||
private: | ||
SP<CZwpIdleInhibitorV1> resource; | ||
wlr_surface* surface = nullptr; | ||
|
||
DYNLISTENER(surfaceDestroy); | ||
}; | ||
|
||
class CIdleInhibitProtocol : public IWaylandProtocol { | ||
public: | ||
CIdleInhibitProtocol(const wl_interface* iface, const int& ver, const std::string& name); | ||
|
||
virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id); | ||
|
||
void onManagerResourceDestroy(wl_resource* res); | ||
void onCreateInhibitor(CZwpIdleInhibitManagerV1* pMgr, uint32_t id, wlr_surface* surface); | ||
|
||
void removeInhibitor(CIdleInhibitorResource*); | ||
|
||
struct { | ||
CSignal newIdleInhibitor; // data: SP<CIdleInhibitor> | ||
} events; | ||
|
||
private: | ||
std::vector<UP<CZwpIdleInhibitManagerV1>> m_vManagers; | ||
std::vector<SP<CIdleInhibitorResource>> m_vInhibitors; | ||
}; | ||
|
||
namespace PROTO { | ||
inline UP<CIdleInhibitProtocol> idleInhibit; | ||
} |
Oops, something went wrong.