Skip to content
This repository has been archived by the owner on Apr 29, 2023. It is now read-only.

Commit

Permalink
Rework InputDeviceHandler focus tracking
Browse files Browse the repository at this point in the history
Summary:
This patch aims at improving the Toplevel, internal window and decoration
focus tracking.

In detail the goals are:
* Clean tracking of beneath and focus Toplevel as well as decoration and
internal windows. Splitting this up in well defined sub routines.
* Minimal find Toplevel operations on window stack.
* Reduce code duplication in pointer and touch child classes.
* Reuse tracking in drag operations.
* Allow direct usage of Wayland input interfaces for decoration and internal
windows in the future.
* Update touch focus on external events like VD switches correctly.

Test Plan: Manually and existing autotests.

Reviewers: #kwin

Subscribers: kwin, zzag

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D15595
  • Loading branch information
romangg committed Dec 2, 2018
1 parent eab71a8 commit 2e29711
Show file tree
Hide file tree
Showing 11 changed files with 635 additions and 427 deletions.
4 changes: 2 additions & 2 deletions autotests/integration/decoration_input_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -836,8 +836,8 @@ void DecorationInputTest::testTouchEvents()
QCOMPARE(hoverMoveSpy.count(), 3);
QCOMPARE(hoverLeaveSpy.count(), 1);
kwinApp()->platform()->touchUp(0, timestamp++);
QCOMPARE(hoverMoveSpy.count(), 4);
QCOMPARE(hoverLeaveSpy.count(), 1);
QCOMPARE(hoverMoveSpy.count(), 3);
QCOMPARE(hoverLeaveSpy.count(), 2);
}

void DecorationInputTest::testTooltipDoesntEatKeyEvents_data()
Expand Down
6 changes: 3 additions & 3 deletions autotests/integration/internal_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,11 @@ void InternalWindowTest::testEnterLeave()

quint32 timestamp = 1;
kwinApp()->platform()->pointerMotion(QPoint(50, 50), timestamp++);
QTRY_COMPARE(enterSpy.count(), 1);
QTRY_COMPARE(moveSpy.count(), 1);

kwinApp()->platform()->pointerMotion(QPoint(60, 50), timestamp++);
QTRY_COMPARE(moveSpy.count(), 1);
QCOMPARE(moveSpy.first().first().toPoint(), QPoint(60, 50));
QTRY_COMPARE(moveSpy.count(), 2);
QCOMPARE(moveSpy[1].first().toPoint(), QPoint(60, 50));

kwinApp()->platform()->pointerMotion(QPoint(101, 50), timestamp++);
QTRY_COMPARE(leaveSpy.count(), 1);
Expand Down
10 changes: 5 additions & 5 deletions autotests/integration/pointer_constraints_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ void TestPointerConstraints::testConfinedPointer()
QVERIFY(unconfinedSpy2.isValid());

// activate it again, this confines again
workspace()->activateClient(static_cast<AbstractClient*>(input()->pointer()->window().data()));
workspace()->activateClient(static_cast<AbstractClient*>(input()->pointer()->focus().data()));
QVERIFY(confinedSpy2.wait());
QCOMPARE(input()->pointer()->isConstrained(), true);

Expand All @@ -241,7 +241,7 @@ void TestPointerConstraints::testConfinedPointer()
QVERIFY(unconfinedSpy2.wait());
QCOMPARE(input()->pointer()->isConstrained(), false);
// activate it again, this confines again
workspace()->activateClient(static_cast<AbstractClient*>(input()->pointer()->window().data()));
workspace()->activateClient(static_cast<AbstractClient*>(input()->pointer()->focus().data()));
QVERIFY(confinedSpy2.wait());
QCOMPARE(input()->pointer()->isConstrained(), true);

Expand Down Expand Up @@ -272,7 +272,7 @@ void TestPointerConstraints::testConfinedPointer()
confinedPointer.reset(nullptr);
Test::flushWaylandConnection();

QSignalSpy constraintsChangedSpy(input()->pointer()->window()->surface(), &KWayland::Server::SurfaceInterface::pointerConstraintsChanged);
QSignalSpy constraintsChangedSpy(input()->pointer()->focus()->surface(), &KWayland::Server::SurfaceInterface::pointerConstraintsChanged);
QVERIFY(constraintsChangedSpy.isValid());
QVERIFY(constraintsChangedSpy.wait());

