protocols: refactor class member vars (a-m) (#10265)
This commit is contained in:
parent
46ac115bd1
commit
adbae0f74d
58 changed files with 1566 additions and 1561 deletions
|
|
@ -1,21 +1,21 @@
|
|||
#include "GlobalShortcuts.hpp"
|
||||
#include "../helpers/time/Time.hpp"
|
||||
|
||||
CShortcutClient::CShortcutClient(SP<CHyprlandGlobalShortcutsManagerV1> resource_) : resource(resource_) {
|
||||
CShortcutClient::CShortcutClient(SP<CHyprlandGlobalShortcutsManagerV1> resource_) : m_resource(resource_) {
|
||||
if UNLIKELY (!good())
|
||||
return;
|
||||
|
||||
resource->setOnDestroy([this](CHyprlandGlobalShortcutsManagerV1* pMgr) { PROTO::globalShortcuts->destroyResource(this); });
|
||||
resource->setDestroy([this](CHyprlandGlobalShortcutsManagerV1* pMgr) { PROTO::globalShortcuts->destroyResource(this); });
|
||||
m_resource->setOnDestroy([this](CHyprlandGlobalShortcutsManagerV1* pMgr) { PROTO::globalShortcuts->destroyResource(this); });
|
||||
m_resource->setDestroy([this](CHyprlandGlobalShortcutsManagerV1* pMgr) { PROTO::globalShortcuts->destroyResource(this); });
|
||||
|
||||
resource->setRegisterShortcut([this](CHyprlandGlobalShortcutsManagerV1* pMgr, uint32_t shortcut, const char* id, const char* app_id, const char* description,
|
||||
const char* trigger_description) {
|
||||
m_resource->setRegisterShortcut([this](CHyprlandGlobalShortcutsManagerV1* pMgr, uint32_t shortcut, const char* id, const char* app_id, const char* description,
|
||||
const char* trigger_description) {
|
||||
if UNLIKELY (PROTO::globalShortcuts->isTaken(id, app_id)) {
|
||||
resource->error(HYPRLAND_GLOBAL_SHORTCUTS_MANAGER_V1_ERROR_ALREADY_TAKEN, "Combination is taken");
|
||||
m_resource->error(HYPRLAND_GLOBAL_SHORTCUTS_MANAGER_V1_ERROR_ALREADY_TAKEN, "Combination is taken");
|
||||
return;
|
||||
}
|
||||
|
||||
const auto PSHORTCUT = shortcuts.emplace_back(makeShared<SShortcut>(makeShared<CHyprlandGlobalShortcutV1>(resource->client(), resource->version(), shortcut)));
|
||||
const auto PSHORTCUT = m_shortcuts.emplace_back(makeShared<SShortcut>(makeShared<CHyprlandGlobalShortcutV1>(m_resource->client(), m_resource->version(), shortcut)));
|
||||
PSHORTCUT->id = id;
|
||||
PSHORTCUT->description = description;
|
||||
PSHORTCUT->appid = app_id;
|
||||
|
|
@ -23,16 +23,16 @@ CShortcutClient::CShortcutClient(SP<CHyprlandGlobalShortcutsManagerV1> resource_
|
|||
|
||||
if UNLIKELY (!PSHORTCUT->resource->resource()) {
|
||||
PSHORTCUT->resource->noMemory();
|
||||
shortcuts.pop_back();
|
||||
m_shortcuts.pop_back();
|
||||
return;
|
||||
}
|
||||
|
||||
PSHORTCUT->resource->setDestroy([this](CHyprlandGlobalShortcutV1* pMgr) { std::erase_if(shortcuts, [&](const auto& other) { return other->resource.get() == pMgr; }); });
|
||||
PSHORTCUT->resource->setDestroy([this](CHyprlandGlobalShortcutV1* pMgr) { std::erase_if(m_shortcuts, [&](const auto& other) { return other->resource.get() == pMgr; }); });
|
||||
});
|
||||
}
|
||||
|
||||
bool CShortcutClient::good() {
|
||||
return resource->resource();
|
||||
return m_resource->resource();
|
||||
}
|
||||
|
||||
CGlobalShortcutsProtocol::CGlobalShortcutsProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
|
||||
|
|
@ -40,22 +40,22 @@ CGlobalShortcutsProtocol::CGlobalShortcutsProtocol(const wl_interface* iface, co
|
|||
}
|
||||
|
||||
void CGlobalShortcutsProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
|
||||
const auto RESROUCE = m_vClients.emplace_back(makeShared<CShortcutClient>(makeShared<CHyprlandGlobalShortcutsManagerV1>(client, ver, id)));
|
||||
const auto RESROUCE = m_clients.emplace_back(makeShared<CShortcutClient>(makeShared<CHyprlandGlobalShortcutsManagerV1>(client, ver, id)));
|
||||
|
||||
if UNLIKELY (!RESROUCE->good()) {
|
||||
wl_client_post_no_memory(client);
|
||||
m_vClients.pop_back();
|
||||
m_clients.pop_back();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void CGlobalShortcutsProtocol::destroyResource(CShortcutClient* client) {
|
||||
std::erase_if(m_vClients, [&](const auto& other) { return other.get() == client; });
|
||||
std::erase_if(m_clients, [&](const auto& other) { return other.get() == client; });
|
||||
}
|
||||
|
||||
bool CGlobalShortcutsProtocol::isTaken(std::string appid, std::string trigger) {
|
||||
for (auto const& c : m_vClients) {
|
||||
for (auto const& sh : c->shortcuts) {
|
||||
for (auto const& c : m_clients) {
|
||||
for (auto const& sh : c->m_shortcuts) {
|
||||
if (sh->appid == appid && sh->id == trigger) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -66,8 +66,8 @@ bool CGlobalShortcutsProtocol::isTaken(std::string appid, std::string trigger) {
|
|||
}
|
||||
|
||||
void CGlobalShortcutsProtocol::sendGlobalShortcutEvent(std::string appid, std::string trigger, bool pressed) {
|
||||
for (auto const& c : m_vClients) {
|
||||
for (auto const& sh : c->shortcuts) {
|
||||
for (auto const& c : m_clients) {
|
||||
for (auto const& sh : c->m_shortcuts) {
|
||||
if (sh->appid == appid && sh->id == trigger) {
|
||||
const auto [sec, nsec] = Time::secNsec(Time::steadyNow());
|
||||
uint32_t tvSecHi = (sizeof(sec) > 4) ? sec >> 32 : 0;
|
||||
|
|
@ -87,15 +87,15 @@ std::vector<SShortcut> CGlobalShortcutsProtocol::getAllShortcuts() {
|
|||
// and potential reallocation is more costly then the added precompute overhead of looping
|
||||
// and finding the total size.
|
||||
size_t totalShortcuts = 0;
|
||||
for (const auto& c : m_vClients) {
|
||||
totalShortcuts += c->shortcuts.size();
|
||||
for (const auto& c : m_clients) {
|
||||
totalShortcuts += c->m_shortcuts.size();
|
||||
}
|
||||
|
||||
// reserve number of elements to avoid reallocations
|
||||
copy.reserve(totalShortcuts);
|
||||
|
||||
for (const auto& c : m_vClients) {
|
||||
for (const auto& sh : c->shortcuts) {
|
||||
for (const auto& c : m_clients) {
|
||||
for (const auto& sh : c->m_shortcuts) {
|
||||
copy.push_back(*sh);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue