Fix tests by checking if InputMethod::self() is null.

Only integration test has InputMethod instance.
This commit is contained in:
Weng Xuetian 2022-01-02 20:55:05 -08:00
parent d81b106c15
commit 6cc0c204fd
No known key found for this signature in database
GPG key ID: 8E8B898CBF2412F9
2 changed files with 9 additions and 2 deletions

View file

@ -1494,7 +1494,12 @@ class InputKeyboardFilter : public InputEventFilter
public:
bool keyEvent(QKeyEvent *event) override
{
if (auto keyboardGrab = InputMethod::self()->keyboardGrab()) {
auto *inputmethod = InputMethod::self();
if (!inputmethod) {
return false;
}
if (auto keyboardGrab = inputmethod->keyboardGrab()) {
if (event->isAutoRepeat()) {
return true;
}

View file

@ -248,7 +248,9 @@ void KeyboardInputRedirection::processKey(uint32_t key, InputRedirection::Keyboa
m_input->processFilters(std::bind(&InputEventFilter::keyEvent, std::placeholders::_1, &event));
m_xkb->forwardModifiers();
InputMethod::self()->forwardModifiers(InputMethod::NoForce);
if (auto *inputmethod = InputMethod::self()) {
inputmethod->forwardModifiers(InputMethod::NoForce);
}
if (event.modifiersRelevantForGlobalShortcuts() == Qt::KeyboardModifier::NoModifier && type != QEvent::KeyRelease) {
m_keyboardLayout->checkLayoutChange(previousLayout);