Expand Down Expand Up @@ -348,7 +348,7 @@ void TestPointerConstraints::testLockedPointer()
QVERIFY(lockedSpy2.isValid());

// activate the client again, this should lock again
workspace()->activateClient(static_cast<AbstractClient*>(input()->pointer()->window().data()));
workspace()->activateClient(static_cast<AbstractClient*>(input()->pointer()->focus().data()));
QVERIFY(lockedSpy2.wait());
QCOMPARE(input()->pointer()->isConstrained(), true);

Expand All @@ -361,7 +361,7 @@ void TestPointerConstraints::testLockedPointer()
lockedPointer.reset(nullptr);
Test::flushWaylandConnection();

QSignalSpy constraintsChangedSpy(input()->pointer()->window()->surface(), &KWayland::Server::SurfaceInterface::pointerConstraintsChanged);
QSignalSpy constraintsChangedSpy(input()->pointer()->focus()->surface(), &KWayland::Server::SurfaceInterface::pointerConstraintsChanged);
QVERIFY(constraintsChangedSpy.isValid());
QVERIFY(constraintsChangedSpy.wait());

Expand Down
4 changes: 2 additions & 2 deletions autotests/integration/pointer_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ void PointerInputTest::testCursorImage()

// move cursor to center of window, this should first set a null pointer, so we still show old cursor
Cursor::setPos(window->geometry().center());
QCOMPARE(p->window().data(), window);
QCOMPARE(p->focus().data(), window);
QCOMPARE(p->cursorImage(), fallbackCursor);
QVERIFY(enteredSpy.wait());

Expand Down Expand Up @@ -1018,7 +1018,7 @@ void PointerInputTest::testCursorImage()

// move cursor somewhere else, should reset to fallback cursor
Cursor::setPos(window->geometry().bottomLeft() + QPoint(20, 20));
QVERIFY(p->window().isNull());
QVERIFY(p->focus().isNull());
QVERIFY(!p->cursorImage().isNull());
QCOMPARE(p->cursorImage(), fallbackCursor);
}
Expand Down
26 changes: 13 additions & 13 deletions autotests/integration/window_selection_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void TestWindowSelection::testSelectOnWindowPointer()
QVERIFY(client);
QVERIFY(keyboardEnteredSpy.wait());
KWin::Cursor::setPos(client->geometry().center());
QCOMPARE(input()->pointer()->window().data(), client);
QCOMPARE(input()->pointer()->focus().data(), client);
QVERIFY(pointerEnteredSpy.wait());

Toplevel *selectedWindow = nullptr;
Expand All @@ -142,11 +142,11 @@ void TestWindowSelection::testSelectOnWindowPointer()
// should not have ended the mode
QCOMPARE(input()->isSelectingWindow(), true);
QVERIFY(!selectedWindow);
QVERIFY(input()->pointer()->window().isNull());
QVERIFY(input()->pointer()->focus().isNull());

// updating the pointer should not change anything
input()->pointer()->update();
QVERIFY(input()->pointer()->window().isNull());
QVERIFY(input()->pointer()->focus().isNull());
// updating keyboard should also not change
input()->keyboard()->update();

