From 82be16df294a219e9e2b29c7d539d1650b1de822 Mon Sep 17 00:00:00 2001 From: Mikhail Vinogradov Date: Tue, 15 Aug 2023 13:56:11 +0300 Subject: [PATCH] Try to refresh textInput active focus status --- autotests/integration/inputmethod_test.cpp | 41 ++++++++++++++++++++++ src/inputmethod.cpp | 11 ++++-- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/autotests/integration/inputmethod_test.cpp b/autotests/integration/inputmethod_test.cpp index 017a9d732e..1ff92e9e8f 100644 --- a/autotests/integration/inputmethod_test.cpp +++ b/autotests/integration/inputmethod_test.cpp @@ -57,6 +57,7 @@ private Q_SLOTS: void testEnableDisableV3(); void testEnableActive(); void testHidePanel(); + void testReactivateFocus(); void testSwitchFocusedSurfaces(); void testV2V3SameClient(); void testV3Styling(); @@ -305,6 +306,46 @@ void InputMethodTest::testHidePanel() QVERIFY(Test::waitForWindowClosed(window)); } +void InputMethodTest::testReactivateFocus() +{ + touchNow(); + QVERIFY(!kwinApp()->inputMethod()->isActive()); + + std::unique_ptr surface(Test::createSurface()); + std::unique_ptr shellSurface(Test::createXdgToplevelSurface(surface.get())); + Window *window = Test::renderAndWaitForShown(surface.get(), QSize(1280, 1024), Qt::red); + QVERIFY(window); + QVERIFY(window->isActive()); + QCOMPARE(window->frameGeometry().size(), QSize(1280, 1024)); + + // Show the keyboard + QSignalSpy windowAddedSpy(workspace(), &Workspace::windowAdded); + std::unique_ptr textInput(Test::waylandTextInputManager()->createTextInput(Test::waylandSeat())); + textInput->enable(surface.get()); + QSignalSpy paneladded(kwinApp()->inputMethod(), &KWin::InputMethod::panelChanged); + QVERIFY(paneladded.wait()); + textInput->showInputPanel(); + QVERIFY(windowAddedSpy.wait()); + QVERIFY(kwinApp()->inputMethod()->isActive()); + + QSignalSpy activeSpy(kwinApp()->inputMethod(), &InputMethod::activeChanged); + + // Hide keyboard like keyboardToggle button on navigation panel + kwinApp()->inputMethod()->setActive(false); + activeSpy.wait(200); + QVERIFY(!kwinApp()->inputMethod()->isActive()); + + // Reactivate + textInput->enable(surface.get()); + textInput->showInputPanel(); + activeSpy.wait(200); + QVERIFY(kwinApp()->inputMethod()->isActive()); + + // Destroy the test window + shellSurface.reset(); + QVERIFY(Test::waitForWindowClosed(window)); +} + void InputMethodTest::testSwitchFocusedSurfaces() { touchNow(); diff --git a/src/inputmethod.cpp b/src/inputmethod.cpp index b5ddc5160a..a54b9cdc84 100644 --- a/src/inputmethod.cpp +++ b/src/inputmethod.cpp @@ -156,8 +156,15 @@ void InputMethod::show() if (m_panel) { m_panel->show(); updateInputPanelState(); - } else if (isActive()) { - adoptInputMethodContext(); + } else { + if (!isActive()) { + refreshActive(); + } + + // refreshActive affects the result of isActive + if (isActive()) { + adoptInputMethodContext(); + } } }