diff options
| author | davc0n <dconti.dev@gmail.com> | 2025-05-04 00:13:29 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-04 00:13:29 +0200 |
| commit | adbae0f74d951e06c575bad3c81a944027dfe413 (patch) | |
| tree | 4ae313af18629596c7e98518c7c1d2c10bc260a3 /src/protocols/InputMethodV2.cpp | |
| parent | 46ac115bd19ee3aff5c816033de0b1d55a74e33f (diff) | |
protocols: refactor class member vars (a-m) (#10265)
Diffstat (limited to 'src/protocols/InputMethodV2.cpp')
| -rw-r--r-- | src/protocols/InputMethodV2.cpp | 219 |
1 files changed, 110 insertions, 109 deletions
diff --git a/src/protocols/InputMethodV2.cpp b/src/protocols/InputMethodV2.cpp index ae575250..63f9f33f 100644 --- a/src/protocols/InputMethodV2.cpp +++ b/src/protocols/InputMethodV2.cpp @@ -6,12 +6,12 @@ #include "core/Compositor.hpp" #include <cstring> -CInputMethodKeyboardGrabV2::CInputMethodKeyboardGrabV2(SP<CZwpInputMethodKeyboardGrabV2> resource_, SP<CInputMethodV2> owner_) : resource(resource_), owner(owner_) { - if UNLIKELY (!resource->resource()) +CInputMethodKeyboardGrabV2::CInputMethodKeyboardGrabV2(SP<CZwpInputMethodKeyboardGrabV2> resource_, SP<CInputMethodV2> owner_) : m_resource(resource_), m_owner(owner_) { + if UNLIKELY (!m_resource->resource()) return; - resource->setRelease([this](CZwpInputMethodKeyboardGrabV2* r) { PROTO::ime->destroyResource(this); }); - resource->setOnDestroy([this](CZwpInputMethodKeyboardGrabV2* r) { PROTO::ime->destroyResource(this); }); + m_resource->setRelease([this](CZwpInputMethodKeyboardGrabV2* r) { PROTO::ime->destroyResource(this); }); + m_resource->setOnDestroy([this](CZwpInputMethodKeyboardGrabV2* r) { PROTO::ime->destroyResource(this); }); if (!g_pSeatManager->m_keyboard) { LOGM(ERR, "IME called but no active keyboard???"); @@ -22,16 +22,16 @@ CInputMethodKeyboardGrabV2::CInputMethodKeyboardGrabV2(SP<CZwpInputMethodKeyboar } CInputMethodKeyboardGrabV2::~CInputMethodKeyboardGrabV2() { - if (!owner.expired()) - std::erase_if(owner->grabs, [](const auto& g) { return g.expired(); }); + if (!m_owner.expired()) + std::erase_if(m_owner->m_grabs, [](const auto& g) { return g.expired(); }); } void CInputMethodKeyboardGrabV2::sendKeyboardData(SP<IKeyboard> keyboard) { - if (keyboard == pLastKeyboard) + if (keyboard == m_lastKeyboard) return; - pLastKeyboard = keyboard; + m_lastKeyboard = keyboard; auto keymapFD = allocateSHMFile(keyboard->m_xkbKeymapString.length() + 1); if UNLIKELY (!keymapFD.isValid()) { @@ -48,95 +48,96 @@ void CInputMethodKeyboardGrabV2::sendKeyboardData(SP<IKeyboard> keyboard) { memcpy(data, keyboard->m_xkbKeymapString.c_str(), keyboard->m_xkbKeymapString.length()); munmap(data, keyboard->m_xkbKeymapString.length() + 1); - resource->sendKeymap(WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, keymapFD.get(), keyboard->m_xkbKeymapString.length() + 1); + m_resource->sendKeymap(WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, keymapFD.get(), keyboard->m_xkbKeymapString.length() + 1); sendMods(keyboard->m_modifiersState.depressed, keyboard->m_modifiersState.latched, keyboard->m_modifiersState.locked, keyboard->m_modifiersState.group); - resource->sendRepeatInfo(keyboard->m_repeatRate, keyboard->m_repeatDelay); + m_resource->sendRepeatInfo(keyboard->m_repeatRate, keyboard->m_repeatDelay); } void CInputMethodKeyboardGrabV2::sendKey(uint32_t time, uint32_t key, wl_keyboard_key_state state) { - const auto SERIAL = g_pSeatManager->nextSerial(g_pSeatManager->seatResourceForClient(resource->client())); + const auto SERIAL = g_pSeatManager->nextSerial(g_pSeatManager->seatResourceForClient(m_resource->client())); - resource->sendKey(SERIAL, time, key, (uint32_t)state); + m_resource->sendKey(SERIAL, time, key, (uint32_t)state); } void CInputMethodKeyboardGrabV2::sendMods(uint32_t depressed, uint32_t latched, uint32_t locked, uint32_t group) { - const auto SERIAL = g_pSeatManager->nextSerial(g_pSeatManager->seatResourceForClient(resource->client())); + const auto SERIAL = g_pSeatManager->nextSerial(g_pSeatManager->seatResourceForClient(m_resource->client())); - resource->sendModifiers(SERIAL, depressed, latched, locked, group); + m_resource->sendModifiers(SERIAL, depressed, latched, locked, group); } bool CInputMethodKeyboardGrabV2::good() { - return resource->resource(); + return m_resource->resource(); } SP<CInputMethodV2> CInputMethodKeyboardGrabV2::getOwner() { - return owner.lock(); + return m_owner.lock(); } wl_client* CInputMethodKeyboardGrabV2::client() { - return resource->resource() ? resource->client() : nullptr; + return m_resource->resource() ? m_resource->client() : nullptr; } -CInputMethodPopupV2::CInputMethodPopupV2(SP<CZwpInputPopupSurfaceV2> resource_, SP<CInputMethodV2> owner_, SP<CWLSurfaceResource> surface) : resource(resource_), owner(owner_) { - if UNLIKELY (!resource->resource()) +CInputMethodPopupV2::CInputMethodPopupV2(SP<CZwpInputPopupSurfaceV2> resource_, SP<CInputMethodV2> owner_, SP<CWLSurfaceResource> surface) : + m_resource(resource_), m_owner(owner_) { + if UNLIKELY (!m_resource->resource()) return; - resource->setDestroy([this](CZwpInputPopupSurfaceV2* r) { PROTO::ime->destroyResource(this); }); - resource->setOnDestroy([this](CZwpInputPopupSurfaceV2* r) { PROTO::ime->destroyResource(this); }); + m_resource->setDestroy([this](CZwpInputPopupSurfaceV2* r) { PROTO::ime->destroyResource(this); }); + m_resource->setOnDestroy([this](CZwpInputPopupSurfaceV2* r) { PROTO::ime->destroyResource(this); }); - pSurface = surface; + m_surface = surface; - listeners.destroySurface = surface->m_events.destroy.registerListener([this](std::any d) { - if (mapped) - events.unmap.emit(); + m_listeners.destroySurface = surface->m_events.destroy.registerListener([this](std::any d) { + if (m_mapped) + m_events.unmap.emit(); - listeners.destroySurface.reset(); - listeners.commitSurface.reset(); + m_listeners.destroySurface.reset(); + m_listeners.commitSurface.reset(); - if (g_pCompositor->m_lastFocus == pSurface) + if (g_pCompositor->m_lastFocus == m_surface) g_pCompositor->m_lastFocus.reset(); - pSurface.reset(); + m_surface.reset(); }); - listeners.commitSurface = surface->m_events.commit.registerListener([this](std::any d) { - if (pSurface->m_current.texture && !mapped) { - mapped = true; - pSurface->map(); - events.map.emit(); + m_listeners.commitSurface = surface->m_events.commit.registerListener([this](std::any d) { + if (m_surface->m_current.texture && !m_mapped) { + m_mapped = true; + m_surface->map(); + m_events.map.emit(); return; } - if (!pSurface->m_current.texture && mapped) { - mapped = false; - pSurface->unmap(); - events.unmap.emit(); + if (!m_surface->m_current.texture && m_mapped) { + m_mapped = false; + m_surface->unmap(); + m_events.unmap.emit(); return; } - events.commit.emit(); + m_events.commit.emit(); }); } CInputMethodPopupV2::~CInputMethodPopupV2() { - if (!owner.expired()) - std::erase_if(owner->popups, [](const auto& p) { return p.expired(); }); + if (!m_owner.expired()) + std::erase_if(m_owner->m_popups, [](const auto& p) { return p.expired(); }); - events.destroy.emit(); + m_events.destroy.emit(); } bool CInputMethodPopupV2::good() { - return resource->resource(); + return m_resource->resource(); } void CInputMethodPopupV2::sendInputRectangle(const CBox& box) { - resource->sendTextInputRectangle(box.x, box.y, box.w, box.h); + m_resource->sendTextInputRectangle(box.x, box.y, box.w, box.h); } SP<CWLSurfaceResource> CInputMethodPopupV2::surface() { - return pSurface.lock(); + return m_surface.lock(); } void CInputMethodV2::SState::reset() { @@ -145,127 +146,127 @@ void CInputMethodV2::SState::reset() { preeditString.committed = false; } -CInputMethodV2::CInputMethodV2(SP<CZwpInputMethodV2> resource_) : resource(resource_) { - if UNLIKELY (!resource->resource()) +CInputMethodV2::CInputMethodV2(SP<CZwpInputMethodV2> resource_) : m_resource(resource_) { + if UNLIKELY (!m_resource->resource()) return; - resource->setDestroy([this](CZwpInputMethodV2* r) { - events.destroy.emit(); + m_resource->setDestroy([this](CZwpInputMethodV2* r) { + m_events.destroy.emit(); PROTO::ime->destroyResource(this); }); - resource->setOnDestroy([this](CZwpInputMethodV2* r) { - events.destroy.emit(); + m_resource->setOnDestroy([this](CZwpInputMethodV2* r) { + m_events.destroy.emit(); PROTO::ime->destroyResource(this); }); - resource->setCommitString([this](CZwpInputMethodV2* r, const char* str) { - pending.committedString.string = str; - pending.committedString.committed = true; + m_resource->setCommitString([this](CZwpInputMethodV2* r, const char* str) { + m_pending.committedString.string = str; + m_pending.committedString.committed = true; }); - resource->setDeleteSurroundingText([this](CZwpInputMethodV2* r, uint32_t before, uint32_t after) { - pending.deleteSurrounding.before = before; - pending.deleteSurrounding.after = after; - pending.deleteSurrounding.committed = true; + m_resource->setDeleteSurroundingText([this](CZwpInputMethodV2* r, uint32_t before, uint32_t after) { + m_pending.deleteSurrounding.before = before; + m_pending.deleteSurrounding.after = after; + m_pending.deleteSurrounding.committed = true; }); - resource->setSetPreeditString([this](CZwpInputMethodV2* r, const char* str, int32_t begin, int32_t end) { - pending.preeditString.string = str; - pending.preeditString.begin = begin; - pending.preeditString.end = end; - pending.preeditString.committed = true; + m_resource->setSetPreeditString([this](CZwpInputMethodV2* r, const char* str, int32_t begin, int32_t end) { + m_pending.preeditString.string = str; + m_pending.preeditString.begin = begin; + m_pending.preeditString.end = end; + m_pending.preeditString.committed = true; }); - resource->setCommit([this](CZwpInputMethodV2* r, uint32_t serial) { - current = pending; - pending.reset(); - events.onCommit.emit(); + m_resource->setCommit([this](CZwpInputMethodV2* r, uint32_t serial) { + m_current = m_pending; + m_pending.reset(); + m_events.onCommit.emit(); }); - resource->setGetInputPopupSurface([this](CZwpInputMethodV2* r, uint32_t id, wl_resource* surface) { - const auto RESOURCE = PROTO::ime->m_vPopups.emplace_back( - makeShared<CInputMethodPopupV2>(makeShared<CZwpInputPopupSurfaceV2>(r->client(), r->version(), id), self.lock(), CWLSurfaceResource::fromResource(surface))); + m_resource->setGetInputPopupSurface([this](CZwpInputMethodV2* r, uint32_t id, wl_resource* surface) { + const auto RESOURCE = PROTO::ime->m_popups.emplace_back( + makeShared<CInputMethodPopupV2>(makeShared<CZwpInputPopupSurfaceV2>(r->client(), r->version(), id), m_self.lock(), CWLSurfaceResource::fromResource(surface))); if UNLIKELY (!RESOURCE->good()) { r->noMemory(); - PROTO::ime->m_vPopups.pop_back(); + PROTO::ime->m_popups.pop_back(); return; } LOGM(LOG, "New IME Popup with resource id {}", id); - popups.emplace_back(RESOURCE); + m_popups.emplace_back(RESOURCE); - events.newPopup.emit(RESOURCE); + m_events.newPopup.emit(RESOURCE); }); - resource->setGrabKeyboard([this](CZwpInputMethodV2* r, uint32_t id) { + m_resource->setGrabKeyboard([this](CZwpInputMethodV2* r, uint32_t id) { const auto RESOURCE = - PROTO::ime->m_vGrabs.emplace_back(makeShared<CInputMethodKeyboardGrabV2>(makeShared<CZwpInputMethodKeyboardGrabV2>(r->client(), r->version(), id), self.lock())); + PROTO::ime->m_grabs.emplace_back(makeShared<CInputMethodKeyboardGrabV2>(makeShared<CZwpInputMethodKeyboardGrabV2>(r->client(), r->version(), id), m_self.lock())); if UNLIKELY (!RESOURCE->good()) { r->noMemory(); - PROTO::ime->m_vGrabs.pop_back(); + PROTO::ime->m_grabs.pop_back(); return; } LOGM(LOG, "New IME Grab with resource id {}", id); - grabs.emplace_back(RESOURCE); + m_grabs.emplace_back(RESOURCE); }); } CInputMethodV2::~CInputMethodV2() { - events.destroy.emit(); + m_events.destroy.emit(); } bool CInputMethodV2::good() { - return resource->resource(); + return m_resource->resource(); } void CInputMethodV2::activate() { - if (active) + if (m_active) return; - resource->sendActivate(); - active = true; + m_resource->sendActivate(); + m_active = true; } void CInputMethodV2::deactivate() { - if (!active) + if (!m_active) return; - resource->sendDeactivate(); - active = false; + m_resource->sendDeactivate(); + m_active = false; } void CInputMethodV2::surroundingText(const std::string& text, uint32_t cursor, uint32_t anchor) { - resource->sendSurroundingText(text.c_str(), cursor, anchor); + m_resource->sendSurroundingText(text.c_str(), cursor, anchor); } void CInputMethodV2::textChangeCause(zwpTextInputV3ChangeCause changeCause) { - resource->sendTextChangeCause((uint32_t)changeCause); + m_resource->sendTextChangeCause((uint32_t)changeCause); } void CInputMethodV2::textContentType(zwpTextInputV3ContentHint hint, zwpTextInputV3ContentPurpose purpose) { - resource->sendContentType((uint32_t)hint, (uint32_t)purpose); + m_resource->sendContentType((uint32_t)hint, (uint32_t)purpose); } void CInputMethodV2::done() { - resource->sendDone(); + m_resource->sendDone(); } void CInputMethodV2::unavailable() { - resource->sendUnavailable(); + m_resource->sendUnavailable(); } bool CInputMethodV2::hasGrab() { - return !grabs.empty(); + return !m_grabs.empty(); } wl_client* CInputMethodV2::grabClient() { - if (grabs.empty()) + if (m_grabs.empty()) return nullptr; - for (auto const& gw : grabs) { + for (auto const& gw : m_grabs) { auto g = gw.lock(); if (!g) @@ -278,19 +279,19 @@ wl_client* CInputMethodV2::grabClient() { } void CInputMethodV2::sendInputRectangle(const CBox& box) { - inputRectangle = box; - for (auto const& wp : popups) { + m_inputRectangle = box; + for (auto const& wp : m_popups) { auto p = wp.lock(); if (!p) continue; - p->sendInputRectangle(inputRectangle); + p->sendInputRectangle(m_inputRectangle); } } void CInputMethodV2::sendKey(uint32_t time, uint32_t key, wl_keyboard_key_state state) { - for (auto const& gw : grabs) { + for (auto const& gw : m_grabs) { auto g = gw.lock(); if (!g) @@ -301,7 +302,7 @@ void CInputMethodV2::sendKey(uint32_t time, uint32_t key, wl_keyboard_key_state } void CInputMethodV2::sendMods(uint32_t depressed, uint32_t latched, uint32_t locked, uint32_t group) { - for (auto const& gw : grabs) { + for (auto const& gw : m_grabs) { auto g = gw.lock(); if (!g) @@ -312,7 +313,7 @@ void CInputMethodV2::sendMods(uint32_t depressed, uint32_t latched, uint32_t loc } void CInputMethodV2::setKeyboard(SP<IKeyboard> keyboard) { - for (auto const& gw : grabs) { + for (auto const& gw : m_grabs) { auto g = gw.lock(); if (!g) @@ -323,7 +324,7 @@ void CInputMethodV2::setKeyboard(SP<IKeyboard> keyboard) { } wl_client* CInputMethodV2::client() { - return resource->client(); + return m_resource->client(); } CInputMethodV2Protocol::CInputMethodV2Protocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) { @@ -331,7 +332,7 @@ CInputMethodV2Protocol::CInputMethodV2Protocol(const wl_interface* iface, const } void CInputMethodV2Protocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) { - const auto RESOURCE = m_vManagers.emplace_back(makeUnique<CZwpInputMethodManagerV2>(client, ver, id)).get(); + const auto RESOURCE = m_managers.emplace_back(makeUnique<CZwpInputMethodManagerV2>(client, ver, id)).get(); RESOURCE->setOnDestroy([this](CZwpInputMethodManagerV2* p) { this->onManagerResourceDestroy(p->resource()); }); RESOURCE->setDestroy([this](CZwpInputMethodManagerV2* pMgr) { this->onManagerResourceDestroy(pMgr->resource()); }); @@ -339,33 +340,33 @@ void CInputMethodV2Protocol::bindManager(wl_client* client, void* data, uint32_t } void CInputMethodV2Protocol::onManagerResourceDestroy(wl_resource* res) { - std::erase_if(m_vManagers, [&](const auto& other) { return other->resource() == res; }); + std::erase_if(m_managers, [&](const auto& other) { return other->resource() == res; }); } void CInputMethodV2Protocol::destroyResource(CInputMethodPopupV2* popup) { - std::erase_if(m_vPopups, [&](const auto& other) { return other.get() == popup; }); + std::erase_if(m_popups, [&](const auto& other) { return other.get() == popup; }); } void CInputMethodV2Protocol::destroyResource(CInputMethodKeyboardGrabV2* grab) { - std::erase_if(m_vGrabs, [&](const auto& other) { return other.get() == grab; }); + std::erase_if(m_grabs, [&](const auto& other) { return other.get() == grab; }); } void CInputMethodV2Protocol::destroyResource(CInputMethodV2* ime) { - std::erase_if(m_vIMEs, [&](const auto& other) { return other.get() == ime; }); + std::erase_if(m_imes, [&](const auto& other) { return other.get() == ime; }); } void CInputMethodV2Protocol::onGetIME(CZwpInputMethodManagerV2* mgr, wl_resource* seat, uint32_t id) { - const auto RESOURCE = m_vIMEs.emplace_back(makeShared<CInputMethodV2>(makeShared<CZwpInputMethodV2>(mgr->client(), mgr->version(), id))); + const auto RESOURCE = m_imes.emplace_back(makeShared<CInputMethodV2>(makeShared<CZwpInputMethodV2>(mgr->client(), mgr->version(), id))); if UNLIKELY (!RESOURCE->good()) { mgr->noMemory(); - m_vIMEs.pop_back(); + m_imes.pop_back(); return; } - RESOURCE->self = RESOURCE; + RESOURCE->m_self = RESOURCE; LOGM(LOG, "New IME with resource id {}", id); - events.newIME.emit(RESOURCE); + m_events.newIME.emit(RESOURCE); } |
