2020-03-15 15:19:28 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
|
2016-05-02 12:28:26 +00:00
|
|
|
|
2020-03-15 15:19:28 +00:00
|
|
|
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
|
|
|
*/
|
2016-05-02 12:28:26 +00:00
|
|
|
// Qt
|
2023-07-03 19:28:19 +00:00
|
|
|
#include <QSignalSpy>
|
|
|
|
#include <QTest>
|
2016-05-02 12:28:26 +00:00
|
|
|
// client
|
2020-04-29 13:59:23 +00:00
|
|
|
#include "KWayland/Client/compositor.h"
|
|
|
|
#include "KWayland/Client/connection_thread.h"
|
|
|
|
#include "KWayland/Client/event_queue.h"
|
|
|
|
#include "KWayland/Client/keyboard.h"
|
|
|
|
#include "KWayland/Client/registry.h"
|
|
|
|
#include "KWayland/Client/seat.h"
|
|
|
|
#include "KWayland/Client/surface.h"
|
|
|
|
#include "KWayland/Client/textinput.h"
|
2016-05-02 12:28:26 +00:00
|
|
|
// server
|
2023-09-13 05:52:59 +00:00
|
|
|
#include "wayland/compositor.h"
|
2022-04-22 09:27:33 +00:00
|
|
|
#include "wayland/display.h"
|
2023-09-13 05:52:59 +00:00
|
|
|
#include "wayland/seat.h"
|
2022-04-22 09:27:33 +00:00
|
|
|
#include "wayland/textinput.h"
|
2023-09-13 05:52:59 +00:00
|
|
|
#include "wayland/textinput_v2.h"
|
2016-05-02 12:28:26 +00:00
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2022-12-21 00:55:20 +00:00
|
|
|
using namespace std::literals;
|
2016-05-02 12:28:26 +00:00
|
|
|
|
|
|
|
class TextInputTest : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
private Q_SLOTS:
|
|
|
|
void init();
|
|
|
|
void cleanup();
|
|
|
|
|
|
|
|
void testEnterLeave_data();
|
|
|
|
void testEnterLeave();
|
2021-12-19 08:00:22 +00:00
|
|
|
void testFocusedBeforeCreateTextInput();
|
2016-05-02 12:28:26 +00:00
|
|
|
void testShowHidePanel();
|
|
|
|
void testCursorRectangle();
|
|
|
|
void testPreferredLanguage();
|
|
|
|
void testReset();
|
|
|
|
void testSurroundingText();
|
|
|
|
void testContentHints_data();
|
|
|
|
void testContentHints();
|
|
|
|
void testContentPurpose_data();
|
|
|
|
void testContentPurpose();
|
|
|
|
void testTextDirection_data();
|
|
|
|
void testTextDirection();
|
|
|
|
void testLanguage();
|
|
|
|
void testKeyEvent();
|
|
|
|
void testPreEdit();
|
|
|
|
void testCommit();
|
|
|
|
|
|
|
|
private:
|
|
|
|
SurfaceInterface *waitForSurface();
|
2022-11-08 21:15:17 +00:00
|
|
|
KWayland::Client::TextInput *createTextInput();
|
2023-09-13 17:59:29 +00:00
|
|
|
KWin::Display *m_display = nullptr;
|
2016-05-02 12:28:26 +00:00
|
|
|
SeatInterface *m_seatInterface = nullptr;
|
|
|
|
CompositorInterface *m_compositorInterface = nullptr;
|
2020-07-28 15:39:13 +00:00
|
|
|
TextInputManagerV2Interface *m_textInputManagerV2Interface = nullptr;
|
2022-11-08 21:15:17 +00:00
|
|
|
KWayland::Client::ConnectionThread *m_connection = nullptr;
|
2016-05-02 12:28:26 +00:00
|
|
|
QThread *m_thread = nullptr;
|
2022-11-08 21:15:17 +00:00
|
|
|
KWayland::Client::EventQueue *m_queue = nullptr;
|
|
|
|
KWayland::Client::Seat *m_seat = nullptr;
|
|
|
|
KWayland::Client::Keyboard *m_keyboard = nullptr;
|
|
|
|
KWayland::Client::Compositor *m_compositor = nullptr;
|
|
|
|
KWayland::Client::TextInputManager *m_textInputManagerV2 = nullptr;
|
2016-05-02 12:28:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const QString s_socketName = QStringLiteral("kwayland-test-text-input-0");
|
|
|
|
|
|
|
|
void TextInputTest::init()
|
|
|
|
{
|
|
|
|
delete m_display;
|
2023-09-13 17:59:29 +00:00
|
|
|
m_display = new KWin::Display(this);
|
2020-10-19 15:52:56 +00:00
|
|
|
m_display->addSocketName(s_socketName);
|
2016-05-02 12:28:26 +00:00
|
|
|
m_display->start();
|
|
|
|
QVERIFY(m_display->isRunning());
|
|
|
|
m_display->createShm();
|
2020-12-09 20:13:19 +00:00
|
|
|
m_seatInterface = new SeatInterface(m_display, m_display);
|
2016-05-02 12:28:26 +00:00
|
|
|
m_seatInterface->setHasKeyboard(true);
|
|
|
|
m_seatInterface->setHasTouch(true);
|
2020-12-09 20:13:19 +00:00
|
|
|
m_compositorInterface = new CompositorInterface(m_display, m_display);
|
|
|
|
m_textInputManagerV2Interface = new TextInputManagerV2Interface(m_display, m_display);
|
2016-05-02 12:28:26 +00:00
|
|
|
|
|
|
|
// setup connection
|
|
|
|
m_connection = new KWayland::Client::ConnectionThread;
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy connectedSpy(m_connection, &KWayland::Client::ConnectionThread::connected);
|
2016-05-02 12:28:26 +00:00
|
|
|
m_connection->setSocketName(s_socketName);
|
|
|
|
|
|
|
|
m_thread = new QThread(this);
|
|
|
|
m_connection->moveToThread(m_thread);
|
|
|
|
m_thread->start();
|
|
|
|
|
|
|
|
m_connection->initConnection();
|
|
|
|
QVERIFY(connectedSpy.wait());
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
m_queue = new KWayland::Client::EventQueue(this);
|
2016-05-02 12:28:26 +00:00
|
|
|
m_queue->setup(m_connection);
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
KWayland::Client::Registry registry;
|
|
|
|
QSignalSpy interfacesAnnouncedSpy(®istry, &KWayland::Client::Registry::interfacesAnnounced);
|
2016-05-02 12:28:26 +00:00
|
|
|
registry.setEventQueue(m_queue);
|
|
|
|
registry.create(m_connection);
|
|
|
|
QVERIFY(registry.isValid());
|
|
|
|
registry.setup();
|
|
|
|
QVERIFY(interfacesAnnouncedSpy.wait());
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
m_seat = registry.createSeat(registry.interface(KWayland::Client::Registry::Interface::Seat).name, registry.interface(KWayland::Client::Registry::Interface::Seat).version, this);
|
2016-05-02 12:28:26 +00:00
|
|
|
QVERIFY(m_seat->isValid());
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy hasKeyboardSpy(m_seat, &KWayland::Client::Seat::hasKeyboardChanged);
|
2016-05-02 12:28:26 +00:00
|
|
|
QVERIFY(hasKeyboardSpy.wait());
|
|
|
|
m_keyboard = m_seat->createKeyboard(this);
|
|
|
|
QVERIFY(m_keyboard->isValid());
|
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
m_compositor =
|
2022-11-08 21:15:17 +00:00
|
|
|
registry.createCompositor(registry.interface(KWayland::Client::Registry::Interface::Compositor).name, registry.interface(KWayland::Client::Registry::Interface::Compositor).version, this);
|
2016-05-02 12:28:26 +00:00
|
|
|
QVERIFY(m_compositor->isValid());
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
m_textInputManagerV2 = registry.createTextInputManager(registry.interface(KWayland::Client::Registry::Interface::TextInputManagerUnstableV2).name,
|
|
|
|
registry.interface(KWayland::Client::Registry::Interface::TextInputManagerUnstableV2).version,
|
2016-05-02 12:28:26 +00:00
|
|
|
this);
|
|
|
|
QVERIFY(m_textInputManagerV2->isValid());
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextInputTest::cleanup()
|
|
|
|
{
|
2022-04-19 10:14:26 +00:00
|
|
|
#define CLEANUP(variable) \
|
|
|
|
if (variable) { \
|
|
|
|
delete variable; \
|
|
|
|
variable = nullptr; \
|
2016-05-02 12:28:26 +00:00
|
|
|
}
|
|
|
|
CLEANUP(m_textInputManagerV2)
|
|
|
|
CLEANUP(m_keyboard)
|
|
|
|
CLEANUP(m_seat)
|
|
|
|
CLEANUP(m_compositor)
|
|
|
|
CLEANUP(m_queue)
|
|
|
|
if (m_connection) {
|
|
|
|
m_connection->deleteLater();
|
|
|
|
m_connection = nullptr;
|
|
|
|
}
|
|
|
|
if (m_thread) {
|
|
|
|
m_thread->quit();
|
|
|
|
m_thread->wait();
|
|
|
|
delete m_thread;
|
|
|
|
m_thread = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
CLEANUP(m_display)
|
|
|
|
#undef CLEANUP
|
2020-10-30 13:36:24 +00:00
|
|
|
|
|
|
|
// these are the children of the display
|
|
|
|
m_textInputManagerV2Interface = nullptr;
|
|
|
|
m_compositorInterface = nullptr;
|
|
|
|
m_seatInterface = nullptr;
|
2016-05-02 12:28:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SurfaceInterface *TextInputTest::waitForSurface()
|
|
|
|
{
|
|
|
|
QSignalSpy surfaceCreatedSpy(m_compositorInterface, &CompositorInterface::surfaceCreated);
|
|
|
|
if (!surfaceCreatedSpy.isValid()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-07-17 09:30:16 +00:00
|
|
|
if (!surfaceCreatedSpy.wait(500)) {
|
2016-05-02 12:28:26 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if (surfaceCreatedSpy.count() != 1) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2021-08-29 05:11:06 +00:00
|
|
|
return surfaceCreatedSpy.first().first().value<SurfaceInterface *>();
|
2016-05-02 12:28:26 +00:00
|
|
|
}
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
KWayland::Client::TextInput *TextInputTest::createTextInput()
|
2016-05-02 12:28:26 +00:00
|
|
|
{
|
2021-08-29 05:11:06 +00:00
|
|
|
return m_textInputManagerV2->createTextInput(m_seat);
|
|
|
|
}
|
2016-05-02 12:28:26 +00:00
|
|
|
|
|
|
|
void TextInputTest::testEnterLeave_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<bool>("updatesDirectly");
|
2020-07-28 15:39:13 +00:00
|
|
|
QTest::newRow("UnstableV2") << true;
|
2016-05-02 12:28:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextInputTest::testEnterLeave()
|
|
|
|
{
|
|
|
|
// this test verifies that enter leave are sent correctly
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(m_compositor->createSurface());
|
2020-07-28 15:39:13 +00:00
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::TextInput> textInput(createTextInput());
|
2016-05-02 12:28:26 +00:00
|
|
|
auto serverSurface = waitForSurface();
|
|
|
|
QVERIFY(serverSurface);
|
2022-08-01 21:29:02 +00:00
|
|
|
QVERIFY(textInput != nullptr);
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy enteredSpy(textInput.get(), &KWayland::Client::TextInput::entered);
|
|
|
|
QSignalSpy leftSpy(textInput.get(), &KWayland::Client::TextInput::left);
|
2020-07-28 15:39:13 +00:00
|
|
|
QSignalSpy textInputChangedSpy(m_seatInterface, &SeatInterface::focusedTextInputSurfaceChanged);
|
2016-05-02 12:28:26 +00:00
|
|
|
|
|
|
|
// now let's try to enter it
|
2016-06-28 12:53:45 +00:00
|
|
|
QVERIFY(!m_seatInterface->focusedTextInputSurface());
|
2016-05-02 12:28:26 +00:00
|
|
|
m_seatInterface->setFocusedKeyboardSurface(serverSurface);
|
2016-06-28 12:53:45 +00:00
|
|
|
QCOMPARE(m_seatInterface->focusedTextInputSurface(), serverSurface);
|
2016-05-02 12:28:26 +00:00
|
|
|
// text input not yet set for the surface
|
|
|
|
QFETCH(bool, updatesDirectly);
|
2020-07-28 15:39:13 +00:00
|
|
|
QCOMPARE(bool(m_seatInterface->textInputV2()), updatesDirectly);
|
2016-05-02 12:28:26 +00:00
|
|
|
QCOMPARE(textInputChangedSpy.isEmpty(), !updatesDirectly);
|
2022-08-01 21:29:02 +00:00
|
|
|
textInput->enable(surface.get());
|
2016-05-02 12:28:26 +00:00
|
|
|
// this should trigger on server side
|
|
|
|
if (!updatesDirectly) {
|
|
|
|
QVERIFY(textInputChangedSpy.wait());
|
|
|
|
}
|
|
|
|
QCOMPARE(textInputChangedSpy.count(), 1);
|
2020-07-28 15:39:13 +00:00
|
|
|
auto serverTextInput = m_seatInterface->textInputV2();
|
2016-05-02 12:28:26 +00:00
|
|
|
QVERIFY(serverTextInput);
|
2020-07-28 15:39:13 +00:00
|
|
|
QSignalSpy enabledChangedSpy(serverTextInput, &TextInputV2Interface::enabledChanged);
|
2016-05-02 12:28:26 +00:00
|
|
|
if (updatesDirectly) {
|
|
|
|
QVERIFY(enabledChangedSpy.wait());
|
|
|
|
enabledChangedSpy.clear();
|
|
|
|
}
|
|
|
|
QCOMPARE(serverTextInput->surface().data(), serverSurface);
|
|
|
|
QVERIFY(serverTextInput->isEnabled());
|
|
|
|
|
|
|
|
// and trigger an enter
|
2016-05-30 06:54:46 +00:00
|
|
|
if (enteredSpy.isEmpty()) {
|
2016-05-02 12:28:26 +00:00
|
|
|
QVERIFY(enteredSpy.wait());
|
|
|
|
}
|
|
|
|
QCOMPARE(enteredSpy.count(), 1);
|
2022-08-01 21:29:02 +00:00
|
|
|
QCOMPARE(textInput->enteredSurface(), surface.get());
|
2016-05-02 12:28:26 +00:00
|
|
|
|
|
|
|
// now trigger a leave
|
|
|
|
m_seatInterface->setFocusedKeyboardSurface(nullptr);
|
|
|
|
QCOMPARE(textInputChangedSpy.count(), 2);
|
|
|
|
QVERIFY(leftSpy.wait());
|
|
|
|
QVERIFY(!textInput->enteredSurface());
|
2021-05-22 00:00:09 +00:00
|
|
|
QVERIFY(!serverTextInput->isEnabled());
|
2016-05-02 12:28:26 +00:00
|
|
|
|
|
|
|
// if we enter again we should directly get the text input as it's still activated
|
|
|
|
m_seatInterface->setFocusedKeyboardSurface(serverSurface);
|
|
|
|
QCOMPARE(textInputChangedSpy.count(), 3);
|
2020-07-28 15:39:13 +00:00
|
|
|
QVERIFY(m_seatInterface->textInputV2());
|
2016-05-02 12:28:26 +00:00
|
|
|
QVERIFY(enteredSpy.wait());
|
|
|
|
QCOMPARE(enteredSpy.count(), 2);
|
2022-08-01 21:29:02 +00:00
|
|
|
QCOMPARE(textInput->enteredSurface(), surface.get());
|
2016-05-02 12:28:26 +00:00
|
|
|
QVERIFY(serverTextInput->isEnabled());
|
|
|
|
|
|
|
|
// let's deactivate on client side
|
2022-08-01 21:29:02 +00:00
|
|
|
textInput->disable(surface.get());
|
2016-05-02 12:28:26 +00:00
|
|
|
QVERIFY(enabledChangedSpy.wait());
|
2021-05-22 00:00:09 +00:00
|
|
|
QCOMPARE(enabledChangedSpy.count(), 3);
|
2016-05-02 12:28:26 +00:00
|
|
|
QVERIFY(!serverTextInput->isEnabled());
|
|
|
|
// does not trigger a leave
|
|
|
|
QCOMPARE(textInputChangedSpy.count(), 3);
|
|
|
|
// should still be the same text input
|
2020-07-28 15:39:13 +00:00
|
|
|
QCOMPARE(m_seatInterface->textInputV2(), serverTextInput);
|
2021-08-29 05:11:06 +00:00
|
|
|
// reset
|
2022-08-01 21:29:02 +00:00
|
|
|
textInput->enable(surface.get());
|
Validate surface is valid when sending TextInput leave event
Summary:
It's possible for the surface to be unbound when we send the leave
event; we've called Resource::unbind() of Surface, so the Surface has,
deleteLater called, but it's still a valid object, and the first check
passes.
We get in this situation because when a surface is destroyed, we're
handling text input from the same source event.
Sending a nullpointer is a protocol error, and wayland kindly closes the
connection.
This fixes my constant:
"Did the Wayland server die" error messages when running clients.
Test Plan:
Got errors after setting up qt virtual keyboard.
Had reproducible case.
Restarted kwin after this patch, now doesn't crash.
Reviewers: #plasma, graesslin
Subscribers: apol, graesslin, plasma-devel, #frameworks
Tags: #plasma_on_wayland, #frameworks
Differential Revision: https://phabricator.kde.org/D5712
2017-05-05 14:43:35 +00:00
|
|
|
QVERIFY(enabledChangedSpy.wait());
|
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
// delete the client and wait for the server to catch up
|
Validate surface is valid when sending TextInput leave event
Summary:
It's possible for the surface to be unbound when we send the leave
event; we've called Resource::unbind() of Surface, so the Surface has,
deleteLater called, but it's still a valid object, and the first check
passes.
We get in this situation because when a surface is destroyed, we're
handling text input from the same source event.
Sending a nullpointer is a protocol error, and wayland kindly closes the
connection.
This fixes my constant:
"Did the Wayland server die" error messages when running clients.
Test Plan:
Got errors after setting up qt virtual keyboard.
Had reproducible case.
Restarted kwin after this patch, now doesn't crash.
Reviewers: #plasma, graesslin
Subscribers: apol, graesslin, plasma-devel, #frameworks
Tags: #plasma_on_wayland, #frameworks
Differential Revision: https://phabricator.kde.org/D5712
2017-05-05 14:43:35 +00:00
|
|
|
QSignalSpy unboundSpy(serverSurface, &QObject::destroyed);
|
|
|
|
surface.reset();
|
|
|
|
QVERIFY(unboundSpy.wait());
|
2017-07-19 18:16:57 +00:00
|
|
|
QVERIFY(leftSpy.wait());
|
|
|
|
QVERIFY(!textInput->enteredSurface());
|
2016-05-02 12:28:26 +00:00
|
|
|
}
|
|
|
|
|
2021-12-19 08:00:22 +00:00
|
|
|
void TextInputTest::testFocusedBeforeCreateTextInput()
|
|
|
|
{
|
|
|
|
// this test verifies that enter leave are sent correctly
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(m_compositor->createSurface());
|
2021-12-19 08:00:22 +00:00
|
|
|
auto serverSurface = waitForSurface();
|
|
|
|
// now let's try to enter it
|
|
|
|
QSignalSpy textInputChangedSpy(m_seatInterface, &SeatInterface::focusedTextInputSurfaceChanged);
|
|
|
|
QVERIFY(!m_seatInterface->focusedTextInputSurface());
|
|
|
|
m_seatInterface->setFocusedKeyboardSurface(serverSurface);
|
|
|
|
QCOMPARE(m_seatInterface->focusedTextInputSurface(), serverSurface);
|
|
|
|
QCOMPARE(textInputChangedSpy.count(), 1);
|
|
|
|
|
|
|
|
// This is null because there is no text input object for this client.
|
|
|
|
QCOMPARE(m_seatInterface->textInputV2()->surface(), nullptr);
|
|
|
|
|
|
|
|
QVERIFY(serverSurface);
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::TextInput> textInput(createTextInput());
|
2022-08-01 21:29:02 +00:00
|
|
|
QVERIFY(textInput != nullptr);
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy enteredSpy(textInput.get(), &KWayland::Client::TextInput::entered);
|
|
|
|
QSignalSpy leftSpy(textInput.get(), &KWayland::Client::TextInput::left);
|
2021-12-19 08:00:22 +00:00
|
|
|
|
|
|
|
// and trigger an enter
|
|
|
|
if (enteredSpy.isEmpty()) {
|
|
|
|
QVERIFY(enteredSpy.wait());
|
|
|
|
}
|
|
|
|
QCOMPARE(enteredSpy.count(), 1);
|
2022-08-01 21:29:02 +00:00
|
|
|
QCOMPARE(textInput->enteredSurface(), surface.get());
|
2021-12-19 08:00:22 +00:00
|
|
|
|
|
|
|
// This is not null anymore because there is a text input object associated with it.
|
|
|
|
QCOMPARE(m_seatInterface->textInputV2()->surface(), serverSurface);
|
|
|
|
|
|
|
|
// now trigger a leave
|
|
|
|
m_seatInterface->setFocusedKeyboardSurface(nullptr);
|
|
|
|
QCOMPARE(textInputChangedSpy.count(), 2);
|
|
|
|
QVERIFY(leftSpy.wait());
|
|
|
|
QVERIFY(!textInput->enteredSurface());
|
|
|
|
|
|
|
|
QCOMPARE(m_seatInterface->textInputV2()->surface(), nullptr);
|
|
|
|
QCOMPARE(m_seatInterface->focusedTextInputSurface(), nullptr);
|
|
|
|
}
|
|
|
|
|
2016-05-02 12:28:26 +00:00
|
|
|
void TextInputTest::testShowHidePanel()
|
|
|
|
{
|
|
|
|
// this test verifies that the requests for show/hide panel work
|
|
|
|
// and that status is properly sent to the client
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(m_compositor->createSurface());
|
2016-05-02 12:28:26 +00:00
|
|
|
auto serverSurface = waitForSurface();
|
|
|
|
QVERIFY(serverSurface);
|
2020-07-28 15:39:13 +00:00
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::TextInput> textInput(createTextInput());
|
2022-08-01 21:29:02 +00:00
|
|
|
QVERIFY(textInput != nullptr);
|
|
|
|
textInput->enable(surface.get());
|
2016-05-02 12:28:26 +00:00
|
|
|
m_connection->flush();
|
|
|
|
m_display->dispatchEvents();
|
|
|
|
|
|
|
|
m_seatInterface->setFocusedKeyboardSurface(serverSurface);
|
2020-07-28 15:39:13 +00:00
|
|
|
auto ti = m_seatInterface->textInputV2();
|
2016-05-02 12:28:26 +00:00
|
|
|
QVERIFY(ti);
|
|
|
|
|
2020-07-28 15:39:13 +00:00
|
|
|
QSignalSpy showPanelRequestedSpy(ti, &TextInputV2Interface::requestShowInputPanel);
|
|
|
|
QSignalSpy hidePanelRequestedSpy(ti, &TextInputV2Interface::requestHideInputPanel);
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy inputPanelStateChangedSpy(textInput.get(), &KWayland::Client::TextInput::inputPanelStateChanged);
|
2016-05-02 12:28:26 +00:00
|
|
|
|
|
|
|
QCOMPARE(textInput->isInputPanelVisible(), false);
|
|
|
|
textInput->showInputPanel();
|
|
|
|
QVERIFY(showPanelRequestedSpy.wait());
|
|
|
|
ti->setInputPanelState(true, QRect(0, 0, 0, 0));
|
|
|
|
QVERIFY(inputPanelStateChangedSpy.wait());
|
|
|
|
QCOMPARE(textInput->isInputPanelVisible(), true);
|
|
|
|
|
|
|
|
textInput->hideInputPanel();
|
|
|
|
QVERIFY(hidePanelRequestedSpy.wait());
|
|
|
|
ti->setInputPanelState(false, QRect(0, 0, 0, 0));
|
|
|
|
QVERIFY(inputPanelStateChangedSpy.wait());
|
|
|
|
QCOMPARE(textInput->isInputPanelVisible(), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextInputTest::testCursorRectangle()
|
|
|
|
{
|
|
|
|
// this test verifies that passing the cursor rectangle from client to server works
|
|
|
|
// and that setting visibility state from server to client works
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(m_compositor->createSurface());
|
2016-05-02 12:28:26 +00:00
|
|
|
auto serverSurface = waitForSurface();
|
|
|
|
QVERIFY(serverSurface);
|
2020-07-28 15:39:13 +00:00
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::TextInput> textInput(createTextInput());
|
2022-08-01 21:29:02 +00:00
|
|
|
QVERIFY(textInput != nullptr);
|
|
|
|
textInput->enable(surface.get());
|
2016-05-02 12:28:26 +00:00
|
|
|
m_connection->flush();
|
|
|
|
m_display->dispatchEvents();
|
|
|
|
|
|
|
|
m_seatInterface->setFocusedKeyboardSurface(serverSurface);
|
2020-07-28 15:39:13 +00:00
|
|
|
auto ti = m_seatInterface->textInputV2();
|
2016-05-02 12:28:26 +00:00
|
|
|
QVERIFY(ti);
|
|
|
|
QCOMPARE(ti->cursorRectangle(), QRect());
|
2020-07-28 15:39:13 +00:00
|
|
|
QSignalSpy cursorRectangleChangedSpy(ti, &TextInputV2Interface::cursorRectangleChanged);
|
2016-05-02 12:28:26 +00:00
|
|
|
|
|
|
|
textInput->setCursorRectangle(QRect(10, 20, 30, 40));
|
|
|
|
QVERIFY(cursorRectangleChangedSpy.wait());
|
|
|
|
QCOMPARE(ti->cursorRectangle(), QRect(10, 20, 30, 40));
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextInputTest::testPreferredLanguage()
|
|
|
|
{
|
|
|
|
// this test verifies that passing the preferred language from client to server works
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(m_compositor->createSurface());
|
2016-05-02 12:28:26 +00:00
|
|
|
auto serverSurface = waitForSurface();
|
|
|
|
QVERIFY(serverSurface);
|
2020-07-28 15:39:13 +00:00
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::TextInput> textInput(createTextInput());
|
2022-08-01 21:29:02 +00:00
|
|
|
QVERIFY(textInput != nullptr);
|
|
|
|
textInput->enable(surface.get());
|
2016-05-02 12:28:26 +00:00
|
|
|
m_connection->flush();
|
|
|
|
m_display->dispatchEvents();
|
|
|
|
|
|
|
|
m_seatInterface->setFocusedKeyboardSurface(serverSurface);
|
2020-07-28 15:39:13 +00:00
|
|
|
auto ti = m_seatInterface->textInputV2();
|
2016-05-02 12:28:26 +00:00
|
|
|
QVERIFY(ti);
|
|
|
|
QVERIFY(ti->preferredLanguage().isEmpty());
|
|
|
|
|
2020-07-28 15:39:13 +00:00
|
|
|
QSignalSpy preferredLanguageChangedSpy(ti, &TextInputV2Interface::preferredLanguageChanged);
|
2016-05-02 12:28:26 +00:00
|
|
|
textInput->setPreferredLanguage(QStringLiteral("foo"));
|
|
|
|
QVERIFY(preferredLanguageChangedSpy.wait());
|
|
|
|
QCOMPARE(ti->preferredLanguage(), QStringLiteral("foo").toUtf8());
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextInputTest::testReset()
|
|
|
|
{
|
|
|
|
// this test verifies that the reset request is properly passed from client to server
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(m_compositor->createSurface());
|
2016-05-02 12:28:26 +00:00
|
|
|
auto serverSurface = waitForSurface();
|
|
|
|
QVERIFY(serverSurface);
|
2020-07-28 15:39:13 +00:00
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::TextInput> textInput(createTextInput());
|
2022-08-01 21:29:02 +00:00
|
|
|
QVERIFY(textInput != nullptr);
|
|
|
|
textInput->enable(surface.get());
|
2016-05-02 12:28:26 +00:00
|
|
|
m_connection->flush();
|
|
|
|
m_display->dispatchEvents();
|
|
|
|
|
|
|
|
m_seatInterface->setFocusedKeyboardSurface(serverSurface);
|
2020-07-28 15:39:13 +00:00
|
|
|
auto ti = m_seatInterface->textInputV2();
|
2016-05-02 12:28:26 +00:00
|
|
|
QVERIFY(ti);
|
|
|
|
|
2020-10-02 11:01:59 +00:00
|
|
|
QSignalSpy stateUpdatedSpy(ti, &TextInputV2Interface::stateUpdated);
|
2016-05-02 12:28:26 +00:00
|
|
|
|
|
|
|
textInput->reset();
|
2020-10-02 11:01:59 +00:00
|
|
|
QVERIFY(stateUpdatedSpy.wait());
|
2016-05-02 12:28:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextInputTest::testSurroundingText()
|
|
|
|
{
|
|
|
|
// this test verifies that surrounding text is properly passed around
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(m_compositor->createSurface());
|
2016-05-02 12:28:26 +00:00
|
|
|
auto serverSurface = waitForSurface();
|
|
|
|
QVERIFY(serverSurface);
|
2020-07-28 15:39:13 +00:00
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::TextInput> textInput(createTextInput());
|
2022-08-01 21:29:02 +00:00
|
|
|
QVERIFY(textInput != nullptr);
|
|
|
|
textInput->enable(surface.get());
|
2016-05-02 12:28:26 +00:00
|
|
|
m_connection->flush();
|
|
|
|
m_display->dispatchEvents();
|
|
|
|
|
|
|
|
m_seatInterface->setFocusedKeyboardSurface(serverSurface);
|
2020-07-28 15:39:13 +00:00
|
|
|
auto ti = m_seatInterface->textInputV2();
|
2016-05-02 12:28:26 +00:00
|
|
|
QVERIFY(ti);
|
|
|
|
QVERIFY(ti->surroundingText().isEmpty());
|
|
|
|
QCOMPARE(ti->surroundingTextCursorPosition(), 0);
|
|
|
|
QCOMPARE(ti->surroundingTextSelectionAnchor(), 0);
|
|
|
|
|
2020-07-28 15:39:13 +00:00
|
|
|
QSignalSpy surroundingTextChangedSpy(ti, &TextInputV2Interface::surroundingTextChanged);
|
2016-05-02 12:28:26 +00:00
|
|
|
|
|
|
|
textInput->setSurroundingText(QStringLiteral("100 €, 100 $"), 5, 6);
|
|
|
|
QVERIFY(surroundingTextChangedSpy.wait());
|
|
|
|
QCOMPARE(ti->surroundingText(), QStringLiteral("100 €, 100 $").toUtf8());
|
|
|
|
QCOMPARE(ti->surroundingTextCursorPosition(), QStringLiteral("100 €, 100 $").toUtf8().indexOf(','));
|
|
|
|
QCOMPARE(ti->surroundingTextSelectionAnchor(), QStringLiteral("100 €, 100 $").toUtf8().indexOf(' ', ti->surroundingTextCursorPosition()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextInputTest::testContentHints_data()
|
|
|
|
{
|
2022-11-08 21:15:17 +00:00
|
|
|
QTest::addColumn<KWayland::Client::TextInput::ContentHints>("clientHints");
|
2023-09-13 17:59:29 +00:00
|
|
|
QTest::addColumn<KWin::TextInputContentHints>("serverHints");
|
2020-07-28 15:39:13 +00:00
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
QTest::newRow("completion/v2") << KWayland::Client::TextInput::ContentHints(KWayland::Client::TextInput::ContentHint::AutoCompletion)
|
2023-09-13 17:59:29 +00:00
|
|
|
<< KWin::TextInputContentHints(KWin::TextInputContentHint::AutoCompletion);
|
2022-11-08 21:15:17 +00:00
|
|
|
QTest::newRow("Correction/v2") << KWayland::Client::TextInput::ContentHints(KWayland::Client::TextInput::ContentHint::AutoCorrection)
|
2023-09-13 17:59:29 +00:00
|
|
|
<< KWin::TextInputContentHints(KWin::TextInputContentHint::AutoCorrection);
|
2022-11-08 21:15:17 +00:00
|
|
|
QTest::newRow("Capitalization/v2") << KWayland::Client::TextInput::ContentHints(KWayland::Client::TextInput::ContentHint::AutoCapitalization)
|
2023-09-13 17:59:29 +00:00
|
|
|
<< KWin::TextInputContentHints(KWin::TextInputContentHint::AutoCapitalization);
|
2022-11-08 21:15:17 +00:00
|
|
|
QTest::newRow("Lowercase/v2") << KWayland::Client::TextInput::ContentHints(KWayland::Client::TextInput::ContentHint::LowerCase)
|
2023-09-13 17:59:29 +00:00
|
|
|
<< KWin::TextInputContentHints(KWin::TextInputContentHint::LowerCase);
|
2022-11-08 21:15:17 +00:00
|
|
|
QTest::newRow("Uppercase/v2") << KWayland::Client::TextInput::ContentHints(KWayland::Client::TextInput::ContentHint::UpperCase)
|
2023-09-13 17:59:29 +00:00
|
|
|
<< KWin::TextInputContentHints(KWin::TextInputContentHint::UpperCase);
|
2022-11-08 21:15:17 +00:00
|
|
|
QTest::newRow("Titlecase/v2") << KWayland::Client::TextInput::ContentHints(KWayland::Client::TextInput::ContentHint::TitleCase)
|
2023-09-13 17:59:29 +00:00
|
|
|
<< KWin::TextInputContentHints(KWin::TextInputContentHint::TitleCase);
|
2022-11-08 21:15:17 +00:00
|
|
|
QTest::newRow("HiddenText/v2") << KWayland::Client::TextInput::ContentHints(KWayland::Client::TextInput::ContentHint::HiddenText)
|
2023-09-13 17:59:29 +00:00
|
|
|
<< KWin::TextInputContentHints(KWin::TextInputContentHint::HiddenText);
|
2022-11-08 21:15:17 +00:00
|
|
|
QTest::newRow("SensitiveData/v2") << KWayland::Client::TextInput::ContentHints(KWayland::Client::TextInput::ContentHint::SensitiveData)
|
2023-09-13 17:59:29 +00:00
|
|
|
<< KWin::TextInputContentHints(KWin::TextInputContentHint::SensitiveData);
|
2022-11-08 21:15:17 +00:00
|
|
|
QTest::newRow("Latin/v2") << KWayland::Client::TextInput::ContentHints(KWayland::Client::TextInput::ContentHint::Latin)
|
2023-09-13 17:59:29 +00:00
|
|
|
<< KWin::TextInputContentHints(KWin::TextInputContentHint::Latin);
|
2022-11-08 21:15:17 +00:00
|
|
|
QTest::newRow("Multiline/v2") << KWayland::Client::TextInput::ContentHints(KWayland::Client::TextInput::ContentHint::MultiLine)
|
2023-09-13 17:59:29 +00:00
|
|
|
<< KWin::TextInputContentHints(KWin::TextInputContentHint::MultiLine);
|
2020-07-28 15:39:13 +00:00
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
QTest::newRow("autos/v2") << (KWayland::Client::TextInput::ContentHint::AutoCompletion | KWayland::Client::TextInput::ContentHint::AutoCorrection | KWayland::Client::TextInput::ContentHint::AutoCapitalization)
|
2023-09-13 17:59:29 +00:00
|
|
|
<< (KWin::TextInputContentHint::AutoCompletion | KWin::TextInputContentHint::AutoCorrection
|
|
|
|
| KWin::TextInputContentHint::AutoCapitalization);
|
2016-05-02 12:28:26 +00:00
|
|
|
|
|
|
|
// all has combinations which don't make sense - what's both lowercase and uppercase?
|
2022-11-08 21:15:17 +00:00
|
|
|
QTest::newRow("all/v2") << (KWayland::Client::TextInput::ContentHint::AutoCompletion | KWayland::Client::TextInput::ContentHint::AutoCorrection | KWayland::Client::TextInput::ContentHint::AutoCapitalization
|
|
|
|
| KWayland::Client::TextInput::ContentHint::LowerCase | KWayland::Client::TextInput::ContentHint::UpperCase | KWayland::Client::TextInput::ContentHint::TitleCase
|
|
|
|
| KWayland::Client::TextInput::ContentHint::HiddenText | KWayland::Client::TextInput::ContentHint::SensitiveData | KWayland::Client::TextInput::ContentHint::Latin
|
|
|
|
| KWayland::Client::TextInput::ContentHint::MultiLine)
|
2023-09-13 17:59:29 +00:00
|
|
|
<< (KWin::TextInputContentHint::AutoCompletion | KWin::TextInputContentHint::AutoCorrection
|
|
|
|
| KWin::TextInputContentHint::AutoCapitalization | KWin::TextInputContentHint::LowerCase
|
|
|
|
| KWin::TextInputContentHint::UpperCase | KWin::TextInputContentHint::TitleCase
|
|
|
|
| KWin::TextInputContentHint::HiddenText | KWin::TextInputContentHint::SensitiveData
|
|
|
|
| KWin::TextInputContentHint::Latin | KWin::TextInputContentHint::MultiLine);
|
2016-05-02 12:28:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextInputTest::testContentHints()
|
|
|
|
{
|
|
|
|
// this test verifies that content hints are properly passed from client to server
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(m_compositor->createSurface());
|
2016-05-02 12:28:26 +00:00
|
|
|
auto serverSurface = waitForSurface();
|
|
|
|
QVERIFY(serverSurface);
|
2020-07-28 15:39:13 +00:00
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::TextInput> textInput(createTextInput());
|
2022-08-01 21:29:02 +00:00
|
|
|
QVERIFY(textInput != nullptr);
|
|
|
|
textInput->enable(surface.get());
|
2016-05-02 12:28:26 +00:00
|
|
|
m_connection->flush();
|
|
|
|
m_display->dispatchEvents();
|
|
|
|
|
|
|
|
m_seatInterface->setFocusedKeyboardSurface(serverSurface);
|
2020-07-28 15:39:13 +00:00
|
|
|
auto ti = m_seatInterface->textInputV2();
|
2016-05-02 12:28:26 +00:00
|
|
|
QVERIFY(ti);
|
2023-09-13 17:59:29 +00:00
|
|
|
QCOMPARE(ti->contentHints(), KWin::TextInputContentHints());
|
2016-05-02 12:28:26 +00:00
|
|
|
|
2020-07-28 15:39:13 +00:00
|
|
|
QSignalSpy contentTypeChangedSpy(ti, &TextInputV2Interface::contentTypeChanged);
|
2022-11-08 21:15:17 +00:00
|
|
|
QFETCH(KWayland::Client::TextInput::ContentHints, clientHints);
|
|
|
|
textInput->setContentType(clientHints, KWayland::Client::TextInput::ContentPurpose::Normal);
|
2016-05-02 12:28:26 +00:00
|
|
|
QVERIFY(contentTypeChangedSpy.wait());
|
|
|
|
QTEST(ti->contentHints(), "serverHints");
|
|
|
|
|
|
|
|
// setting to same should not trigger an update
|
2022-11-08 21:15:17 +00:00
|
|
|
textInput->setContentType(clientHints, KWayland::Client::TextInput::ContentPurpose::Normal);
|
2016-05-02 12:28:26 +00:00
|
|
|
QVERIFY(!contentTypeChangedSpy.wait(100));
|
|
|
|
|
|
|
|
// unsetting should work
|
2022-11-08 21:15:17 +00:00
|
|
|
textInput->setContentType(KWayland::Client::TextInput::ContentHints(), KWayland::Client::TextInput::ContentPurpose::Normal);
|
2016-05-02 12:28:26 +00:00
|
|
|
QVERIFY(contentTypeChangedSpy.wait());
|
2023-09-13 17:59:29 +00:00
|
|
|
QCOMPARE(ti->contentHints(), KWin::TextInputContentHints());
|
2016-05-02 12:28:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextInputTest::testContentPurpose_data()
|
|
|
|
{
|
2022-11-08 21:15:17 +00:00
|
|
|
QTest::addColumn<KWayland::Client::TextInput::ContentPurpose>("clientPurpose");
|
2023-09-13 17:59:29 +00:00
|
|
|
QTest::addColumn<KWin::TextInputContentPurpose>("serverPurpose");
|
|
|
|
|
|
|
|
QTest::newRow("Alpha/v2") << KWayland::Client::TextInput::ContentPurpose::Alpha << KWin::TextInputContentPurpose::Alpha;
|
|
|
|
QTest::newRow("Digits/v2") << KWayland::Client::TextInput::ContentPurpose::Digits << KWin::TextInputContentPurpose::Digits;
|
|
|
|
QTest::newRow("Number/v2") << KWayland::Client::TextInput::ContentPurpose::Number << KWin::TextInputContentPurpose::Number;
|
|
|
|
QTest::newRow("Phone/v2") << KWayland::Client::TextInput::ContentPurpose::Phone << KWin::TextInputContentPurpose::Phone;
|
|
|
|
QTest::newRow("Url/v2") << KWayland::Client::TextInput::ContentPurpose::Url << KWin::TextInputContentPurpose::Url;
|
|
|
|
QTest::newRow("Email/v2") << KWayland::Client::TextInput::ContentPurpose::Email << KWin::TextInputContentPurpose::Email;
|
|
|
|
QTest::newRow("Name/v2") << KWayland::Client::TextInput::ContentPurpose::Name << KWin::TextInputContentPurpose::Name;
|
|
|
|
QTest::newRow("Password/v2") << KWayland::Client::TextInput::ContentPurpose::Password << KWin::TextInputContentPurpose::Password;
|
|
|
|
QTest::newRow("Date/v2") << KWayland::Client::TextInput::ContentPurpose::Date << KWin::TextInputContentPurpose::Date;
|
|
|
|
QTest::newRow("Time/v2") << KWayland::Client::TextInput::ContentPurpose::Time << KWin::TextInputContentPurpose::Time;
|
|
|
|
QTest::newRow("Datetime/v2") << KWayland::Client::TextInput::ContentPurpose::DateTime << KWin::TextInputContentPurpose::DateTime;
|
|
|
|
QTest::newRow("Terminal/v2") << KWayland::Client::TextInput::ContentPurpose::Terminal << KWin::TextInputContentPurpose::Terminal;
|
2016-05-02 12:28:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextInputTest::testContentPurpose()
|
|
|
|
{
|
|
|
|
// this test verifies that content purpose are properly passed from client to server
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(m_compositor->createSurface());
|
2016-05-02 12:28:26 +00:00
|
|
|
auto serverSurface = waitForSurface();
|
|
|
|
QVERIFY(serverSurface);
|
2020-07-28 15:39:13 +00:00
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::TextInput> textInput(createTextInput());
|
2022-08-01 21:29:02 +00:00
|
|
|
QVERIFY(textInput != nullptr);
|
|
|
|
textInput->enable(surface.get());
|
2016-05-02 12:28:26 +00:00
|
|
|
m_connection->flush();
|
|
|
|
m_display->dispatchEvents();
|
|
|
|
|
|
|
|
m_seatInterface->setFocusedKeyboardSurface(serverSurface);
|
2020-07-28 15:39:13 +00:00
|
|
|
auto ti = m_seatInterface->textInputV2();
|
2016-05-02 12:28:26 +00:00
|
|
|
QVERIFY(ti);
|
2023-09-13 17:59:29 +00:00
|
|
|
QCOMPARE(ti->contentPurpose(), KWin::TextInputContentPurpose::Normal);
|
2016-05-02 12:28:26 +00:00
|
|
|
|
2020-07-28 15:39:13 +00:00
|
|
|
QSignalSpy contentTypeChangedSpy(ti, &TextInputV2Interface::contentTypeChanged);
|
2022-11-08 21:15:17 +00:00
|
|
|
QFETCH(KWayland::Client::TextInput::ContentPurpose, clientPurpose);
|
|
|
|
textInput->setContentType(KWayland::Client::TextInput::ContentHints(), clientPurpose);
|
2016-05-02 12:28:26 +00:00
|
|
|
QVERIFY(contentTypeChangedSpy.wait());
|
|
|
|
QTEST(ti->contentPurpose(), "serverPurpose");
|
|
|
|
|
|
|
|
// setting to same should not trigger an update
|
2022-11-08 21:15:17 +00:00
|
|
|
textInput->setContentType(KWayland::Client::TextInput::ContentHints(), clientPurpose);
|
2016-05-02 12:28:26 +00:00
|
|
|
QVERIFY(!contentTypeChangedSpy.wait(100));
|
|
|
|
|
|
|
|
// unsetting should work
|
2022-11-08 21:15:17 +00:00
|
|
|
textInput->setContentType(KWayland::Client::TextInput::ContentHints(), KWayland::Client::TextInput::ContentPurpose::Normal);
|
2016-05-02 12:28:26 +00:00
|
|
|
QVERIFY(contentTypeChangedSpy.wait());
|
2023-09-13 17:59:29 +00:00
|
|
|
QCOMPARE(ti->contentPurpose(), KWin::TextInputContentPurpose::Normal);
|
2016-05-02 12:28:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextInputTest::testTextDirection_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<Qt::LayoutDirection>("textDirection");
|
|
|
|
|
2020-07-28 15:39:13 +00:00
|
|
|
QTest::newRow("ltr/v0") << Qt::LeftToRight;
|
|
|
|
QTest::newRow("rtl/v0") << Qt::RightToLeft;
|
2016-05-02 12:28:26 +00:00
|
|
|
|
2020-07-28 15:39:13 +00:00
|
|
|
QTest::newRow("ltr/v2") << Qt::LeftToRight;
|
|
|
|
QTest::newRow("rtl/v2") << Qt::RightToLeft;
|
2016-05-02 12:28:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextInputTest::testTextDirection()
|
|
|
|
{
|
|
|
|
// this test verifies that the text direction is sent from server to client
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(m_compositor->createSurface());
|
2016-05-02 12:28:26 +00:00
|
|
|
auto serverSurface = waitForSurface();
|
|
|
|
QVERIFY(serverSurface);
|
2020-07-28 15:39:13 +00:00
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::TextInput> textInput(createTextInput());
|
2022-08-01 21:29:02 +00:00
|
|
|
QVERIFY(textInput != nullptr);
|
2016-05-02 12:28:26 +00:00
|
|
|
// default should be auto
|
|
|
|
QCOMPARE(textInput->textDirection(), Qt::LayoutDirectionAuto);
|
2022-08-01 21:29:02 +00:00
|
|
|
textInput->enable(surface.get());
|
2016-05-02 12:28:26 +00:00
|
|
|
m_connection->flush();
|
|
|
|
m_display->dispatchEvents();
|
|
|
|
|
|
|
|
m_seatInterface->setFocusedKeyboardSurface(serverSurface);
|
2020-07-28 15:39:13 +00:00
|
|
|
auto ti = m_seatInterface->textInputV2();
|
2016-05-02 12:28:26 +00:00
|
|
|
QVERIFY(ti);
|
|
|
|
|
|
|
|
// let's send the new text direction
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy textDirectionChangedSpy(textInput.get(), &KWayland::Client::TextInput::textDirectionChanged);
|
2016-05-02 12:28:26 +00:00
|
|
|
QFETCH(Qt::LayoutDirection, textDirection);
|
|
|
|
ti->setTextDirection(textDirection);
|
|
|
|
QVERIFY(textDirectionChangedSpy.wait());
|
|
|
|
QCOMPARE(textInput->textDirection(), textDirection);
|
|
|
|
// setting again should not change
|
|
|
|
ti->setTextDirection(textDirection);
|
|
|
|
QVERIFY(!textDirectionChangedSpy.wait(100));
|
|
|
|
|
|
|
|
// setting back to auto
|
|
|
|
ti->setTextDirection(Qt::LayoutDirectionAuto);
|
|
|
|
QVERIFY(textDirectionChangedSpy.wait());
|
|
|
|
QCOMPARE(textInput->textDirection(), Qt::LayoutDirectionAuto);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextInputTest::testLanguage()
|
|
|
|
{
|
|
|
|
// this test verifies that language is sent from server to client
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(m_compositor->createSurface());
|
2016-05-02 12:28:26 +00:00
|
|
|
auto serverSurface = waitForSurface();
|
|
|
|
QVERIFY(serverSurface);
|
2020-07-28 15:39:13 +00:00
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::TextInput> textInput(createTextInput());
|
2022-08-01 21:29:02 +00:00
|
|
|
QVERIFY(textInput != nullptr);
|
2016-05-02 12:28:26 +00:00
|
|
|
// default should be empty
|
|
|
|
QVERIFY(textInput->language().isEmpty());
|
2022-08-01 21:29:02 +00:00
|
|
|
textInput->enable(surface.get());
|
2016-05-02 12:28:26 +00:00
|
|
|
m_connection->flush();
|
|
|
|
m_display->dispatchEvents();
|
|
|
|
|
|
|
|
m_seatInterface->setFocusedKeyboardSurface(serverSurface);
|
2020-07-28 15:39:13 +00:00
|
|
|
auto ti = m_seatInterface->textInputV2();
|
2016-05-02 12:28:26 +00:00
|
|
|
QVERIFY(ti);
|
|
|
|
|
|
|
|
// let's send the new language
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy langugageChangedSpy(textInput.get(), &KWayland::Client::TextInput::languageChanged);
|
2016-05-02 12:28:26 +00:00
|
|
|
ti->setLanguage(QByteArrayLiteral("foo"));
|
|
|
|
QVERIFY(langugageChangedSpy.wait());
|
|
|
|
QCOMPARE(textInput->language(), QByteArrayLiteral("foo"));
|
|
|
|
// setting to same should not trigger
|
|
|
|
ti->setLanguage(QByteArrayLiteral("foo"));
|
|
|
|
QVERIFY(!langugageChangedSpy.wait(100));
|
|
|
|
// but to something else should trigger again
|
|
|
|
ti->setLanguage(QByteArrayLiteral("bar"));
|
|
|
|
QVERIFY(langugageChangedSpy.wait());
|
|
|
|
QCOMPARE(textInput->language(), QByteArrayLiteral("bar"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextInputTest::testKeyEvent()
|
|
|
|
{
|
|
|
|
qRegisterMetaType<Qt::KeyboardModifiers>();
|
2022-11-08 21:15:17 +00:00
|
|
|
qRegisterMetaType<KWayland::Client::TextInput::KeyState>();
|
2016-05-02 12:28:26 +00:00
|
|
|
// this test verifies that key events are properly sent to the client
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(m_compositor->createSurface());
|
2016-05-02 12:28:26 +00:00
|
|
|
auto serverSurface = waitForSurface();
|
|
|
|
QVERIFY(serverSurface);
|
2020-07-28 15:39:13 +00:00
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::TextInput> textInput(createTextInput());
|
2022-08-01 21:29:02 +00:00
|
|
|
QVERIFY(textInput != nullptr);
|
|
|
|
textInput->enable(surface.get());
|
2016-05-02 12:28:26 +00:00
|
|
|
m_connection->flush();
|
|
|
|
m_display->dispatchEvents();
|
|
|
|
|
|
|
|
m_seatInterface->setFocusedKeyboardSurface(serverSurface);
|
2020-07-28 15:39:13 +00:00
|
|
|
auto ti = m_seatInterface->textInputV2();
|
2016-05-02 12:28:26 +00:00
|
|
|
QVERIFY(ti);
|
|
|
|
|
|
|
|
// TODO: test modifiers
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy keyEventSpy(textInput.get(), &KWayland::Client::TextInput::keyEvent);
|
2022-12-21 00:55:20 +00:00
|
|
|
m_seatInterface->setTimestamp(100ms);
|
2016-05-02 12:28:26 +00:00
|
|
|
ti->keysymPressed(2);
|
|
|
|
QVERIFY(keyEventSpy.wait());
|
|
|
|
QCOMPARE(keyEventSpy.count(), 1);
|
|
|
|
QCOMPARE(keyEventSpy.last().at(0).value<quint32>(), 2u);
|
2022-11-08 21:15:17 +00:00
|
|
|
QCOMPARE(keyEventSpy.last().at(1).value<KWayland::Client::TextInput::KeyState>(), KWayland::Client::TextInput::KeyState::Pressed);
|
2016-05-02 12:28:26 +00:00
|
|
|
QCOMPARE(keyEventSpy.last().at(2).value<Qt::KeyboardModifiers>(), Qt::KeyboardModifiers());
|
|
|
|
QCOMPARE(keyEventSpy.last().at(3).value<quint32>(), 100u);
|
2022-12-21 00:55:20 +00:00
|
|
|
m_seatInterface->setTimestamp(101ms);
|
2016-05-02 12:28:26 +00:00
|
|
|
ti->keysymReleased(2);
|
|
|
|
QVERIFY(keyEventSpy.wait());
|
|
|
|
QCOMPARE(keyEventSpy.count(), 2);
|
|
|
|
QCOMPARE(keyEventSpy.last().at(0).value<quint32>(), 2u);
|
2022-11-08 21:15:17 +00:00
|
|
|
QCOMPARE(keyEventSpy.last().at(1).value<KWayland::Client::TextInput::KeyState>(), KWayland::Client::TextInput::KeyState::Released);
|
2016-05-02 12:28:26 +00:00
|
|
|
QCOMPARE(keyEventSpy.last().at(2).value<Qt::KeyboardModifiers>(), Qt::KeyboardModifiers());
|
|
|
|
QCOMPARE(keyEventSpy.last().at(3).value<quint32>(), 101u);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextInputTest::testPreEdit()
|
|
|
|
{
|
|
|
|
// this test verifies that pre-edit is correctly passed to the client
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(m_compositor->createSurface());
|
2016-05-02 12:28:26 +00:00
|
|
|
auto serverSurface = waitForSurface();
|
|
|
|
QVERIFY(serverSurface);
|
2020-07-28 15:39:13 +00:00
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::TextInput> textInput(createTextInput());
|
2022-08-01 21:29:02 +00:00
|
|
|
QVERIFY(textInput != nullptr);
|
2016-05-02 12:28:26 +00:00
|
|
|
// verify default values
|
|
|
|
QVERIFY(textInput->composingText().isEmpty());
|
|
|
|
QVERIFY(textInput->composingFallbackText().isEmpty());
|
|
|
|
QCOMPARE(textInput->composingTextCursorPosition(), 0);
|
|
|
|
|
2022-08-01 21:29:02 +00:00
|
|
|
textInput->enable(surface.get());
|
2016-05-02 12:28:26 +00:00
|
|
|
m_connection->flush();
|
|
|
|
m_display->dispatchEvents();
|
|
|
|
|
|
|
|
m_seatInterface->setFocusedKeyboardSurface(serverSurface);
|
2020-07-28 15:39:13 +00:00
|
|
|
auto ti = m_seatInterface->textInputV2();
|
2016-05-02 12:28:26 +00:00
|
|
|
QVERIFY(ti);
|
|
|
|
|
|
|
|
// now let's pass through some pre-edit events
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy composingTextChangedSpy(textInput.get(), &KWayland::Client::TextInput::composingTextChanged);
|
2016-05-02 12:28:26 +00:00
|
|
|
ti->setPreEditCursor(1);
|
|
|
|
ti->preEdit(QByteArrayLiteral("foo"), QByteArrayLiteral("bar"));
|
|
|
|
QVERIFY(composingTextChangedSpy.wait());
|
|
|
|
QCOMPARE(composingTextChangedSpy.count(), 1);
|
|
|
|
QCOMPARE(textInput->composingText(), QByteArrayLiteral("foo"));
|
|
|
|
QCOMPARE(textInput->composingFallbackText(), QByteArrayLiteral("bar"));
|
|
|
|
QCOMPARE(textInput->composingTextCursorPosition(), 1);
|
|
|
|
|
|
|
|
// when no pre edit cursor is sent, it's at end of text
|
|
|
|
ti->preEdit(QByteArrayLiteral("foobar"), QByteArray());
|
|
|
|
QVERIFY(composingTextChangedSpy.wait());
|
|
|
|
QCOMPARE(composingTextChangedSpy.count(), 2);
|
|
|
|
QCOMPARE(textInput->composingText(), QByteArrayLiteral("foobar"));
|
|
|
|
QCOMPARE(textInput->composingFallbackText(), QByteArray());
|
|
|
|
QCOMPARE(textInput->composingTextCursorPosition(), 6);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextInputTest::testCommit()
|
|
|
|
{
|
|
|
|
// this test verifies that the commit is handled correctly by the client
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(m_compositor->createSurface());
|
2016-05-02 12:28:26 +00:00
|
|
|
auto serverSurface = waitForSurface();
|
|
|
|
QVERIFY(serverSurface);
|
2020-07-28 15:39:13 +00:00
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::TextInput> textInput(createTextInput());
|
2022-08-01 21:29:02 +00:00
|
|
|
QVERIFY(textInput != nullptr);
|
2016-05-02 12:28:26 +00:00
|
|
|
// verify default values
|
|
|
|
QCOMPARE(textInput->commitText(), QByteArray());
|
|
|
|
QCOMPARE(textInput->cursorPosition(), 0);
|
|
|
|
QCOMPARE(textInput->anchorPosition(), 0);
|
|
|
|
QCOMPARE(textInput->deleteSurroundingText().beforeLength, 0u);
|
|
|
|
QCOMPARE(textInput->deleteSurroundingText().afterLength, 0u);
|
|
|
|
|
2022-08-01 21:29:02 +00:00
|
|
|
textInput->enable(surface.get());
|
2016-05-02 12:28:26 +00:00
|
|
|
m_connection->flush();
|
|
|
|
m_display->dispatchEvents();
|
|
|
|
|
|
|
|
m_seatInterface->setFocusedKeyboardSurface(serverSurface);
|
2020-07-28 15:39:13 +00:00
|
|
|
auto ti = m_seatInterface->textInputV2();
|
2016-05-02 12:28:26 +00:00
|
|
|
QVERIFY(ti);
|
|
|
|
|
|
|
|
// now let's commit
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy committedSpy(textInput.get(), &KWayland::Client::TextInput::committed);
|
2016-05-02 12:28:26 +00:00
|
|
|
ti->setCursorPosition(3, 4);
|
|
|
|
ti->deleteSurroundingText(2, 1);
|
2020-09-15 07:27:46 +00:00
|
|
|
ti->commitString(QByteArrayLiteral("foo"));
|
2016-05-02 12:28:26 +00:00
|
|
|
|
|
|
|
QVERIFY(committedSpy.wait());
|
|
|
|
QCOMPARE(textInput->commitText(), QByteArrayLiteral("foo"));
|
|
|
|
QCOMPARE(textInput->cursorPosition(), 3);
|
|
|
|
QCOMPARE(textInput->anchorPosition(), 4);
|
|
|
|
QCOMPARE(textInput->deleteSurroundingText().beforeLength, 2u);
|
|
|
|
QCOMPARE(textInput->deleteSurroundingText().afterLength, 1u);
|
|
|
|
}
|
|
|
|
|
|
|
|
QTEST_GUILESS_MAIN(TextInputTest)
|
2020-09-23 08:21:22 +00:00
|
|
|
#include "test_text_input_v2.moc"
|