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"
|
|
|
|
#include "abstract_client.h"
|
2021-08-31 07:03:05 +00:00
|
|
|
#include "abstract_output.h"
|
2020-09-01 08:58:46 +00:00
|
|
|
#include "cursor.h"
|
|
|
|
#include "effects.h"
|
|
|
|
#include "deleted.h"
|
|
|
|
#include "platform.h"
|
|
|
|
#include "screens.h"
|
|
|
|
#include "wayland_server.h"
|
|
|
|
#include "workspace.h"
|
2020-09-29 14:46:32 +00:00
|
|
|
#include "inputmethod.h"
|
2020-09-01 08:58:46 +00:00
|
|
|
#include "virtualkeyboard_dbus.h"
|
|
|
|
#include "qwayland-input-method-unstable-v1.h"
|
2020-09-25 06:51:04 +00:00
|
|
|
#include "qwayland-text-input-unstable-v3.h"
|
2020-09-01 08:58:46 +00:00
|
|
|
|
|
|
|
#include <QTest>
|
|
|
|
#include <QSignalSpy>
|
|
|
|
#include <QDBusConnection>
|
|
|
|
#include <QDBusMessage>
|
|
|
|
#include <QDBusPendingReply>
|
|
|
|
#include <KWaylandServer/clientconnection.h>
|
|
|
|
#include <KWaylandServer/display.h>
|
2021-07-20 23:41:38 +00:00
|
|
|
#include <KWaylandServer/seat_interface.h>
|
2020-09-01 08:58:46 +00:00
|
|
|
#include <KWaylandServer/surface_interface.h>
|
|
|
|
|
|
|
|
#include <KWayland/Client/compositor.h>
|
|
|
|
#include <KWayland/Client/output.h>
|
2021-07-20 23:41:38 +00:00
|
|
|
#include <KWayland/Client/region.h>
|
2020-09-01 08:58:46 +00:00
|
|
|
#include <KWayland/Client/surface.h>
|
|
|
|
#include <KWayland/Client/textinput.h>
|
2020-09-25 06:51:04 +00:00
|
|
|
#include <KWayland/Client/seat.h>
|
2020-09-01 08:58:46 +00:00
|
|
|
|
|
|
|
using namespace KWin;
|
|
|
|
using namespace KWayland::Client;
|
|
|
|
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();
|
2021-10-18 13:41:05 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void touchNow() {
|
|
|
|
static int time = 0;
|
|
|
|
kwinApp()->platform()->touchDown(0, {100, 100}, ++time);
|
|
|
|
kwinApp()->platform()->touchUp(0, ++time);
|
|
|
|
}
|
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"));
|
|
|
|
|
2020-09-01 08:58:46 +00:00
|
|
|
qRegisterMetaType<KWin::Deleted *>();
|
|
|
|
qRegisterMetaType<KWin::AbstractClient *>();
|
|
|
|
qRegisterMetaType<KWayland::Client::Output *>();
|
|
|
|
|
|
|
|
QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
|
|
|
|
QVERIFY(applicationStartedSpy.isValid());
|
|
|
|
kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024));
|
2020-12-09 13:06:15 +00:00
|
|
|
QVERIFY(waylandServer()->init(s_socketName));
|
2020-09-01 08:58:46 +00:00
|
|
|
QMetaObject::invokeMethod(kwinApp()->platform(), "setVirtualOutputs", Qt::DirectConnection, Q_ARG(int, 2));
|
|
|
|
|
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());
|
2021-08-31 07:03:05 +00:00
|
|
|
const auto outputs = kwinApp()->platform()->enabledOutputs();
|
|
|
|
QCOMPARE(outputs.count(), 2);
|
|
|
|
QCOMPARE(outputs[0]->geometry(), QRect(0, 0, 1280, 1024));
|
|
|
|
QCOMPARE(outputs[1]->geometry(), QRect(1280, 0, 1280, 1024));
|
2021-05-08 00:08:22 +00:00
|
|
|
Test::initWaylandWorkspace();
|
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
|
|
|
{
|
2021-10-18 13:41:05 +00:00
|
|
|
touchNow();
|
2020-09-01 08:58:46 +00:00
|
|
|
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Seat |
|
2020-09-25 06:51:04 +00:00
|
|
|
Test::AdditionalWaylandInterface::TextInputManagerV2 |
|
|
|
|
Test::AdditionalWaylandInterface::InputMethodV1 |
|
|
|
|
Test::AdditionalWaylandInterface::TextInputManagerV3));
|
2020-09-01 08:58:46 +00:00
|
|
|
|
2020-11-27 19:57:24 +00:00
|
|
|
|
2021-08-28 18:58:29 +00:00
|
|
|
workspace()->setActiveOutput(QPoint(640, 512));
|
2021-08-28 18:40:12 +00:00
|
|
|
KWin::Cursors::self()->mouse()->setPos(QPoint(640, 512));
|
2020-11-27 19:57:24 +00:00
|
|
|
|
2021-04-23 19:08:29 +00:00
|
|
|
InputMethod::self()->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
|
|
|
{
|
|
|
|
QSignalSpy clientAddedSpy(workspace(), &Workspace::clientAdded);
|
|
|
|
QSignalSpy clientRemovedSpy(workspace(), &Workspace::clientRemoved);
|
|
|
|
QVERIFY(clientAddedSpy.isValid());
|
|
|
|
|
|
|
|
// Create an xdg_toplevel surface and wait for the compositor to catch up.
|
2021-09-03 17:54:03 +00:00
|
|
|
QScopedPointer<KWayland::Client::Surface> surface(Test::createSurface());
|
2021-05-11 05:26:51 +00:00
|
|
|
QScopedPointer<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.data()));
|
2020-09-01 08:58:46 +00:00
|
|
|
AbstractClient *client = Test::renderAndWaitForShown(surface.data(), QSize(1280, 1024), Qt::red);
|
|
|
|
QVERIFY(client);
|
|
|
|
QVERIFY(client->isActive());
|
|
|
|
QCOMPARE(client->frameGeometry().size(), QSize(1280, 1024));
|
|
|
|
QSignalSpy frameGeometryChangedSpy(client, &AbstractClient::frameGeometryChanged);
|
|
|
|
QVERIFY(frameGeometryChangedSpy.isValid());
|
2021-05-11 05:26:51 +00:00
|
|
|
QSignalSpy toplevelConfigureRequestedSpy(shellSurface.data(), &Test::XdgToplevel::configureRequested);
|
|
|
|
QSignalSpy surfaceConfigureRequestedSpy(shellSurface->xdgSurface(), &Test::XdgSurface::configureRequested);
|
2020-09-01 08:58:46 +00:00
|
|
|
|
|
|
|
QScopedPointer<TextInput> textInput(Test::waylandTextInputManager()->createTextInput(Test::waylandSeat()));
|
|
|
|
|
|
|
|
QVERIFY(!textInput.isNull());
|
|
|
|
textInput->enable(surface.data());
|
2021-05-11 05:26:51 +00:00
|
|
|
QVERIFY(surfaceConfigureRequestedSpy.wait());
|
2020-09-01 08:58:46 +00:00
|
|
|
|
|
|
|
// Show the keyboard
|
2021-10-18 13:41:05 +00:00
|
|
|
touchNow();
|
2020-09-01 08:58:46 +00:00
|
|
|
textInput->showInputPanel();
|
|
|
|
QVERIFY(clientAddedSpy.wait());
|
|
|
|
|
|
|
|
AbstractClient *keyboardClient = clientAddedSpy.last().first().value<AbstractClient *>();
|
|
|
|
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
|
|
|
|
2021-05-11 05:26:51 +00:00
|
|
|
Test::render(surface.data(), toplevelConfigureRequestedSpy.last().first().value<QSize>(), Qt::red);
|
2020-09-01 08:58:46 +00:00
|
|
|
QVERIFY(frameGeometryChangedSpy.wait());
|
|
|
|
|
|
|
|
QCOMPARE(client->frameGeometry().height(), 1024 - keyboardClient->inputGeometry().height() + 1);
|
|
|
|
|
|
|
|
// Hide the keyboard
|
|
|
|
textInput->hideInputPanel();
|
|
|
|
|
2021-05-11 05:26:51 +00:00
|
|
|
QVERIFY(surfaceConfigureRequestedSpy.wait());
|
|
|
|
Test::render(surface.data(), toplevelConfigureRequestedSpy.last().first().value<QSize>(), Qt::red);
|
2020-09-01 08:58:46 +00:00
|
|
|
QVERIFY(frameGeometryChangedSpy.wait());
|
|
|
|
|
|
|
|
QCOMPARE(client->frameGeometry().height(), 1024);
|
|
|
|
|
|
|
|
// Destroy the test client.
|
|
|
|
shellSurface.reset();
|
|
|
|
QVERIFY(Test::waitForWindowDestroyed(client));
|
|
|
|
}
|
|
|
|
|
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.
|
2021-09-03 17:54:03 +00:00
|
|
|
QScopedPointer<KWayland::Client::Surface> surface(Test::createSurface());
|
2021-05-11 05:26:51 +00:00
|
|
|
QScopedPointer<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.data()));
|
2020-09-25 06:51:04 +00:00
|
|
|
AbstractClient *client = Test::renderAndWaitForShown(surface.data(), QSize(1280, 1024), Qt::red);
|
|
|
|
QVERIFY(client);
|
|
|
|
QVERIFY(client->isActive());
|
|
|
|
QCOMPARE(client->frameGeometry().size(), QSize(1280, 1024));
|
|
|
|
|
|
|
|
Test::TextInputV3 *textInputV3 = new Test::TextInputV3();
|
|
|
|
textInputV3->init(Test::waylandTextInputManagerV3()->get_text_input(*(Test::waylandSeat())));
|
|
|
|
textInputV3->enable();
|
|
|
|
|
2021-05-10 16:01:41 +00:00
|
|
|
QSignalSpy inputMethodActiveSpy(InputMethod::self(), &InputMethod::activeChanged);
|
|
|
|
// just enabling the text-input should not show it but rather on commit
|
|
|
|
QVERIFY(!InputMethod::self()->isActive());
|
2020-09-25 06:51:04 +00:00
|
|
|
textInputV3->commit();
|
2021-05-10 16:01:41 +00:00
|
|
|
QVERIFY(inputMethodActiveSpy.count() || inputMethodActiveSpy.wait());
|
|
|
|
QVERIFY(InputMethod::self()->isActive());
|
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();
|
|
|
|
QVERIFY(InputMethod::self()->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());
|
|
|
|
QVERIFY(!InputMethod::self()->isActive());
|
2020-09-25 06:51:04 +00:00
|
|
|
}
|
|
|
|
|
2021-07-20 23:41:38 +00:00
|
|
|
void InputMethodTest::testEnableActive()
|
|
|
|
{
|
|
|
|
QVERIFY(!InputMethod::self()->isActive());
|
|
|
|
|
|
|
|
QSignalSpy clientAddedSpy(workspace(), &Workspace::clientAdded);
|
|
|
|
QSignalSpy clientRemovedSpy(workspace(), &Workspace::clientRemoved);
|
|
|
|
|
|
|
|
QSignalSpy activateSpy(InputMethod::self(), &InputMethod::activeChanged);
|
|
|
|
|
|
|
|
// Create an xdg_toplevel surface and wait for the compositor to catch up.
|
2021-09-03 17:54:03 +00:00
|
|
|
QScopedPointer<KWayland::Client::Surface> surface(Test::createSurface());
|
2021-07-20 23:41:38 +00:00
|
|
|
QScopedPointer<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.data()));
|
|
|
|
AbstractClient *client = Test::renderAndWaitForShown(surface.data(), QSize(1280, 1024), Qt::red);
|
|
|
|
QVERIFY(client);
|
|
|
|
QVERIFY(client->isActive());
|
|
|
|
QCOMPARE(client->frameGeometry().size(), QSize(1280, 1024));
|
|
|
|
QSignalSpy frameGeometryChangedSpy(client, &AbstractClient::frameGeometryChanged);
|
|
|
|
QVERIFY(frameGeometryChangedSpy.isValid());
|
|
|
|
QSignalSpy toplevelConfigureRequestedSpy(shellSurface.data(), &Test::XdgToplevel::configureRequested);
|
|
|
|
QSignalSpy surfaceConfigureRequestedSpy(shellSurface->xdgSurface(), &Test::XdgSurface::configureRequested);
|
|
|
|
|
|
|
|
QScopedPointer<TextInput> textInput(Test::waylandTextInputManager()->createTextInput(Test::waylandSeat()));
|
|
|
|
|
|
|
|
QVERIFY(!textInput.isNull());
|
|
|
|
textInput->enable(surface.data());
|
|
|
|
QVERIFY(surfaceConfigureRequestedSpy.wait());
|
|
|
|
QCOMPARE(clientAddedSpy.count(), 1);
|
|
|
|
|
|
|
|
// Show the keyboard
|
|
|
|
textInput->showInputPanel();
|
|
|
|
QVERIFY(clientAddedSpy.wait());
|
|
|
|
|
|
|
|
QCOMPARE(workspace()->activeClient(), client);
|
|
|
|
|
|
|
|
activateSpy.clear();
|
|
|
|
textInput->enable(surface.get());
|
|
|
|
textInput->showInputPanel();
|
|
|
|
activateSpy.wait(200);
|
|
|
|
QVERIFY(activateSpy.isEmpty());
|
|
|
|
QVERIFY(InputMethod::self()->isActive());
|
|
|
|
auto keyboardClient = Test::inputPanelClient();
|
|
|
|
QVERIFY(keyboardClient);
|
|
|
|
textInput->enable(surface.get());
|
|
|
|
|
|
|
|
QVERIFY(InputMethod::self()->isActive());
|
|
|
|
|
|
|
|
// Destroy the test client.
|
|
|
|
shellSurface.reset();
|
|
|
|
QVERIFY(Test::waitForWindowDestroyed(client));
|
|
|
|
}
|
|
|
|
|
2021-07-21 00:04:33 +00:00
|
|
|
void InputMethodTest::testHidePanel()
|
|
|
|
{
|
|
|
|
QVERIFY(!InputMethod::self()->isActive());
|
|
|
|
|
|
|
|
QSignalSpy clientAddedSpy(workspace(), &Workspace::clientAdded);
|
|
|
|
QSignalSpy clientRemovedSpy(workspace(), &Workspace::clientRemoved);
|
|
|
|
QVERIFY(clientAddedSpy.isValid());
|
|
|
|
|
|
|
|
QSignalSpy activateSpy(InputMethod::self(), &InputMethod::activeChanged);
|
|
|
|
QScopedPointer<TextInput> textInput(Test::waylandTextInputManager()->createTextInput(Test::waylandSeat()));
|
|
|
|
textInput->showInputPanel();
|
|
|
|
QVERIFY(clientAddedSpy.wait());
|
|
|
|
|
|
|
|
// Create an xdg_toplevel surface and wait for the compositor to catch up.
|
2021-09-03 17:54:03 +00:00
|
|
|
QScopedPointer<KWayland::Client::Surface> surface(Test::createSurface());
|
2021-07-21 00:04:33 +00:00
|
|
|
QScopedPointer<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.data()));
|
|
|
|
AbstractClient *client = Test::renderAndWaitForShown(surface.data(), QSize(1280, 1024), Qt::red);
|
|
|
|
waylandServer()->seat()->setFocusedTextInputSurface(client->surface());
|
|
|
|
|
|
|
|
QCOMPARE(workspace()->activeClient(), client);
|
|
|
|
|
|
|
|
QCOMPARE(clientAddedSpy.count(), 2);
|
|
|
|
QVERIFY(activateSpy.count() || activateSpy.wait());
|
|
|
|
QVERIFY(InputMethod::self()->isActive());
|
|
|
|
|
|
|
|
auto keyboardClient = Test::inputPanelClient();
|
|
|
|
auto ipsurface = Test::inputPanelSurface();
|
|
|
|
QVERIFY(keyboardClient);
|
|
|
|
clientRemovedSpy.clear();
|
|
|
|
delete ipsurface;
|
|
|
|
QVERIFY(InputMethod::self()->isVisible());
|
|
|
|
QVERIFY(clientRemovedSpy.count() || clientRemovedSpy.wait());
|
|
|
|
QVERIFY(!InputMethod::self()->isVisible());
|
|
|
|
|
|
|
|
// Destroy the test client.
|
|
|
|
shellSurface.reset();
|
|
|
|
QVERIFY(Test::waitForWindowDestroyed(client));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-07-30 18:29:01 +00:00
|
|
|
void InputMethodTest::testSwitchFocusedSurfaces()
|
|
|
|
{
|
|
|
|
QVERIFY(!InputMethod::self()->isActive());
|
|
|
|
|
|
|
|
QSignalSpy clientAddedSpy(workspace(), &Workspace::clientAdded);
|
|
|
|
QSignalSpy clientRemovedSpy(workspace(), &Workspace::clientRemoved);
|
|
|
|
QVERIFY(clientAddedSpy.isValid());
|
|
|
|
|
|
|
|
QSignalSpy activateSpy(InputMethod::self(), &InputMethod::activeChanged);
|
|
|
|
QScopedPointer<TextInput> textInput(Test::waylandTextInputManager()->createTextInput(Test::waylandSeat()));
|
|
|
|
textInput->showInputPanel();
|
|
|
|
QVERIFY(clientAddedSpy.wait(10000));
|
|
|
|
|
|
|
|
QVector<AbstractClient *> clients;
|
2021-09-03 17:54:03 +00:00
|
|
|
QVector<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) {
|
|
|
|
auto surface = Test::createSurface();
|
|
|
|
auto shellSurface = Test::createXdgToplevelSurface(surface);
|
|
|
|
clients += Test::renderAndWaitForShown(surface, QSize(1280, 1024), Qt::red);
|
|
|
|
QCOMPARE(workspace()->activeClient(), clients.constLast());
|
|
|
|
surfaces += surface;
|
|
|
|
toplevels += shellSurface;
|
|
|
|
}
|
|
|
|
waylandServer()->seat()->setFocusedTextInputSurface(clients.constFirst()->surface());
|
|
|
|
|
|
|
|
QCOMPARE(clientAddedSpy.count(), 4);
|
|
|
|
QVERIFY(activateSpy.count() || activateSpy.wait());
|
|
|
|
QVERIFY(!InputMethod::self()->isActive());
|
|
|
|
textInput->enable(surfaces.last());
|
|
|
|
QVERIFY(!InputMethod::self()->isActive());
|
|
|
|
waylandServer()->seat()->setFocusedTextInputSurface(clients.first()->surface());
|
|
|
|
QVERIFY(!InputMethod::self()->isActive());
|
|
|
|
activateSpy.clear();
|
|
|
|
waylandServer()->seat()->setFocusedTextInputSurface(clients.last()->surface());
|
|
|
|
QVERIFY(activateSpy.count() || activateSpy.wait());
|
|
|
|
QVERIFY(InputMethod::self()->isActive());
|
|
|
|
|
|
|
|
activateSpy.clear();
|
|
|
|
waylandServer()->seat()->setFocusedTextInputSurface(clients.first()->surface());
|
|
|
|
QVERIFY(activateSpy.count() || activateSpy.wait());
|
|
|
|
QVERIFY(!InputMethod::self()->isActive());
|
|
|
|
|
|
|
|
// Destroy the test client.
|
|
|
|
for (int i = 0; i < clients.count(); ++i) {
|
|
|
|
delete toplevels[i];
|
|
|
|
QVERIFY(Test::waitForWindowDestroyed(clients[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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"
|