2022-08-05 13:03:37 +02:00
|
|
|
#include "InputMethodRelay.hpp"
|
|
|
|
#include "InputManager.hpp"
|
2022-08-05 16:21:08 +02:00
|
|
|
#include "../../Compositor.hpp"
|
2022-08-05 13:03:37 +02:00
|
|
|
|
2023-02-19 21:54:53 +01:00
|
|
|
CInputMethodRelay::CInputMethodRelay() {
|
|
|
|
g_pHookSystem->hookDynamic("keyboardFocus", [&](void* self, std::any param) { onKeyboardFocus(std::any_cast<wlr_surface*>(param)); });
|
|
|
|
}
|
2022-08-05 13:03:37 +02:00
|
|
|
|
|
|
|
void CInputMethodRelay::onNewIME(wlr_input_method_v2* pIME) {
|
|
|
|
if (m_pWLRIME) {
|
|
|
|
Debug::log(ERR, "Cannot register 2 IMEs at once!");
|
|
|
|
|
|
|
|
wlr_input_method_v2_send_unavailable(pIME);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_pWLRIME = pIME;
|
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
hyprListener_IMECommit.initCallback(
|
|
|
|
&m_pWLRIME->events.commit,
|
|
|
|
[&](void* owner, void* data) {
|
|
|
|
const auto PTI = getFocusedTextInput();
|
|
|
|
const auto PIMR = (CInputMethodRelay*)owner;
|
2022-08-05 13:03:37 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
if (!PTI) {
|
|
|
|
Debug::log(LOG, "No focused TextInput on IME Commit");
|
|
|
|
return;
|
|
|
|
}
|
2022-08-05 13:03:37 +02:00
|
|
|
|
2023-03-14 13:57:50 +01:00
|
|
|
if (PTI->pWlrInput) {
|
|
|
|
if (PIMR->m_pWLRIME->current.preedit.text) {
|
|
|
|
wlr_text_input_v3_send_preedit_string(PTI->pWlrInput, PIMR->m_pWLRIME->current.preedit.text, PIMR->m_pWLRIME->current.preedit.cursor_begin,
|
|
|
|
PIMR->m_pWLRIME->current.preedit.cursor_end);
|
|
|
|
}
|
2022-08-05 13:03:37 +02:00
|
|
|
|
2023-03-14 13:57:50 +01:00
|
|
|
if (PIMR->m_pWLRIME->current.commit_text) {
|
|
|
|
wlr_text_input_v3_send_commit_string(PTI->pWlrInput, PIMR->m_pWLRIME->current.commit_text);
|
|
|
|
}
|
2022-08-05 13:03:37 +02:00
|
|
|
|
2023-03-14 13:57:50 +01:00
|
|
|
if (PIMR->m_pWLRIME->current.delete_.before_length || PIMR->m_pWLRIME->current.delete_.after_length) {
|
|
|
|
wlr_text_input_v3_send_delete_surrounding_text(PTI->pWlrInput, PIMR->m_pWLRIME->current.delete_.before_length, PIMR->m_pWLRIME->current.delete_.after_length);
|
|
|
|
}
|
2022-08-05 13:03:37 +02:00
|
|
|
|
2023-03-14 13:57:50 +01:00
|
|
|
wlr_text_input_v3_send_done(PTI->pWlrInput);
|
|
|
|
} else {
|
|
|
|
if (PIMR->m_pWLRIME->current.preedit.text) {
|
2023-03-14 15:37:00 +01:00
|
|
|
zwp_text_input_v1_send_preedit_cursor(PTI->pV1Input->resourceImpl, PIMR->m_pWLRIME->current.preedit.cursor_begin);
|
2023-03-14 13:57:50 +01:00
|
|
|
zwp_text_input_v1_send_preedit_styling(PTI->pV1Input->resourceImpl, 0, std::string(PIMR->m_pWLRIME->current.preedit.text).length() - 1,
|
2023-03-14 15:37:00 +01:00
|
|
|
ZWP_TEXT_INPUT_V1_PREEDIT_STYLE_NONE);
|
2023-03-14 13:57:50 +01:00
|
|
|
zwp_text_input_v1_send_preedit_string(PTI->pV1Input->resourceImpl, PTI->pV1Input->serial, PIMR->m_pWLRIME->current.preedit.text, "");
|
2023-03-14 15:37:00 +01:00
|
|
|
} else {
|
|
|
|
zwp_text_input_v1_send_preedit_cursor(PTI->pV1Input->resourceImpl, PIMR->m_pWLRIME->current.preedit.cursor_begin);
|
|
|
|
zwp_text_input_v1_send_preedit_styling(PTI->pV1Input->resourceImpl, 0, 0, ZWP_TEXT_INPUT_V1_PREEDIT_STYLE_NONE);
|
|
|
|
zwp_text_input_v1_send_preedit_string(PTI->pV1Input->resourceImpl, PTI->pV1Input->serial, "", "");
|
2023-03-14 13:57:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (PIMR->m_pWLRIME->current.commit_text) {
|
|
|
|
zwp_text_input_v1_send_commit_string(PTI->pV1Input->resourceImpl, PTI->pV1Input->serial, PIMR->m_pWLRIME->current.commit_text);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PIMR->m_pWLRIME->current.delete_.before_length || PIMR->m_pWLRIME->current.delete_.after_length) {
|
2023-03-14 15:37:00 +01:00
|
|
|
zwp_text_input_v1_send_delete_surrounding_text(PTI->pV1Input->resourceImpl,
|
|
|
|
std::string(PIMR->m_pWLRIME->current.preedit.text).length() - PIMR->m_pWLRIME->current.delete_.before_length,
|
|
|
|
PIMR->m_pWLRIME->current.delete_.after_length + PIMR->m_pWLRIME->current.delete_.before_length);
|
2023-03-14 13:57:50 +01:00
|
|
|
|
|
|
|
if (PIMR->m_pWLRIME->current.preedit.text)
|
|
|
|
zwp_text_input_v1_send_commit_string(PTI->pV1Input->resourceImpl, PTI->pV1Input->serial, PIMR->m_pWLRIME->current.preedit.text);
|
|
|
|
}
|
|
|
|
}
|
2022-12-16 18:17:31 +01:00
|
|
|
},
|
|
|
|
this, "IMERelay");
|
2022-08-05 13:03:37 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
hyprListener_IMEDestroy.initCallback(
|
|
|
|
&m_pWLRIME->events.destroy,
|
|
|
|
[&](void* owner, void* data) {
|
|
|
|
m_pWLRIME = nullptr;
|
2022-08-05 13:03:37 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
hyprListener_IMEDestroy.removeCallback();
|
|
|
|
hyprListener_IMECommit.removeCallback();
|
|
|
|
hyprListener_IMEGrab.removeCallback();
|
|
|
|
hyprListener_IMENewPopup.removeCallback();
|
2022-08-05 16:21:08 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
m_pKeyboardGrab.reset(nullptr);
|
2022-08-05 16:21:08 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
const auto PTI = getFocusedTextInput();
|
2022-08-05 16:21:08 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
Debug::log(LOG, "IME Destroy");
|
2022-08-05 16:21:08 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
if (PTI) {
|
2023-03-14 13:57:50 +01:00
|
|
|
setPendingSurface(PTI, focusedSurface(PTI));
|
2022-08-05 16:21:08 +02:00
|
|
|
|
2023-03-14 13:57:50 +01:00
|
|
|
if (PTI->pWlrInput)
|
|
|
|
wlr_text_input_v3_send_leave(PTI->pWlrInput);
|
|
|
|
else
|
|
|
|
zwp_text_input_v1_send_leave(PTI->pV1Input->resourceImpl);
|
2022-12-16 18:17:31 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
this, "IMERelay");
|
2022-08-05 16:21:08 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
hyprListener_IMEGrab.initCallback(
|
|
|
|
&m_pWLRIME->events.grab_keyboard,
|
|
|
|
[&](void* owner, void* data) {
|
|
|
|
Debug::log(LOG, "IME TextInput Keyboard Grab new");
|
2022-08-05 16:21:08 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
m_pKeyboardGrab.reset(nullptr);
|
2022-08-05 16:21:08 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
m_pKeyboardGrab = std::make_unique<SIMEKbGrab>();
|
2022-08-05 16:21:08 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
m_pKeyboardGrab->pKeyboard = wlr_seat_get_keyboard(g_pCompositor->m_sSeat.seat);
|
2022-08-05 16:21:08 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
const auto PKBGRAB = (wlr_input_method_keyboard_grab_v2*)data;
|
2022-08-05 16:21:08 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
m_pKeyboardGrab->pWlrKbGrab = PKBGRAB;
|
2022-08-05 16:21:08 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
wlr_input_method_keyboard_grab_v2_set_keyboard(m_pKeyboardGrab->pWlrKbGrab, m_pKeyboardGrab->pKeyboard);
|
2022-08-05 16:21:08 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
m_pKeyboardGrab->hyprListener_grabDestroy.initCallback(
|
|
|
|
&PKBGRAB->events.destroy,
|
|
|
|
[&](void* owner, void* data) {
|
|
|
|
m_pKeyboardGrab->hyprListener_grabDestroy.removeCallback();
|
2022-08-05 16:21:08 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
Debug::log(LOG, "IME TextInput Keyboard Grab destroy");
|
2022-08-05 16:21:08 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
if (m_pKeyboardGrab->pKeyboard) {
|
|
|
|
wlr_seat_keyboard_notify_modifiers(g_pCompositor->m_sSeat.seat, &m_pKeyboardGrab->pKeyboard->modifiers);
|
|
|
|
}
|
2022-09-25 20:07:48 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
m_pKeyboardGrab.reset(nullptr);
|
|
|
|
},
|
|
|
|
m_pKeyboardGrab.get(), "IME Keyboard Grab");
|
|
|
|
},
|
|
|
|
this, "IMERelay");
|
2022-08-05 17:07:01 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
hyprListener_IMENewPopup.initCallback(
|
|
|
|
&m_pWLRIME->events.new_popup_surface,
|
|
|
|
[&](void* owner, void* data) {
|
|
|
|
const auto PNEWPOPUP = &m_lIMEPopups.emplace_back();
|
2022-08-05 17:07:01 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
PNEWPOPUP->pSurface = (wlr_input_popup_surface_v2*)data;
|
2022-08-05 17:07:01 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
PNEWPOPUP->hyprListener_commitPopup.initCallback(&PNEWPOPUP->pSurface->surface->events.commit, &Events::listener_commitInputPopup, PNEWPOPUP, "IME Popup");
|
|
|
|
PNEWPOPUP->hyprListener_mapPopup.initCallback(&PNEWPOPUP->pSurface->events.map, &Events::listener_mapInputPopup, PNEWPOPUP, "IME Popup");
|
|
|
|
PNEWPOPUP->hyprListener_unmapPopup.initCallback(&PNEWPOPUP->pSurface->events.unmap, &Events::listener_unmapInputPopup, PNEWPOPUP, "IME Popup");
|
|
|
|
PNEWPOPUP->hyprListener_destroyPopup.initCallback(&PNEWPOPUP->pSurface->events.destroy, &Events::listener_destroyInputPopup, PNEWPOPUP, "IME Popup");
|
2022-08-05 17:07:01 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
Debug::log(LOG, "New input popup");
|
|
|
|
},
|
|
|
|
this, "IMERelay");
|
2022-08-05 17:07:01 +02:00
|
|
|
|
2022-08-05 13:03:37 +02:00
|
|
|
const auto PTI = getFocusableTextInput();
|
|
|
|
|
|
|
|
if (PTI) {
|
2023-03-14 13:57:50 +01:00
|
|
|
if (PTI->pWlrInput)
|
|
|
|
wlr_text_input_v3_send_enter(PTI->pWlrInput, PTI->pPendingSurface);
|
|
|
|
else
|
|
|
|
zwp_text_input_v1_send_enter(PTI->pV1Input->resourceImpl, PTI->pPendingSurface->resource);
|
|
|
|
|
2022-08-05 13:19:16 +02:00
|
|
|
setPendingSurface(PTI, nullptr);
|
2022-08-05 13:03:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-14 13:57:50 +01:00
|
|
|
wlr_surface* CInputMethodRelay::focusedSurface(STextInput* pTI) {
|
|
|
|
return pTI->pWlrInput ? pTI->pWlrInput->focused_surface : pTI->pV1Input->focusedSurface;
|
|
|
|
}
|
|
|
|
|
2022-08-05 17:07:01 +02:00
|
|
|
void CInputMethodRelay::updateInputPopup(SIMEPopup* pPopup) {
|
2022-09-25 20:07:48 +02:00
|
|
|
if (!pPopup->pSurface->mapped)
|
2022-08-05 17:07:01 +02:00
|
|
|
return;
|
|
|
|
|
2022-08-23 11:16:27 +02:00
|
|
|
// damage last known pos & size
|
|
|
|
g_pHyprRenderer->damageBox(pPopup->realX, pPopup->realY, pPopup->lastSize.x, pPopup->lastSize.y);
|
|
|
|
|
2022-08-05 17:07:01 +02:00
|
|
|
const auto PFOCUSEDTI = getFocusedTextInput();
|
|
|
|
|
2023-03-14 13:57:50 +01:00
|
|
|
if (!PFOCUSEDTI || !focusedSurface(PFOCUSEDTI))
|
2022-08-05 17:07:01 +02:00
|
|
|
return;
|
|
|
|
|
2023-03-14 13:57:50 +01:00
|
|
|
bool cursorRect = PFOCUSEDTI->pWlrInput ? PFOCUSEDTI->pWlrInput->current.features & WLR_TEXT_INPUT_V3_FEATURE_CURSOR_RECTANGLE : true;
|
|
|
|
const auto PFOCUSEDSURFACE = focusedSurface(PFOCUSEDTI);
|
|
|
|
auto cursorBox = PFOCUSEDTI->pWlrInput ? PFOCUSEDTI->pWlrInput->current.cursor_rectangle : PFOCUSEDTI->pV1Input->cursorRectangle;
|
2022-08-05 17:07:01 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
Vector2D parentPos;
|
|
|
|
Vector2D parentSize;
|
2022-08-05 17:07:01 +02:00
|
|
|
|
2023-02-03 13:43:43 +01:00
|
|
|
if (wlr_layer_surface_v1_try_from_wlr_surface(PFOCUSEDSURFACE)) {
|
|
|
|
const auto PLS = g_pCompositor->getLayerSurfaceFromWlr(wlr_layer_surface_v1_try_from_wlr_surface(PFOCUSEDSURFACE));
|
2022-08-05 17:07:01 +02:00
|
|
|
|
|
|
|
if (PLS) {
|
2022-12-16 18:17:31 +01:00
|
|
|
parentPos = Vector2D(PLS->geometry.x, PLS->geometry.y) + g_pCompositor->getMonitorFromID(PLS->monitorID)->vecPosition;
|
2022-08-05 17:07:01 +02:00
|
|
|
parentSize = Vector2D(PLS->geometry.width, PLS->geometry.height);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
const auto PWINDOW = g_pCompositor->getWindowFromSurface(PFOCUSEDSURFACE);
|
|
|
|
|
|
|
|
if (PWINDOW) {
|
2022-12-16 18:17:31 +01:00
|
|
|
parentPos = PWINDOW->m_vRealPosition.goalv();
|
2022-08-05 17:07:01 +02:00
|
|
|
parentSize = PWINDOW->m_vRealSize.goalv();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!cursorRect) {
|
|
|
|
cursorBox = {0, 0, (int)parentSize.x, (int)parentSize.y};
|
|
|
|
}
|
|
|
|
|
|
|
|
// todo: anti-overflow
|
|
|
|
|
|
|
|
wlr_box finalBox = cursorBox;
|
|
|
|
|
|
|
|
pPopup->x = finalBox.x;
|
2022-08-05 18:54:59 +02:00
|
|
|
pPopup->y = finalBox.y + finalBox.height;
|
2022-08-05 17:07:01 +02:00
|
|
|
|
|
|
|
pPopup->realX = finalBox.x + parentPos.x;
|
2022-08-05 18:54:59 +02:00
|
|
|
pPopup->realY = finalBox.y + parentPos.y + finalBox.height;
|
2022-08-05 17:07:01 +02:00
|
|
|
|
2022-08-23 11:16:27 +02:00
|
|
|
pPopup->lastSize = Vector2D(pPopup->pSurface->surface->current.width, pPopup->pSurface->surface->current.height);
|
|
|
|
|
2022-08-05 17:07:01 +02:00
|
|
|
wlr_input_popup_surface_v2_send_text_input_rectangle(pPopup->pSurface, &finalBox);
|
|
|
|
|
|
|
|
damagePopup(pPopup);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CInputMethodRelay::setIMEPopupFocus(SIMEPopup* pPopup, wlr_surface* pSurface) {
|
|
|
|
updateInputPopup(pPopup);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Events::listener_mapInputPopup(void* owner, void* data) {
|
|
|
|
const auto PPOPUP = (SIMEPopup*)owner;
|
|
|
|
|
|
|
|
Debug::log(LOG, "Mapped an IME Popup");
|
|
|
|
|
|
|
|
g_pInputManager->m_sIMERelay.updateInputPopup(PPOPUP);
|
2023-01-10 19:21:59 +01:00
|
|
|
|
|
|
|
if (const auto PMONITOR = g_pCompositor->getMonitorFromVector(Vector2D(PPOPUP->realX, PPOPUP->realY) + PPOPUP->lastSize / 2.f); PMONITOR)
|
|
|
|
wlr_surface_send_enter(PPOPUP->pSurface->surface, PMONITOR->output);
|
2022-08-05 17:07:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Events::listener_unmapInputPopup(void* owner, void* data) {
|
|
|
|
const auto PPOPUP = (SIMEPopup*)owner;
|
|
|
|
|
|
|
|
Debug::log(LOG, "Unmapped an IME Popup");
|
|
|
|
|
2022-08-23 11:16:27 +02:00
|
|
|
g_pHyprRenderer->damageBox(PPOPUP->realX, PPOPUP->realY, PPOPUP->lastSize.x, PPOPUP->lastSize.y);
|
|
|
|
|
2022-08-05 17:07:01 +02:00
|
|
|
g_pInputManager->m_sIMERelay.updateInputPopup(PPOPUP);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Events::listener_destroyInputPopup(void* owner, void* data) {
|
|
|
|
const auto PPOPUP = (SIMEPopup*)owner;
|
|
|
|
|
|
|
|
Debug::log(LOG, "Removed an IME Popup");
|
|
|
|
|
|
|
|
PPOPUP->hyprListener_commitPopup.removeCallback();
|
|
|
|
PPOPUP->hyprListener_destroyPopup.removeCallback();
|
|
|
|
PPOPUP->hyprListener_focusedSurfaceUnmap.removeCallback();
|
|
|
|
PPOPUP->hyprListener_mapPopup.removeCallback();
|
|
|
|
PPOPUP->hyprListener_unmapPopup.removeCallback();
|
|
|
|
|
|
|
|
g_pInputManager->m_sIMERelay.removePopup(PPOPUP);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Events::listener_commitInputPopup(void* owner, void* data) {
|
|
|
|
const auto PPOPUP = (SIMEPopup*)owner;
|
|
|
|
|
|
|
|
g_pInputManager->m_sIMERelay.updateInputPopup(PPOPUP);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CInputMethodRelay::removePopup(SIMEPopup* pPopup) {
|
|
|
|
m_lIMEPopups.remove(*pPopup);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CInputMethodRelay::damagePopup(SIMEPopup* pPopup) {
|
|
|
|
if (!pPopup->pSurface->mapped)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const auto PFOCUSEDTI = getFocusedTextInput();
|
|
|
|
|
2023-03-14 13:57:50 +01:00
|
|
|
if (!PFOCUSEDTI || !focusedSurface(PFOCUSEDTI))
|
2022-08-05 17:07:01 +02:00
|
|
|
return;
|
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
Vector2D parentPos;
|
2022-08-05 17:07:01 +02:00
|
|
|
|
2023-03-14 13:57:50 +01:00
|
|
|
const auto PFOCUSEDSURFACE = focusedSurface(PFOCUSEDTI);
|
2022-08-05 17:07:01 +02:00
|
|
|
|
2023-02-03 13:43:43 +01:00
|
|
|
if (wlr_layer_surface_v1_try_from_wlr_surface(PFOCUSEDSURFACE)) {
|
|
|
|
const auto PLS = g_pCompositor->getLayerSurfaceFromWlr(wlr_layer_surface_v1_try_from_wlr_surface(PFOCUSEDSURFACE));
|
2022-08-05 17:07:01 +02:00
|
|
|
|
|
|
|
if (PLS) {
|
|
|
|
parentPos = Vector2D(PLS->geometry.x, PLS->geometry.y) + g_pCompositor->getMonitorFromID(PLS->monitorID)->vecPosition;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
const auto PWINDOW = g_pCompositor->getWindowFromSurface(PFOCUSEDSURFACE);
|
|
|
|
|
|
|
|
if (PWINDOW) {
|
|
|
|
parentPos = PWINDOW->m_vRealPosition.goalv();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_pHyprRenderer->damageSurface(pPopup->pSurface->surface, parentPos.x + pPopup->x, parentPos.y + pPopup->y);
|
|
|
|
}
|
|
|
|
|
2022-08-05 16:21:08 +02:00
|
|
|
SIMEKbGrab* CInputMethodRelay::getIMEKeyboardGrab(SKeyboard* pKeyboard) {
|
|
|
|
|
|
|
|
if (!m_pWLRIME)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
if (!m_pKeyboardGrab.get())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
const auto VIRTKB = wlr_input_device_get_virtual_keyboard(pKeyboard->keyboard);
|
|
|
|
|
|
|
|
if (VIRTKB && (wl_resource_get_client(VIRTKB->resource) == wl_resource_get_client(m_pKeyboardGrab->pWlrKbGrab->resource)))
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return m_pKeyboardGrab.get();
|
|
|
|
}
|
|
|
|
|
2022-08-05 13:03:37 +02:00
|
|
|
STextInput* CInputMethodRelay::getFocusedTextInput() {
|
2023-03-14 13:57:50 +01:00
|
|
|
|
2022-08-05 13:03:37 +02:00
|
|
|
for (auto& ti : m_lTextInputs) {
|
2023-03-14 13:57:50 +01:00
|
|
|
if (focusedSurface(&ti)) {
|
2022-08-05 13:03:37 +02:00
|
|
|
return &ti;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
STextInput* CInputMethodRelay::getFocusableTextInput() {
|
|
|
|
for (auto& ti : m_lTextInputs) {
|
|
|
|
if (ti.pPendingSurface) {
|
|
|
|
return &ti;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CInputMethodRelay::onNewTextInput(wlr_text_input_v3* pInput) {
|
|
|
|
createNewTextInput(pInput);
|
|
|
|
}
|
|
|
|
|
2023-03-14 13:57:50 +01:00
|
|
|
void CInputMethodRelay::createNewTextInput(wlr_text_input_v3* pInput, STextInputV1* pTIV1) {
|
2022-08-05 13:03:37 +02:00
|
|
|
const auto PTEXTINPUT = &m_lTextInputs.emplace_back();
|
|
|
|
|
|
|
|
PTEXTINPUT->pWlrInput = pInput;
|
2023-03-14 13:57:50 +01:00
|
|
|
PTEXTINPUT->pV1Input = pTIV1;
|
|
|
|
|
|
|
|
if (pTIV1)
|
|
|
|
pTIV1->pTextInput = PTEXTINPUT;
|
2022-08-05 13:03:37 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
PTEXTINPUT->hyprListener_textInputEnable.initCallback(
|
2023-03-14 13:57:50 +01:00
|
|
|
pInput ? &pInput->events.enable : &pTIV1->sEnable,
|
2022-12-16 18:17:31 +01:00
|
|
|
[](void* owner, void* data) {
|
|
|
|
const auto PINPUT = (STextInput*)owner;
|
2022-08-05 13:03:37 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
if (!g_pInputManager->m_sIMERelay.m_pWLRIME) {
|
|
|
|
// Debug::log(WARN, "Enabling TextInput on no IME!");
|
|
|
|
return;
|
|
|
|
}
|
2022-08-05 13:03:37 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
Debug::log(LOG, "Enable TextInput");
|
2022-08-05 13:03:37 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
wlr_input_method_v2_send_activate(g_pInputManager->m_sIMERelay.m_pWLRIME);
|
2023-03-14 13:57:50 +01:00
|
|
|
g_pInputManager->m_sIMERelay.commitIMEState(PINPUT);
|
2022-12-16 18:17:31 +01:00
|
|
|
},
|
|
|
|
PTEXTINPUT, "textInput");
|
2022-08-05 13:03:37 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
PTEXTINPUT->hyprListener_textInputCommit.initCallback(
|
2023-03-14 13:57:50 +01:00
|
|
|
pInput ? &pInput->events.commit : &pTIV1->sCommit,
|
2022-12-16 18:17:31 +01:00
|
|
|
[](void* owner, void* data) {
|
|
|
|
const auto PINPUT = (STextInput*)owner;
|
2022-08-05 13:03:37 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
if (!g_pInputManager->m_sIMERelay.m_pWLRIME) {
|
|
|
|
// Debug::log(WARN, "Committing TextInput on no IME!");
|
|
|
|
return;
|
|
|
|
}
|
2022-08-05 13:03:37 +02:00
|
|
|
|
2023-03-14 14:51:08 +01:00
|
|
|
if (!(PINPUT->pWlrInput ? PINPUT->pWlrInput->current_enabled : PINPUT->pV1Input->active)) {
|
2022-12-16 18:17:31 +01:00
|
|
|
Debug::log(WARN, "Disabled TextInput commit?");
|
|
|
|
return;
|
|
|
|
}
|
2022-08-05 13:03:37 +02:00
|
|
|
|
2023-03-14 13:57:50 +01:00
|
|
|
g_pInputManager->m_sIMERelay.commitIMEState(PINPUT);
|
2022-12-16 18:17:31 +01:00
|
|
|
},
|
|
|
|
PTEXTINPUT, "textInput");
|
2022-08-05 13:03:37 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
PTEXTINPUT->hyprListener_textInputDisable.initCallback(
|
2023-03-14 13:57:50 +01:00
|
|
|
pInput ? &pInput->events.disable : &pTIV1->sDisable,
|
2022-12-16 18:17:31 +01:00
|
|
|
[](void* owner, void* data) {
|
|
|
|
const auto PINPUT = (STextInput*)owner;
|
2022-08-05 13:03:37 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
if (!g_pInputManager->m_sIMERelay.m_pWLRIME) {
|
|
|
|
// Debug::log(WARN, "Disabling TextInput on no IME!");
|
|
|
|
return;
|
|
|
|
}
|
2022-08-05 13:03:37 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
Debug::log(LOG, "Disable TextInput");
|
2022-08-05 13:03:37 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
wlr_input_method_v2_send_deactivate(g_pInputManager->m_sIMERelay.m_pWLRIME);
|
2022-08-05 13:03:37 +02:00
|
|
|
|
2023-03-14 13:57:50 +01:00
|
|
|
g_pInputManager->m_sIMERelay.commitIMEState(PINPUT);
|
2022-12-16 18:17:31 +01:00
|
|
|
},
|
|
|
|
PTEXTINPUT, "textInput");
|
2022-08-05 13:03:37 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
PTEXTINPUT->hyprListener_textInputDestroy.initCallback(
|
2023-03-14 13:57:50 +01:00
|
|
|
pInput ? &pInput->events.destroy : &pTIV1->sDestroy,
|
2022-12-16 18:17:31 +01:00
|
|
|
[](void* owner, void* data) {
|
|
|
|
const auto PINPUT = (STextInput*)owner;
|
2022-08-05 13:03:37 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
if (!g_pInputManager->m_sIMERelay.m_pWLRIME) {
|
|
|
|
// Debug::log(WARN, "Disabling TextInput on no IME!");
|
|
|
|
return;
|
|
|
|
}
|
2022-08-05 13:03:37 +02:00
|
|
|
|
2023-03-14 13:57:50 +01:00
|
|
|
if (PINPUT->pWlrInput && PINPUT->pWlrInput->current_enabled) {
|
2022-12-16 18:17:31 +01:00
|
|
|
wlr_input_method_v2_send_deactivate(g_pInputManager->m_sIMERelay.m_pWLRIME);
|
2022-08-05 13:03:37 +02:00
|
|
|
|
2023-03-14 13:57:50 +01:00
|
|
|
g_pInputManager->m_sIMERelay.commitIMEState(PINPUT);
|
2022-12-16 18:17:31 +01:00
|
|
|
}
|
2022-08-05 13:19:16 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
g_pInputManager->m_sIMERelay.setPendingSurface(PINPUT, nullptr);
|
2022-08-05 13:03:37 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
PINPUT->hyprListener_textInputCommit.removeCallback();
|
|
|
|
PINPUT->hyprListener_textInputDestroy.removeCallback();
|
|
|
|
PINPUT->hyprListener_textInputDisable.removeCallback();
|
|
|
|
PINPUT->hyprListener_textInputEnable.removeCallback();
|
2022-08-05 13:03:37 +02:00
|
|
|
|
2023-03-14 13:57:50 +01:00
|
|
|
g_pInputManager->m_sIMERelay.removeTextInput(PINPUT);
|
2022-12-16 18:17:31 +01:00
|
|
|
},
|
|
|
|
PTEXTINPUT, "textInput");
|
2022-08-05 13:03:37 +02:00
|
|
|
}
|
|
|
|
|
2023-03-14 13:57:50 +01:00
|
|
|
void CInputMethodRelay::removeTextInput(STextInput* pInput) {
|
|
|
|
m_lTextInputs.remove_if([&](const auto& other) { return other.pWlrInput == pInput->pWlrInput && other.pV1Input == pInput->pV1Input; });
|
2022-08-05 13:03:37 +02:00
|
|
|
}
|
|
|
|
|
2023-03-14 13:57:50 +01:00
|
|
|
void CInputMethodRelay::commitIMEState(STextInput* pInput) {
|
2022-08-05 17:19:49 +02:00
|
|
|
if (!m_pWLRIME)
|
|
|
|
return;
|
|
|
|
|
2023-03-14 13:57:50 +01:00
|
|
|
if (pInput->pWlrInput) {
|
|
|
|
// V3
|
|
|
|
if (pInput->pWlrInput->active_features & WLR_TEXT_INPUT_V3_FEATURE_SURROUNDING_TEXT)
|
|
|
|
wlr_input_method_v2_send_surrounding_text(m_pWLRIME, pInput->pWlrInput->current.surrounding.text, pInput->pWlrInput->current.surrounding.cursor,
|
|
|
|
pInput->pWlrInput->current.surrounding.anchor);
|
|
|
|
|
|
|
|
wlr_input_method_v2_send_text_change_cause(m_pWLRIME, pInput->pWlrInput->current.text_change_cause);
|
|
|
|
|
|
|
|
if (pInput->pWlrInput->active_features & WLR_TEXT_INPUT_V3_FEATURE_CONTENT_TYPE)
|
|
|
|
wlr_input_method_v2_send_content_type(m_pWLRIME, pInput->pWlrInput->current.content_type.hint, pInput->pWlrInput->current.content_type.purpose);
|
|
|
|
} else {
|
|
|
|
// V1
|
|
|
|
if (pInput->pV1Input->pendingSurrounding.isPending)
|
|
|
|
wlr_input_method_v2_send_surrounding_text(m_pWLRIME, pInput->pV1Input->pendingSurrounding.text.c_str(), pInput->pV1Input->pendingSurrounding.cursor,
|
|
|
|
pInput->pV1Input->pendingSurrounding.anchor);
|
2022-08-05 16:21:08 +02:00
|
|
|
|
2023-03-14 13:57:50 +01:00
|
|
|
wlr_input_method_v2_send_text_change_cause(m_pWLRIME, 0);
|
2022-08-05 16:21:08 +02:00
|
|
|
|
2023-03-14 13:57:50 +01:00
|
|
|
if (pInput->pV1Input->pendingContentType.isPending)
|
|
|
|
wlr_input_method_v2_send_content_type(m_pWLRIME, pInput->pV1Input->pendingContentType.hint, pInput->pV1Input->pendingContentType.purpose);
|
|
|
|
}
|
2022-08-05 16:21:08 +02:00
|
|
|
|
2022-08-05 17:07:01 +02:00
|
|
|
for (auto& p : m_lIMEPopups) {
|
|
|
|
updateInputPopup(&p);
|
|
|
|
}
|
|
|
|
|
2022-08-05 13:03:37 +02:00
|
|
|
wlr_input_method_v2_send_done(m_pWLRIME);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CInputMethodRelay::onKeyboardFocus(wlr_surface* pSurface) {
|
|
|
|
if (!m_pWLRIME)
|
|
|
|
return;
|
|
|
|
|
2023-03-14 13:57:50 +01:00
|
|
|
auto client = [](STextInput* pTI) -> wl_client* { return pTI->pWlrInput ? wl_resource_get_client(pTI->pWlrInput->resource) : pTI->pV1Input->client; };
|
|
|
|
|
2022-08-05 13:03:37 +02:00
|
|
|
for (auto& ti : m_lTextInputs) {
|
|
|
|
if (ti.pPendingSurface) {
|
|
|
|
|
2022-09-25 20:07:48 +02:00
|
|
|
if (pSurface != ti.pPendingSurface)
|
2022-08-05 13:19:16 +02:00
|
|
|
setPendingSurface(&ti, nullptr);
|
2022-08-05 13:03:37 +02:00
|
|
|
|
2023-03-14 13:57:50 +01:00
|
|
|
} else if (focusedSurface(&ti)) {
|
2022-08-05 13:03:37 +02:00
|
|
|
|
2023-03-14 13:57:50 +01:00
|
|
|
if (pSurface != focusedSurface(&ti)) {
|
2022-08-05 13:03:37 +02:00
|
|
|
wlr_input_method_v2_send_deactivate(m_pWLRIME);
|
2023-03-14 13:57:50 +01:00
|
|
|
commitIMEState(&ti);
|
|
|
|
|
|
|
|
if (ti.pWlrInput)
|
|
|
|
wlr_text_input_v3_send_leave(ti.pWlrInput);
|
|
|
|
else {
|
|
|
|
zwp_text_input_v1_send_leave(ti.pV1Input->resourceImpl);
|
|
|
|
ti.pV1Input->focusedSurface = nullptr;
|
2023-03-14 14:51:08 +01:00
|
|
|
ti.pV1Input->active = false;
|
2023-03-14 13:57:50 +01:00
|
|
|
}
|
2022-08-05 13:03:37 +02:00
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-14 13:57:50 +01:00
|
|
|
if (pSurface && client(&ti) == wl_resource_get_client(pSurface->resource)) {
|
2022-08-05 13:03:37 +02:00
|
|
|
|
|
|
|
if (m_pWLRIME) {
|
2023-03-14 13:57:50 +01:00
|
|
|
if (ti.pWlrInput)
|
|
|
|
wlr_text_input_v3_send_enter(ti.pWlrInput, pSurface);
|
|
|
|
else {
|
|
|
|
zwp_text_input_v1_send_enter(ti.pV1Input->resourceImpl, pSurface->resource);
|
|
|
|
ti.pV1Input->focusedSurface = pSurface;
|
2023-03-14 14:51:08 +01:00
|
|
|
ti.pV1Input->active = true;
|
2023-03-14 13:57:50 +01:00
|
|
|
}
|
2022-08-05 13:03:37 +02:00
|
|
|
} else {
|
2022-08-05 13:19:16 +02:00
|
|
|
setPendingSurface(&ti, pSurface);
|
2022-08-05 13:03:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-05 13:19:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CInputMethodRelay::setPendingSurface(STextInput* pInput, wlr_surface* pSurface) {
|
|
|
|
pInput->pPendingSurface = pSurface;
|
|
|
|
|
|
|
|
if (pSurface) {
|
2022-12-16 18:17:31 +01:00
|
|
|
pInput->hyprListener_pendingSurfaceDestroy.initCallback(
|
|
|
|
&pSurface->events.destroy,
|
|
|
|
[](void* owner, void* data) {
|
|
|
|
const auto PINPUT = (STextInput*)owner;
|
2022-08-05 13:19:16 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
PINPUT->pPendingSurface = nullptr;
|
2022-08-05 13:19:16 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
PINPUT->hyprListener_pendingSurfaceDestroy.removeCallback();
|
|
|
|
},
|
|
|
|
pInput, "TextInput");
|
2022-08-05 13:19:16 +02:00
|
|
|
} else {
|
|
|
|
pInput->hyprListener_pendingSurfaceDestroy.removeCallback();
|
|
|
|
}
|
2022-09-25 20:07:48 +02:00
|
|
|
}
|