diff --git a/autotests/integration/pointer_constraints_test.cpp b/autotests/integration/pointer_constraints_test.cpp index 17a710249..c80557352 100644 --- a/autotests/integration/pointer_constraints_test.cpp +++ b/autotests/integration/pointer_constraints_test.cpp @@ -211,7 +211,7 @@ void TestPointerConstraints::testConfinedPointer() QVERIFY(unconfinedSpy2.isValid()); // activate it again, this confines again - workspace()->activateClient(static_cast(input()->pointer()->focus().data())); + workspace()->activateClient(static_cast(input()->pointer()->focus())); QVERIFY(confinedSpy2.wait()); QCOMPARE(input()->pointer()->isConstrained(), true); @@ -220,7 +220,7 @@ void TestPointerConstraints::testConfinedPointer() QVERIFY(unconfinedSpy2.wait()); QCOMPARE(input()->pointer()->isConstrained(), false); // activate it again, this confines again - workspace()->activateClient(static_cast(input()->pointer()->focus().data())); + workspace()->activateClient(static_cast(input()->pointer()->focus())); QVERIFY(confinedSpy2.wait()); QCOMPARE(input()->pointer()->isConstrained(), true); @@ -325,7 +325,7 @@ void TestPointerConstraints::testLockedPointer() QVERIFY(lockedSpy2.isValid()); // activate the client again, this should lock again - workspace()->activateClient(static_cast(input()->pointer()->focus().data())); + workspace()->activateClient(static_cast(input()->pointer()->focus())); QVERIFY(lockedSpy2.wait()); QCOMPARE(input()->pointer()->isConstrained(), true); diff --git a/autotests/integration/pointer_input.cpp b/autotests/integration/pointer_input.cpp index d745c9e32..63f27ade3 100644 --- a/autotests/integration/pointer_input.cpp +++ b/autotests/integration/pointer_input.cpp @@ -1003,7 +1003,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->frameGeometry().center()); - QCOMPARE(p->focus().data(), window); + QCOMPARE(p->focus(), window); QCOMPARE(cursor->image(), fallbackCursor); QVERIFY(enteredSpy.wait()); @@ -1058,7 +1058,7 @@ void PointerInputTest::testCursorImage() // move cursor somewhere else, should reset to fallback cursor Cursors::self()->mouse()->setPos(window->frameGeometry().bottomLeft() + QPoint(20, 20)); - QVERIFY(p->focus().isNull()); + QVERIFY(!p->focus()); QVERIFY(!cursor->image().isNull()); QCOMPARE(cursor->image(), fallbackCursor); } diff --git a/autotests/integration/window_selection_test.cpp b/autotests/integration/window_selection_test.cpp index d29337593..91c3ac23b 100644 --- a/autotests/integration/window_selection_test.cpp +++ b/autotests/integration/window_selection_test.cpp @@ -102,7 +102,7 @@ void TestWindowSelection::testSelectOnWindowPointer() QVERIFY(client); QVERIFY(keyboardEnteredSpy.wait()); KWin::Cursors::self()->mouse()->setPos(client->frameGeometry().center()); - QCOMPARE(input()->pointer()->focus().data(), client); + QCOMPARE(input()->pointer()->focus(), client); QVERIFY(pointerEnteredSpy.wait()); Toplevel *selectedWindow = nullptr; @@ -129,11 +129,11 @@ void TestWindowSelection::testSelectOnWindowPointer() // should not have ended the mode QCOMPARE(input()->isSelectingWindow(), true); QVERIFY(!selectedWindow); - QVERIFY(input()->pointer()->focus().isNull()); + QVERIFY(!input()->pointer()->focus()); // updating the pointer should not change anything input()->pointer()->update(); - QVERIFY(input()->pointer()->focus().isNull()); + QVERIFY(!input()->pointer()->focus()); // updating keyboard should also not change input()->keyboard()->update(); @@ -147,7 +147,7 @@ void TestWindowSelection::testSelectOnWindowPointer() kwinApp()->platform()->pointerButtonReleased(BTN_LEFT, timestamp++); QCOMPARE(input()->isSelectingWindow(), false); QCOMPARE(selectedWindow, client); - QCOMPARE(input()->pointer()->focus().data(), client); + QCOMPARE(input()->pointer()->focus(), client); // should give back keyboard and pointer QVERIFY(pointerEnteredSpy.wait()); if (keyboardEnteredSpy.count() != 2) { @@ -227,7 +227,7 @@ void TestWindowSelection::testSelectOnWindowKeyboard() kwinApp()->platform()->keyboardKeyPressed(key, timestamp++); QCOMPARE(input()->isSelectingWindow(), false); QCOMPARE(selectedWindow, client); - QCOMPARE(input()->pointer()->focus().data(), client); + QCOMPARE(input()->pointer()->focus(), client); // should give back keyboard and pointer QVERIFY(pointerEnteredSpy.wait()); if (keyboardEnteredSpy.count() != 2) { @@ -323,7 +323,7 @@ void TestWindowSelection::testCancelOnWindowPointer() QVERIFY(client); QVERIFY(keyboardEnteredSpy.wait()); KWin::Cursors::self()->mouse()->setPos(client->frameGeometry().center()); - QCOMPARE(input()->pointer()->focus().data(), client); + QCOMPARE(input()->pointer()->focus(), client); QVERIFY(pointerEnteredSpy.wait()); Toplevel *selectedWindow = nullptr; @@ -350,7 +350,7 @@ void TestWindowSelection::testCancelOnWindowPointer() kwinApp()->platform()->pointerButtonReleased(BTN_RIGHT, timestamp++); QCOMPARE(input()->isSelectingWindow(), false); QVERIFY(!selectedWindow); - QCOMPARE(input()->pointer()->focus().data(), client); + QCOMPARE(input()->pointer()->focus(), client); // should give back keyboard and pointer QVERIFY(pointerEnteredSpy.wait()); if (keyboardEnteredSpy.count() != 2) { @@ -382,7 +382,7 @@ void TestWindowSelection::testCancelOnWindowKeyboard() QVERIFY(client); QVERIFY(keyboardEnteredSpy.wait()); KWin::Cursors::self()->mouse()->setPos(client->frameGeometry().center()); - QCOMPARE(input()->pointer()->focus().data(), client); + QCOMPARE(input()->pointer()->focus(), client); QVERIFY(pointerEnteredSpy.wait()); Toplevel *selectedWindow = nullptr; @@ -408,7 +408,7 @@ void TestWindowSelection::testCancelOnWindowKeyboard() kwinApp()->platform()->keyboardKeyPressed(KEY_ESC, timestamp++); QCOMPARE(input()->isSelectingWindow(), false); QVERIFY(!selectedWindow); - QCOMPARE(input()->pointer()->focus().data(), client); + QCOMPARE(input()->pointer()->focus(), client); // should give back keyboard and pointer QVERIFY(pointerEnteredSpy.wait()); if (keyboardEnteredSpy.count() != 2) { @@ -441,7 +441,7 @@ void TestWindowSelection::testSelectPointPointer() QVERIFY(client); QVERIFY(keyboardEnteredSpy.wait()); KWin::Cursors::self()->mouse()->setPos(client->frameGeometry().center()); - QCOMPARE(input()->pointer()->focus().data(), client); + QCOMPARE(input()->pointer()->focus(), client); QVERIFY(pointerEnteredSpy.wait()); QPoint point; @@ -475,11 +475,11 @@ void TestWindowSelection::testSelectPointPointer() // should not have ended the mode QCOMPARE(input()->isSelectingWindow(), true); QCOMPARE(point, QPoint()); - QVERIFY(input()->pointer()->focus().isNull()); + QVERIFY(!input()->pointer()->focus()); // updating the pointer should not change anything input()->pointer()->update(); - QVERIFY(input()->pointer()->focus().isNull()); + QVERIFY(!input()->pointer()->focus()); // updating keyboard should also not change input()->keyboard()->update(); @@ -493,7 +493,7 @@ void TestWindowSelection::testSelectPointPointer() kwinApp()->platform()->pointerButtonReleased(BTN_LEFT, timestamp++); QCOMPARE(input()->isSelectingWindow(), false); QCOMPARE(point, input()->globalPointer().toPoint()); - QCOMPARE(input()->pointer()->focus().data(), client); + QCOMPARE(input()->pointer()->focus(), client); // should give back keyboard and pointer QVERIFY(pointerEnteredSpy.wait()); if (keyboardEnteredSpy.count() != 2) { diff --git a/input.cpp b/input.cpp index 680576521..4211ae32c 100644 --- a/input.cpp +++ b/input.cpp @@ -1318,7 +1318,7 @@ public: if (event->type() != QEvent::MouseButtonPress) { return false; } - AbstractClient *c = dynamic_cast(input()->pointer()->focus().data()); + AbstractClient *c = dynamic_cast(input()->pointer()->focus()); if (!c) { return false; } @@ -1333,7 +1333,7 @@ public: // only actions on vertical scroll return false; } - AbstractClient *c = dynamic_cast(input()->pointer()->focus().data()); + AbstractClient *c = dynamic_cast(input()->pointer()->focus()); if (!c) { return false; } @@ -1350,7 +1350,7 @@ public: if (seat->isTouchSequence()) { return false; } - AbstractClient *c = dynamic_cast(input()->touch()->focus().data()); + AbstractClient *c = dynamic_cast(input()->touch()->focus()); if (!c) { return false; } @@ -2718,6 +2718,16 @@ void InputDeviceHandler::update() } } +Toplevel *InputDeviceHandler::at() const +{ + return m_at.at.data(); +} + +Toplevel *InputDeviceHandler::focus() const +{ + return m_focus.focus.data(); +} + QWindow* InputDeviceHandler::findInternalWindow(const QPoint &pos) const { if (waylandServer()->isScreenLocked()) { diff --git a/input.h b/input.h index 4e6c89976..18dc7f1aa 100644 --- a/input.h +++ b/input.h @@ -417,18 +417,19 @@ public: * @brief First Toplevel currently at the position of the input device * according to the stacking order. * @return Toplevel* at device position. + * + * This will be null if no toplevel is at the position */ - QPointer at() const { - return m_at.at; - } + Toplevel *at() const; /** * @brief Toplevel currently having pointer input focus (this might * be different from the Toplevel at the position of the pointer). * @return Toplevel* with pointer focus. + * + * This will be null if no toplevel has focus */ - QPointer focus() const { - return m_focus.focus; - } + Toplevel *focus() const; + /** * @brief The Decoration currently receiving events. * @return decoration with pointer focus. diff --git a/pointer_input.cpp b/pointer_input.cpp index c1eccf9d4..289fe20bb 100644 --- a/pointer_input.cpp +++ b/pointer_input.cpp @@ -179,7 +179,7 @@ void PointerInputRedirection::updateToReset() setDecoration(nullptr); } if (focus()) { - if (AbstractClient *c = qobject_cast(focus().data())) { + if (AbstractClient *c = qobject_cast(focus())) { c->leaveEvent(); } disconnect(m_focusGeometryConnection); @@ -636,7 +636,7 @@ void PointerInputRedirection::setEnableConstraints(bool set) void PointerInputRedirection::updatePointerConstraints() { - if (focus().isNull()) { + if (!focus()) { return; } const auto s = focus()->surface(); @@ -660,7 +660,7 @@ void PointerInputRedirection::updatePointerConstraints() } return; } - const QRegion r = getConstraintRegion(focus().data(), cf.data()); + const QRegion r = getConstraintRegion(focus(), cf.data()); if (canConstrain && r.contains(m_pos.toPoint())) { cf->setConfined(true); m_confined = true; @@ -674,7 +674,7 @@ void PointerInputRedirection::updatePointerConstraints() return; } const auto cf = s->confinedPointer(); - if (!getConstraintRegion(focus().data(), cf.data()).contains(m_pos.toPoint())) { + if (!getConstraintRegion(focus(), cf.data()).contains(m_pos.toPoint())) { // pointer no longer in confined region, break the confinement cf->setConfined(false); m_confined = false; @@ -706,7 +706,7 @@ void PointerInputRedirection::updatePointerConstraints() } return; } - const QRegion r = getConstraintRegion(focus().data(), lock.data()); + const QRegion r = getConstraintRegion(focus(), lock.data()); if (canConstrain && r.contains(m_pos.toPoint())) { lock->setLocked(true); m_locked = true; @@ -782,7 +782,7 @@ QPointF PointerInputRedirection::applyPointerConfinement(const QPointF &pos) con return pos; } - const QRegion confinementRegion = getConstraintRegion(focus().data(), cf.data()); + const QRegion confinementRegion = getConstraintRegion(focus(), cf.data()); if (confinementRegion.contains(pos.toPoint())) { return pos; } @@ -1338,7 +1338,7 @@ void CursorImage::reevaluteSource() setSource(CursorSource::Decoration); return; } - if (!m_pointer->focus().isNull() && waylandServer()->seat()->focusedPointer()) { + if (m_pointer->focus() && waylandServer()->seat()->focusedPointer()) { setSource(CursorSource::PointerSurface); return; } diff --git a/touch_input.cpp b/touch_input.cpp index 81346711f..5fdbac9a8 100644 --- a/touch_input.cpp +++ b/touch_input.cpp @@ -109,11 +109,11 @@ void TouchInputRedirection::focusUpdate(Toplevel *focusOld, Toplevel *focusNow) seat->setFocusedTouchSurface(focusNow->surface(), -1 * focusNow->inputTransformation().map(focusNow->pos()) + focusNow->pos()); m_focusGeometryConnection = connect(focusNow, &Toplevel::frameGeometryChanged, this, [this] { - if (focus().isNull()) { + if (!focus()) { return; } auto seat = waylandServer()->seat(); - if (focus().data()->surface() != seat->focusedTouchSurface()) { + if (focus()->surface() != seat->focusedTouchSurface()) { return; } seat->setFocusedTouchSurfacePosition(-1 * focus()->inputTransformation().map(focus()->pos()) + focus()->pos());