Commit 50761ce0 authored by Bhushan Shah's avatar Bhushan Shah 📱
Browse files

text-input-v3: track commit counts per resource

If we track the commit counts at compositor global, this will fail
horribly for anything other than the first text-input-v3 client, as for
new client the serial count will not be what it expects in the done()
request and it will simply consider events as outdated and will refuse
to accept those events
parent c7fe867e
......@@ -92,6 +92,7 @@ private Q_SLOTS:
void testContentPurpose();
void testContentHints_data();
void testContentHints();
void testMultipleTextinputs();
private:
KWayland::Client::ConnectionThread *m_connection;
......@@ -509,6 +510,113 @@ void TestTextInputV3Interface::testContentHints()
m_totalCommits++;
}
void TestTextInputV3Interface::testMultipleTextinputs()
{
// create two more text inputs
TextInputV3 *ti1 = new TextInputV3();
ti1->init(m_clientTextInputManagerV3->get_text_input(*m_clientSeat));
QVERIFY(ti1);
TextInputV3 *ti2 = new TextInputV3();
ti2->init(m_clientTextInputManagerV3->get_text_input(*m_clientSeat));
QVERIFY(ti2);
// create a surface
QSignalSpy serverSurfaceCreatedSpy(m_serverCompositor, &CompositorInterface::surfaceCreated);
QVERIFY(serverSurfaceCreatedSpy.isValid());
QScopedPointer<KWayland::Client::Surface> clientSurface(m_clientCompositor->createSurface(this));
QVERIFY(serverSurfaceCreatedSpy.wait());
SurfaceInterface *serverSurface = serverSurfaceCreatedSpy.first().first().value<SurfaceInterface *>();
QVERIFY(serverSurface);
QSignalSpy focusedSurfaceChangedSpy(m_seat, &SeatInterface::focusedTextInputSurfaceChanged);
// Make sure that entering surface does not trigger the text input
m_seat->setFocusedTextInputSurface(serverSurface);
QCOMPARE(focusedSurfaceChangedSpy.count(), 1);
m_serverTextInputV3 = m_seat->textInputV3();
QVERIFY(m_serverTextInputV3);
QSignalSpy committedSpy(m_serverTextInputV3, &TextInputV3Interface::stateCommitted);
// Enable ti1
ti1->enable();
ti1->commit();
QVERIFY(committedSpy.wait());
QCOMPARE(committedSpy.last().at(0).value<quint32>(), 1);
// Send another three commits on ti1
ti1->enable();
ti1->set_surrounding_text("hello", 0, 1);
ti1->commit();
QVERIFY(committedSpy.wait());
QCOMPARE(committedSpy.last().at(0).value<quint32>(), 2);
ti1->enable();
ti1->set_content_type(QtWayland::zwp_text_input_v3::content_hint_none, QtWayland::zwp_text_input_v3::content_purpose_normal);
ti1->commit();
QVERIFY(committedSpy.wait());
QCOMPARE(committedSpy.last().at(0).value<quint32>(), 3);
// at this point total commit count to ti1 is 3
QSignalSpy doneSpy1(ti1, &TextInputV3::done);
QSignalSpy doneSpy2(ti2, &TextInputV3::done);
m_serverTextInputV3->commitString("Hello");
m_serverTextInputV3->done();
QVERIFY(doneSpy1.wait());
// zwp_text_input_v3.done event have serial of total commits
QCOMPARE(doneSpy1.last().at(0).value<quint32>(), 3);
// now ti1 is at 4 commit, while ti2 is still 0
ti1->disable();
ti1->commit();
QVERIFY(committedSpy.wait());
QCOMPARE(committedSpy.last().at(0).value<quint32>(), 4);
// first commit to ti2
ti2->enable();
ti2->commit();
QVERIFY(committedSpy.wait());
QCOMPARE(committedSpy.last().at(0).value<quint32>(), 1);
// send commit string
m_serverTextInputV3->commitString("Hello world");
m_serverTextInputV3->done();
QVERIFY(doneSpy2.wait());
// ti2 is at one commit
QCOMPARE(doneSpy2.last().at(0).value<quint32>(), 1);
ti2->disable();
ti2->commit();
QVERIFY(committedSpy.wait());
QCOMPARE(committedSpy.last().at(0).value<quint32>(), 2);
// now re-enable the ti1 and verify sending commits to t2 hasn't affected it's serial
// Enable ti1 : 5 commits now
ti1->enable();
ti1->commit();
QVERIFY(committedSpy.wait());
QCOMPARE(committedSpy.last().at(0).value<quint32>(), 5);
// send done signal
m_serverTextInputV3->commitString("Hello");
m_serverTextInputV3->done();
QVERIFY(doneSpy1.wait());
QCOMPARE(doneSpy1.last().at(0).value<quint32>(), 5);
// cleanup
if (ti1) {
delete ti1;
ti1 = nullptr;
}
if (ti2) {
delete ti2;
ti2 = nullptr;
}
}
QTEST_GUILESS_MAIN(TestTextInputV3Interface)
#include "test_textinputv3_interface.moc"
......@@ -139,6 +139,18 @@ TextInputV3InterfacePrivate::TextInputV3InterfacePrivate(SeatInterface *seat, Te
{
}
void TextInputV3InterfacePrivate::zwp_text_input_v3_bind_resource(Resource *resource)
{
// we initialize the serial for the resource to be 0
serialHash.insert(resource, 0);
}
void TextInputV3InterfacePrivate::zwp_text_input_v3_destroy(Resource *resource)
{
// drop resource from the serial hash
serialHash.remove(resource);
}
void TextInputV3InterfacePrivate::sendEnter(SurfaceInterface *s)
{
if (!s) {
......@@ -204,7 +216,7 @@ void TextInputV3InterfacePrivate::done()
const QList<Resource *> textInputs = textInputsForClient(surface->client());
for (auto resource : textInputs) {
// zwp_text_input_v3.done takes the serial argument which is equal to number of commit requests issued
send_done(resource->handle, serial);
send_done(resource->handle, serialHash[resource]);
}
}
......@@ -273,14 +285,13 @@ void TextInputV3InterfacePrivate::zwp_text_input_v3_set_text_change_cause(Resour
void TextInputV3InterfacePrivate::zwp_text_input_v3_commit(Resource *resource)
{
Q_UNUSED(resource)
serial++;
serialHash[resource]++;
if (enabled != pending.enabled) {
enabled = pending.enabled;
emit q->enabledChanged();
}
if (surroundingTextChangeCause != pending.surroundingTextChangeCause) {
surroundingTextChangeCause = pending.surroundingTextChangeCause;
pending.surroundingTextChangeCause = TextInputChangeCause::InputMethod;
......@@ -293,7 +304,7 @@ void TextInputV3InterfacePrivate::zwp_text_input_v3_commit(Resource *resource)
emit q->contentTypeChanged();
}
}
if (cursorRectangle != pending.cursorRectangle) {
cursorRectangle = pending.cursorRectangle;
if (enabled) {
......@@ -310,7 +321,7 @@ void TextInputV3InterfacePrivate::zwp_text_input_v3_commit(Resource *resource)
}
}
emit q->stateCommitted(serial);
emit q->stateCommitted(serialHash[resource]);
}
void TextInputV3InterfacePrivate::defaultPending()
......
......@@ -13,6 +13,7 @@
#include <QPointer>
#include <QRect>
#include <QVector>
#include <QHash>
#include <qwayland-server-text-input-unstable-v3.h>
......@@ -71,14 +72,16 @@ public:
qint32 surroundingTextCursorPosition = 0;
qint32 surroundingTextSelectionAnchor = 0;
} pending;
quint32 serial = 0;
QHash<Resource *, quint32> serialHash;
void defaultPending();
TextInputV3Interface *q;
protected:
void zwp_text_input_v3_bind_resource(Resource *resource) override;
void zwp_text_input_v3_destroy(Resource *resource) override;
// requests
void zwp_text_input_v3_enable(Resource *resource) override;
void zwp_text_input_v3_disable(Resource *resource) override;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment