From 1d40af64d352bd5a87c7d53a52707fc5cfc6940e Mon Sep 17 00:00:00 2001 From: Vaxry Date: Thu, 25 Apr 2024 23:27:25 +0100 Subject: text-input-v3: move to new impl --- src/protocols/TextInputV3.hpp | 92 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 src/protocols/TextInputV3.hpp (limited to 'src/protocols/TextInputV3.hpp') diff --git a/src/protocols/TextInputV3.hpp b/src/protocols/TextInputV3.hpp new file mode 100644 index 00000000..6d4f3d54 --- /dev/null +++ b/src/protocols/TextInputV3.hpp @@ -0,0 +1,92 @@ +#pragma once + +#include +#include +#include +#include +#include "WaylandProtocol.hpp" +#include "text-input-unstable-v3.hpp" +#include "../helpers/signal/Signal.hpp" +#include "../helpers/Box.hpp" + +class CTextInputV3 { + public: + CTextInputV3(SP resource_); + ~CTextInputV3(); + + void enter(wlr_surface* surf); + void leave(wlr_surface* surf); + void preeditString(const std::string& text, int32_t cursorBegin, int32_t cursorEnd); + void commitString(const std::string& text); + void deleteSurroundingText(uint32_t beforeLength, uint32_t afterLength); + void sendDone(); + + bool good(); + + wl_client* client(); + + struct { + CSignal onCommit; + CSignal enable; + CSignal disable; + CSignal destroy; + } events; + + struct SState { + struct { + bool updated = false; + std::string text = ""; + uint32_t cursor = 0; + uint32_t anchor = 0; + } surrounding; + + struct { + bool updated = false; + zwpTextInputV3ContentHint hint = ZWP_TEXT_INPUT_V3_CONTENT_HINT_NONE; + zwpTextInputV3ContentPurpose purpose = ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_NORMAL; + } contentType; + + struct { + bool updated = false; + CBox cursorBox; + } box; + + bool enabled = false; + + zwpTextInputV3ChangeCause cause = ZWP_TEXT_INPUT_V3_CHANGE_CAUSE_INPUT_METHOD; + + void reset(); + }; + SState pending, current; + + private: + SP resource; + + int serial = 0; +}; + +class CTextInputV3Protocol : public IWaylandProtocol { + public: + CTextInputV3Protocol(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); + + struct { + CSignal newTextInput; // WP + } events; + + private: + void onManagerResourceDestroy(wl_resource* res); + void destroyTextInput(CTextInputV3* input); + void onGetTextInput(CZwpTextInputManagerV3* pMgr, uint32_t id, wl_resource* seat); + + // + std::vector> m_vManagers; + std::vector> m_vTextInputs; + + friend class CTextInputV3; +}; + +namespace PROTO { + inline UP textInputV3; +}; \ No newline at end of file -- cgit v1.2.3