Expand All @@ -160,7 +160,7 @@ void TestWindowSelection::testSelectOnWindowPointer()
kwinApp()->platform()->pointerButtonReleased(BTN_LEFT, timestamp++);
QCOMPARE(input()->isSelectingWindow(), false);
QCOMPARE(selectedWindow, client);
QCOMPARE(input()->pointer()->window().data(), client);
QCOMPARE(input()->pointer()->focus().data(), client);
// should give back keyboard and pointer
QVERIFY(pointerEnteredSpy.wait());
if (keyboardEnteredSpy.count() != 2) {
Expand Down Expand Up @@ -240,7 +240,7 @@ void TestWindowSelection::testSelectOnWindowKeyboard()
kwinApp()->platform()->keyboardKeyPressed(key, timestamp++);
QCOMPARE(input()->isSelectingWindow(), false);
QCOMPARE(selectedWindow, client);
QCOMPARE(input()->pointer()->window().data(), client);
QCOMPARE(input()->pointer()->focus().data(), client);
// should give back keyboard and pointer
QVERIFY(pointerEnteredSpy.wait());
if (keyboardEnteredSpy.count() != 2) {
Expand Down Expand Up @@ -336,7 +336,7 @@ void TestWindowSelection::testCancelOnWindowPointer()
QVERIFY(client);
QVERIFY(keyboardEnteredSpy.wait());
KWin::Cursor::setPos(client->geometry().center());
QCOMPARE(input()->pointer()->window().data(), client);
QCOMPARE(input()->pointer()->focus().data(), client);
QVERIFY(pointerEnteredSpy.wait());

Toplevel *selectedWindow = nullptr;
Expand All @@ -363,7 +363,7 @@ void TestWindowSelection::testCancelOnWindowPointer()
kwinApp()->platform()->pointerButtonReleased(BTN_RIGHT, timestamp++);
QCOMPARE(input()->isSelectingWindow(), false);
QVERIFY(!selectedWindow);
QCOMPARE(input()->pointer()->window().data(), client);
QCOMPARE(input()->pointer()->focus().data(), client);
// should give back keyboard and pointer
QVERIFY(pointerEnteredSpy.wait());
if (keyboardEnteredSpy.count() != 2) {
Expand Down Expand Up @@ -395,7 +395,7 @@ void TestWindowSelection::testCancelOnWindowKeyboard()
QVERIFY(client);
QVERIFY(keyboardEnteredSpy.wait());
KWin::Cursor::setPos(client->geometry().center());
QCOMPARE(input()->pointer()->window().data(), client);
QCOMPARE(input()->pointer()->focus().data(), client);
QVERIFY(pointerEnteredSpy.wait());

Toplevel *selectedWindow = nullptr;
Expand All @@ -421,7 +421,7 @@ void TestWindowSelection::testCancelOnWindowKeyboard()
kwinApp()->platform()->keyboardKeyPressed(KEY_ESC, timestamp++);
QCOMPARE(input()->isSelectingWindow(), false);
QVERIFY(!selectedWindow);
QCOMPARE(input()->pointer()->window().data(), client);
QCOMPARE(input()->pointer()->focus().data(), client);
// should give back keyboard and pointer
QVERIFY(pointerEnteredSpy.wait());
if (keyboardEnteredSpy.count() != 2) {
Expand Down Expand Up @@ -454,7 +454,7 @@ void TestWindowSelection::testSelectPointPointer()
QVERIFY(client);
QVERIFY(keyboardEnteredSpy.wait());
KWin::Cursor::setPos(client->geometry().center());
QCOMPARE(input()->pointer()->window().data(), client);
QCOMPARE(input()->pointer()->focus().data(), client);
QVERIFY(pointerEnteredSpy.wait());

QPoint point;
Expand Down Expand Up @@ -488,11 +488,11 @@ void TestWindowSelection::testSelectPointPointer()
// should not have ended the mode
QCOMPARE(input()->isSelectingWindow(), true);
QCOMPARE(point, QPoint());
QVERIFY(input()->pointer()->window().isNull());
QVERIFY(input()->pointer()->focus().isNull());

// updating the pointer should not change anything
input()->pointer()->update();
QVERIFY(input()->pointer()->window().isNull());
QVERIFY(input()->pointer()->focus().isNull());
// updating keyboard should also not change
input()->keyboard()->update();

Expand All @@ -506,7 +506,7 @@ void TestWindowSelection::testSelectPointPointer()
kwinApp()->platform()->pointerButtonReleased(BTN_LEFT, timestamp++);
QCOMPARE(input()->isSelectingWindow(), false);
QCOMPARE(point, input()->globalPointer().toPoint());
QCOMPARE(input()->pointer()->window().data(), client);
QCOMPARE(input()->pointer()->focus().data(), client);
// should give back keyboard and pointer
QVERIFY(pointerEnteredSpy.wait());
if (keyboardEnteredSpy.count() != 2) {
Expand Down
Loading

0 comments on commit 2e29711

Please sign in to comment.