Port away from QRectF::contains()

QRectF::contains() considers right and bottom edges inside the
rectangle, but the relevant code has the opposite expectations.
This commit is contained in:
Vlad Zahorodnii 2023-02-20 23:36:45 +02:00
parent bae75abf6d
commit e0062f675d
14 changed files with 36 additions and 36 deletions

View file

@ -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;

View file

@ -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);

View file

@ -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);

View file

@ -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<EffectsHandlerImpl *>(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<Window *>();
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++);

View file

@ -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) {

View file

@ -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());

View file

@ -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;
}
}

View file

@ -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;

View file

@ -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

View file

@ -1361,7 +1361,7 @@ EffectWindow *WindowMotionManager::windowAtPoint(QPoint point, bool useStackingO
// TODO: Stacking order uses EffectsHandler::stackingOrder() then filters by m_managedWindows
QHash<EffectWindow *, WindowMotion>::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;

View file

@ -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;

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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();