protocols: move text-input-v1 to hyprwayland-scanner (#7096)

* move text-input-v1 to hyprwayland-scanner

* vro
This commit is contained in:
Ikalco 2024-07-29 11:14:19 -05:00 committed by GitHub
parent 01560c9d7c
commit 60b663e276
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 196 additions and 314 deletions

View file

@ -292,10 +292,7 @@ protocol(
"subprojects/hyprland-protocols/protocols/hyprland-global-shortcuts-v1.xml" "subprojects/hyprland-protocols/protocols/hyprland-global-shortcuts-v1.xml"
"hyprland-global-shortcuts-v1" true) "hyprland-global-shortcuts-v1" true)
protocol( protocolnew("unstable/text-input" "text-input-unstable-v1" false)
"unstable/text-input/text-input-unstable-v1.xml"
"text-input-unstable-v1" false)
protocolnew("subprojects/hyprland-protocols/protocols" "hyprland-toplevel-export-v1" true) protocolnew("subprojects/hyprland-protocols/protocols" "hyprland-toplevel-export-v1" true)
protocolnew("protocols" "wlr-screencopy-unstable-v1" true) protocolnew("protocols" "wlr-screencopy-unstable-v1" true)
protocolnew("protocols" "wlr-gamma-control-unstable-v1" true) protocolnew("protocols" "wlr-gamma-control-unstable-v1" true)

View file

