protocols: move text-input-v1 to hyprwayland-scanner (#7096)
* move text-input-v1 to hyprwayland-scanner * vro
This commit is contained in:
parent
01560c9d7c
commit
60b663e276
11 changed files with 196 additions and 314 deletions
|
|
@ -41,6 +41,7 @@
|
|||
#include "../protocols/DRMSyncobj.hpp"
|
||||
#include "../protocols/Screencopy.hpp"
|
||||
#include "../protocols/ToplevelExport.hpp"
|
||||
#include "../protocols/TextInputV1.hpp"
|
||||
|
||||
#include "../protocols/core/Seat.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::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::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::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");
|
||||
|
|
@ -165,7 +167,6 @@ CProtocolManager::CProtocolManager() {
|
|||
|
||||
// Old protocol implementations.
|
||||
// TODO: rewrite them to use hyprwayland-scanner.
|
||||
m_pTextInputV1ProtocolManager = std::make_unique<CTextInputV1ProtocolManager>();
|
||||
m_pGlobalShortcutsProtocolManager = std::make_unique<CGlobalShortcutsProtocolManager>();
|
||||
}
|
||||
|
||||
|
|
@ -197,6 +198,7 @@ CProtocolManager::~CProtocolManager() {
|
|||
PROTO::pointerGestures.reset();
|
||||
PROTO::foreignToplevelWlr.reset();
|
||||
PROTO::shortcutsInhibit.reset();
|
||||
PROTO::textInputV1.reset();
|
||||
PROTO::textInputV3.reset();
|
||||
PROTO::constraints.reset();
|
||||
PROTO::outputPower.reset();
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "../defines.hpp"
|
||||
#include "../protocols/TextInputV1.hpp"
|
||||
#include "../protocols/GlobalShortcuts.hpp"
|
||||
#include "../helpers/Monitor.hpp"
|
||||
#include "../helpers/memory/Memory.hpp"
|
||||
|
|
@ -14,7 +13,6 @@ class CProtocolManager {
|
|||
~CProtocolManager();
|
||||
|
||||
// TODO: rewrite to use the new protocol framework
|
||||
std::unique_ptr<CTextInputV1ProtocolManager> m_pTextInputV1ProtocolManager;
|
||||
std::unique_ptr<CGlobalShortcutsProtocolManager> m_pGlobalShortcutsProtocolManager;
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#include "InputManager.hpp"
|
||||
#include "../../Compositor.hpp"
|
||||
#include "../../protocols/TextInputV3.hpp"
|
||||
#include "../../protocols/TextInputV1.hpp"
|
||||
#include "../../protocols/InputMethodV2.hpp"
|
||||
#include "../../protocols/core/Compositor.hpp"
|
||||
|
||||
|
|
@ -9,7 +10,8 @@ CInputMethodRelay::CInputMethodRelay() {
|
|||
static auto P =
|
||||
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)); });
|
||||
}
|
||||
|
||||
|
|
@ -86,11 +88,11 @@ CTextInput* CInputMethodRelay::getFocusedTextInput() {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
void CInputMethodRelay::onNewTextInput(std::any tiv3) {
|
||||
m_vTextInputs.emplace_back(std::make_unique<CTextInput>(std::any_cast<WP<CTextInputV3>>(tiv3)));
|
||||
void CInputMethodRelay::onNewTextInput(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));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
class CInputManager;
|
||||
class CHyprRenderer;
|
||||
struct STextInputV1;
|
||||
class CTextInputV1;
|
||||
class CInputMethodV2;
|
||||
|
||||
class CInputMethodRelay {
|
||||
|
|
@ -18,8 +18,8 @@ class CInputMethodRelay {
|
|||
CInputMethodRelay();
|
||||
|
||||
void onNewIME(SP<CInputMethodV2>);
|
||||
void onNewTextInput(std::any tiv3);
|
||||
void onNewTextInput(STextInputV1* pTIV1);
|
||||
void onNewTextInput(WP<CTextInputV3> tiv3);
|
||||
void onNewTextInput(WP<CTextInputV1> pTIV1);
|
||||
|
||||
void activateIME(CTextInput* pInput);
|
||||
void deactivateIME(CTextInput* pInput);
|
||||
|
|
@ -48,6 +48,7 @@ class CInputMethodRelay {
|
|||
|
||||
struct {
|
||||
CHyprSignalListener newTIV3;
|
||||
CHyprSignalListener newTIV1;
|
||||
CHyprSignalListener newIME;
|
||||
CHyprSignalListener commitIME;
|
||||
CHyprSignalListener destroyIME;
|
||||
|
|
|
|||
|
|
@ -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};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
struct wl_client;
|
||||
|
||||
struct STextInputV1;
|
||||
class CTextInputV1;
|
||||
class CTextInputV3;
|
||||
class CInputMethodV2;
|
||||
class CWLSurfaceResource;
|
||||
|
|
@ -16,8 +16,7 @@ class CWLSurfaceResource;
|
|||
class CTextInput {
|
||||
public:
|
||||
CTextInput(WP<CTextInputV3> ti);
|
||||
CTextInput(STextInputV1* ti);
|
||||
~CTextInput();
|
||||
CTextInput(WP<CTextInputV1> ti);
|
||||
|
||||
bool isV3();
|
||||
void enter(SP<CWLSurfaceResource> pSurface);
|
||||
|
|
@ -43,12 +42,7 @@ class CTextInput {
|
|||
WP<CWLSurfaceResource> pFocusedSurface;
|
||||
int enterLocks = 0;
|
||||
WP<CTextInputV3> pV3Input;
|
||||
STextInputV1* pV1Input = nullptr;
|
||||
|
||||
DYNLISTENER(textInputEnable);
|
||||
DYNLISTENER(textInputDisable);
|
||||
DYNLISTENER(textInputCommit);
|
||||
DYNLISTENER(textInputDestroy);
|
||||
WP<CTextInputV1> pV1Input;
|
||||
|
||||
struct {
|
||||
CHyprSignalListener enable;
|
||||
|
|
@ -58,4 +52,4 @@ class CTextInput {
|
|||
CHyprSignalListener surfaceUnmap;
|
||||
CHyprSignalListener surfaceDestroy;
|
||||
} listeners;
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue