From 8bcccf9f0f0f69986e315d4288dfdbf119dd19db Mon Sep 17 00:00:00 2001 From: Vaxry Date: Wed, 1 May 2024 16:41:17 +0100 Subject: ime-v2: move to new impl --- src/protocols/InputMethodV2.hpp | 160 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 src/protocols/InputMethodV2.hpp (limited to 'src/protocols/InputMethodV2.hpp') diff --git a/src/protocols/InputMethodV2.hpp b/src/protocols/InputMethodV2.hpp new file mode 100644 index 00000000..1f5d2598 --- /dev/null +++ b/src/protocols/InputMethodV2.hpp @@ -0,0 +1,160 @@ +#pragma once + +#include +#include +#include +#include "WaylandProtocol.hpp" +#include "input-method-unstable-v2.hpp" +#include "text-input-unstable-v3.hpp" +#include "../helpers/signal/Signal.hpp" +#include "../desktop/WLSurface.hpp" + +class CInputMethodKeyboardGrabV2; +class CInputMethodPopupV2; + +class CInputMethodV2 { + public: + CInputMethodV2(SP resource_); + ~CInputMethodV2(); + + struct { + CSignal onCommit; + CSignal destroy; + CSignal newPopup; + } events; + + struct SState { + void reset(); + + struct { + std::string string; + bool committed = false; + } committedString; + + struct { + std::string string; + int32_t begin = 0, end = 0; + bool committed = false; + } preeditString; + + struct { + uint32_t before = 0, after = 0; + bool committed = false; + } deleteSurrounding; + }; + + SState pending, current; + + bool good(); + void activate(); + void deactivate(); + void surroundingText(const std::string& text, uint32_t cursor, uint32_t anchor); + void textChangeCause(zwpTextInputV3ChangeCause changeCause); + void textContentType(zwpTextInputV3ContentHint hint, zwpTextInputV3ContentPurpose purpose); + void done(); + void unavailable(); + + void sendInputRectangle(const CBox& box); + bool hasGrab(); + void sendKey(uint32_t time, uint32_t key, wl_keyboard_key_state state); + void sendMods(uint32_t depressed, uint32_t latched, uint32_t locked, uint32_t group); + void setKeyboard(wlr_keyboard* keyboard); + + wl_client* client(); + wl_client* grabClient(); + + private: + SP resource; + std::vector> grabs; + std::vector> popups; + + WP self; + + bool active = false; + + CBox inputRectangle; + + friend class CInputMethodPopupV2; + friend class CInputMethodKeyboardGrabV2; + friend class CInputMethodV2Protocol; +}; + +class CInputMethodKeyboardGrabV2 { + public: + CInputMethodKeyboardGrabV2(SP resource_, SP owner_); + ~CInputMethodKeyboardGrabV2(); + + bool good(); + SP getOwner(); + wl_client* client(); + + void sendKey(uint32_t time, uint32_t key, wl_keyboard_key_state state); + void sendMods(uint32_t depressed, uint32_t latched, uint32_t locked, uint32_t group); + void sendKeyboardData(wlr_keyboard* keyboard); + + private: + SP resource; + WP owner; + + wlr_keyboard* pLastKeyboard = nullptr; // READ-ONLY +}; + +class CInputMethodPopupV2 { + public: + CInputMethodPopupV2(SP resource_, SP owner_, wlr_surface* surface); + ~CInputMethodPopupV2(); + + bool good(); + void sendInputRectangle(const CBox& box); + wlr_surface* surface(); + + struct { + CSignal map; + CSignal unmap; + CSignal commit; + CSignal destroy; + } events; + + bool mapped = false; + + private: + SP resource; + WP owner; + wlr_surface* pSurface = nullptr; + + DYNLISTENER(commitSurface); + DYNLISTENER(destroySurface); +}; + +class CInputMethodV2Protocol : public IWaylandProtocol { + public: + CInputMethodV2Protocol(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 newIME; // SP + } events; + + private: + void onManagerResourceDestroy(wl_resource* res); + void destroyResource(CInputMethodPopupV2* popup); + void destroyResource(CInputMethodKeyboardGrabV2* grab); + void destroyResource(CInputMethodV2* ime); + + void onGetIME(CZwpInputMethodManagerV2* mgr, wl_resource* seat, uint32_t id); + + // + std::vector> m_vManagers; + std::vector> m_vIMEs; + std::vector> m_vGrabs; + std::vector> m_vPopups; + + friend class CInputMethodPopupV2; + friend class CInputMethodKeyboardGrabV2; + friend class CInputMethodV2; +}; + +namespace PROTO { + inline UP ime; +}; \ No newline at end of file -- cgit v1.2.3