@ -24,7 +24,6 @@ hyprwayland_scanner = find_program(
) )
protocols = [ protocols = [
[wl_protocol_dir, 'unstable/text-input/text-input-unstable-v1.xml'],
[hl_protocol_dir, 'protocols/hyprland-global-shortcuts-v1.xml'] [hl_protocol_dir, 'protocols/hyprland-global-shortcuts-v1.xml']
] ]
@ -55,6 +54,7 @@ new_protocols = [
[wl_protocol_dir, 'unstable/pointer-gestures/pointer-gestures-unstable-v1.xml'], [wl_protocol_dir, 'unstable/pointer-gestures/pointer-gestures-unstable-v1.xml'],
[wl_protocol_dir, 'unstable/keyboard-shortcuts-inhibit/keyboard-shortcuts-inhibit-unstable-v1.xml'], [wl_protocol_dir, 'unstable/keyboard-shortcuts-inhibit/keyboard-shortcuts-inhibit-unstable-v1.xml'],
[wl_protocol_dir, 'unstable/text-input/text-input-unstable-v3.xml'], [wl_protocol_dir, 'unstable/text-input/text-input-unstable-v3.xml'],
[wl_protocol_dir, 'unstable/text-input/text-input-unstable-v1.xml'],
[wl_protocol_dir, 'unstable/pointer-constraints/pointer-constraints-unstable-v1.xml'], [wl_protocol_dir, 'unstable/pointer-constraints/pointer-constraints-unstable-v1.xml'],
[wl_protocol_dir, 'staging/xdg-activation/xdg-activation-v1.xml'], [wl_protocol_dir, 'staging/xdg-activation/xdg-activation-v1.xml'],
[wl_protocol_dir, 'staging/ext-idle-notify/ext-idle-notify-v1.xml'], [wl_protocol_dir, 'staging/ext-idle-notify/ext-idle-notify-v1.xml'],

View file

@ -41,6 +41,7 @@
#include "../protocols/DRMSyncobj.hpp" #include "../protocols/DRMSyncobj.hpp"
#include "../protocols/Screencopy.hpp" #include "../protocols/Screencopy.hpp"
#include "../protocols/ToplevelExport.hpp" #include "../protocols/ToplevelExport.hpp"
#include "../protocols/TextInputV1.hpp"
#include "../protocols/core/Seat.hpp" #include "../protocols/core/Seat.hpp"
#include "../protocols/core/DataDevice.hpp" #include "../protocols/core/DataDevice.hpp"
@ -125,6 +126,7 @@ CProtocolManager::CProtocolManager() {
PROTO::pointerGestures = std::make_unique<CPointerGesturesProtocol>(&zwp_pointer_gestures_v1_interface, 3, "PointerGestures"); PROTO::pointerGestures = std::make_unique<CPointerGesturesProtocol>(&zwp_pointer_gestures_v1_interface, 3, "PointerGestures");
PROTO::foreignToplevelWlr = std::make_unique<CForeignToplevelWlrProtocol>(&zwlr_foreign_toplevel_manager_v1_interface, 3, "ForeignToplevelWlr"); PROTO::foreignToplevelWlr = std::make_unique<CForeignToplevelWlrProtocol>(&zwlr_foreign_toplevel_manager_v1_interface, 3, "ForeignToplevelWlr");
PROTO::shortcutsInhibit = std::make_unique<CKeyboardShortcutsInhibitProtocol>(&zwp_keyboard_shortcuts_inhibit_manager_v1_interface, 1, "ShortcutsInhibit"); PROTO::shortcutsInhibit = std::make_unique<CKeyboardShortcutsInhibitProtocol>(&zwp_keyboard_shortcuts_inhibit_manager_v1_interface, 1, "ShortcutsInhibit");
PROTO::textInputV1 = std::make_unique<CTextInputV1Protocol>(&zwp_text_input_manager_v1_interface, 1, "TextInputV1");
PROTO::textInputV3 = std::make_unique<CTextInputV3Protocol>(&zwp_text_input_manager_v3_interface, 1, "TextInputV3"); PROTO::textInputV3 = std::make_unique<CTextInputV3Protocol>(&zwp_text_input_manager_v3_interface, 1, "TextInputV3");
PROTO::constraints = std::make_unique<CPointerConstraintsProtocol>(&zwp_pointer_constraints_v1_interface, 1, "PointerConstraints"); PROTO::constraints = std::make_unique<CPointerConstraintsProtocol>(&zwp_pointer_constraints_v1_interface, 1, "PointerConstraints");
PROTO::outputPower = std::make_unique<COutputPowerProtocol>(&zwlr_output_power_manager_v1_interface, 1, "OutputPower"); PROTO::outputPower = std::make_unique<COutputPowerProtocol>(&zwlr_output_power_manager_v1_interface, 1, "OutputPower");
@ -165,7 +167,6 @@ CProtocolManager::CProtocolManager() {
// Old protocol implementations. // Old protocol implementations.
// TODO: rewrite them to use hyprwayland-scanner. // TODO: rewrite them to use hyprwayland-scanner.
m_pTextInputV1ProtocolManager = std::make_unique<CTextInputV1ProtocolManager>();
m_pGlobalShortcutsProtocolManager = std::make_unique<CGlobalShortcutsProtocolManager>(); m_pGlobalShortcutsProtocolManager = std::make_unique<CGlobalShortcutsProtocolManager>();
} }
@ -197,6 +198,7 @@ CProtocolManager::~CProtocolManager() {
PROTO::pointerGestures.reset(); PROTO::pointerGestures.reset();
PROTO::foreignToplevelWlr.reset(); PROTO::foreignToplevelWlr.reset();
PROTO::shortcutsInhibit.reset(); PROTO::shortcutsInhibit.reset();
PROTO::textInputV1.reset();
PROTO::textInputV3.reset(); PROTO::textInputV3.reset();
PROTO::constraints.reset(); PROTO::constraints.reset();
PROTO::outputPower.reset(); PROTO::outputPower.reset();

View file

@ -1,7 +1,6 @@
#pragma once #pragma once
#include "../defines.hpp" #include "../defines.hpp"
#include "../protocols/TextInputV1.hpp"
#include "../protocols/GlobalShortcuts.hpp" #include "../protocols/GlobalShortcuts.hpp"
#include "../helpers/Monitor.hpp" #include "../helpers/Monitor.hpp"
#include "../helpers/memory/Memory.hpp" #include "../helpers/memory/Memory.hpp"
@ -14,7 +13,6 @@ class CProtocolManager {
~CProtocolManager(); ~CProtocolManager();
// TODO: rewrite to use the new protocol framework // TODO: rewrite to use the new protocol framework
std::unique_ptr<CTextInputV1ProtocolManager> m_pTextInputV1ProtocolManager;
std::unique_ptr<CGlobalShortcutsProtocolManager> m_pGlobalShortcutsProtocolManager; std::unique_ptr<CGlobalShortcutsProtocolManager> m_pGlobalShortcutsProtocolManager;
private: private:

View file

@ -2,6 +2,7 @@
#include "InputManager.hpp" #include "InputManager.hpp"
#include "../../Compositor.hpp" #include "../../Compositor.hpp"
#include "../../protocols/TextInputV3.hpp" #include "../../protocols/TextInputV3.hpp"
#include "../../protocols/TextInputV1.hpp"
#include "../../protocols/InputMethodV2.hpp" #include "../../protocols/InputMethodV2.hpp"
#include "../../protocols/core/Compositor.hpp" #include "../../protocols/core/Compositor.hpp"
@ -9,7 +10,8 @@ CInputMethodRelay::CInputMethodRelay() {
static auto P = static auto P =
g_pHookSystem->hookDynamic("keyboardFocus", [&](void* self, SCallbackInfo& info, std::any param) { onKeyboardFocus(std::any_cast<SP<CWLSurfaceResource>>(param)); }); g_pHookSystem->hookDynamic("keyboardFocus", [&](void* self, SCallbackInfo& info, std::any param) { onKeyboardFocus(std::any_cast<SP<CWLSurfaceResource>>(param)); });
listeners.newTIV3 = PROTO::textInputV3->events.newTextInput.registerListener([this](std::any ti) { onNewTextInput(ti); }); listeners.newTIV3 = PROTO::textInputV3->events.newTextInput.registerListener([this](std::any ti) { onNewTextInput(std::any_cast<WP<CTextInputV3>>(ti)); });
listeners.newTIV1 = PROTO::textInputV1->events.newTextInput.registerListener([this](std::any ti) { onNewTextInput(std::any_cast<WP<CTextInputV1>>(ti)); });
listeners.newIME = PROTO::ime->events.newIME.registerListener([this](std::any ime) { onNewIME(std::any_cast<SP<CInputMethodV2>>(ime)); }); listeners.newIME = PROTO::ime->events.newIME.registerListener([this](std::any ime) { onNewIME(std::any_cast<SP<CInputMethodV2>>(ime)); });
} }
@ -86,11 +88,11 @@ CTextInput* CInputMethodRelay::getFocusedTextInput() {
return nullptr; return nullptr;
} }
void CInputMethodRelay::onNewTextInput(std::any tiv3) { void CInputMethodRelay::onNewTextInput(WP<CTextInputV3> tiv3) {
m_vTextInputs.emplace_back(std::make_unique<CTextInput>(std::any_cast<WP<CTextInputV3>>(tiv3))); m_vTextInputs.emplace_back(std::make_unique<CTextInput>(tiv3));
} }
void CInputMethodRelay::onNewTextInput(STextInputV1* pTIV1) { void CInputMethodRelay::onNewTextInput(WP<CTextInputV1> pTIV1) {
m_vTextInputs.emplace_back(std::make_unique<CTextInput>(pTIV1)); m_vTextInputs.emplace_back(std::make_unique<CTextInput>(pTIV1));
} }

View file

@ -10,7 +10,7 @@
class CInputManager; class CInputManager;
class CHyprRenderer; class CHyprRenderer;
struct STextInputV1; class CTextInputV1;
class CInputMethodV2; class CInputMethodV2;
class CInputMethodRelay { class CInputMethodRelay {
@ -18,8 +18,8 @@ class CInputMethodRelay {
CInputMethodRelay(); CInputMethodRelay();
void onNewIME(SP<CInputMethodV2>); void onNewIME(SP<CInputMethodV2>);
void onNewTextInput(std::any tiv3); void onNewTextInput(WP<CTextInputV3> tiv3);
void onNewTextInput(STextInputV1* pTIV1); void onNewTextInput(WP<CTextInputV1> pTIV1);
void activateIME(CTextInput* pInput); void activateIME(CTextInput* pInput);
void deactivateIME(CTextInput* pInput); void deactivateIME(CTextInput* pInput);
@ -48,6 +48,7 @@ class CInputMethodRelay {
struct { struct {
CHyprSignalListener newTIV3; CHyprSignalListener newTIV3;
CHyprSignalListener newTIV1;
CHyprSignalListener newIME; CHyprSignalListener newIME;
CHyprSignalListener commitIME; CHyprSignalListener commitIME;
CHyprSignalListener destroyIME; CHyprSignalListener destroyIME;

View file

@ -7,8 +7,7 @@
#include "../../protocols/InputMethodV2.hpp" #include "../../protocols/InputMethodV2.hpp"
#include "../../protocols/core/Compositor.hpp" #include "../../protocols/core/Compositor.hpp"
CTextInput::CTextInput(STextInputV1* ti) : pV1Input(ti) { CTextInput::CTextInput(WP<CTextInputV1> ti) : pV1Input(ti) {
ti->pTextInput = this;
initCallbacks(); initCallbacks();
} }
@ -16,17 +15,6 @@ CTextInput::CTextInput(WP<CTextInputV3> ti) : pV3Input(ti) {
initCallbacks(); initCallbacks();
} }
CTextInput::~CTextInput() {
if (pV1Input)
pV1Input->pTextInput = nullptr;
}
void CTextInput::tiV1Destroyed() {
pV1Input = nullptr;
g_pInputManager->m_sIMERelay.removeTextInput(this);
}
void CTextInput::initCallbacks() { void CTextInput::initCallbacks() {
if (isV3()) { if (isV3()) {
const auto INPUT = pV3Input.lock(); const auto INPUT = pV3Input.lock();
@ -41,25 +29,19 @@ void CTextInput::initCallbacks() {
g_pInputManager->m_sIMERelay.removeTextInput(this); g_pInputManager->m_sIMERelay.removeTextInput(this);
}); });
} else { } else {
hyprListener_textInputEnable.initCallback(&pV1Input->sEnable, [this](void* owner, void* data) { onEnabled(); }, this, "textInput"); const auto INPUT = pV1Input.lock();
hyprListener_textInputCommit.initCallback(&pV1Input->sCommit, [this](void* owner, void* data) { onCommit(); }, this, "textInput"); listeners.enable = INPUT->events.enable.registerListener([this](std::any p) {
const auto SURFACE = std::any_cast<SP<CWLSurfaceResource>>(p);
hyprListener_textInputDisable.initCallback(&pV1Input->sDisable, [this](void* owner, void* data) { onDisabled(); }, this, "textInput"); onEnabled(SURFACE);
});
hyprListener_textInputDestroy.initCallback( listeners.disable = INPUT->events.disable.registerListener([this](std::any p) { onDisabled(); });
&pV1Input->sDestroy, listeners.commit = INPUT->events.onCommit.registerListener([this](std::any p) { onCommit(); });
[this](void* owner, void* data) { listeners.destroy = INPUT->events.destroy.registerListener([this](std::any p) {
hyprListener_textInputCommit.removeCallback();
hyprListener_textInputDestroy.removeCallback();
hyprListener_textInputDisable.removeCallback();
hyprListener_textInputEnable.removeCallback();
listeners.surfaceUnmap.reset(); listeners.surfaceUnmap.reset();
listeners.surfaceDestroy.reset(); listeners.surfaceDestroy.reset();
g_pInputManager->m_sIMERelay.removeTextInput(this); g_pInputManager->m_sIMERelay.removeTextInput(this);
}, });
this, "textInput");
} }
} }
@ -149,7 +131,7 @@ void CTextInput::setFocusedSurface(SP<CWLSurfaceResource> pSurface) {
} }
bool CTextInput::isV3() { bool CTextInput::isV3() {
return !pV1Input; return pV3Input && !pV1Input;
} }
void CTextInput::enter(SP<CWLSurfaceResource> pSurface) { void CTextInput::enter(SP<CWLSurfaceResource> pSurface) {
@ -174,8 +156,7 @@ void CTextInput::enter(SP<CWLSurfaceResource> pSurface) {
if (isV3()) if (isV3())
pV3Input->enter(pSurface); pV3Input->enter(pSurface);
else { else {
zwp_text_input_v1_send_enter(pV1Input->resourceImpl, pSurface->getResource()->resource()); pV1Input->enter(pSurface);
pV1Input->active = true;
} }
setFocusedSurface(pSurface); setFocusedSurface(pSurface);
@ -194,8 +175,7 @@ void CTextInput::leave() {
if (isV3() && focusedSurface()) if (isV3() && focusedSurface())
pV3Input->leave(focusedSurface()); pV3Input->leave(focusedSurface());
else if (focusedSurface() && pV1Input) { else if (focusedSurface() && pV1Input) {
zwp_text_input_v1_send_leave(pV1Input->resourceImpl); pV1Input->leave();
pV1Input->active = false;
} }
setFocusedSurface(nullptr); setFocusedSurface(nullptr);
@ -208,7 +188,7 @@ SP<CWLSurfaceResource> CTextInput::focusedSurface() {
} }
wl_client* CTextInput::client() { wl_client* CTextInput::client() {
return isV3() ? pV3Input->client() : pV1Input->client; return isV3() ? pV3Input->client() : pV1Input->client();
} }
void CTextInput::commitStateToIME(SP<CInputMethodV2> ime) { void CTextInput::commitStateToIME(SP<CInputMethodV2> ime) {
@ -223,13 +203,15 @@ void CTextInput::commitStateToIME(SP<CInputMethodV2> ime) {
if (INPUT->current.contentType.updated) if (INPUT->current.contentType.updated)
ime->textContentType(INPUT->current.contentType.hint, INPUT->current.contentType.purpose); ime->textContentType(INPUT->current.contentType.hint, INPUT->current.contentType.purpose);
} else { } else {
if (pV1Input->pendingSurrounding.isPending) const auto INPUT = pV1Input.lock();
ime->surroundingText(pV1Input->pendingSurrounding.text, pV1Input->pendingSurrounding.cursor, pV1Input->pendingSurrounding.anchor);
if (INPUT->pendingSurrounding.isPending)
ime->surroundingText(INPUT->pendingSurrounding.text, INPUT->pendingSurrounding.cursor, INPUT->pendingSurrounding.anchor);
ime->textChangeCause(ZWP_TEXT_INPUT_V3_CHANGE_CAUSE_INPUT_METHOD); ime->textChangeCause(ZWP_TEXT_INPUT_V3_CHANGE_CAUSE_INPUT_METHOD);
if (pV1Input->pendingContentType.isPending) if (pV1Input->pendingContentType.isPending)
ime->textContentType((zwpTextInputV3ContentHint)pV1Input->pendingContentType.hint, (zwpTextInputV3ContentPurpose)pV1Input->pendingContentType.purpose); ime->textContentType((zwpTextInputV3ContentHint)INPUT->pendingContentType.hint, (zwpTextInputV3ContentPurpose)INPUT->pendingContentType.purpose);
} }
g_pInputManager->m_sIMERelay.updateAllPopups(); g_pInputManager->m_sIMERelay.updateAllPopups();
@ -252,25 +234,27 @@ void CTextInput::updateIMEState(SP<CInputMethodV2> ime) {
INPUT->sendDone(); INPUT->sendDone();
} else { } else {
const auto INPUT = pV1Input.lock();
if (ime->current.preeditString.committed) { if (ime->current.preeditString.committed) {
zwp_text_input_v1_send_preedit_cursor(pV1Input->resourceImpl, ime->current.preeditString.begin); INPUT->preeditCursor(ime->current.preeditString.begin);
zwp_text_input_v1_send_preedit_styling(pV1Input->resourceImpl, 0, std::string(ime->current.preeditString.string).length(), ZWP_TEXT_INPUT_V1_PREEDIT_STYLE_HIGHLIGHT); INPUT->preeditStyling(0, std::string(ime->current.preeditString.string).length(), ZWP_TEXT_INPUT_V1_PREEDIT_STYLE_HIGHLIGHT);
zwp_text_input_v1_send_preedit_string(pV1Input->resourceImpl, pV1Input->serial, ime->current.preeditString.string.c_str(), ""); INPUT->preeditString(pV1Input->serial, ime->current.preeditString.string.c_str(), "");
} else { } else {
zwp_text_input_v1_send_preedit_cursor(pV1Input->resourceImpl, ime->current.preeditString.begin); INPUT->preeditCursor(ime->current.preeditString.begin);
zwp_text_input_v1_send_preedit_styling(pV1Input->resourceImpl, 0, 0, ZWP_TEXT_INPUT_V1_PREEDIT_STYLE_HIGHLIGHT); INPUT->preeditStyling(0, 0, ZWP_TEXT_INPUT_V1_PREEDIT_STYLE_HIGHLIGHT);
zwp_text_input_v1_send_preedit_string(pV1Input->resourceImpl, pV1Input->serial, "", ""); INPUT->preeditString(pV1Input->serial, "", "");
} }
if (ime->current.committedString.committed) if (ime->current.committedString.committed)
zwp_text_input_v1_send_commit_string(pV1Input->resourceImpl, pV1Input->serial, ime->current.committedString.string.c_str()); INPUT->commitString(pV1Input->serial, ime->current.committedString.string.c_str());
if (ime->current.deleteSurrounding.committed) { if (ime->current.deleteSurrounding.committed) {
zwp_text_input_v1_send_delete_surrounding_text(pV1Input->resourceImpl, std::string(ime->current.preeditString.string).length() - ime->current.deleteSurrounding.before, INPUT->deleteSurroundingText(std::string(ime->current.preeditString.string).length() - ime->current.deleteSurrounding.before,
ime->current.deleteSurrounding.after + ime->current.deleteSurrounding.before); ime->current.deleteSurrounding.after + ime->current.deleteSurrounding.before);
if (ime->current.preeditString.committed) if (ime->current.preeditString.committed)
zwp_text_input_v1_send_commit_string(pV1Input->resourceImpl, pV1Input->serial, ime->current.preeditString.string.c_str()); INPUT->commitString(pV1Input->serial, ime->current.preeditString.string.c_str());
} }
} }
} }

View file

@ -8,7 +8,7 @@
struct wl_client; struct wl_client;
struct STextInputV1; class CTextInputV1;
class CTextInputV3; class CTextInputV3;
class CInputMethodV2; class CInputMethodV2;
class CWLSurfaceResource; class CWLSurfaceResource;
@ -16,8 +16,7 @@ class CWLSurfaceResource;
class CTextInput { class CTextInput {
public: public:
CTextInput(WP<CTextInputV3> ti); CTextInput(WP<CTextInputV3> ti);
CTextInput(STextInputV1* ti); CTextInput(WP<CTextInputV1> ti);
~CTextInput();
bool isV3(); bool isV3();
void enter(SP<CWLSurfaceResource> pSurface); void enter(SP<CWLSurfaceResource> pSurface);
@ -43,12 +42,7 @@ class CTextInput {
WP<CWLSurfaceResource> pFocusedSurface; WP<CWLSurfaceResource> pFocusedSurface;
int enterLocks = 0; int enterLocks = 0;
WP<CTextInputV3> pV3Input; WP<CTextInputV3> pV3Input;
STextInputV1* pV1Input = nullptr; WP<CTextInputV1> pV1Input;
DYNLISTENER(textInputEnable);
DYNLISTENER(textInputDisable);
DYNLISTENER(textInputCommit);
DYNLISTENER(textInputDestroy);
struct { struct {
CHyprSignalListener enable; CHyprSignalListener enable;

View file

@ -3,228 +3,125 @@
#include "../Compositor.hpp" #include "../Compositor.hpp"
#include "core/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) { CTextInputV1::~CTextInputV1() {
g_pProtocolManager->m_pTextInputV1ProtocolManager->bindManager(client, data, version, id); events.destroy.emit();
} }
static void handleDisplayDestroy(struct wl_listener* listener, void* data) { CTextInputV1::CTextInputV1(SP<CZwpTextInputV1> resource_) : resource(resource_) {
CTextInputV1ProtocolManager* proto = wl_container_of(listener, proto, m_liDisplayDestroy); if (!good())
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!");
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);
}
static const struct zwp_text_input_manager_v1_interface textInputManagerImpl = {
.create_text_input = createTI,
};
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);
Debug::log(LOG, "TextInputV1Manager bound successfully!");
}
//
static void handleActivate(wl_client* client, wl_resource* resource, wl_resource* seat, wl_resource* surface) {
g_pProtocolManager->m_pTextInputV1ProtocolManager->handleActivate(client, resource, seat, surface);
}
static void handleDeactivate(wl_client* client, wl_resource* resource, wl_resource* seat) {
g_pProtocolManager->m_pTextInputV1ProtocolManager->handleDeactivate(client, resource, seat);
}
static void handleShowInputPanel(wl_client* client, wl_resource* resource) {
g_pProtocolManager->m_pTextInputV1ProtocolManager->handleShowInputPanel(client, resource);
}
static void handleHideInputPanel(wl_client* client, wl_resource* resource) {
g_pProtocolManager->m_pTextInputV1ProtocolManager->handleHideInputPanel(client, resource);
}
static void handleReset(wl_client* client, wl_resource* resource) {
g_pProtocolManager->m_pTextInputV1ProtocolManager->handleReset(client, resource);
}
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);
}
static void handleSetContentType(wl_client* client, wl_resource* resource, uint32_t hint, uint32_t purpose) {
g_pProtocolManager->m_pTextInputV1ProtocolManager->handleSetContentType(client, resource, hint, purpose);
}
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);
}
static void handleSetPreferredLanguage(wl_client* client, wl_resource* resource, const char* language) {
g_pProtocolManager->m_pTextInputV1ProtocolManager->handleSetPreferredLanguage(client, resource, language);
}
static void handleCommitState(wl_client* client, wl_resource* resource, uint32_t serial) {
g_pProtocolManager->m_pTextInputV1ProtocolManager->handleCommitState(client, resource, serial);
}
static void handleInvokeAction(wl_client* client, wl_resource* resource, uint32_t button, uint32_t index) {
g_pProtocolManager->m_pTextInputV1ProtocolManager->handleInvokeAction(client, resource, button, index);
}
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; return;
// if ((*TI)->resourceImpl) resource->setOnDestroy([this](CZwpTextInputV1* pMgr) { PROTO::textInputV1->destroyResource(this); });
// wl_resource_destroy((*TI)->resourceImpl);
std::erase_if(m_pClients, [&](const auto& other) { return other.get() == pTI; }); resource->setActivate([this](CZwpTextInputV1* pMgr, wl_resource* seat, wl_resource* surface) {
}
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);
}
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 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) { if (!surface) {
Debug::log(WARN, "Text-input-v1 PTI{:x}: No surface to activate text input on!", (uintptr_t)PTI); LOGM(WARN, "Text-input-v1 PTI{:x}: No surface to activate text input on!", (uintptr_t)this);
return; return;
} }
PTI->active = true;
PTI->pTextInput->onEnabled(CWLSurfaceResource::fromResource(surface));
}
void CTextInputV1ProtocolManager::handleDeactivate(wl_client* client, wl_resource* resource, wl_resource* seat) { active = true;
const auto PTI = tiFromResource(resource); events.enable.emit(CWLSurfaceResource::fromResource(surface));
PTI->active = false; });
PTI->pTextInput->onDisabled();
}
void CTextInputV1ProtocolManager::handleShowInputPanel(wl_client* client, wl_resource* resource) { resource->setDeactivate([this](CZwpTextInputV1* pMgr, wl_resource* seat) {
; active = false;
} events.disable.emit();
});
void CTextInputV1ProtocolManager::handleHideInputPanel(wl_client* client, wl_resource* resource) { resource->setReset([this](CZwpTextInputV1* pMgr) {
; pendingSurrounding.isPending = false;
} pendingContentType.isPending = false;
});
void CTextInputV1ProtocolManager::handleReset(wl_client* client, wl_resource* resource) { resource->setSetSurroundingText(
const auto PTI = tiFromResource(resource); [this](CZwpTextInputV1* pMgr, const char* text, uint32_t cursor, uint32_t anchor) { pendingSurrounding = {true, std::string(text), cursor, anchor}; });
PTI->pendingSurrounding.isPending = false;
PTI->pendingContentType.isPending = false;
}
void CTextInputV1ProtocolManager::handleSetSurroundingText(wl_client* client, wl_resource* resource, const char* text, uint32_t cursor, uint32_t anchor) { resource->setSetContentType([this](CZwpTextInputV1* pMgr, uint32_t hint, uint32_t purpose) {
const auto PTI = tiFromResource(resource); pendingContentType = {true, hint == (uint32_t)ZWP_TEXT_INPUT_V1_CONTENT_HINT_DEFAULT ? (uint32_t)ZWP_TEXT_INPUT_V1_CONTENT_HINT_NONE : hint,
PTI->pendingSurrounding = {true, std::string(text), cursor, anchor};
}
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}; purpose > (uint32_t)ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_PASSWORD ? hint + 1 : hint};
});
resource->setSetCursorRectangle([this](CZwpTextInputV1* pMgr, int32_t x, int32_t y, int32_t width, int32_t height) { cursorRectangle = CBox{x, y, width, height}; });
resource->setCommitState([this](CZwpTextInputV1* pMgr, uint32_t serial_) {
serial = serial_;
events.onCommit.emit();
});
// 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) {});
} }
void CTextInputV1ProtocolManager::handleSetCursorRectangle(wl_client* client, wl_resource* resource, int32_t x, int32_t y, int32_t width, int32_t height) { bool CTextInputV1::good() {
const auto PTI = tiFromResource(resource); return resource->resource();
PTI->cursorRectangle = CBox{x, y, width, height};
} }
void CTextInputV1ProtocolManager::handleSetPreferredLanguage(wl_client* client, wl_resource* resource, const char* language) { wl_client* CTextInputV1::client() {
return resource->client();
}
void CTextInputV1::enter(SP<CWLSurfaceResource> surface) {
resource->sendEnter(surface->getResource()->resource());
active = true;
}
void CTextInputV1::leave() {
resource->sendLeave();
active = false;
}
void CTextInputV1::preeditCursor(int32_t index) {
resource->sendPreeditCursor(index);
}
void CTextInputV1::preeditStyling(uint32_t index, uint32_t length, zwpTextInputV1PreeditStyle style) {
resource->sendPreeditStyling(index, length, style);
}
void CTextInputV1::preeditString(uint32_t serial, const char* text, const char* commit) {
resource->sendPreeditString(serial, text, commit);
}
void CTextInputV1::commitString(uint32_t serial, const char* text) {
resource->sendCommitString(serial, text);
}
void CTextInputV1::deleteSurroundingText(int32_t index, uint32_t length) {
resource->sendDeleteSurroundingText(index, length);
}
CTextInputV1Protocol::CTextInputV1Protocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
; ;
} }
void CTextInputV1ProtocolManager::handleCommitState(wl_client* client, wl_resource* resource, uint32_t serial) { void CTextInputV1Protocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto PTI = tiFromResource(resource); const auto RESOURCE = m_vManagers.emplace_back(makeShared<CZwpTextInputManagerV1>(client, ver, id));
PTI->serial = serial;
PTI->pTextInput->onCommit(); 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());
if (!PTI->good()) {
LOGM(ERR, "Could not alloc wl_resource for TIV1");
pMgr->noMemory();
PROTO::textInputV1->destroyResource(PTI.get());
return;
}
events.newTextInput.emit(WP<CTextInputV1>(PTI));
});
} }
void CTextInputV1ProtocolManager::handleInvokeAction(wl_client* client, wl_resource* resource, uint32_t button, uint32_t index) { void CTextInputV1Protocol::destroyResource(CTextInputV1* client) {
; std::erase_if(m_vClients, [&](const auto& other) { return other.get() == client; });
}
void CTextInputV1Protocol::destroyResource(CZwpTextInputManagerV1* client) {
std::erase_if(m_vManagers, [&](const auto& other) { return other.get() == client; });
} }

