mirror of
https://github.com/hyprwm/Hyprland.git
synced 2025-08-15 03:55:46 -07:00
protocols: move text-input-v1 to hyprwayland-scanner (#7096)
* move text-input-v1 to hyprwayland-scanner * vro
This commit is contained in:
@@ -7,8 +7,7 @@
|
||||
#include "../../protocols/InputMethodV2.hpp"
|
||||
#include "../../protocols/core/Compositor.hpp"
|
||||
|
||||
CTextInput::CTextInput(STextInputV1* ti) : pV1Input(ti) {
|
||||
ti->pTextInput = this;
|
||||
CTextInput::CTextInput(WP<CTextInputV1> ti) : pV1Input(ti) {
|
||||
initCallbacks();
|
||||
}
|
||||
|
||||
@@ -16,17 +15,6 @@ CTextInput::CTextInput(WP<CTextInputV3> ti) : pV3Input(ti) {
|
||||
initCallbacks();
|
||||
}
|
||||
|
||||
CTextInput::~CTextInput() {
|
||||
if (pV1Input)
|
||||
pV1Input->pTextInput = nullptr;
|
||||
}
|
||||
|
||||
void CTextInput::tiV1Destroyed() {
|
||||
pV1Input = nullptr;
|
||||
|
||||
g_pInputManager->m_sIMERelay.removeTextInput(this);
|
||||
}
|
||||
|
||||
void CTextInput::initCallbacks() {
|
||||
if (isV3()) {
|
||||
const auto INPUT = pV3Input.lock();
|
||||
@@ -41,25 +29,19 @@ void CTextInput::initCallbacks() {
|
||||
g_pInputManager->m_sIMERelay.removeTextInput(this);
|
||||
});
|
||||
} 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");
|
||||
|
||||
hyprListener_textInputDisable.initCallback(&pV1Input->sDisable, [this](void* owner, void* data) { onDisabled(); }, this, "textInput");
|
||||
|
||||
hyprListener_textInputDestroy.initCallback(
|
||||
&pV1Input->sDestroy,
|
||||
[this](void* owner, void* data) {
|
||||
hyprListener_textInputCommit.removeCallback();
|
||||
hyprListener_textInputDestroy.removeCallback();
|
||||
hyprListener_textInputDisable.removeCallback();
|
||||
hyprListener_textInputEnable.removeCallback();
|
||||
listeners.surfaceUnmap.reset();
|
||||
listeners.surfaceDestroy.reset();
|
||||
|
||||
g_pInputManager->m_sIMERelay.removeTextInput(this);
|
||||
},
|
||||
this, "textInput");
|
||||
listeners.enable = INPUT->events.enable.registerListener([this](std::any p) {
|
||||
const auto SURFACE = std::any_cast<SP<CWLSurfaceResource>>(p);
|
||||
onEnabled(SURFACE);
|
||||
});
|
||||
listeners.disable = INPUT->events.disable.registerListener([this](std::any p) { onDisabled(); });
|
||||
listeners.commit = INPUT->events.onCommit.registerListener([this](std::any p) { onCommit(); });
|
||||
listeners.destroy = INPUT->events.destroy.registerListener([this](std::any p) {
|
||||
listeners.surfaceUnmap.reset();
|
||||
listeners.surfaceDestroy.reset();
|
||||
g_pInputManager->m_sIMERelay.removeTextInput(this);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,7 +131,7 @@ void CTextInput::setFocusedSurface(SP<CWLSurfaceResource> pSurface) {
|
||||
}
|
||||
|
||||
bool CTextInput::isV3() {
|
||||
return !pV1Input;
|
||||
return pV3Input && !pV1Input;
|
||||
}
|
||||
|
||||
void CTextInput::enter(SP<CWLSurfaceResource> pSurface) {
|
||||
@@ -174,8 +156,7 @@ void CTextInput::enter(SP<CWLSurfaceResource> pSurface) {
|
||||
if (isV3())
|
||||
pV3Input->enter(pSurface);
|
||||
else {
|
||||
zwp_text_input_v1_send_enter(pV1Input->resourceImpl, pSurface->getResource()->resource());
|
||||
pV1Input->active = true;
|
||||
pV1Input->enter(pSurface);
|
||||
}
|
||||
|
||||
setFocusedSurface(pSurface);
|
||||
@@ -194,8 +175,7 @@ void CTextInput::leave() {
|
||||
if (isV3() && focusedSurface())
|
||||
pV3Input->leave(focusedSurface());
|
||||
else if (focusedSurface() && pV1Input) {
|
||||
zwp_text_input_v1_send_leave(pV1Input->resourceImpl);
|
||||
pV1Input->active = false;
|
||||
pV1Input->leave();
|
||||
}
|
||||
|
||||
setFocusedSurface(nullptr);
|
||||
@@ -208,7 +188,7 @@ SP<CWLSurfaceResource> CTextInput::focusedSurface() {
|
||||
}
|
||||
|
||||
wl_client* CTextInput::client() {
|
||||
return isV3() ? pV3Input->client() : pV1Input->client;
|
||||
return isV3() ? pV3Input->client() : pV1Input->client();
|
||||
}
|
||||
|
||||
void CTextInput::commitStateToIME(SP<CInputMethodV2> ime) {
|
||||
@@ -223,13 +203,15 @@ void CTextInput::commitStateToIME(SP<CInputMethodV2> ime) {
|
||||
if (INPUT->current.contentType.updated)
|
||||
ime->textContentType(INPUT->current.contentType.hint, INPUT->current.contentType.purpose);
|
||||
} else {
|
||||
if (pV1Input->pendingSurrounding.isPending)
|
||||
ime->surroundingText(pV1Input->pendingSurrounding.text, pV1Input->pendingSurrounding.cursor, pV1Input->pendingSurrounding.anchor);
|
||||
const auto INPUT = pV1Input.lock();
|
||||
|
||||
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);
|
||||
|
||||
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();
|
||||
@@ -252,25 +234,27 @@ void CTextInput::updateIMEState(SP<CInputMethodV2> ime) {
|
||||
|
||||
INPUT->sendDone();
|
||||
} else {
|
||||
const auto INPUT = pV1Input.lock();
|
||||
|
||||
if (ime->current.preeditString.committed) {
|
||||
zwp_text_input_v1_send_preedit_cursor(pV1Input->resourceImpl, 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);
|
||||
zwp_text_input_v1_send_preedit_string(pV1Input->resourceImpl, pV1Input->serial, ime->current.preeditString.string.c_str(), "");
|
||||
INPUT->preeditCursor(ime->current.preeditString.begin);
|
||||
INPUT->preeditStyling(0, std::string(ime->current.preeditString.string).length(), ZWP_TEXT_INPUT_V1_PREEDIT_STYLE_HIGHLIGHT);
|
||||
INPUT->preeditString(pV1Input->serial, ime->current.preeditString.string.c_str(), "");
|
||||
} else {
|
||||
zwp_text_input_v1_send_preedit_cursor(pV1Input->resourceImpl, ime->current.preeditString.begin);
|
||||
zwp_text_input_v1_send_preedit_styling(pV1Input->resourceImpl, 0, 0, ZWP_TEXT_INPUT_V1_PREEDIT_STYLE_HIGHLIGHT);
|
||||
zwp_text_input_v1_send_preedit_string(pV1Input->resourceImpl, pV1Input->serial, "", "");
|
||||
INPUT->preeditCursor(ime->current.preeditString.begin);
|
||||
INPUT->preeditStyling(0, 0, ZWP_TEXT_INPUT_V1_PREEDIT_STYLE_HIGHLIGHT);
|
||||
INPUT->preeditString(pV1Input->serial, "", "");
|
||||
}
|
||||
|
||||
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) {
|
||||
zwp_text_input_v1_send_delete_surrounding_text(pV1Input->resourceImpl, std::string(ime->current.preeditString.string).length() - ime->current.deleteSurrounding.before,
|
||||
ime->current.deleteSurrounding.after + 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);
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -281,4 +265,4 @@ bool CTextInput::hasCursorRectangle() {
|
||||
|
||||
CBox CTextInput::cursorBox() {
|
||||
return CBox{isV3() ? pV3Input->current.box.cursorBox : pV1Input->cursorRectangle};
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user