summaryrefslogtreecommitdiff
path: root/src/protocols/TextInputV1.cpp
diff options
context:
space:
mode:
authorIkalco <73481042+ikalco@users.noreply.github.com>2024-07-29 11:14:19 -0500
committerGitHub <noreply@github.com>2024-07-29 18:14:19 +0200
commit60b663e2765c4cdb7e14fff75c4f88bf7ae312e2 (patch)
treedb6ee9dac9da1e2a1b584927543c542e31c62f80 /src/protocols/TextInputV1.cpp
parent01560c9d7ccd0beec1a9c190862ee325e6f3c45e (diff)
protocols: move text-input-v1 to hyprwayland-scanner (#7096)
* move text-input-v1 to hyprwayland-scanner * vro
Diffstat (limited to 'src/protocols/TextInputV1.cpp')
-rw-r--r--src/protocols/TextInputV1.cpp257
1 files changed, 77 insertions, 180 deletions
diff --git a/src/protocols/TextInputV1.cpp b/src/protocols/TextInputV1.cpp
index 12068671..78e910cb 100644
--- a/src/protocols/TextInputV1.cpp
+++ b/src/protocols/TextInputV1.cpp
@@ -3,228 +3,125 @@
#include "../Compositor.hpp"
#include "core/Compositor.hpp"
-#define TEXT_INPUT_VERSION 1
+#define LOGM PROTO::textInputV1->protoLog
-static void bindManagerInt(wl_client* client, void* data, uint32_t version, uint32_t id) {
- g_pProtocolManager->m_pTextInputV1ProtocolManager->bindManager(client, data, version, id);
+CTextInputV1::~CTextInputV1() {
+ events.destroy.emit();
}
-static void handleDisplayDestroy(struct wl_listener* listener, void* data) {
- CTextInputV1ProtocolManager* proto = wl_container_of(listener, proto, m_liDisplayDestroy);
- proto->displayDestroy();
-}
-
-void CTextInputV1ProtocolManager::displayDestroy() {
- wl_list_remove(&m_liDisplayDestroy.link);
- wl_list_init(&m_liDisplayDestroy.link);
- wl_global_destroy(m_pGlobal);
-}
-
-CTextInputV1ProtocolManager::~CTextInputV1ProtocolManager() {
- displayDestroy();
-}
-
-CTextInputV1ProtocolManager::CTextInputV1ProtocolManager() {
- m_pGlobal = wl_global_create(g_pCompositor->m_sWLDisplay, &zwp_text_input_manager_v1_interface, TEXT_INPUT_VERSION, this, bindManagerInt);
-
- if (!m_pGlobal) {
- Debug::log(ERR, "TextInputV1Manager could not start!");
+CTextInputV1::CTextInputV1(SP<CZwpTextInputV1> resource_) : resource(resource_) {
+ if (!good())
return;
- }
-
- m_liDisplayDestroy.notify = handleDisplayDestroy;
- wl_display_add_destroy_listener(g_pCompositor->m_sWLDisplay, &m_liDisplayDestroy);
-
- Debug::log(LOG, "TextInputV1Manager started successfully!");
-}
-static void createTI(wl_client* client, wl_resource* resource, uint32_t id) {
- g_pProtocolManager->m_pTextInputV1ProtocolManager->createTI(client, resource, id);
-}
+ resource->setOnDestroy([this](CZwpTextInputV1* pMgr) { PROTO::textInputV1->destroyResource(this); });
-static const struct zwp_text_input_manager_v1_interface textInputManagerImpl = {
- .create_text_input = createTI,
-};
+ resource->setActivate([this](CZwpTextInputV1* pMgr, wl_resource* seat, wl_resource* surface) {
+ if (!surface) {
+ LOGM(WARN, "Text-input-v1 PTI{:x}: No surface to activate text input on!", (uintptr_t)this);
+ return;
+ }
-void CTextInputV1ProtocolManager::bindManager(wl_client* client, void* data, uint32_t version, uint32_t id) {
- const auto RESOURCE = wl_resource_create(client, &zwp_text_input_manager_v1_interface, version, id);
- wl_resource_set_implementation(RESOURCE, &textInputManagerImpl, this, nullptr);
+ active = true;
+ events.enable.emit(CWLSurfaceResource::fromResource(surface));
+ });
- Debug::log(LOG, "TextInputV1Manager bound successfully!");
-}
+ resource->setDeactivate([this](CZwpTextInputV1* pMgr, wl_resource* seat) {
+ active = false;
+ events.disable.emit();
+ });
-//
+ resource->setReset([this](CZwpTextInputV1* pMgr) {
+ pendingSurrounding.isPending = false;
+ pendingContentType.isPending = false;
+ });
-static void handleActivate(wl_client* client, wl_resource* resource, wl_resource* seat, wl_resource* surface) {
- g_pProtocolManager->m_pTextInputV1ProtocolManager->handleActivate(client, resource, seat, surface);
-}
+ resource->setSetSurroundingText(
+ [this](CZwpTextInputV1* pMgr, const char* text, uint32_t cursor, uint32_t anchor) { pendingSurrounding = {true, std::string(text), cursor, anchor}; });
-static void handleDeactivate(wl_client* client, wl_resource* resource, wl_resource* seat) {
- g_pProtocolManager->m_pTextInputV1ProtocolManager->handleDeactivate(client, resource, seat);
-}
+ resource->setSetContentType([this](CZwpTextInputV1* pMgr, uint32_t hint, uint32_t purpose) {
+ pendingContentType = {true, hint == (uint32_t)ZWP_TEXT_INPUT_V1_CONTENT_HINT_DEFAULT ? (uint32_t)ZWP_TEXT_INPUT_V1_CONTENT_HINT_NONE : hint,
+ purpose > (uint32_t)ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_PASSWORD ? hint + 1 : hint};
+ });
-static void handleShowInputPanel(wl_client* client, wl_resource* resource) {
- g_pProtocolManager->m_pTextInputV1ProtocolManager->handleShowInputPanel(client, resource);
-}
+ resource->setSetCursorRectangle([this](CZwpTextInputV1* pMgr, int32_t x, int32_t y, int32_t width, int32_t height) { cursorRectangle = CBox{x, y, width, height}; });
-static void handleHideInputPanel(wl_client* client, wl_resource* resource) {
- g_pProtocolManager->m_pTextInputV1ProtocolManager->handleHideInputPanel(client, resource);
-}
+ resource->setCommitState([this](CZwpTextInputV1* pMgr, uint32_t serial_) {
+ serial = serial_;
+ events.onCommit.emit();
+ });
-static void handleReset(wl_client* client, wl_resource* resource) {
- g_pProtocolManager->m_pTextInputV1ProtocolManager->handleReset(client, resource);
+ // nothing
+ resource->setShowInputPanel([this](CZwpTextInputV1* pMgr) {});
+ resource->setHideInputPanel([this](CZwpTextInputV1* pMgr) {});
+ resource->setSetPreferredLanguage([this](CZwpTextInputV1* pMgr, const char* language) {});
+ resource->setInvokeAction([this](CZwpTextInputV1* pMgr, uint32_t button, uint32_t index) {});
}
-static void handleSetSurroundingText(wl_client* client, wl_resource* resource, const char* text, uint32_t cursor, uint32_t anchor) {
- g_pProtocolManager->m_pTextInputV1ProtocolManager->handleSetSurroundingText(client, resource, text, cursor, anchor);
+bool CTextInputV1::good() {
+ return resource->resource();
}
-static void handleSetContentType(wl_client* client, wl_resource* resource, uint32_t hint, uint32_t purpose) {
- g_pProtocolManager->m_pTextInputV1ProtocolManager->handleSetContentType(client, resource, hint, purpose);
+wl_client* CTextInputV1::client() {
+ return resource->client();
}
-static void handleSetCursorRectangle(wl_client* client, wl_resource* resource, int32_t x, int32_t y, int32_t width, int32_t height) {
- g_pProtocolManager->m_pTextInputV1ProtocolManager->handleSetCursorRectangle(client, resource, x, y, width, height);
+void CTextInputV1::enter(SP<CWLSurfaceResource> surface) {
+ resource->sendEnter(surface->getResource()->resource());
+ active = true;
}
-static void handleSetPreferredLanguage(wl_client* client, wl_resource* resource, const char* language) {
- g_pProtocolManager->m_pTextInputV1ProtocolManager->handleSetPreferredLanguage(client, resource, language);
+void CTextInputV1::leave() {
+ resource->sendLeave();
+ active = false;
}
-static void handleCommitState(wl_client* client, wl_resource* resource, uint32_t serial) {
- g_pProtocolManager->m_pTextInputV1ProtocolManager->handleCommitState(client, resource, serial);
+void CTextInputV1::preeditCursor(int32_t index) {
+ resource->sendPreeditCursor(index);
}
-static void handleInvokeAction(wl_client* client, wl_resource* resource, uint32_t button, uint32_t index) {
- g_pProtocolManager->m_pTextInputV1ProtocolManager->handleInvokeAction(client, resource, button, index);
+void CTextInputV1::preeditStyling(uint32_t index, uint32_t length, zwpTextInputV1PreeditStyle style) {
+ resource->sendPreeditStyling(index, length, style);
}
-static const struct zwp_text_input_v1_interface textInputImpl = {
- .activate = handleActivate,
- .deactivate = handleDeactivate,
- .show_input_panel = handleShowInputPanel,
- .hide_input_panel = handleHideInputPanel,
- .reset = handleReset,
- .set_surrounding_text = handleSetSurroundingText,
- .set_content_type = handleSetContentType,
- .set_cursor_rectangle = handleSetCursorRectangle,
- .set_preferred_language = handleSetPreferredLanguage,
- .commit_state = handleCommitState,
- .invoke_action = handleInvokeAction,
-};
-
-void CTextInputV1ProtocolManager::removeTI(STextInputV1* pTI) {
- const auto TI = std::find_if(m_pClients.begin(), m_pClients.end(), [&](const auto& other) { return other->resourceCaller == pTI->resourceCaller; });
- if (TI == m_pClients.end())
- return;
-
- // if ((*TI)->resourceImpl)
- // wl_resource_destroy((*TI)->resourceImpl);
-
- std::erase_if(m_pClients, [&](const auto& other) { return other.get() == pTI; });
+void CTextInputV1::preeditString(uint32_t serial, const char* text, const char* commit) {
+ resource->sendPreeditString(serial, text, commit);
}
-STextInputV1* tiFromResource(wl_resource* resource) {
- ASSERT(wl_resource_instance_of(resource, &zwp_text_input_v1_interface, &textInputImpl));
- return (STextInputV1*)wl_resource_get_user_data(resource);
+void CTextInputV1::commitString(uint32_t serial, const char* text) {
+ resource->sendCommitString(serial, text);
}
-static void destroyTI(wl_resource* resource) {
- const auto TI = tiFromResource(resource);
-
- if (!TI)
- return;
-
- if (TI->resourceImpl) {
- wl_resource_set_user_data(resource, nullptr);
- }
-
- TI->pTextInput->tiV1Destroyed();
-
- g_pProtocolManager->m_pTextInputV1ProtocolManager->removeTI(TI);
+void CTextInputV1::deleteSurroundingText(int32_t index, uint32_t length) {
+ resource->sendDeleteSurroundingText(index, length);
}
-void CTextInputV1ProtocolManager::createTI(wl_client* client, wl_resource* resource, uint32_t id) {
- const auto PTI = m_pClients.emplace_back(std::make_unique<STextInputV1>()).get();
- Debug::log(LOG, "New TI V1 at {:x}", (uintptr_t)PTI);
-
- PTI->client = client;
- PTI->resourceCaller = resource;
- PTI->resourceImpl = wl_resource_create(client, &zwp_text_input_v1_interface, TEXT_INPUT_VERSION, id);
-
- if (!PTI->resourceImpl) {
- Debug::log(ERR, "Could not alloc wl_resource for TIV1");
- removeTI(PTI);
- return;
- }
-
- wl_resource_set_implementation(PTI->resourceImpl, &textInputImpl, PTI, &destroyTI);
- wl_resource_set_user_data(PTI->resourceImpl, PTI);
-
- wl_signal_init(&PTI->sEnable);
- wl_signal_init(&PTI->sDisable);
- wl_signal_init(&PTI->sDestroy);
- wl_signal_init(&PTI->sCommit);
-
- g_pInputManager->m_sIMERelay.onNewTextInput(PTI);
-}
-
-void CTextInputV1ProtocolManager::handleActivate(wl_client* client, wl_resource* resource, wl_resource* seat, wl_resource* surface) {
- const auto PTI = tiFromResource(resource);
- if (!surface) {
- Debug::log(WARN, "Text-input-v1 PTI{:x}: No surface to activate text input on!", (uintptr_t)PTI);
- return;
- }
- PTI->active = true;
- PTI->pTextInput->onEnabled(CWLSurfaceResource::fromResource(surface));
-}
-
-void CTextInputV1ProtocolManager::handleDeactivate(wl_client* client, wl_resource* resource, wl_resource* seat) {
- const auto PTI = tiFromResource(resource);
- PTI->active = false;
- PTI->pTextInput->onDisabled();
-}
-
-void CTextInputV1ProtocolManager::handleShowInputPanel(wl_client* client, wl_resource* resource) {
+CTextInputV1Protocol::CTextInputV1Protocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
;
}
-void CTextInputV1ProtocolManager::handleHideInputPanel(wl_client* client, wl_resource* resource) {
- ;
-}
+void CTextInputV1Protocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
+ const auto RESOURCE = m_vManagers.emplace_back(makeShared<CZwpTextInputManagerV1>(client, ver, id));
-void CTextInputV1ProtocolManager::handleReset(wl_client* client, wl_resource* resource) {
- const auto PTI = tiFromResource(resource);
- PTI->pendingSurrounding.isPending = false;
- PTI->pendingContentType.isPending = false;
-}
+ RESOURCE->setOnDestroy([this](CZwpTextInputManagerV1* pMgr) { PROTO::textInputV1->destroyResource(pMgr); });
+ RESOURCE->setCreateTextInput([this](CZwpTextInputManagerV1* pMgr, uint32_t id) {
+ const auto PTI = m_vClients.emplace_back(makeShared<CTextInputV1>(makeShared<CZwpTextInputV1>(pMgr->client(), pMgr->version(), id)));
+ LOGM(LOG, "New TI V1 at {:x}", (uintptr_t)PTI.get());
-void CTextInputV1ProtocolManager::handleSetSurroundingText(wl_client* client, wl_resource* resource, const char* text, uint32_t cursor, uint32_t anchor) {
- const auto PTI = tiFromResource(resource);
- PTI->pendingSurrounding = {true, std::string(text), cursor, anchor};
-}
+ if (!PTI->good()) {
+ LOGM(ERR, "Could not alloc wl_resource for TIV1");
+ pMgr->noMemory();
+ PROTO::textInputV1->destroyResource(PTI.get());
+ return;
+ }
-void CTextInputV1ProtocolManager::handleSetContentType(wl_client* client, wl_resource* resource, uint32_t hint, uint32_t purpose) {
- const auto PTI = tiFromResource(resource);
- PTI->pendingContentType = {true, hint == (uint32_t)ZWP_TEXT_INPUT_V1_CONTENT_HINT_DEFAULT ? (uint32_t)ZWP_TEXT_INPUT_V1_CONTENT_HINT_NONE : hint,
- purpose > (uint32_t)ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_PASSWORD ? hint + 1 : hint};
+ events.newTextInput.emit(WP<CTextInputV1>(PTI));
+ });
}
-void CTextInputV1ProtocolManager::handleSetCursorRectangle(wl_client* client, wl_resource* resource, int32_t x, int32_t y, int32_t width, int32_t height) {
- const auto PTI = tiFromResource(resource);
- PTI->cursorRectangle = CBox{x, y, width, height};
+void CTextInputV1Protocol::destroyResource(CTextInputV1* client) {
+ std::erase_if(m_vClients, [&](const auto& other) { return other.get() == client; });
}
-void CTextInputV1ProtocolManager::handleSetPreferredLanguage(wl_client* client, wl_resource* resource, const char* language) {
- ;
-}
-
-void CTextInputV1ProtocolManager::handleCommitState(wl_client* client, wl_resource* resource, uint32_t serial) {
- const auto PTI = tiFromResource(resource);
- PTI->serial = serial;
- PTI->pTextInput->onCommit();
-}
-
-void CTextInputV1ProtocolManager::handleInvokeAction(wl_client* client, wl_resource* resource, uint32_t button, uint32_t index) {
- ;
+void CTextInputV1Protocol::destroyResource(CZwpTextInputManagerV1* client) {
+ std::erase_if(m_vManagers, [&](const auto& other) { return other.get() == client; });
}