From e0062f675dcf0e0da60bf66f44b32afff406c649 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Mon, 20 Feb 2023 23:36:45 +0200 Subject: [PATCH] Port away from QRectF::contains() QRectF::contains() considers right and bottom edges inside the rectangle, but the relevant code has the opposite expectations. --- .../integration/decoration_input_test.cpp | 2 +- .../integration/move_resize_window_test.cpp | 2 +- .../integration/pointer_constraints_test.cpp | 6 ++-- autotests/integration/pointer_input.cpp | 32 +++++++++---------- .../integration/window_selection_test.cpp | 2 +- autotests/integration/xwayland_input_test.cpp | 4 +-- src/activation.cpp | 2 +- .../screenshot/screenshotdbusinterface1.cpp | 2 +- src/events.cpp | 2 +- src/libkwineffects/kwineffects.cpp | 2 +- src/plugins/screencast/screencaststream.cpp | 8 ++--- src/popup_input_filter.cpp | 4 +-- src/screenedge.cpp | 2 +- src/tiles/tilemanager.cpp | 2 +- 14 files changed, 36 insertions(+), 36 deletions(-) diff --git a/autotests/integration/decoration_input_test.cpp b/autotests/integration/decoration_input_test.cpp index 7be7da1d9f..c41d240c2c 100644 --- a/autotests/integration/decoration_input_test.cpp +++ b/autotests/integration/decoration_input_test.cpp @@ -516,7 +516,7 @@ void DecorationInputTest::testResizeOutsideWindow() default: break; } - QVERIFY(!window->frameGeometry().contains(KWin::Cursors::self()->mouse()->pos())); + QVERIFY(!exclusiveContains(window->frameGeometry(), KWin::Cursors::self()->mouse()->pos())); // pressing should trigger resize PRESS; diff --git a/autotests/integration/move_resize_window_test.cpp b/autotests/integration/move_resize_window_test.cpp index 898ab7acb2..fa6e2c0e14 100644 --- a/autotests/integration/move_resize_window_test.cpp +++ b/autotests/integration/move_resize_window_test.cpp @@ -621,7 +621,7 @@ void MoveResizeWindowTest::testNetMove() // let's move the cursor outside the window input()->pointer()->warp(workspace()->activeOutput()->geometry().center()); - QVERIFY(!origGeo.contains(Cursors::self()->mouse()->pos())); + QVERIFY(!exclusiveContains(origGeo, Cursors::self()->mouse()->pos())); QSignalSpy moveStartSpy(window, &X11Window::clientStartUserMovedResized); QSignalSpy moveEndSpy(window, &X11Window::clientFinishUserMovedResized); diff --git a/autotests/integration/pointer_constraints_test.cpp b/autotests/integration/pointer_constraints_test.cpp index 4cc62b6292..ebdc33eb32 100644 --- a/autotests/integration/pointer_constraints_test.cpp +++ b/autotests/integration/pointer_constraints_test.cpp @@ -132,7 +132,7 @@ void TestPointerConstraints::testConfinedPointer() if (window->pos() == QPoint(0, 0)) { window->move(QPoint(1, 1)); } - QVERIFY(!window->frameGeometry().contains(KWin::Cursors::self()->mouse()->pos())); + QVERIFY(!exclusiveContains(window->frameGeometry(), KWin::Cursors::self()->mouse()->pos())); // now let's confine QCOMPARE(input()->pointer()->isConstrained(), false); @@ -281,7 +281,7 @@ void TestPointerConstraints::testLockedPointer() // now map the window auto window = Test::renderAndWaitForShown(surface.get(), QSize(100, 100), Qt::blue); QVERIFY(window); - QVERIFY(!window->frameGeometry().contains(KWin::Cursors::self()->mouse()->pos())); + QVERIFY(!exclusiveContains(window->frameGeometry(), KWin::Cursors::self()->mouse()->pos())); // now let's lock QCOMPARE(input()->pointer()->isConstrained(), false); @@ -343,7 +343,7 @@ void TestPointerConstraints::testCloseWindowWithLockedPointer() // now map the window auto window = Test::renderAndWaitForShown(surface.get(), QSize(100, 100), Qt::blue); QVERIFY(window); - QVERIFY(!window->frameGeometry().contains(KWin::Cursors::self()->mouse()->pos())); + QVERIFY(!exclusiveContains(window->frameGeometry(), KWin::Cursors::self()->mouse()->pos())); // now let's lock QCOMPARE(input()->pointer()->isConstrained(), false); diff --git a/autotests/integration/pointer_input.cpp b/autotests/integration/pointer_input.cpp index f882f76b41..1d5e603d91 100644 --- a/autotests/integration/pointer_input.cpp +++ b/autotests/integration/pointer_input.cpp @@ -285,7 +285,7 @@ void PointerInputTest::testWarpingDuringFilter() QVERIFY(window); QCOMPARE(window->pos(), QPoint(0, 0)); - QVERIFY(window->frameGeometry().contains(Cursors::self()->mouse()->pos())); + QVERIFY(exclusiveContains(window->frameGeometry(), Cursors::self()->mouse()->pos())); // is WindowView effect for top left screen edge loaded QVERIFY(static_cast(effects)->isEffectLoaded("windowview")); @@ -365,13 +365,13 @@ void PointerInputTest::testUpdateFocusAfterScreenChange() QVERIFY(windowAddedSpy.wait()); Window *window = workspace()->activeWindow(); QVERIFY(window); - QVERIFY(window->frameGeometry().contains(Cursors::self()->mouse()->pos())); + QVERIFY(exclusiveContains(window->frameGeometry(), Cursors::self()->mouse()->pos())); QVERIFY(enteredSpy.wait()); QCOMPARE(enteredSpy.count(), 1); // move the cursor to the second screen input()->pointer()->warp(QPointF(1500, 300)); - QVERIFY(!window->frameGeometry().contains(Cursors::self()->mouse()->pos())); + QVERIFY(!exclusiveContains(window->frameGeometry(), Cursors::self()->mouse()->pos())); QVERIFY(leftSpy.wait()); // now let's remove the screen containing the cursor @@ -382,7 +382,7 @@ void PointerInputTest::testUpdateFocusAfterScreenChange() // this should have warped the cursor QCOMPARE(Cursors::self()->mouse()->pos(), QPoint(639, 511)); - QVERIFY(window->frameGeometry().contains(Cursors::self()->mouse()->pos())); + QVERIFY(exclusiveContains(window->frameGeometry(), Cursors::self()->mouse()->pos())); // and we should get an enter event QVERIFY(enteredSpy.wait()); @@ -919,8 +919,8 @@ void PointerInputTest::testFocusFollowsMouse() QVERIFY(window2->isActive()); // move on top of first window - QVERIFY(window1->frameGeometry().contains(10, 10)); - QVERIFY(!window2->frameGeometry().contains(10, 10)); + QVERIFY(exclusiveContains(window1->frameGeometry(), QPointF(10, 10))); + QVERIFY(!exclusiveContains(window2->frameGeometry(), QPointF(10, 10))); input()->pointer()->warp(QPointF(10, 10)); QVERIFY(stackingOrderChangedSpy.wait()); QCOMPARE(stackingOrderChangedSpy.count(), 1); @@ -1001,8 +1001,8 @@ void PointerInputTest::testMouseActionInactiveWindow() QVERIFY(window2->isActive()); // move on top of first window - QVERIFY(window1->frameGeometry().contains(10, 10)); - QVERIFY(!window2->frameGeometry().contains(10, 10)); + QVERIFY(exclusiveContains(window1->frameGeometry(), QPointF(10, 10))); + QVERIFY(!exclusiveContains(window2->frameGeometry(), QPointF(10, 10))); input()->pointer()->warp(QPointF(10, 10)); // no focus follows mouse QVERIFY(!stackingOrderChangedSpy.wait(200)); @@ -1088,8 +1088,8 @@ void PointerInputTest::testMouseActionActiveWindow() QSignalSpy stackingOrderChangedSpy(workspace(), &Workspace::stackingOrderChanged); // move on top of second window - QVERIFY(!window1->frameGeometry().contains(900, 900)); - QVERIFY(window2->frameGeometry().contains(900, 900)); + QVERIFY(!exclusiveContains(window1->frameGeometry(), QPointF(900, 900))); + QVERIFY(exclusiveContains(window2->frameGeometry(), QPointF(900, 900))); input()->pointer()->warp(QPointF(900, 900)); // and click @@ -1246,7 +1246,7 @@ void PointerInputTest::testEffectOverrideCursorImage() QVERIFY(window); // and move cursor to the window - QVERIFY(!window->frameGeometry().contains(QPoint(800, 800))); + QVERIFY(!exclusiveContains(window->frameGeometry(), QPoint(800, 800))); input()->pointer()->warp(window->frameGeometry().center()); QVERIFY(enteredSpy.wait()); // cursor image should still be fallback @@ -1316,7 +1316,7 @@ void PointerInputTest::testPopup() QVERIFY(window); QCOMPARE(window->hasPopupGrab(), false); // move pointer into window - QVERIFY(!window->frameGeometry().contains(QPoint(800, 800))); + QVERIFY(!exclusiveContains(window->frameGeometry(), QPoint(800, 800))); input()->pointer()->warp(window->frameGeometry().center()); QVERIFY(enteredSpy.wait()); // click inside window to create serial @@ -1397,7 +1397,7 @@ void PointerInputTest::testDecoCancelsPopup() QVERIFY(window->isDecorated()); // move pointer into window - QVERIFY(!window->frameGeometry().contains(QPoint(800, 800))); + QVERIFY(!exclusiveContains(window->frameGeometry(), QPoint(800, 800))); input()->pointer()->warp(window->frameGeometry().center()); QVERIFY(enteredSpy.wait()); // click inside window to create serial @@ -1459,7 +1459,7 @@ void PointerInputTest::testWindowUnderCursorWhileButtonPressed() QVERIFY(window); // move cursor over window - QVERIFY(!window->frameGeometry().contains(QPoint(800, 800))); + QVERIFY(!exclusiveContains(window->frameGeometry(), QPoint(800, 800))); input()->pointer()->warp(window->frameGeometry().center()); QVERIFY(enteredSpy.wait()); // click inside window @@ -1481,8 +1481,8 @@ void PointerInputTest::testWindowUnderCursorWhileButtonPressed() auto popupWindow = windowAddedSpy.last().first().value(); QVERIFY(popupWindow); QVERIFY(popupWindow != window); - QVERIFY(window->frameGeometry().contains(Cursors::self()->mouse()->pos())); - QVERIFY(popupWindow->frameGeometry().contains(Cursors::self()->mouse()->pos())); + QVERIFY(exclusiveContains(window->frameGeometry(), Cursors::self()->mouse()->pos())); + QVERIFY(exclusiveContains(popupWindow->frameGeometry(), Cursors::self()->mouse()->pos())); QVERIFY(!leftSpy.wait()); Test::pointerButtonReleased(BTN_LEFT, timestamp++); diff --git a/autotests/integration/window_selection_test.cpp b/autotests/integration/window_selection_test.cpp index f907afa79c..67a405fd86 100644 --- a/autotests/integration/window_selection_test.cpp +++ b/autotests/integration/window_selection_test.cpp @@ -176,7 +176,7 @@ void TestWindowSelection::testSelectOnWindowKeyboard() auto window = Test::renderAndWaitForShown(surface.get(), QSize(100, 50), Qt::blue); QVERIFY(window); QVERIFY(keyboardEnteredSpy.wait()); - QVERIFY(!window->frameGeometry().contains(KWin::Cursors::self()->mouse()->pos())); + QVERIFY(!exclusiveContains(window->frameGeometry(), KWin::Cursors::self()->mouse()->pos())); Window *selectedWindow = nullptr; auto callback = [&selectedWindow](Window *t) { diff --git a/autotests/integration/xwayland_input_test.cpp b/autotests/integration/xwayland_input_test.cpp index f36acece0c..49eba1850d 100644 --- a/autotests/integration/xwayland_input_test.cpp +++ b/autotests/integration/xwayland_input_test.cpp @@ -163,7 +163,7 @@ void XWaylandInputTest::testPointerEnterLeaveSsd() QVERIFY(Test::waitForWaylandSurface(window)); // move pointer into the window, should trigger an enter - QVERIFY(!window->frameGeometry().contains(Cursors::self()->mouse()->pos())); + QVERIFY(!exclusiveContains(window->frameGeometry(), Cursors::self()->mouse()->pos())); QVERIFY(enteredSpy.isEmpty()); input()->pointer()->warp(window->frameGeometry().center().toPoint()); QCOMPARE(waylandServer()->seat()->focusedPointerSurface(), window->surface()); @@ -251,7 +251,7 @@ void XWaylandInputTest::testPointerEventLeaveCsd() QVERIFY(Test::waitForWaylandSurface(window)); // Move pointer into the window, should trigger an enter. - QVERIFY(!window->frameGeometry().contains(Cursors::self()->mouse()->pos())); + QVERIFY(!exclusiveContains(window->frameGeometry(), Cursors::self()->mouse()->pos())); QVERIFY(enteredSpy.isEmpty()); input()->pointer()->warp(window->frameGeometry().center().toPoint()); QCOMPARE(waylandServer()->seat()->focusedPointerSurface(), window->surface()); diff --git a/src/activation.cpp b/src/activation.cpp index cf37db68e5..2055384400 100644 --- a/src/activation.cpp +++ b/src/activation.cpp @@ -441,7 +441,7 @@ Window *Workspace::windowUnderMouse(Output *output) const continue; } - if (window->frameGeometry().contains(Cursors::self()->mouse()->pos())) { + if (exclusiveContains(window->frameGeometry(), Cursors::self()->mouse()->pos())) { return window; } } diff --git a/src/effects/screenshot/screenshotdbusinterface1.cpp b/src/effects/screenshot/screenshotdbusinterface1.cpp index 4d0cf93417..959140ce06 100644 --- a/src/effects/screenshot/screenshotdbusinterface1.cpp +++ b/src/effects/screenshot/screenshotdbusinterface1.cpp @@ -549,7 +549,7 @@ void ScreenShotDBusInterface1::screenshotWindowUnderCursor(int mask) if (hoveredWindow->isOnCurrentDesktop() && !hoveredWindow->isMinimized() && !hoveredWindow->isDeleted() - && hoveredWindow->frameGeometry().contains(cursor)) { + && exclusiveContains(hoveredWindow->frameGeometry(), cursor)) { break; } hoveredWindow = nullptr; diff --git a/src/events.cpp b/src/events.cpp index b691c91853..2747a37751 100644 --- a/src/events.cpp +++ b/src/events.cpp @@ -718,7 +718,7 @@ void X11Window::leaveNotifyEvent(xcb_leave_notify_event_t *e) setInteractiveMoveResizeGravity(Gravity::None); updateCursor(); } - bool lostMouse = !rect().contains(QPoint(e->event_x, e->event_y)); + bool lostMouse = !exclusiveContains(rect(), QPointF(e->event_x, e->event_y)); // 'lostMouse' wouldn't work with e.g. B2 or Keramik, which have non-rectangular decorations // (i.e. the LeaveNotify event comes before leaving the rect and no LeaveNotify event // comes after leaving the rect) - so lets check if the pointer is really outside the window diff --git a/src/libkwineffects/kwineffects.cpp b/src/libkwineffects/kwineffects.cpp index cf6f5b2921..576e40fa76 100644 --- a/src/libkwineffects/kwineffects.cpp +++ b/src/libkwineffects/kwineffects.cpp @@ -1361,7 +1361,7 @@ EffectWindow *WindowMotionManager::windowAtPoint(QPoint point, bool useStackingO // TODO: Stacking order uses EffectsHandler::stackingOrder() then filters by m_managedWindows QHash::ConstIterator it = m_managedWindows.constBegin(); while (it != m_managedWindows.constEnd()) { - if (transformedGeometry(it.key()).contains(point)) { + if (exclusiveContains(transformedGeometry(it.key()), point)) { return it.key(); } ++it; diff --git a/src/plugins/screencast/screencaststream.cpp b/src/plugins/screencast/screencaststream.cpp index 1672b13f49..8af91c0112 100644 --- a/src/plugins/screencast/screencaststream.cpp +++ b/src/plugins/screencast/screencaststream.cpp @@ -443,7 +443,7 @@ void ScreenCastStream::recordFrame(const QRegion &_damagedRegion) m_source->render(&dest); auto cursor = Cursors::self()->currentCursor(); - if (m_cursor.mode == KWaylandServer::ScreencastV1Interface::Embedded && m_cursor.viewport.contains(cursor->pos())) { + if (m_cursor.mode == KWaylandServer::ScreencastV1Interface::Embedded && exclusiveContains(m_cursor.viewport, cursor->pos())) { QPainter painter(&dest); const auto position = (cursor->pos() - m_cursor.viewport.topLeft() - cursor->hotspot()) * m_cursor.scale; painter.drawImage(QRect{position.toPoint(), cursor->image().size()}, cursor->image()); @@ -463,7 +463,7 @@ void ScreenCastStream::recordFrame(const QRegion &_damagedRegion) m_source->render(buf->framebuffer()); auto cursor = Cursors::self()->currentCursor(); - if (m_cursor.mode == KWaylandServer::ScreencastV1Interface::Embedded && m_cursor.viewport.contains(cursor->pos())) { + if (m_cursor.mode == KWaylandServer::ScreencastV1Interface::Embedded && exclusiveContains(m_cursor.viewport, cursor->pos())) { if (!cursor->image().isNull()) { GLFramebuffer::pushFramebuffer(buf->framebuffer()); @@ -573,7 +573,7 @@ void ScreenCastStream::recordCursor() return; } - if (!m_cursor.viewport.contains(Cursors::self()->currentCursor()->pos()) && !m_cursor.visible) { + if (!exclusiveContains(m_cursor.viewport, Cursors::self()->currentCursor()->pos()) && !m_cursor.visible) { return; } @@ -708,7 +708,7 @@ void ScreenCastStream::sendCursorData(Cursor *cursor, spa_meta_cursor *spa_meta_ return; } - if (!m_cursor.viewport.contains(cursor->pos())) { + if (!exclusiveContains(m_cursor.viewport, cursor->pos())) { spa_meta_cursor->id = 0; spa_meta_cursor->position.x = -1; spa_meta_cursor->position.y = -1; diff --git a/src/popup_input_filter.cpp b/src/popup_input_filter.cpp index b84cabebab..9c1ec869fa 100644 --- a/src/popup_input_filter.cpp +++ b/src/popup_input_filter.cpp @@ -56,7 +56,7 @@ bool PopupInputFilter::pointerEvent(MouseEvent *event, quint32 nativeButton) } if (pointerFocus && pointerFocus->isDecorated()) { // test whether it is on the decoration - if (!pointerFocus->clientGeometry().contains(event->globalPos())) { + if (!exclusiveContains(pointerFocus->clientGeometry(), event->globalPos())) { cancelPopups(); return true; } @@ -101,7 +101,7 @@ bool PopupInputFilter::touchDown(qint32 id, const QPointF &pos, std::chrono::mic } if (pointerFocus && pointerFocus->isDecorated()) { // test whether it is on the decoration - if (!pointerFocus->clientGeometry().contains(pos)) { + if (!exclusiveContains(pointerFocus->clientGeometry(), pos)) { cancelPopups(); return true; } diff --git a/src/screenedge.cpp b/src/screenedge.cpp index dec4fd3825..be85062de7 100644 --- a/src/screenedge.cpp +++ b/src/screenedge.cpp @@ -573,7 +573,7 @@ void Edge::setGeometry(const QRect &geometry) void Edge::checkBlocking() { Window *client = Workspace::self()->activeWindow(); - const bool newValue = !m_edges->remainActiveOnFullscreen() && client && client->isFullScreen() && client->frameGeometry().contains(m_geometry.center()) && !(effects && effects->hasActiveFullScreenEffect()); + const bool newValue = !m_edges->remainActiveOnFullscreen() && client && client->isFullScreen() && exclusiveContains(client->frameGeometry(), m_geometry.center()) && !(effects && effects->hasActiveFullScreenEffect()); if (newValue == m_blocked) { return; } diff --git a/src/tiles/tilemanager.cpp b/src/tiles/tilemanager.cpp index 9371124516..c65d283015 100644 --- a/src/tiles/tilemanager.cpp +++ b/src/tiles/tilemanager.cpp @@ -93,7 +93,7 @@ Tile *TileManager::bestTileForPosition(const QPointF &pos) const auto r = t->absoluteGeometry(); // It's possible for tiles to overlap, so take the one which center is nearer to mouse pos qreal distance = (r.center() - pos).manhattanLength(); - if (!r.contains(pos)) { + if (!exclusiveContains(r, pos)) { // This gives a strong preference for tiles that contain the point // still base on distance though as floating tiles can overlap distance += m_output->fractionalGeometry().width();