mirror of
https://github.com/hyprwm/Hyprland.git
synced 2024-11-23 21:14:24 +03:00
multiple IME fixes
This commit is contained in:
parent
cb5521ec6e
commit
9a8a6317ff
@ -201,6 +201,7 @@ void CCompositor::initAllSignals() {
|
||||
addWLSignal(&m_sWLRPointerConstraints->events.new_constraint, &Events::listen_newConstraint, m_sWLRPointerConstraints, "PointerConstraints");
|
||||
addWLSignal(&m_sWLRXDGDecoMgr->events.new_toplevel_decoration, &Events::listen_NewXDGDeco, m_sWLRXDGDecoMgr, "XDGDecoMgr");
|
||||
addWLSignal(&m_sWLRVirtPtrMgr->events.new_virtual_pointer, &Events::listen_newVirtPtr, m_sWLRVirtPtrMgr, "VirtPtrMgr");
|
||||
addWLSignal(&m_sWLRVKeyboardMgr->events.new_virtual_keyboard, &Events::listen_newVirtualKeyboard, m_sWLRVKeyboardMgr, "VKeyboardMgr");
|
||||
addWLSignal(&m_sWLRRenderer->events.destroy, &Events::listen_RendererDestroy, m_sWLRRenderer, "WLRRenderer");
|
||||
addWLSignal(&m_sWLRIdleInhibitMgr->events.new_inhibitor, &Events::listen_newIdleInhibitor, m_sWLRIdleInhibitMgr, "WLRIdleInhibitMgr");
|
||||
addWLSignal(&m_sWLROutputPowerMgr->events.set_mode, &Events::listen_powerMgrSetMode, m_sWLROutputPowerMgr, "PowerMgr");
|
||||
|
@ -189,4 +189,10 @@ void Events::listener_pinchUpdate(wl_listener* listener, void* data) {
|
||||
void Events::listener_pinchEnd(wl_listener* listener, void* data) {
|
||||
const auto EV = (wlr_pointer_pinch_end_event*)data;
|
||||
wlr_pointer_gestures_v1_send_pinch_end(g_pCompositor->m_sWLRPointerGestures, g_pCompositor->m_sSeat.seat, EV->time_msec, EV->cancelled);
|
||||
}
|
||||
|
||||
void Events::listener_newVirtualKeyboard(wl_listener* listener, void* data) {
|
||||
const auto WLRKB = (wlr_virtual_keyboard_v1*)data;
|
||||
|
||||
g_pInputManager->newVirtualKeyboard(&WLRKB->keyboard.base);
|
||||
}
|
@ -137,4 +137,5 @@ namespace Events {
|
||||
// IME
|
||||
LISTENER(newIME);
|
||||
LISTENER(newTextInput);
|
||||
LISTENER(newVirtualKeyboard);
|
||||
};
|
@ -96,6 +96,7 @@ struct SKeyboard {
|
||||
DYNLISTENER(keyboardKey);
|
||||
DYNLISTENER(keyboardDestroy);
|
||||
|
||||
bool isVirtual = false;
|
||||
bool active = false;
|
||||
|
||||
std::string name = "";
|
||||
@ -285,4 +286,12 @@ struct STextInput {
|
||||
DYNLISTENER(textInputDestroy);
|
||||
|
||||
DYNLISTENER(pendingSurfaceDestroy);
|
||||
};
|
||||
|
||||
struct SIMEKbGrab {
|
||||
wlr_input_method_keyboard_grab_v2* pWlrKbGrab = nullptr;
|
||||
|
||||
wlr_keyboard* pKeyboard = nullptr;
|
||||
|
||||
DYNLISTENER(grabDestroy);
|
||||
};
|
@ -93,6 +93,9 @@ uint32_t CKeybindManager::stringToModMask(std::string mods) {
|
||||
}
|
||||
|
||||
bool CKeybindManager::onKeyEvent(wlr_keyboard_key_event* e, SKeyboard* pKeyboard) {
|
||||
if (pKeyboard->isVirtual)
|
||||
return true;
|
||||
|
||||
const auto KEYCODE = e->keycode + 8; // Because to xkbcommon it's +8 from libinput
|
||||
|
||||
const xkb_keysym_t keysym = xkb_state_key_get_one_sym(wlr_keyboard_from_input_device(pKeyboard->keyboard)->xkb_state, KEYCODE);
|
||||
|
@ -436,6 +436,33 @@ void CInputManager::newKeyboard(wlr_input_device* keyboard) {
|
||||
Debug::log(LOG, "New keyboard created, pointers Hypr: %x and WLR: %x", PNEWKEYBOARD, keyboard);
|
||||
}
|
||||
|
||||
void CInputManager::newVirtualKeyboard(wlr_input_device* keyboard) {
|
||||
const auto PNEWKEYBOARD = &m_lKeyboards.emplace_back();
|
||||
|
||||
PNEWKEYBOARD->keyboard = keyboard;
|
||||
PNEWKEYBOARD->isVirtual = true;
|
||||
|
||||
try {
|
||||
PNEWKEYBOARD->name = std::string(keyboard->name);
|
||||
} catch (std::exception& e) {
|
||||
Debug::log(ERR, "Keyboard had no name???"); // logic error
|
||||
}
|
||||
|
||||
PNEWKEYBOARD->hyprListener_keyboardMod.initCallback(&wlr_keyboard_from_input_device(keyboard)->events.modifiers, &Events::listener_keyboardMod, PNEWKEYBOARD, "Keyboard");
|
||||
PNEWKEYBOARD->hyprListener_keyboardKey.initCallback(&wlr_keyboard_from_input_device(keyboard)->events.key, &Events::listener_keyboardKey, PNEWKEYBOARD, "Keyboard");
|
||||
PNEWKEYBOARD->hyprListener_keyboardDestroy.initCallback(&keyboard->events.destroy, &Events::listener_keyboardDestroy, PNEWKEYBOARD, "Keyboard");
|
||||
|
||||
if (m_pActiveKeyboard)
|
||||
m_pActiveKeyboard->active = false;
|
||||
m_pActiveKeyboard = PNEWKEYBOARD;
|
||||
|
||||
applyConfigToKeyboard(PNEWKEYBOARD);
|
||||
|
||||
wlr_seat_set_keyboard(g_pCompositor->m_sSeat.seat, wlr_keyboard_from_input_device(keyboard));
|
||||
|
||||
Debug::log(LOG, "New virtual keyboard created, pointers Hypr: %x and WLR: %x", PNEWKEYBOARD, keyboard);
|
||||
}
|
||||
|
||||
void CInputManager::setKeyboardLayout() {
|
||||
for (auto& k : m_lKeyboards)
|
||||
applyConfigToKeyboard(&k);
|
||||
@ -667,14 +694,29 @@ void CInputManager::onKeyboardKey(wlr_keyboard_key_event* e, SKeyboard* pKeyboar
|
||||
wlr_idle_notify_activity(g_pCompositor->m_sWLRIdle, g_pCompositor->m_sSeat.seat);
|
||||
|
||||
if (passEvent) {
|
||||
wlr_seat_set_keyboard(g_pCompositor->m_sSeat.seat, wlr_keyboard_from_input_device(pKeyboard->keyboard));
|
||||
wlr_seat_keyboard_notify_key(g_pCompositor->m_sSeat.seat, e->time_msec, e->keycode, e->state);
|
||||
|
||||
const auto PIMEGRAB = m_sIMERelay.getIMEKeyboardGrab(pKeyboard);
|
||||
|
||||
if (PIMEGRAB && PIMEGRAB->pWlrKbGrab && PIMEGRAB->pWlrKbGrab->input_method) {
|
||||
wlr_input_method_keyboard_grab_v2_set_keyboard(PIMEGRAB->pWlrKbGrab, wlr_keyboard_from_input_device(pKeyboard->keyboard));
|
||||
wlr_input_method_keyboard_grab_v2_send_key(PIMEGRAB->pWlrKbGrab, e->time_msec, e->keycode, e->state);
|
||||
} else {
|
||||
wlr_seat_set_keyboard(g_pCompositor->m_sSeat.seat, wlr_keyboard_from_input_device(pKeyboard->keyboard));
|
||||
wlr_seat_keyboard_notify_key(g_pCompositor->m_sSeat.seat, e->time_msec, e->keycode, e->state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CInputManager::onKeyboardMod(void* data, SKeyboard* pKeyboard) {
|
||||
wlr_seat_set_keyboard(g_pCompositor->m_sSeat.seat, wlr_keyboard_from_input_device(pKeyboard->keyboard));
|
||||
wlr_seat_keyboard_notify_modifiers(g_pCompositor->m_sSeat.seat, &wlr_keyboard_from_input_device(pKeyboard->keyboard)->modifiers);
|
||||
const auto PIMEGRAB = m_sIMERelay.getIMEKeyboardGrab(pKeyboard);
|
||||
|
||||
if (PIMEGRAB && PIMEGRAB->pWlrKbGrab && PIMEGRAB->pWlrKbGrab->input_method) {
|
||||
wlr_input_method_keyboard_grab_v2_set_keyboard(PIMEGRAB->pWlrKbGrab, wlr_keyboard_from_input_device(pKeyboard->keyboard));
|
||||
wlr_input_method_keyboard_grab_v2_send_modifiers(PIMEGRAB->pWlrKbGrab, &wlr_keyboard_from_input_device(pKeyboard->keyboard)->modifiers);
|
||||
} else {
|
||||
wlr_seat_set_keyboard(g_pCompositor->m_sSeat.seat, wlr_keyboard_from_input_device(pKeyboard->keyboard));
|
||||
wlr_seat_keyboard_notify_modifiers(g_pCompositor->m_sSeat.seat, &wlr_keyboard_from_input_device(pKeyboard->keyboard)->modifiers);
|
||||
}
|
||||
}
|
||||
|
||||
void CInputManager::refocus() {
|
||||
|
@ -23,6 +23,7 @@ public:
|
||||
void onKeyboardMod(void*, SKeyboard*);
|
||||
|
||||
void newKeyboard(wlr_input_device*);
|
||||
void newVirtualKeyboard(wlr_input_device*);
|
||||
void newMouse(wlr_input_device*, bool virt = false);
|
||||
void destroyKeyboard(SKeyboard*);
|
||||
void destroyMouse(wlr_input_device*);
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "InputMethodRelay.hpp"
|
||||
#include "InputManager.hpp"
|
||||
#include "../../Compositor.hpp"
|
||||
|
||||
CInputMethodRelay::CInputMethodRelay() {
|
||||
|
||||
@ -29,15 +30,17 @@ void CInputMethodRelay::onNewIME(wlr_input_method_v2* pIME) {
|
||||
Debug::log(LOG, "IME Commit");
|
||||
|
||||
if (PIMR->m_pWLRIME->current.preedit.text) {
|
||||
Debug::log(LOG, "IME TextInput preedit");
|
||||
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);
|
||||
}
|
||||
|
||||
if (PIMR->m_pWLRIME->current.commit_text) {
|
||||
Debug::log(LOG, "IME TextInput commit");
|
||||
wlr_text_input_v3_send_commit_string(PTI->pWlrInput, PIMR->m_pWLRIME->current.commit_text);
|
||||
}
|
||||
|
||||
if (PIMR->m_pWLRIME->current.delete_.before_length ||
|
||||
PIMR->m_pWLRIME->current.delete_.after_length) {
|
||||
if (PIMR->m_pWLRIME->current.delete_.before_length || PIMR->m_pWLRIME->current.delete_.after_length) {
|
||||
Debug::log(LOG, "IME TextInput delete");
|
||||
wlr_text_input_v3_send_delete_surrounding_text(PTI->pWlrInput, PIMR->m_pWLRIME->current.delete_.before_length, PIMR->m_pWLRIME->current.delete_.after_length);
|
||||
}
|
||||
|
||||
@ -51,6 +54,9 @@ void CInputMethodRelay::onNewIME(wlr_input_method_v2* pIME) {
|
||||
|
||||
hyprListener_IMEDestroy.removeCallback();
|
||||
hyprListener_IMECommit.removeCallback();
|
||||
hyprListener_IMEGrab.removeCallback();
|
||||
|
||||
m_pKeyboardGrab.reset(nullptr);
|
||||
|
||||
const auto PTI = getFocusedTextInput();
|
||||
|
||||
@ -64,6 +70,38 @@ void CInputMethodRelay::onNewIME(wlr_input_method_v2* pIME) {
|
||||
|
||||
}, this, "IMERelay");
|
||||
|
||||
hyprListener_IMEGrab.initCallback(&m_pWLRIME->events.grab_keyboard, [&](void* owner, void* data) {
|
||||
|
||||
Debug::log(LOG, "IME TextInput Keyboard Grab new");
|
||||
|
||||
m_pKeyboardGrab.reset(nullptr);
|
||||
|
||||
m_pKeyboardGrab = std::make_unique<SIMEKbGrab>();
|
||||
|
||||
m_pKeyboardGrab->pKeyboard = wlr_seat_get_keyboard(g_pCompositor->m_sSeat.seat);
|
||||
|
||||
const auto PKBGRAB = (wlr_input_method_keyboard_grab_v2*)data;
|
||||
|
||||
m_pKeyboardGrab->pWlrKbGrab = PKBGRAB;
|
||||
|
||||
wlr_input_method_keyboard_grab_v2_set_keyboard(m_pKeyboardGrab->pWlrKbGrab, m_pKeyboardGrab->pKeyboard);
|
||||
|
||||
m_pKeyboardGrab->hyprListener_grabDestroy.initCallback(&PKBGRAB->events.destroy, [&](void* owner, void* data) {
|
||||
|
||||
m_pKeyboardGrab->hyprListener_grabDestroy.removeCallback();
|
||||
|
||||
Debug::log(LOG, "IME TextInput Keyboard Grab destroy");
|
||||
|
||||
if (m_pKeyboardGrab->pKeyboard) {
|
||||
wlr_seat_keyboard_notify_modifiers(g_pCompositor->m_sSeat.seat, &m_pKeyboardGrab->pKeyboard->modifiers);
|
||||
}
|
||||
|
||||
m_pKeyboardGrab.reset(nullptr);
|
||||
|
||||
}, m_pKeyboardGrab.get(), "IME Keyboard Grab");
|
||||
|
||||
}, this, "IMERelay");
|
||||
|
||||
const auto PTI = getFocusableTextInput();
|
||||
|
||||
if (PTI) {
|
||||
@ -72,6 +110,25 @@ void CInputMethodRelay::onNewIME(wlr_input_method_v2* pIME) {
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if (wlr_keyboard_from_input_device(pKeyboard->keyboard) != m_pKeyboardGrab->pKeyboard)
|
||||
return nullptr;
|
||||
|
||||
return m_pKeyboardGrab.get();
|
||||
}
|
||||
|
||||
STextInput* CInputMethodRelay::getFocusedTextInput() {
|
||||
for (auto& ti : m_lTextInputs) {
|
||||
if (ti.pWlrInput->focused_surface) {
|
||||
@ -184,9 +241,14 @@ void CInputMethodRelay::removeTextInput(wlr_text_input_v3* pInput) {
|
||||
}
|
||||
|
||||
void CInputMethodRelay::commitIMEState(wlr_text_input_v3* pInput) {
|
||||
wlr_input_method_v2_send_surrounding_text(m_pWLRIME, pInput->current.surrounding.text, pInput->current.surrounding.cursor, pInput->current.surrounding.anchor);
|
||||
if (pInput->active_features & WLR_TEXT_INPUT_V3_FEATURE_SURROUNDING_TEXT)
|
||||
wlr_input_method_v2_send_surrounding_text(m_pWLRIME, pInput->current.surrounding.text, pInput->current.surrounding.cursor, pInput->current.surrounding.anchor);
|
||||
|
||||
wlr_input_method_v2_send_text_change_cause(m_pWLRIME, pInput->current.text_change_cause);
|
||||
wlr_input_method_v2_send_content_type(m_pWLRIME, pInput->current.content_type.hint, pInput->current.content_type.purpose);
|
||||
|
||||
if (pInput->active_features & WLR_TEXT_INPUT_V3_FEATURE_CONTENT_TYPE)
|
||||
wlr_input_method_v2_send_content_type(m_pWLRIME, pInput->current.content_type.hint, pInput->current.content_type.purpose);
|
||||
|
||||
wlr_input_method_v2_send_done(m_pWLRIME);
|
||||
}
|
||||
|
||||
|
@ -22,13 +22,18 @@ public:
|
||||
|
||||
void setPendingSurface(STextInput*, wlr_surface*);
|
||||
|
||||
SIMEKbGrab* getIMEKeyboardGrab(SKeyboard*);
|
||||
|
||||
private:
|
||||
|
||||
std::unique_ptr<SIMEKbGrab> m_pKeyboardGrab;
|
||||
|
||||
std::list<STextInput> m_lTextInputs;
|
||||
|
||||
DYNLISTENER(textInputNew);
|
||||
DYNLISTENER(IMECommit);
|
||||
DYNLISTENER(IMEDestroy);
|
||||
DYNLISTENER(IMEGrab);
|
||||
|
||||
void createNewTextInput(wlr_text_input_v3*);
|
||||
};
|
Loading…
Reference in New Issue
Block a user