-
-
Notifications
You must be signed in to change notification settings - Fork 962
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
protocols: add hyprland_lock_notify_v1 implementation (#9092)
- Loading branch information
1 parent
8dd2cd4
commit 4074531
Showing
8 changed files
with
154 additions
and
7 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,88 @@ | ||
#include "LockNotify.hpp" | ||
|
||
CHyprlandLockNotification::CHyprlandLockNotification(SP<CHyprlandLockNotificationV1> resource_) : m_resource(resource_) { | ||
if UNLIKELY (!m_resource->resource()) | ||
return; | ||
|
||
m_resource->setDestroy([this](CHyprlandLockNotificationV1* r) { PROTO::lockNotify->destroyNotification(this); }); | ||
m_resource->setOnDestroy([this](CHyprlandLockNotificationV1* r) { PROTO::lockNotify->destroyNotification(this); }); | ||
} | ||
|
||
bool CHyprlandLockNotification::good() { | ||
return m_resource->resource(); | ||
} | ||
|
||
void CHyprlandLockNotification::onLocked() { | ||
if LIKELY (!m_locked) | ||
m_resource->sendLocked(); | ||
|
||
m_locked = true; | ||
} | ||
|
||
void CHyprlandLockNotification::onUnlocked() { | ||
if LIKELY (m_locked) | ||
m_resource->sendUnlocked(); | ||
|
||
m_locked = false; | ||
} | ||
|
||
CLockNotifyProtocol::CLockNotifyProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) { | ||
; | ||
} | ||
|
||
void CLockNotifyProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) { | ||
const auto RESOURCE = m_managers.emplace_back(std::make_unique<CHyprlandLockNotifierV1>(client, ver, id)).get(); | ||
RESOURCE->setOnDestroy([this](CHyprlandLockNotifierV1* p) { this->onManagerResourceDestroy(p->resource()); }); | ||
|
||
RESOURCE->setDestroy([this](CHyprlandLockNotifierV1* pMgr) { this->onManagerResourceDestroy(pMgr->resource()); }); | ||
RESOURCE->setGetLockNotification([this](CHyprlandLockNotifierV1* pMgr, uint32_t id) { this->onGetNotification(pMgr, id); }); | ||
} | ||
|
||
void CLockNotifyProtocol::onManagerResourceDestroy(wl_resource* res) { | ||
std::erase_if(m_managers, [&](const auto& other) { return other->resource() == res; }); | ||
} | ||
|
||
void CLockNotifyProtocol::destroyNotification(CHyprlandLockNotification* notif) { | ||
std::erase_if(m_notifications, [&](const auto& other) { return other.get() == notif; }); | ||
} | ||
|
||
void CLockNotifyProtocol::onGetNotification(CHyprlandLockNotifierV1* pMgr, uint32_t id) { | ||
const auto CLIENT = pMgr->client(); | ||
const auto RESOURCE = m_notifications.emplace_back(makeShared<CHyprlandLockNotification>(makeShared<CHyprlandLockNotificationV1>(CLIENT, pMgr->version(), id))).get(); | ||
|
||
if UNLIKELY (!RESOURCE->good()) { | ||
pMgr->noMemory(); | ||
m_notifications.pop_back(); | ||
return; | ||
} | ||
|
||
// Already locked?? Send locked right away | ||
if UNLIKELY (m_isLocked) | ||
m_notifications.back()->onLocked(); | ||
} | ||
|
||
void CLockNotifyProtocol::onLocked() { | ||
if UNLIKELY (m_isLocked) { | ||
LOGM(ERR, "Not sending lock notification. Already locked!"); | ||
return; | ||
} | ||
|
||
for (auto const& n : m_notifications) { | ||
n->onLocked(); | ||
} | ||
|
||
m_isLocked = true; | ||
} | ||
|
||
void CLockNotifyProtocol::onUnlocked() { | ||
if UNLIKELY (!m_isLocked) { | ||
LOGM(ERR, "Not sending unlock notification. Not locked!"); | ||
return; | ||
} | ||
|
||
for (auto const& n : m_notifications) { | ||
n->onUnlocked(); | ||
} | ||
|
||
m_isLocked = false; | ||
} |
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,50 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
#include <vector> | ||
#include <unordered_map> | ||
#include "WaylandProtocol.hpp" | ||
#include "hyprland-lock-notify-v1.hpp" | ||
|
||
class CEventLoopTimer; | ||
|
||
class CHyprlandLockNotification { | ||
public: | ||
CHyprlandLockNotification(SP<CHyprlandLockNotificationV1> resource_); | ||
~CHyprlandLockNotification() = default; | ||
|
||
bool good(); | ||
void onLocked(); | ||
void onUnlocked(); | ||
|
||
private: | ||
SP<CHyprlandLockNotificationV1> m_resource; | ||
bool m_locked = false; | ||
}; | ||
|
||
class CLockNotifyProtocol : public IWaylandProtocol { | ||
public: | ||
CLockNotifyProtocol(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 onLocked(); | ||
void onUnlocked(); | ||
|
||
private: | ||
void onManagerResourceDestroy(wl_resource* res); | ||
void destroyNotification(CHyprlandLockNotification* notif); | ||
void onGetNotification(CHyprlandLockNotifierV1* pMgr, uint32_t id); | ||
|
||
bool m_isLocked = false; | ||
|
||
// | ||
std::vector<UP<CHyprlandLockNotifierV1>> m_managers; | ||
std::vector<SP<CHyprlandLockNotification>> m_notifications; | ||
|
||
friend class CHyprlandLockNotification; | ||
}; | ||
|
||
namespace PROTO { | ||
inline UP<CLockNotifyProtocol> lockNotify; | ||
}; |
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
Submodule hyprland-protocols
updated
4 files
+9 −4 | README.md | |
+1 −1 | VERSION | |
+1 −0 | meson.build | |
+99 −0 | protocols/hyprland-lock-notify-v1.xml |