View file

@ -1,29 +1,45 @@
#pragma once #pragma once
#include "../defines.hpp" #include "../defines.hpp"
#include "text-input-unstable-v1-protocol.h" #include "../protocols/core/Compositor.hpp"
#include "text-input-unstable-v1.hpp"
#include "WaylandProtocol.hpp"
#include <vector> #include <vector>
class CTextInput; class CTextInput;
struct STextInputV1 { class CTextInputV1 {
wl_client* client = nullptr; public:
wl_resource* resourceCaller = nullptr; CTextInputV1(SP<CZwpTextInputV1> resource);
~CTextInputV1();
wl_resource* resourceImpl = nullptr; void enter(SP<CWLSurfaceResource> surface);
void leave();
CTextInput* pTextInput = nullptr; void preeditCursor(int32_t index);
void preeditStyling(uint32_t index, uint32_t length, zwpTextInputV1PreeditStyle style);
void preeditString(uint32_t serial, const char* text, const char* commit);
void commitString(uint32_t serial, const char* text);
void deleteSurroundingText(int32_t index, uint32_t length);
wl_signal sEnable; bool good();
wl_signal sDisable; wl_client* client();
wl_signal sCommit;
wl_signal sDestroy; private:
SP<CZwpTextInputV1> resource;
WP<CTextInputV1> self;
uint32_t serial = 0; uint32_t serial = 0;
bool active = false; bool active = false;
struct {
CSignal onCommit;
CSignal enable;
CSignal disable;
CSignal destroy;
} events;
struct SPendingSurr { struct SPendingSurr {
bool isPending = false; bool isPending = false;
std::string text = ""; std::string text = "";
@ -39,39 +55,29 @@ struct STextInputV1 {
CBox cursorRectangle = {0, 0, 0, 0}; CBox cursorRectangle = {0, 0, 0, 0};
bool operator==(const STextInputV1& other) { friend class CTextInput;
return other.client == client && other.resourceCaller == resourceCaller && other.resourceImpl == resourceImpl; friend class CTextInputV1Protocol;
}
}; };
class CTextInputV1ProtocolManager { class CTextInputV1Protocol : IWaylandProtocol {
public: public:
CTextInputV1ProtocolManager(); CTextInputV1Protocol(const wl_interface* iface, const int& ver, const std::string& name);
~CTextInputV1ProtocolManager();
void bindManager(wl_client* client, void* data, uint32_t version, uint32_t id); virtual void bindManager(wl_client* client, void* data, uint32_t version, uint32_t id);
void createTI(wl_client* client, wl_resource* resource, uint32_t id); void destroyResource(CTextInputV1* resource);
void removeTI(STextInputV1* pTI); void destroyResource(CZwpTextInputManagerV1* client);
void displayDestroy(); struct {
CSignal newTextInput; // WP<CTextInputV3>
// handlers for tiv1 } events;
void handleActivate(wl_client* client, wl_resource* resource, wl_resource* seat, wl_resource* surface);
void handleDeactivate(wl_client* client, wl_resource* resource, wl_resource* seat);
void handleShowInputPanel(wl_client* client, wl_resource* resource);
void handleHideInputPanel(wl_client* client, wl_resource* resource);
void handleReset(wl_client* client, wl_resource* resource);
void handleSetSurroundingText(wl_client* client, wl_resource* resource, const char* text, uint32_t cursor, uint32_t anchor);
void handleSetContentType(wl_client* client, wl_resource* resource, uint32_t hint, uint32_t purpose);
void handleSetCursorRectangle(wl_client* client, wl_resource* resource, int32_t x, int32_t y, int32_t width, int32_t height);
void handleSetPreferredLanguage(wl_client* client, wl_resource* resource, const char* language);
void handleCommitState(wl_client* client, wl_resource* resource, uint32_t serial);
void handleInvokeAction(wl_client* client, wl_resource* resource, uint32_t button, uint32_t index);
wl_listener m_liDisplayDestroy;
private: private:
wl_global* m_pGlobal = nullptr; std::vector<SP<CZwpTextInputManagerV1>> m_vManagers;
std::vector<SP<CTextInputV1>> m_vClients;
std::vector<std::unique_ptr<STextInputV1>> m_pClients; friend class CTextInputV1;
};
namespace PROTO {
inline UP<CTextInputV1Protocol> textInputV1;
}; };

View file

@ -8,6 +8,7 @@
#include "wlr-virtual-pointer-unstable-v1.hpp" #include "wlr-virtual-pointer-unstable-v1.hpp"
#include "../helpers/signal/Signal.hpp" #include "../helpers/signal/Signal.hpp"
#include "../devices/IPointer.hpp" #include "../devices/IPointer.hpp"
#include "../helpers/Monitor.hpp"
class CVirtualPointerV1Resource { class CVirtualPointerV1Resource {
public: public: