2020-09-01 08:58:46 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
SPDX-FileCopyrightText: 2020 Marco Martin <mart@kde.org>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
|
|
|
#include "kwin_wayland_test.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
|
2022-08-29 07:55:49 +00:00
|
|
|
#include "core/output.h"
|
2022-11-05 10:43:41 +00:00
|
|
|
#include "core/outputbackend.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
#include "effects.h"
|
2020-09-29 14:46:32 +00:00
|
|
|
#include "inputmethod.h"
|
2022-05-17 11:53:13 +00:00
|
|
|
#include "keyboard_input.h"
|
2023-02-09 13:07:56 +00:00
|
|
|
#include "pointer_input.h"
|
2020-09-01 08:58:46 +00:00
|
|
|
#include "qwayland-input-method-unstable-v1.h"
|
2020-09-25 06:51:04 +00:00
|
|
|
#include "qwayland-text-input-unstable-v3.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
#include "virtualkeyboard_dbus.h"
|
2022-04-22 09:27:33 +00:00
|
|
|
#include "wayland/clientconnection.h"
|
|
|
|
#include "wayland/display.h"
|
|
|
|
#include "wayland/seat_interface.h"
|
|
|
|
#include "wayland/surface_interface.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
#include "wayland_server.h"
|
2022-04-22 17:39:12 +00:00
|
|
|
#include "window.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
#include "workspace.h"
|
2022-05-17 11:53:13 +00:00
|
|
|
#include "xkb.h"
|
2020-09-01 08:58:46 +00:00
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
#include <QDBusConnection>
|
|
|
|
#include <QDBusMessage>
|
|
|
|
#include <QDBusPendingReply>
|
|
|
|
#include <QSignalSpy>
|
|
|
|
#include <QTest>
|
2020-09-01 08:58:46 +00:00
|
|
|
|
|
|
|
#include <KWayland/Client/compositor.h>
|
2021-12-29 17:19:43 +00:00
|
|
|
#include <KWayland/Client/keyboard.h>
|
2020-09-01 08:58:46 +00:00
|
|
|
#include <KWayland/Client/output.h>
|
2021-07-20 23:41:38 +00:00
|
|
|
#include <KWayland/Client/region.h>
|
2021-12-29 17:19:43 +00:00
|
|
|
#include <KWayland/Client/seat.h>
|
2020-09-01 08:58:46 +00:00
|
|
|
#include <KWayland/Client/surface.h>
|
|
|
|
#include <KWayland/Client/textinput.h>
|
2021-12-29 17:19:43 +00:00
|
|
|
#include <linux/input-event-codes.h>
|
2020-09-01 08:58:46 +00:00
|
|
|
|
|
|
|
using namespace KWin;
|
|
|
|
using KWin::VirtualKeyboardDBus;
|
|
|
|
|
2020-09-30 10:28:42 +00:00
|
|
|
static const QString s_socketName = QStringLiteral("wayland_test_kwin_inputmethod-0");
|
2020-09-01 08:58:46 +00:00
|
|
|
|
2020-09-30 10:28:42 +00:00
|
|
|
class InputMethodTest : public QObject
|
2020-09-01 08:58:46 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
private Q_SLOTS:
|
|
|
|
void initTestCase();
|
|
|
|
void init();
|
|
|
|
void cleanup();
|
|
|
|
|
|
|
|
void testOpenClose();
|
2020-09-25 06:51:04 +00:00
|
|
|
void testEnableDisableV3();
|
2021-07-20 23:41:38 +00:00
|
|
|
void testEnableActive();
|
2021-07-21 00:04:33 +00:00
|
|
|
void testHidePanel();
|
2021-07-30 18:29:01 +00:00
|
|
|
void testSwitchFocusedSurfaces();
|
2022-10-16 05:03:32 +00:00
|
|
|
void testV2V3SameClient();
|
2021-12-23 08:42:00 +00:00
|
|
|
void testV3Styling();
|
2021-12-23 22:33:30 +00:00
|
|
|
void testDisableShowInputPanel();
|
2021-12-29 17:19:43 +00:00
|
|
|
void testModifierForwarding();
|
2022-05-17 11:53:13 +00:00
|
|
|
void testFakeEventFallback();
|
2021-10-18 13:41:05 +00:00
|
|
|
|
|
|
|
private:
|
2022-03-23 10:13:38 +00:00
|
|
|
void touchNow()
|
|
|
|
{
|
2021-10-18 13:41:05 +00:00
|
|
|
static int time = 0;
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::touchDown(0, {100, 100}, ++time);
|
|
|
|
Test::touchUp(0, ++time);
|
2021-10-18 13:41:05 +00:00
|
|
|
}
|
2020-09-01 08:58:46 +00:00
|
|
|
};
|
|
|
|
|
2020-09-30 10:28:42 +00:00
|
|
|
void InputMethodTest::initTestCase()
|
2020-09-01 08:58:46 +00:00
|
|
|
{
|
2021-02-22 16:03:16 +00:00
|
|
|
QDBusConnection::sessionBus().registerService(QStringLiteral("org.kde.kwin.testvirtualkeyboard"));
|
|
|
|
|
2022-04-22 17:39:12 +00:00
|
|
|
qRegisterMetaType<KWin::Window *>();
|
2020-09-01 08:58:46 +00:00
|
|
|
qRegisterMetaType<KWayland::Client::Output *>();
|
|
|
|
|
|
|
|
QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
|
2020-12-09 13:06:15 +00:00
|
|
|
QVERIFY(waylandServer()->init(s_socketName));
|
2022-11-16 21:03:50 +00:00
|
|
|
QMetaObject::invokeMethod(kwinApp()->outputBackend(), "setVirtualOutputs", Qt::DirectConnection, Q_ARG(QVector<QRect>, QVector<QRect>() << QRect(0, 0, 1280, 1024) << QRect(1280, 0, 1280, 1024)));
|
2020-09-01 08:58:46 +00:00
|
|
|
|
2021-07-21 11:10:06 +00:00
|
|
|
static_cast<WaylandTestApplication *>(kwinApp())->setInputMethodServerToStart("internal");
|
2020-09-01 08:58:46 +00:00
|
|
|
kwinApp()->start();
|
|
|
|
QVERIFY(applicationStartedSpy.wait());
|
2022-07-11 10:41:15 +00:00
|
|
|
const auto outputs = workspace()->outputs();
|
2021-08-31 07:03:05 +00:00
|
|
|
QCOMPARE(outputs.count(), 2);
|
|
|
|
QCOMPARE(outputs[0]->geometry(), QRect(0, 0, 1280, 1024));
|
|
|
|
QCOMPARE(outputs[1]->geometry(), QRect(1280, 0, 1280, 1024));
|
2020-09-01 08:58:46 +00:00
|
|
|
}
|
|
|
|
|
2020-09-30 10:28:42 +00:00
|
|
|
void InputMethodTest::init()
|
2020-09-01 08:58:46 +00:00
|
|
|
{
|
2023-02-09 13:07:56 +00:00
|
|
|
workspace()->setActiveOutput(QPoint(640, 512));
|
|
|
|
KWin::input()->pointer()->warp(QPoint(640, 512));
|
|
|
|
|
2021-10-18 13:41:05 +00:00
|
|
|
touchNow();
|
2020-09-01 08:58:46 +00:00
|
|
|
|
2023-02-09 13:07:56 +00:00
|
|
|
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Seat | Test::AdditionalWaylandInterface::TextInputManagerV2 | Test::AdditionalWaylandInterface::InputMethodV1 | Test::AdditionalWaylandInterface::TextInputManagerV3));
|
2020-11-27 19:57:24 +00:00
|
|
|
|
2022-07-20 10:14:27 +00:00
|
|
|
kwinApp()->inputMethod()->setEnabled(true);
|
2020-09-01 08:58:46 +00:00
|
|
|
}
|
|
|
|
|
2020-09-30 10:28:42 +00:00
|
|
|
void InputMethodTest::cleanup()
|
2020-09-01 08:58:46 +00:00
|
|
|
{
|
|
|
|
Test::destroyWaylandConnection();
|
|
|
|
}
|
|
|
|
|
2020-09-30 10:28:42 +00:00
|
|
|
void InputMethodTest::testOpenClose()
|
2020-09-01 08:58:46 +00:00
|
|
|
{
|
2022-04-23 08:33:23 +00:00
|
|
|
QSignalSpy windowAddedSpy(workspace(), &Workspace::windowAdded);
|
|
|
|
QSignalSpy windowRemovedSpy(workspace(), &Workspace::windowRemoved);
|
2020-09-01 08:58:46 +00:00
|
|
|
|
|
|
|
// Create an xdg_toplevel surface and wait for the compositor to catch up.
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
|
|
|
|
std::unique_ptr<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.get()));
|
|
|
|
Window *window = Test::renderAndWaitForShown(surface.get(), QSize(1280, 1024), Qt::red);
|
2022-04-23 19:51:16 +00:00
|
|
|
QVERIFY(window);
|
|
|
|
QVERIFY(window->isActive());
|
|
|
|
QCOMPARE(window->frameGeometry().size(), QSize(1280, 1024));
|
|
|
|
QSignalSpy frameGeometryChangedSpy(window, &Window::frameGeometryChanged);
|
2022-08-01 21:29:02 +00:00
|
|
|
QSignalSpy toplevelConfigureRequestedSpy(shellSurface.get(), &Test::XdgToplevel::configureRequested);
|
2021-05-11 05:26:51 +00:00
|
|
|
QSignalSpy surfaceConfigureRequestedSpy(shellSurface->xdgSurface(), &Test::XdgSurface::configureRequested);
|
2022-10-21 19:44:57 +00:00
|
|
|
QVERIFY(surfaceConfigureRequestedSpy.wait());
|
2020-09-01 08:58:46 +00:00
|
|
|
|
2022-11-07 21:33:00 +00:00
|
|
|
std::unique_ptr<KWayland::Client::TextInput> textInput(Test::waylandTextInputManager()->createTextInput(Test::waylandSeat()));
|
2022-08-01 21:29:02 +00:00
|
|
|
QVERIFY(textInput != nullptr);
|
2020-09-01 08:58:46 +00:00
|
|
|
|
|
|
|
// Show the keyboard
|
2021-10-18 13:41:05 +00:00
|
|
|
touchNow();
|
2022-10-21 19:44:57 +00:00
|
|
|
textInput->enable(surface.get());
|
2020-09-01 08:58:46 +00:00
|
|
|
textInput->showInputPanel();
|
2022-10-21 19:44:57 +00:00
|
|
|
QSignalSpy paneladded(kwinApp()->inputMethod(), &KWin::InputMethod::panelChanged);
|
2022-04-23 08:33:23 +00:00
|
|
|
QVERIFY(windowAddedSpy.wait());
|
2022-10-21 19:44:57 +00:00
|
|
|
QCOMPARE(paneladded.count(), 1);
|
2020-09-01 08:58:46 +00:00
|
|
|
|
2022-04-23 08:33:23 +00:00
|
|
|
Window *keyboardClient = windowAddedSpy.last().first().value<Window *>();
|
2020-09-01 08:58:46 +00:00
|
|
|
QVERIFY(keyboardClient);
|
|
|
|
QVERIFY(keyboardClient->isInputMethod());
|
|
|
|
|
|
|
|
// Do the actual resize
|
2021-05-11 05:26:51 +00:00
|
|
|
QVERIFY(surfaceConfigureRequestedSpy.wait());
|
2020-09-01 08:58:46 +00:00
|
|
|
|
2022-08-01 21:29:02 +00:00
|
|
|
Test::render(surface.get(), toplevelConfigureRequestedSpy.last().first().value<QSize>(), Qt::red);
|
2020-09-01 08:58:46 +00:00
|
|
|
QVERIFY(frameGeometryChangedSpy.wait());
|
|
|
|
|
2023-03-31 17:18:55 +00:00
|
|
|
QCOMPARE(window->frameGeometry().height(), 1024 - keyboardClient->frameGeometry().height());
|
2020-09-01 08:58:46 +00:00
|
|
|
|
|
|
|
// Hide the keyboard
|
|
|
|
textInput->hideInputPanel();
|
|
|
|
|
2021-05-11 05:26:51 +00:00
|
|
|
QVERIFY(surfaceConfigureRequestedSpy.wait());
|
2022-08-01 21:29:02 +00:00
|
|
|
Test::render(surface.get(), toplevelConfigureRequestedSpy.last().first().value<QSize>(), Qt::red);
|
2020-09-01 08:58:46 +00:00
|
|
|
QVERIFY(frameGeometryChangedSpy.wait());
|
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
QCOMPARE(window->frameGeometry().height(), 1024);
|
2020-09-01 08:58:46 +00:00
|
|
|
|
2022-10-21 19:44:57 +00:00
|
|
|
// show the keyboard again
|
|
|
|
touchNow();
|
|
|
|
textInput->enable(surface.get());
|
|
|
|
textInput->showInputPanel();
|
|
|
|
|
|
|
|
QVERIFY(surfaceConfigureRequestedSpy.wait());
|
|
|
|
QVERIFY(keyboardClient->isShown());
|
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
// Destroy the test window.
|
2020-09-01 08:58:46 +00:00
|
|
|
shellSurface.reset();
|
2022-04-23 19:51:16 +00:00
|
|
|
QVERIFY(Test::waitForWindowDestroyed(window));
|
2020-09-01 08:58:46 +00:00
|
|
|
}
|
|
|
|
|
2020-09-30 10:28:42 +00:00
|
|
|
void InputMethodTest::testEnableDisableV3()
|
2020-09-25 06:51:04 +00:00
|
|
|
{
|
|
|
|
// Create an xdg_toplevel surface and wait for the compositor to catch up.
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
|
|
|
|
std::unique_ptr<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.get()));
|
|
|
|
Window *window = Test::renderAndWaitForShown(surface.get(), QSize(1280, 1024), Qt::red);
|
2022-04-23 19:51:16 +00:00
|
|
|
QVERIFY(window);
|
|
|
|
QVERIFY(window->isActive());
|
|
|
|
QCOMPARE(window->frameGeometry().size(), QSize(1280, 1024));
|
2020-09-25 06:51:04 +00:00
|
|
|
|
2022-10-16 05:03:32 +00:00
|
|
|
auto textInputV3 = std::make_unique<Test::TextInputV3>();
|
2020-09-25 06:51:04 +00:00
|
|
|
textInputV3->init(Test::waylandTextInputManagerV3()->get_text_input(*(Test::waylandSeat())));
|
2022-10-24 23:38:40 +00:00
|
|
|
|
|
|
|
// Show the keyboard
|
|
|
|
touchNow();
|
2020-09-25 06:51:04 +00:00
|
|
|
textInputV3->enable();
|
|
|
|
|
2022-10-24 23:38:40 +00:00
|
|
|
QSignalSpy windowAddedSpy(workspace(), &Workspace::windowAdded);
|
2022-07-20 10:14:27 +00:00
|
|
|
QSignalSpy inputMethodActiveSpy(kwinApp()->inputMethod(), &InputMethod::activeChanged);
|
2021-05-10 16:01:41 +00:00
|
|
|
// just enabling the text-input should not show it but rather on commit
|
2022-07-20 10:14:27 +00:00
|
|
|
QVERIFY(!kwinApp()->inputMethod()->isActive());
|
2020-09-25 06:51:04 +00:00
|
|
|
textInputV3->commit();
|
2021-05-10 16:01:41 +00:00
|
|
|
QVERIFY(inputMethodActiveSpy.count() || inputMethodActiveSpy.wait());
|
2022-07-20 10:14:27 +00:00
|
|
|
QVERIFY(kwinApp()->inputMethod()->isActive());
|
2020-09-25 06:51:04 +00:00
|
|
|
|
2022-10-24 23:38:40 +00:00
|
|
|
QVERIFY(windowAddedSpy.wait());
|
|
|
|
Window *keyboardClient = windowAddedSpy.last().first().value<Window *>();
|
|
|
|
QVERIFY(keyboardClient);
|
|
|
|
QVERIFY(keyboardClient->isInputMethod());
|
|
|
|
QVERIFY(keyboardClient->isShown());
|
|
|
|
|
|
|
|
// Text input v3 doesn't have hideInputPanel, just simiulate the hide from dbus call
|
|
|
|
kwinApp()->inputMethod()->hide();
|
|
|
|
QVERIFY(!keyboardClient->isShown());
|
|
|
|
|
|
|
|
QSignalSpy windowShownSpy(keyboardClient, &Window::windowShown);
|
|
|
|
// Force enable the text input object. This is what's done by Gtk.
|
|
|
|
textInputV3->enable();
|
|
|
|
textInputV3->commit();
|
|
|
|
|
|
|
|
windowShownSpy.wait();
|
|
|
|
QVERIFY(keyboardClient->isShown());
|
|
|
|
|
2020-09-25 06:51:04 +00:00
|
|
|
// disable text input and ensure that it is not hiding input panel without commit
|
2021-05-10 16:01:41 +00:00
|
|
|
inputMethodActiveSpy.clear();
|
2022-07-20 10:14:27 +00:00
|
|
|
QVERIFY(kwinApp()->inputMethod()->isActive());
|
2020-09-25 06:51:04 +00:00
|
|
|
textInputV3->disable();
|
|
|
|
textInputV3->commit();
|
2021-05-10 16:01:41 +00:00
|
|
|
QVERIFY(inputMethodActiveSpy.count() || inputMethodActiveSpy.wait());
|
2022-07-20 10:14:27 +00:00
|
|
|
QVERIFY(!kwinApp()->inputMethod()->isActive());
|
2020-09-25 06:51:04 +00:00
|
|
|
}
|
|
|
|
|
2021-07-20 23:41:38 +00:00
|
|
|
void InputMethodTest::testEnableActive()
|
|
|
|
{
|
2022-09-08 07:04:14 +00:00
|
|
|
// This test verifies that enabling text-input twice won't change the active input method status.
|
2022-07-20 10:14:27 +00:00
|
|
|
QVERIFY(!kwinApp()->inputMethod()->isActive());
|
2021-07-20 23:41:38 +00:00
|
|
|
|
|
|
|
// Create an xdg_toplevel surface and wait for the compositor to catch up.
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
|
|
|
|
std::unique_ptr<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.get()));
|
|
|
|
Window *window = Test::renderAndWaitForShown(surface.get(), QSize(1280, 1024), Qt::red);
|
2022-04-23 19:51:16 +00:00
|
|
|
QVERIFY(window);
|
|
|
|
QVERIFY(window->isActive());
|
2021-07-20 23:41:38 +00:00
|
|
|
|
|
|
|
// Show the keyboard
|
2022-07-13 15:24:19 +00:00
|
|
|
QSignalSpy windowAddedSpy(workspace(), &Workspace::windowAdded);
|
2022-11-07 21:33:00 +00:00
|
|
|
std::unique_ptr<KWayland::Client::TextInput> textInput(Test::waylandTextInputManager()->createTextInput(Test::waylandSeat()));
|
2022-09-08 07:04:14 +00:00
|
|
|
textInput->enable(surface.get());
|
2022-09-22 19:49:53 +00:00
|
|
|
QSignalSpy paneladded(kwinApp()->inputMethod(), &KWin::InputMethod::panelChanged);
|
|
|
|
QVERIFY(paneladded.wait());
|
2021-07-20 23:41:38 +00:00
|
|
|
textInput->showInputPanel();
|
2022-04-23 08:33:23 +00:00
|
|
|
QVERIFY(windowAddedSpy.wait());
|
2022-09-08 07:04:14 +00:00
|
|
|
QVERIFY(kwinApp()->inputMethod()->isActive());
|
2021-07-20 23:41:38 +00:00
|
|
|
|
2022-09-08 07:04:14 +00:00
|
|
|
// Ask the keyboard to be shown again.
|
|
|
|
QSignalSpy activateSpy(kwinApp()->inputMethod(), &InputMethod::activeChanged);
|
2021-07-20 23:41:38 +00:00
|
|
|
textInput->enable(surface.get());
|
|
|
|
textInput->showInputPanel();
|
|
|
|
activateSpy.wait(200);
|
|
|
|
QVERIFY(activateSpy.isEmpty());
|
2022-07-20 10:14:27 +00:00
|
|
|
QVERIFY(kwinApp()->inputMethod()->isActive());
|
2021-07-20 23:41:38 +00:00
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
// Destroy the test window.
|
2021-07-20 23:41:38 +00:00
|
|
|
shellSurface.reset();
|
2022-04-23 19:51:16 +00:00
|
|
|
QVERIFY(Test::waitForWindowDestroyed(window));
|
2021-07-20 23:41:38 +00:00
|
|
|
}
|
|
|
|
|
2021-07-21 00:04:33 +00:00
|
|
|
void InputMethodTest::testHidePanel()
|
|
|
|
{
|
2022-07-20 10:14:27 +00:00
|
|
|
QVERIFY(!kwinApp()->inputMethod()->isActive());
|
2021-07-21 00:04:33 +00:00
|
|
|
|
2022-01-19 01:52:44 +00:00
|
|
|
touchNow();
|
2022-04-23 08:33:23 +00:00
|
|
|
QSignalSpy windowAddedSpy(workspace(), &Workspace::windowAdded);
|
|
|
|
QSignalSpy windowRemovedSpy(workspace(), &Workspace::windowRemoved);
|
2021-07-21 00:04:33 +00:00
|
|
|
|
2022-07-20 10:14:27 +00:00
|
|
|
QSignalSpy activateSpy(kwinApp()->inputMethod(), &InputMethod::activeChanged);
|
2022-11-07 21:33:00 +00:00
|
|
|
std::unique_ptr<KWayland::Client::TextInput> textInput(Test::waylandTextInputManager()->createTextInput(Test::waylandSeat()));
|
2021-07-21 00:04:33 +00:00
|
|
|
|
|
|
|
// Create an xdg_toplevel surface and wait for the compositor to catch up.
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
|
|
|
|
std::unique_ptr<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.get()));
|
|
|
|
Window *window = Test::renderAndWaitForShown(surface.get(), QSize(1280, 1024), Qt::red);
|
2022-04-23 19:51:16 +00:00
|
|
|
waylandServer()->seat()->setFocusedTextInputSurface(window->surface());
|
2021-07-21 00:04:33 +00:00
|
|
|
|
2022-01-19 01:52:44 +00:00
|
|
|
textInput->enable(surface.get());
|
2022-09-22 19:49:53 +00:00
|
|
|
QSignalSpy paneladded(kwinApp()->inputMethod(), &KWin::InputMethod::panelChanged);
|
|
|
|
QVERIFY(paneladded.wait());
|
2022-01-19 01:52:44 +00:00
|
|
|
textInput->showInputPanel();
|
2022-04-23 08:33:23 +00:00
|
|
|
QVERIFY(windowAddedSpy.wait());
|
2022-01-19 01:52:44 +00:00
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
QCOMPARE(workspace()->activeWindow(), window);
|
2021-07-21 00:04:33 +00:00
|
|
|
|
2022-04-23 08:33:23 +00:00
|
|
|
QCOMPARE(windowAddedSpy.count(), 2);
|
2021-07-21 00:04:33 +00:00
|
|
|
QVERIFY(activateSpy.count() || activateSpy.wait());
|
2022-07-20 10:14:27 +00:00
|
|
|
QVERIFY(kwinApp()->inputMethod()->isActive());
|
2021-07-21 00:04:33 +00:00
|
|
|
|
2022-09-22 19:49:53 +00:00
|
|
|
auto keyboardWindow = kwinApp()->inputMethod()->panel();
|
2021-07-21 00:04:33 +00:00
|
|
|
auto ipsurface = Test::inputPanelSurface();
|
2022-04-23 19:51:16 +00:00
|
|
|
QVERIFY(keyboardWindow);
|
2022-04-23 08:33:23 +00:00
|
|
|
windowRemovedSpy.clear();
|
2021-07-21 00:04:33 +00:00
|
|
|
delete ipsurface;
|
2022-07-20 10:14:27 +00:00
|
|
|
QVERIFY(kwinApp()->inputMethod()->isVisible());
|
2022-04-23 08:33:23 +00:00
|
|
|
QVERIFY(windowRemovedSpy.count() || windowRemovedSpy.wait());
|
2022-07-20 10:14:27 +00:00
|
|
|
QVERIFY(!kwinApp()->inputMethod()->isVisible());
|
2021-07-21 00:04:33 +00:00
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
// Destroy the test window.
|
2021-07-21 00:04:33 +00:00
|
|
|
shellSurface.reset();
|
2022-04-23 19:51:16 +00:00
|
|
|
QVERIFY(Test::waitForWindowDestroyed(window));
|
2021-07-21 00:04:33 +00:00
|
|
|
}
|
|
|
|
|
2021-07-30 18:29:01 +00:00
|
|
|
void InputMethodTest::testSwitchFocusedSurfaces()
|
|
|
|
{
|
2022-01-19 01:52:44 +00:00
|
|
|
touchNow();
|
2022-07-20 10:14:27 +00:00
|
|
|
QVERIFY(!kwinApp()->inputMethod()->isActive());
|
2021-07-30 18:29:01 +00:00
|
|
|
|
2022-04-23 08:33:23 +00:00
|
|
|
QSignalSpy windowAddedSpy(workspace(), &Workspace::windowAdded);
|
|
|
|
QSignalSpy windowRemovedSpy(workspace(), &Workspace::windowRemoved);
|
2021-07-30 18:29:01 +00:00
|
|
|
|
2022-07-20 10:14:27 +00:00
|
|
|
QSignalSpy activateSpy(kwinApp()->inputMethod(), &InputMethod::activeChanged);
|
2022-11-07 21:33:00 +00:00
|
|
|
std::unique_ptr<KWayland::Client::TextInput> textInput(Test::waylandTextInputManager()->createTextInput(Test::waylandSeat()));
|
2021-07-30 18:29:01 +00:00
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
QVector<Window *> windows;
|
2022-08-16 11:43:33 +00:00
|
|
|
std::vector<std::unique_ptr<KWayland::Client::Surface>> surfaces;
|
2021-07-30 18:29:01 +00:00
|
|
|
QVector<Test::XdgToplevel *> toplevels;
|
|
|
|
// We create 3 surfaces
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
2022-08-16 11:43:33 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface = Test::createSurface();
|
|
|
|
auto shellSurface = Test::createXdgToplevelSurface(surface.get());
|
|
|
|
windows += Test::renderAndWaitForShown(surface.get(), QSize(1280, 1024), Qt::red);
|
2022-04-23 19:51:16 +00:00
|
|
|
QCOMPARE(workspace()->activeWindow(), windows.constLast());
|
2022-08-16 11:43:33 +00:00
|
|
|
surfaces.push_back(std::move(surface));
|
2021-07-30 18:29:01 +00:00
|
|
|
toplevels += shellSurface;
|
|
|
|
}
|
2022-04-23 08:33:23 +00:00
|
|
|
QCOMPARE(windowAddedSpy.count(), 3);
|
2022-04-23 19:51:16 +00:00
|
|
|
waylandServer()->seat()->setFocusedTextInputSurface(windows.constFirst()->surface());
|
2021-07-30 18:29:01 +00:00
|
|
|
|
2022-07-20 10:14:27 +00:00
|
|
|
QVERIFY(!kwinApp()->inputMethod()->isActive());
|
2022-08-16 11:43:33 +00:00
|
|
|
textInput->enable(surfaces.back().get());
|
2022-07-20 10:14:27 +00:00
|
|
|
QVERIFY(!kwinApp()->inputMethod()->isActive());
|
2022-04-23 19:51:16 +00:00
|
|
|
waylandServer()->seat()->setFocusedTextInputSurface(windows.first()->surface());
|
2022-07-20 10:14:27 +00:00
|
|
|
QVERIFY(!kwinApp()->inputMethod()->isActive());
|
2021-07-30 18:29:01 +00:00
|
|
|
activateSpy.clear();
|
2022-04-23 19:51:16 +00:00
|
|
|
waylandServer()->seat()->setFocusedTextInputSurface(windows.last()->surface());
|
2021-07-30 18:29:01 +00:00
|
|
|
QVERIFY(activateSpy.count() || activateSpy.wait());
|
2022-07-20 10:14:27 +00:00
|
|
|
QVERIFY(kwinApp()->inputMethod()->isActive());
|
2021-07-30 18:29:01 +00:00
|
|
|
|
|
|
|
activateSpy.clear();
|
2022-04-23 19:51:16 +00:00
|
|
|
waylandServer()->seat()->setFocusedTextInputSurface(windows.first()->surface());
|
2021-07-30 18:29:01 +00:00
|
|
|
QVERIFY(activateSpy.count() || activateSpy.wait());
|
2022-07-20 10:14:27 +00:00
|
|
|
QVERIFY(!kwinApp()->inputMethod()->isActive());
|
2021-07-30 18:29:01 +00:00
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
// Destroy the test window.
|
|
|
|
for (int i = 0; i < windows.count(); ++i) {
|
2021-07-30 18:29:01 +00:00
|
|
|
delete toplevels[i];
|
2022-04-23 19:51:16 +00:00
|
|
|
QVERIFY(Test::waitForWindowDestroyed(windows[i]));
|
2021-07-30 18:29:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-16 05:03:32 +00:00
|
|
|
void InputMethodTest::testV2V3SameClient()
|
|
|
|
{
|
|
|
|
touchNow();
|
|
|
|
QVERIFY(!kwinApp()->inputMethod()->isActive());
|
|
|
|
|
|
|
|
QSignalSpy windowAddedSpy(workspace(), &Workspace::windowAdded);
|
|
|
|
QSignalSpy windowRemovedSpy(workspace(), &Workspace::windowRemoved);
|
|
|
|
|
|
|
|
QSignalSpy activateSpy(kwinApp()->inputMethod(), &InputMethod::activeChanged);
|
2022-11-07 21:33:00 +00:00
|
|
|
std::unique_ptr<KWayland::Client::TextInput> textInput(Test::waylandTextInputManager()->createTextInput(Test::waylandSeat()));
|
2022-10-16 05:03:32 +00:00
|
|
|
|
|
|
|
auto textInputV3 = std::make_unique<Test::TextInputV3>();
|
|
|
|
textInputV3->init(Test::waylandTextInputManagerV3()->get_text_input(*(Test::waylandSeat())));
|
|
|
|
|
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface = Test::createSurface();
|
|
|
|
std::unique_ptr<Test::XdgToplevel> toplevel(Test::createXdgToplevelSurface(surface.get()));
|
|
|
|
Window *window = Test::renderAndWaitForShown(surface.get(), QSize(1280, 1024), Qt::red);
|
|
|
|
QCOMPARE(workspace()->activeWindow(), window);
|
|
|
|
QCOMPARE(windowAddedSpy.count(), 1);
|
|
|
|
waylandServer()->seat()->setFocusedTextInputSurface(window->surface());
|
|
|
|
QVERIFY(!kwinApp()->inputMethod()->isActive());
|
|
|
|
|
|
|
|
// Enable and disable v2
|
|
|
|
textInput->enable(surface.get());
|
|
|
|
QVERIFY(activateSpy.count() || activateSpy.wait());
|
|
|
|
QVERIFY(kwinApp()->inputMethod()->isActive());
|
|
|
|
|
|
|
|
activateSpy.clear();
|
|
|
|
textInput->disable(surface.get());
|
|
|
|
QVERIFY(activateSpy.count() || activateSpy.wait());
|
|
|
|
QVERIFY(!kwinApp()->inputMethod()->isActive());
|
|
|
|
|
|
|
|
// Enable and disable v3
|
|
|
|
activateSpy.clear();
|
|
|
|
textInputV3->enable();
|
|
|
|
textInputV3->commit();
|
|
|
|
QVERIFY(activateSpy.count() || activateSpy.wait());
|
|
|
|
QVERIFY(kwinApp()->inputMethod()->isActive());
|
|
|
|
|
|
|
|
activateSpy.clear();
|
|
|
|
textInputV3->disable();
|
|
|
|
textInputV3->commit();
|
|
|
|
activateSpy.clear();
|
|
|
|
QVERIFY(activateSpy.count() || activateSpy.wait());
|
|
|
|
QVERIFY(!kwinApp()->inputMethod()->isActive());
|
|
|
|
|
|
|
|
// Enable v2 and v3
|
|
|
|
activateSpy.clear();
|
|
|
|
textInputV3->enable();
|
|
|
|
textInputV3->commit();
|
|
|
|
textInput->enable(surface.get());
|
|
|
|
QVERIFY(activateSpy.count() || activateSpy.wait());
|
|
|
|
QVERIFY(kwinApp()->inputMethod()->isActive());
|
|
|
|
|
|
|
|
// Disable v3, should still be active since v2 is active.
|
|
|
|
activateSpy.clear();
|
|
|
|
textInputV3->disable();
|
|
|
|
textInputV3->commit();
|
|
|
|
activateSpy.wait(200);
|
|
|
|
QVERIFY(kwinApp()->inputMethod()->isActive());
|
|
|
|
|
|
|
|
// Disable v2
|
|
|
|
activateSpy.clear();
|
|
|
|
textInput->disable(surface.get());
|
|
|
|
QVERIFY(activateSpy.count() || activateSpy.wait());
|
|
|
|
QVERIFY(!kwinApp()->inputMethod()->isActive());
|
|
|
|
|
|
|
|
toplevel.reset();
|
|
|
|
QVERIFY(Test::waitForWindowDestroyed(window));
|
|
|
|
}
|
|
|
|
|
2021-12-23 08:42:00 +00:00
|
|
|
void InputMethodTest::testV3Styling()
|
|
|
|
{
|
|
|
|
// Create an xdg_toplevel surface and wait for the compositor to catch up.
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
|
|
|
|
std::unique_ptr<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.get()));
|
|
|
|
Window *window = Test::renderAndWaitForShown(surface.get(), QSize(1280, 1024), Qt::red);
|
2022-04-23 19:51:16 +00:00
|
|
|
QVERIFY(window);
|
|
|
|
QVERIFY(window->isActive());
|
|
|
|
QCOMPARE(window->frameGeometry().size(), QSize(1280, 1024));
|
2021-12-23 08:42:00 +00:00
|
|
|
|
2022-10-16 05:03:32 +00:00
|
|
|
auto textInputV3 = std::make_unique<Test::TextInputV3>();
|
2021-12-23 08:42:00 +00:00
|
|
|
textInputV3->init(Test::waylandTextInputManagerV3()->get_text_input(*(Test::waylandSeat())));
|
|
|
|
textInputV3->enable();
|
|
|
|
|
2022-07-20 10:14:27 +00:00
|
|
|
QSignalSpy inputMethodActiveSpy(kwinApp()->inputMethod(), &InputMethod::activeChanged);
|
2021-12-23 08:42:00 +00:00
|
|
|
QSignalSpy inputMethodActivateSpy(Test::inputMethod(), &Test::MockInputMethod::activate);
|
|
|
|
// just enabling the text-input should not show it but rather on commit
|
2022-07-20 10:14:27 +00:00
|
|
|
QVERIFY(!kwinApp()->inputMethod()->isActive());
|
2021-12-23 08:42:00 +00:00
|
|
|
textInputV3->commit();
|
|
|
|
QVERIFY(inputMethodActiveSpy.count() || inputMethodActiveSpy.wait());
|
2022-07-20 10:14:27 +00:00
|
|
|
QVERIFY(kwinApp()->inputMethod()->isActive());
|
2021-12-23 08:42:00 +00:00
|
|
|
QVERIFY(inputMethodActivateSpy.wait());
|
|
|
|
auto context = Test::inputMethod()->context();
|
2022-10-16 05:03:32 +00:00
|
|
|
QSignalSpy textInputPreeditSpy(textInputV3.get(), &Test::TextInputV3::preeditString);
|
2021-12-23 08:42:00 +00:00
|
|
|
zwp_input_method_context_v1_preedit_cursor(context, 0);
|
|
|
|
zwp_input_method_context_v1_preedit_styling(context, 0, 3, 7);
|
|
|
|
zwp_input_method_context_v1_preedit_string(context, 0, "ABCD", "ABCD");
|
|
|
|
QVERIFY(textInputPreeditSpy.wait());
|
|
|
|
QCOMPARE(textInputPreeditSpy.last().at(0), QString("ABCD"));
|
|
|
|
QCOMPARE(textInputPreeditSpy.last().at(1), 0);
|
|
|
|
QCOMPARE(textInputPreeditSpy.last().at(2), 0);
|
|
|
|
|
|
|
|
zwp_input_method_context_v1_preedit_cursor(context, 1);
|
|
|
|
zwp_input_method_context_v1_preedit_styling(context, 0, 3, 7);
|
|
|
|
zwp_input_method_context_v1_preedit_string(context, 0, "ABCDE", "ABCDE");
|
|
|
|
QVERIFY(textInputPreeditSpy.wait());
|
|
|
|
QCOMPARE(textInputPreeditSpy.last().at(0), QString("ABCDE"));
|
|
|
|
QCOMPARE(textInputPreeditSpy.last().at(1), 1);
|
|
|
|
QCOMPARE(textInputPreeditSpy.last().at(2), 1);
|
|
|
|
|
|
|
|
zwp_input_method_context_v1_preedit_cursor(context, 2);
|
|
|
|
// Use selection for [2, 2+2)
|
|
|
|
zwp_input_method_context_v1_preedit_styling(context, 2, 2, 6);
|
|
|
|
// Use high light for [3, 3+3)
|
|
|
|
zwp_input_method_context_v1_preedit_styling(context, 3, 3, 4);
|
|
|
|
zwp_input_method_context_v1_preedit_string(context, 0, "ABCDEF", "ABCDEF");
|
|
|
|
QVERIFY(textInputPreeditSpy.wait());
|
|
|
|
QCOMPARE(textInputPreeditSpy.last().at(0), QString("ABCDEF"));
|
|
|
|
// Merged range should be [2, 6)
|
|
|
|
QCOMPARE(textInputPreeditSpy.last().at(1), 2);
|
|
|
|
QCOMPARE(textInputPreeditSpy.last().at(2), 6);
|
|
|
|
|
|
|
|
zwp_input_method_context_v1_preedit_cursor(context, 2);
|
|
|
|
// Use selection for [0, 0+2)
|
|
|
|
zwp_input_method_context_v1_preedit_styling(context, 0, 2, 6);
|
|
|
|
// Use high light for [3, 3+3)
|
|
|
|
zwp_input_method_context_v1_preedit_styling(context, 3, 3, 4);
|
|
|
|
zwp_input_method_context_v1_preedit_string(context, 0, "ABCDEF", "ABCDEF");
|
|
|
|
QVERIFY(textInputPreeditSpy.wait());
|
|
|
|
QCOMPARE(textInputPreeditSpy.last().at(0), QString("ABCDEF"));
|
|
|
|
// Merged range should be none, because of the disjunction highlight.
|
|
|
|
QCOMPARE(textInputPreeditSpy.last().at(1), 2);
|
|
|
|
QCOMPARE(textInputPreeditSpy.last().at(2), 2);
|
|
|
|
|
|
|
|
zwp_input_method_context_v1_preedit_cursor(context, 1);
|
|
|
|
// Use selection for [0, 0+2)
|
|
|
|
zwp_input_method_context_v1_preedit_styling(context, 0, 2, 6);
|
|
|
|
// Use high light for [2, 2+3)
|
|
|
|
zwp_input_method_context_v1_preedit_styling(context, 2, 3, 4);
|
|
|
|
zwp_input_method_context_v1_preedit_string(context, 0, "ABCDEF", "ABCDEF");
|
|
|
|
QVERIFY(textInputPreeditSpy.wait());
|
|
|
|
QCOMPARE(textInputPreeditSpy.last().at(0), QString("ABCDEF"));
|
|
|
|
// Merged range should be none, starting offset does not match.
|
|
|
|
QCOMPARE(textInputPreeditSpy.last().at(1), 1);
|
|
|
|
QCOMPARE(textInputPreeditSpy.last().at(2), 1);
|
|
|
|
|
|
|
|
// Use different order of styling and cursor
|
|
|
|
// Use high light for [3, 3+3)
|
|
|
|
zwp_input_method_context_v1_preedit_styling(context, 3, 3, 4);
|
|
|
|
zwp_input_method_context_v1_preedit_cursor(context, 1);
|
|
|
|
// Use selection for [1, 1+2)
|
|
|
|
zwp_input_method_context_v1_preedit_styling(context, 1, 2, 6);
|
|
|
|
zwp_input_method_context_v1_preedit_string(context, 0, "ABCDEF", "ABCDEF");
|
|
|
|
QVERIFY(textInputPreeditSpy.wait());
|
|
|
|
QCOMPARE(textInputPreeditSpy.last().at(0), QString("ABCDEF"));
|
|
|
|
// Merged range should be [1,6).
|
|
|
|
QCOMPARE(textInputPreeditSpy.last().at(1), 1);
|
|
|
|
QCOMPARE(textInputPreeditSpy.last().at(2), 6);
|
|
|
|
}
|
|
|
|
|
2021-12-23 22:33:30 +00:00
|
|
|
void InputMethodTest::testDisableShowInputPanel()
|
|
|
|
{
|
|
|
|
// Create an xdg_toplevel surface and wait for the compositor to catch up.
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
|
|
|
|
std::unique_ptr<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.get()));
|
|
|
|
Window *window = Test::renderAndWaitForShown(surface.get(), QSize(1280, 1024), Qt::red);
|
2022-04-23 19:51:16 +00:00
|
|
|
QVERIFY(window);
|
|
|
|
QVERIFY(window->isActive());
|
|
|
|
QCOMPARE(window->frameGeometry().size(), QSize(1280, 1024));
|
2021-12-23 22:33:30 +00:00
|
|
|
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::TextInput> textInputV2(Test::waylandTextInputManager()->createTextInput(Test::waylandSeat()));
|
2021-12-23 22:33:30 +00:00
|
|
|
|
2022-07-20 10:14:27 +00:00
|
|
|
QSignalSpy inputMethodActiveSpy(kwinApp()->inputMethod(), &InputMethod::activeChanged);
|
2021-12-23 22:33:30 +00:00
|
|
|
// just enabling the text-input should not show it but rather on commit
|
2022-07-20 10:14:27 +00:00
|
|
|
QVERIFY(!kwinApp()->inputMethod()->isActive());
|
2021-12-23 22:33:30 +00:00
|
|
|
textInputV2->enable(surface.get());
|
|
|
|
QVERIFY(inputMethodActiveSpy.count() || inputMethodActiveSpy.wait());
|
2022-07-20 10:14:27 +00:00
|
|
|
QVERIFY(kwinApp()->inputMethod()->isActive());
|
2021-12-23 22:33:30 +00:00
|
|
|
|
|
|
|
// disable text input and ensure that it is not hiding input panel without commit
|
|
|
|
inputMethodActiveSpy.clear();
|
2022-07-20 10:14:27 +00:00
|
|
|
QVERIFY(kwinApp()->inputMethod()->isActive());
|
2021-12-23 22:33:30 +00:00
|
|
|
textInputV2->disable(surface.get());
|
|
|
|
QVERIFY(inputMethodActiveSpy.count() || inputMethodActiveSpy.wait());
|
2022-07-20 10:14:27 +00:00
|
|
|
QVERIFY(!kwinApp()->inputMethod()->isActive());
|
2021-12-23 22:33:30 +00:00
|
|
|
|
|
|
|
QSignalSpy requestShowInputPanelSpy(waylandServer()->seat()->textInputV2(), &KWaylandServer::TextInputV2Interface::requestShowInputPanel);
|
|
|
|
textInputV2->showInputPanel();
|
|
|
|
QVERIFY(requestShowInputPanelSpy.count() || requestShowInputPanelSpy.wait());
|
2022-07-20 10:14:27 +00:00
|
|
|
QVERIFY(!kwinApp()->inputMethod()->isActive());
|
2021-12-23 22:33:30 +00:00
|
|
|
}
|
|
|
|
|
2021-12-29 17:19:43 +00:00
|
|
|
void InputMethodTest::testModifierForwarding()
|
|
|
|
{
|
|
|
|
// Create an xdg_toplevel surface and wait for the compositor to catch up.
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
|
|
|
|
std::unique_ptr<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.get()));
|
|
|
|
Window *window = Test::renderAndWaitForShown(surface.get(), QSize(1280, 1024), Qt::red);
|
2022-04-23 19:51:16 +00:00
|
|
|
QVERIFY(window);
|
|
|
|
QVERIFY(window->isActive());
|
|
|
|
QCOMPARE(window->frameGeometry().size(), QSize(1280, 1024));
|
2021-12-29 17:19:43 +00:00
|
|
|
|
2022-10-16 05:03:32 +00:00
|
|
|
auto textInputV3 = std::make_unique<Test::TextInputV3>();
|
2021-12-29 17:19:43 +00:00
|
|
|
textInputV3->init(Test::waylandTextInputManagerV3()->get_text_input(*(Test::waylandSeat())));
|
|
|
|
textInputV3->enable();
|
|
|
|
|
2022-07-20 10:14:27 +00:00
|
|
|
QSignalSpy inputMethodActiveSpy(kwinApp()->inputMethod(), &InputMethod::activeChanged);
|
2021-12-29 17:19:43 +00:00
|
|
|
QSignalSpy inputMethodActivateSpy(Test::inputMethod(), &Test::MockInputMethod::activate);
|
|
|
|
// just enabling the text-input should not show it but rather on commit
|
2022-07-20 10:14:27 +00:00
|
|
|
QVERIFY(!kwinApp()->inputMethod()->isActive());
|
2021-12-29 17:19:43 +00:00
|
|
|
textInputV3->commit();
|
|
|
|
QVERIFY(inputMethodActiveSpy.count() || inputMethodActiveSpy.wait());
|
2022-07-20 10:14:27 +00:00
|
|
|
QVERIFY(kwinApp()->inputMethod()->isActive());
|
2021-12-29 17:19:43 +00:00
|
|
|
QVERIFY(inputMethodActivateSpy.wait());
|
|
|
|
auto context = Test::inputMethod()->context();
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Keyboard> keyboardGrab(new KWayland::Client::Keyboard);
|
2021-12-29 17:19:43 +00:00
|
|
|
keyboardGrab->setup(zwp_input_method_context_v1_grab_keyboard(context));
|
2022-11-07 21:33:00 +00:00
|
|
|
QSignalSpy modifierSpy(keyboardGrab.get(), &KWayland::Client::Keyboard::modifiersChanged);
|
2021-12-29 17:19:43 +00:00
|
|
|
// Wait for initial modifiers update
|
|
|
|
QVERIFY(modifierSpy.wait());
|
|
|
|
|
|
|
|
quint32 timestamp = 1;
|
|
|
|
|
2022-11-07 21:33:00 +00:00
|
|
|
QSignalSpy keySpy(keyboardGrab.get(), &KWayland::Client::Keyboard::keyChanged);
|
2021-12-29 17:19:43 +00:00
|
|
|
bool keyChanged = false;
|
|
|
|
bool modifiersChanged = false;
|
|
|
|
// We want to verify the order of two signals, so SignalSpy is not very useful here.
|
2022-11-07 21:33:00 +00:00
|
|
|
auto keyChangedConnection = connect(keyboardGrab.get(), &KWayland::Client::Keyboard::keyChanged, [&keyChanged, &modifiersChanged]() {
|
2021-12-29 17:19:43 +00:00
|
|
|
QVERIFY(!modifiersChanged);
|
|
|
|
keyChanged = true;
|
|
|
|
});
|
2022-11-07 21:33:00 +00:00
|
|
|
auto modifiersChangedConnection = connect(keyboardGrab.get(), &KWayland::Client::Keyboard::modifiersChanged, [&keyChanged, &modifiersChanged]() {
|
2021-12-29 17:19:43 +00:00
|
|
|
QVERIFY(keyChanged);
|
|
|
|
modifiersChanged = true;
|
|
|
|
});
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(KEY_LEFTCTRL, timestamp++);
|
2021-12-29 17:19:43 +00:00
|
|
|
QVERIFY(keySpy.count() == 1 || keySpy.wait());
|
|
|
|
QVERIFY(modifierSpy.count() == 2 || modifierSpy.wait());
|
|
|
|
disconnect(keyChangedConnection);
|
|
|
|
disconnect(modifiersChangedConnection);
|
|
|
|
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(KEY_A, timestamp++);
|
2021-12-29 17:19:43 +00:00
|
|
|
QVERIFY(keySpy.count() == 2 || keySpy.wait());
|
|
|
|
QVERIFY(modifierSpy.count() == 2 || modifierSpy.wait());
|
|
|
|
|
|
|
|
// verify the order of key and modifiers again. Key first, then modifiers.
|
|
|
|
keyChanged = false;
|
|
|
|
modifiersChanged = false;
|
2022-11-07 21:33:00 +00:00
|
|
|
keyChangedConnection = connect(keyboardGrab.get(), &KWayland::Client::Keyboard::keyChanged, [&keyChanged, &modifiersChanged]() {
|
2021-12-29 17:19:43 +00:00
|
|
|
QVERIFY(!modifiersChanged);
|
|
|
|
keyChanged = true;
|
|
|
|
});
|
2022-11-07 21:33:00 +00:00
|
|
|
modifiersChangedConnection = connect(keyboardGrab.get(), &KWayland::Client::Keyboard::modifiersChanged, [&keyChanged, &modifiersChanged]() {
|
2021-12-29 17:19:43 +00:00
|
|
|
QVERIFY(keyChanged);
|
|
|
|
modifiersChanged = true;
|
|
|
|
});
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyReleased(KEY_LEFTCTRL, timestamp++);
|
2021-12-29 17:19:43 +00:00
|
|
|
QVERIFY(keySpy.count() == 3 || keySpy.wait());
|
|
|
|
QVERIFY(modifierSpy.count() == 3 || modifierSpy.wait());
|
|
|
|
disconnect(keyChangedConnection);
|
|
|
|
disconnect(modifiersChangedConnection);
|
|
|
|
}
|
|
|
|
|
2022-05-17 11:53:13 +00:00
|
|
|
void InputMethodTest::testFakeEventFallback()
|
|
|
|
{
|
|
|
|
// Create an xdg_toplevel surface and wait for the compositor to catch up.
|
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface = Test::createSurface();
|
|
|
|
std::unique_ptr<Test::XdgToplevel> 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));
|
|
|
|
|
|
|
|
// Since we don't have a way to communicate with the client, manually activate
|
|
|
|
// the input method.
|
|
|
|
QSignalSpy inputMethodActiveSpy(Test::inputMethod(), &Test::MockInputMethod::activate);
|
|
|
|
kwinApp()->inputMethod()->setActive(true);
|
|
|
|
QVERIFY(inputMethodActiveSpy.count() || inputMethodActiveSpy.wait());
|
|
|
|
|
|
|
|
// Without a way to communicate to the client, we send fake key events. This
|
|
|
|
// means the client needs to be able to receive them, so create a keyboard for
|
|
|
|
// the client and listen whether it gets the right events.
|
|
|
|
auto keyboard = Test::waylandSeat()->createKeyboard(window);
|
|
|
|
QSignalSpy keySpy(keyboard, &KWayland::Client::Keyboard::keyChanged);
|
|
|
|
|
|
|
|
auto context = Test::inputMethod()->context();
|
|
|
|
QVERIFY(context);
|
|
|
|
|
|
|
|
// First, send a simple one-character string and check to see if that
|
|
|
|
// generates a key press followed by a key release on the client side.
|
|
|
|
zwp_input_method_context_v1_commit_string(context, 0, "a");
|
|
|
|
|
|
|
|
keySpy.wait();
|
|
|
|
QVERIFY(keySpy.count() == 2);
|
|
|
|
|
2022-11-07 21:33:00 +00:00
|
|
|
auto compare = [](const QList<QVariant> &input, quint32 key, KWayland::Client::Keyboard::KeyState state) {
|
2022-05-17 11:53:13 +00:00
|
|
|
auto inputKey = input.at(0).toInt();
|
2022-11-07 21:33:00 +00:00
|
|
|
auto inputState = input.at(1).value<KWayland::Client::Keyboard::KeyState>();
|
2022-05-17 11:53:13 +00:00
|
|
|
QCOMPARE(inputKey, key);
|
|
|
|
QCOMPARE(inputState, state);
|
|
|
|
};
|
|
|
|
|
2022-11-07 21:33:00 +00:00
|
|
|
compare(keySpy.at(0), KEY_A, KWayland::Client::Keyboard::KeyState::Pressed);
|
|
|
|
compare(keySpy.at(1), KEY_A, KWayland::Client::Keyboard::KeyState::Released);
|
2022-05-17 11:53:13 +00:00
|
|
|
|
|
|
|
keySpy.clear();
|
|
|
|
|
|
|
|
// Capital letters are recognised and sent as a combination of Shift + the
|
|
|
|
// letter.
|
|
|
|
|
|
|
|
zwp_input_method_context_v1_commit_string(context, 0, "A");
|
|
|
|
|
|
|
|
keySpy.wait();
|
|
|
|
QVERIFY(keySpy.count() == 4);
|
|
|
|
|
2022-11-07 21:33:00 +00:00
|
|
|
compare(keySpy.at(0), KEY_LEFTSHIFT, KWayland::Client::Keyboard::KeyState::Pressed);
|
|
|
|
compare(keySpy.at(1), KEY_A, KWayland::Client::Keyboard::KeyState::Pressed);
|
|
|
|
compare(keySpy.at(2), KEY_A, KWayland::Client::Keyboard::KeyState::Released);
|
|
|
|
compare(keySpy.at(3), KEY_LEFTSHIFT, KWayland::Client::Keyboard::KeyState::Released);
|
2022-05-17 11:53:13 +00:00
|
|
|
|
|
|
|
keySpy.clear();
|
|
|
|
|
|
|
|
// Special keys are not sent through commit_string but instead use keysym.
|
|
|
|
auto enter = input()->keyboard()->xkb()->toKeysym(KEY_ENTER);
|
|
|
|
zwp_input_method_context_v1_keysym(context, 0, 0, enter, uint32_t(KWaylandServer::KeyboardKeyState::Pressed), 0);
|
|
|
|
zwp_input_method_context_v1_keysym(context, 0, 1, enter, uint32_t(KWaylandServer::KeyboardKeyState::Released), 0);
|
|
|
|
|
|
|
|
keySpy.wait();
|
|
|
|
QVERIFY(keySpy.count() == 2);
|
|
|
|
|
2022-11-07 21:33:00 +00:00
|
|
|
compare(keySpy.at(0), KEY_ENTER, KWayland::Client::Keyboard::KeyState::Pressed);
|
|
|
|
compare(keySpy.at(1), KEY_ENTER, KWayland::Client::Keyboard::KeyState::Released);
|
2022-05-17 11:53:13 +00:00
|
|
|
}
|
|
|
|
|
2020-09-30 10:28:42 +00:00
|
|
|
WAYLANDTEST_MAIN(InputMethodTest)
|
2020-09-01 08:58:46 +00:00
|
|
|
|
2020-09-30 10:46:32 +00:00
|
|
|
#include "inputmethod_test.moc"
|