summaryrefslogtreecommitdiff
path: root/src/managers/input
diff options
context:
space:
mode:
authorVaxry <vaxry@vaxry.net>2024-04-25 23:27:25 +0100
committerVaxry <vaxry@vaxry.net>2024-04-25 23:27:44 +0100
commit1d40af64d352bd5a87c7d53a52707fc5cfc6940e (patch)
tree7ad6d1f0dbe3f4d972faf487ffa0cbc9420ee82d /src/managers/input
parente87227e00ae350adebafd2adde95a47e1f68cb3a (diff)
text-input-v3: move to new impl
Diffstat (limited to 'src/managers/input')
-rw-r--r--src/managers/input/InputMethodRelay.cpp7
-rw-r--r--src/managers/input/InputMethodRelay.hpp8
-rw-r--r--src/managers/input/TextInput.cpp111
-rw-r--r--src/managers/input/TextInput.hpp25
4 files changed, 91 insertions, 60 deletions
diff --git a/src/managers/input/InputMethodRelay.cpp b/src/managers/input/InputMethodRelay.cpp
index 17da87ea..4f1cd278 100644
--- a/src/managers/input/InputMethodRelay.cpp
+++ b/src/managers/input/InputMethodRelay.cpp
@@ -1,9 +1,12 @@
#include "InputMethodRelay.hpp"
#include "InputManager.hpp"
#include "../../Compositor.hpp"
+#include "../../protocols/TextInputV3.hpp"
CInputMethodRelay::CInputMethodRelay() {
static auto P = g_pHookSystem->hookDynamic("keyboardFocus", [&](void* self, SCallbackInfo& info, std::any param) { onKeyboardFocus(std::any_cast<wlr_surface*>(param)); });
+
+ listeners.newTIV3 = PROTO::textInputV3->events.newTextInput.registerListener([this](std::any ti) { onNewTextInput(ti); });
}
void CInputMethodRelay::onNewIME(wlr_input_method_v2* pIME) {
@@ -142,8 +145,8 @@ CTextInput* CInputMethodRelay::getFocusedTextInput() {
return nullptr;
}
-void CInputMethodRelay::onNewTextInput(wlr_text_input_v3* pInput) {
- m_vTextInputs.emplace_back(std::make_unique<CTextInput>(pInput));
+void CInputMethodRelay::onNewTextInput(std::any tiv3) {
+ m_vTextInputs.emplace_back(std::make_unique<CTextInput>(std::any_cast<std::weak_ptr<CTextInputV3>>(tiv3)));
}
void CInputMethodRelay::onNewTextInput(STextInputV1* pTIV1) {
diff --git a/src/managers/input/InputMethodRelay.hpp b/src/managers/input/InputMethodRelay.hpp
index 01d36675..1b2cb07a 100644
--- a/src/managers/input/InputMethodRelay.hpp
+++ b/src/managers/input/InputMethodRelay.hpp
@@ -3,8 +3,10 @@
#include <list>
#include "../../defines.hpp"
#include "../../helpers/WLClasses.hpp"
+#include "../../helpers/signal/Listener.hpp"
#include "TextInput.hpp"
#include "InputMethodPopup.hpp"
+#include <any>
class CInputManager;
class CHyprRenderer;
@@ -15,7 +17,7 @@ class CInputMethodRelay {
CInputMethodRelay();
void onNewIME(wlr_input_method_v2*);
- void onNewTextInput(wlr_text_input_v3*);
+ void onNewTextInput(std::any tiv3);
void onNewTextInput(STextInputV1* pTIV1);
wlr_input_method_v2* m_pWLRIME = nullptr;
@@ -47,6 +49,10 @@ class CInputMethodRelay {
wlr_surface* m_pLastKbFocus = nullptr;
+ struct {
+ CHyprSignalListener newTIV3;
+ } listeners;
+
DYNLISTENER(textInputNew);
DYNLISTENER(IMECommit);
DYNLISTENER(IMEDestroy);
diff --git a/src/managers/input/TextInput.cpp b/src/managers/input/TextInput.cpp
index be26d39c..12f13971 100644
--- a/src/managers/input/TextInput.cpp
+++ b/src/managers/input/TextInput.cpp
@@ -3,13 +3,14 @@
#include "InputManager.hpp"
#include "../../protocols/TextInputV1.hpp"
#include "../../Compositor.hpp"
+#include "../../protocols/TextInputV3.hpp"
CTextInput::CTextInput(STextInputV1* ti) : pV1Input(ti) {
ti->pTextInput = this;
initCallbacks();
}
-CTextInput::CTextInput(wlr_text_input_v3* ti) : pWlrInput(ti) {
+CTextInput::CTextInput(std::weak_ptr<CTextInputV3> ti) : pV3Input(ti) {
initCallbacks();
}
@@ -25,31 +26,42 @@ void CTextInput::tiV1Destroyed() {
}
void CTextInput::initCallbacks() {
- hyprListener_textInputEnable.initCallback(
- isV3() ? &pWlrInput->events.enable : &pV1Input->sEnable, [this](void* owner, void* data) { onEnabled(); }, this, "textInput");
-
- hyprListener_textInputCommit.initCallback(
- isV3() ? &pWlrInput->events.commit : &pV1Input->sCommit, [this](void* owner, void* data) { onCommit(); }, this, "textInput");
-
- hyprListener_textInputDisable.initCallback(
- isV3() ? &pWlrInput->events.disable : &pV1Input->sDisable, [this](void* owner, void* data) { onDisabled(); }, this, "textInput");
-
- hyprListener_textInputDestroy.initCallback(
- isV3() ? &pWlrInput->events.destroy : &pV1Input->sDestroy,
- [this](void* owner, void* data) {
- if (pWlrInput && pWlrInput->current_enabled && focusedSurface())
+ if (isV3()) {
+ const auto INPUT = pV3Input.lock();
+
+ listeners.enable = INPUT->events.enable.registerListener([this](std::any p) { onEnabled(); });
+ 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) {
+ const auto INPUT = pV3Input.lock();
+ if (INPUT && INPUT->current.enabled && focusedSurface())
g_pInputManager->m_sIMERelay.deactivateIME(this);
-
- hyprListener_textInputCommit.removeCallback();
- hyprListener_textInputDestroy.removeCallback();
- hyprListener_textInputDisable.removeCallback();
- hyprListener_textInputEnable.removeCallback();
- hyprListener_surfaceDestroyed.removeCallback();
- hyprListener_surfaceUnmapped.removeCallback();
-
g_pInputManager->m_sIMERelay.removeTextInput(this);
- },
- this, "textInput");
+ });
+ } else {
+ hyprListener_textInputEnable.initCallback(
+ &pV1Input->sEnable, [this](void* owner, void* data) { onEnabled(); }, this, "textInput");
+
+ 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();
+ hyprListener_surfaceDestroyed.removeCallback();
+ hyprListener_surfaceUnmapped.removeCallback();
+
+ g_pInputManager->m_sIMERelay.removeTextInput(this);
+ },
+ this, "textInput");
+ }
}
void CTextInput::onEnabled(wlr_surface* surfV1) {
@@ -96,7 +108,7 @@ void CTextInput::onCommit() {
return;
}
- if (!(pWlrInput ? pWlrInput->current_enabled : pV1Input->active)) {
+ if (!(isV3() ? pV3Input.lock()->current.enabled : pV1Input->active)) {
Debug::log(WARN, "Disabled TextInput commit?");
return;
}
@@ -144,7 +156,7 @@ void CTextInput::setFocusedSurface(wlr_surface* pSurface) {
}
bool CTextInput::isV3() {
- return pWlrInput;
+ return !pV1Input;
}
void CTextInput::enter(wlr_surface* pSurface) {
@@ -166,8 +178,8 @@ void CTextInput::enter(wlr_surface* pSurface) {
enterLocks = 1;
}
- if (pWlrInput)
- wlr_text_input_v3_send_enter(pWlrInput, pSurface);
+ if (isV3())
+ pV3Input.lock()->enter(pSurface);
else {
zwp_text_input_v1_send_enter(pV1Input->resourceImpl, pSurface->resource);
pV1Input->active = true;
@@ -186,8 +198,8 @@ void CTextInput::leave() {
enterLocks = 0;
}
- if (pWlrInput && pWlrInput->focused_surface)
- wlr_text_input_v3_send_leave(pWlrInput);
+ if (isV3() && focusedSurface())
+ pV3Input.lock()->leave(focusedSurface());
else if (focusedSurface() && pV1Input) {
zwp_text_input_v1_send_leave(pV1Input->resourceImpl);
pV1Input->active = false;
@@ -199,22 +211,24 @@ void CTextInput::leave() {
}
wlr_surface* CTextInput::focusedSurface() {
- return pWlrInput ? pWlrInput->focused_surface : pFocusedSurface;
+ return pFocusedSurface;
}
wl_client* CTextInput::client() {
- return pWlrInput ? wl_resource_get_client(pWlrInput->resource) : pV1Input->client;
+ return isV3() ? pV3Input.lock()->client() : pV1Input->client;
}
void CTextInput::commitStateToIME(wlr_input_method_v2* ime) {
if (isV3()) {
- if (pWlrInput->active_features & WLR_TEXT_INPUT_V3_FEATURE_SURROUNDING_TEXT)
- wlr_input_method_v2_send_surrounding_text(ime, pWlrInput->current.surrounding.text, pWlrInput->current.surrounding.cursor, pWlrInput->current.surrounding.anchor);
+ const auto INPUT = pV3Input.lock();
+
+ if (INPUT->current.surrounding.updated)
+ wlr_input_method_v2_send_surrounding_text(ime, INPUT->current.surrounding.text.c_str(), INPUT->current.surrounding.cursor, INPUT->current.surrounding.anchor);
- wlr_input_method_v2_send_text_change_cause(ime, pWlrInput->current.text_change_cause);
+ wlr_input_method_v2_send_text_change_cause(ime, INPUT->current.cause);
- if (pWlrInput->active_features & WLR_TEXT_INPUT_V3_FEATURE_CONTENT_TYPE)
- wlr_input_method_v2_send_content_type(ime, pWlrInput->current.content_type.hint, pWlrInput->current.content_type.purpose);
+ if (INPUT->current.contentType.updated)
+ wlr_input_method_v2_send_content_type(ime, INPUT->current.contentType.hint, INPUT->current.contentType.purpose);
} else {
if (pV1Input->pendingSurrounding.isPending)
wlr_input_method_v2_send_surrounding_text(ime, pV1Input->pendingSurrounding.text.c_str(), pV1Input->pendingSurrounding.cursor, pV1Input->pendingSurrounding.anchor);
@@ -232,19 +246,18 @@ void CTextInput::commitStateToIME(wlr_input_method_v2* ime) {
void CTextInput::updateIMEState(wlr_input_method_v2* ime) {
if (isV3()) {
- if (ime->current.preedit.text) {
- wlr_text_input_v3_send_preedit_string(pWlrInput, ime->current.preedit.text, ime->current.preedit.cursor_begin, ime->current.preedit.cursor_end);
- }
+ const auto INPUT = pV3Input.lock();
- if (ime->current.commit_text) {
- wlr_text_input_v3_send_commit_string(pWlrInput, ime->current.commit_text);
- }
+ if (ime->current.preedit.text)
+ INPUT->preeditString(ime->current.preedit.text, ime->current.preedit.cursor_begin, ime->current.preedit.cursor_end);
- if (ime->current.delete_.before_length || ime->current.delete_.after_length) {
- wlr_text_input_v3_send_delete_surrounding_text(pWlrInput, ime->current.delete_.before_length, ime->current.delete_.after_length);
- }
+ if (ime->current.commit_text)
+ INPUT->commitString(ime->current.commit_text);
+
+ if (ime->current.delete_.before_length || ime->current.delete_.after_length)
+ INPUT->deleteSurroundingText(ime->current.delete_.before_length, ime->current.delete_.after_length);
- wlr_text_input_v3_send_done(pWlrInput);
+ INPUT->sendDone();
} else {
if (ime->current.preedit.text) {
zwp_text_input_v1_send_preedit_cursor(pV1Input->resourceImpl, ime->current.preedit.cursor_begin);
@@ -271,9 +284,9 @@ void CTextInput::updateIMEState(wlr_input_method_v2* ime) {
}
bool CTextInput::hasCursorRectangle() {
- return !isV3() || pWlrInput->current.features & WLR_TEXT_INPUT_V3_FEATURE_CURSOR_RECTANGLE;
+ return !isV3() || pV3Input.lock()->current.box.updated;
}
CBox CTextInput::cursorBox() {
- return CBox{isV3() ? pWlrInput->current.cursor_rectangle : pV1Input->cursorRectangle};
+ return CBox{isV3() ? pV3Input.lock()->current.box.cursorBox : pV1Input->cursorRectangle};
} \ No newline at end of file
diff --git a/src/managers/input/TextInput.hpp b/src/managers/input/TextInput.hpp
index 4acfb960..6d7e9c59 100644
--- a/src/managers/input/TextInput.hpp
+++ b/src/managers/input/TextInput.hpp
@@ -3,17 +3,19 @@
#include "../../helpers/WLListener.hpp"
#include "../../macros.hpp"
#include "../../helpers/Box.hpp"
+#include "../../helpers/signal/Listener.hpp"
+#include <memory>
-struct wlr_text_input_v3;
struct wlr_surface;
struct wl_client;
struct STextInputV1;
+class CTextInputV3;
class CTextInput {
public:
+ CTextInput(std::weak_ptr<CTextInputV3> ti);
CTextInput(STextInputV1* ti);
- CTextInput(wlr_text_input_v3* ti);
~CTextInput();
bool isV3();
@@ -34,13 +36,13 @@ class CTextInput {
wlr_surface* focusedSurface();
private:
- void setFocusedSurface(wlr_surface* pSurface);
- void initCallbacks();
+ void setFocusedSurface(wlr_surface* pSurface);
+ void initCallbacks();
- wlr_surface* pFocusedSurface = nullptr;
- int enterLocks = 0;
- wlr_text_input_v3* pWlrInput = nullptr;
- STextInputV1* pV1Input = nullptr;
+ wlr_surface* pFocusedSurface = nullptr;
+ int enterLocks = 0;
+ std::weak_ptr<CTextInputV3> pV3Input;
+ STextInputV1* pV1Input = nullptr;
DYNLISTENER(textInputEnable);
DYNLISTENER(textInputDisable);
@@ -48,4 +50,11 @@ class CTextInput {
DYNLISTENER(textInputDestroy);
DYNLISTENER(surfaceUnmapped);
DYNLISTENER(surfaceDestroyed);
+
+ struct {
+ CHyprSignalListener enable;
+ CHyprSignalListener disable;
+ CHyprSignalListener commit;
+ CHyprSignalListener destroy;
+ } listeners;
}; \ No newline at end of file