2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2016-03-03 12:32:50 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
|
2016-03-03 12:32:50 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2016-03-03 12:32:50 +00:00
|
|
|
#include "kwin_wayland_test.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
|
2022-08-29 07:55:49 +00:00
|
|
|
#include "core/output.h"
|
2023-02-09 13:07:56 +00:00
|
|
|
#include "pointer_input.h"
|
2023-09-13 05:52:59 +00:00
|
|
|
#include "wayland/seat.h"
|
|
|
|
#include "wayland/surface.h"
|
2016-03-03 12:32:50 +00:00
|
|
|
#include "wayland_server.h"
|
2022-04-22 17:39:12 +00:00
|
|
|
#include "window.h"
|
2016-03-03 12:32:50 +00:00
|
|
|
#include "workspace.h"
|
|
|
|
|
|
|
|
#include <KWayland/Client/compositor.h>
|
2022-03-23 10:13:38 +00:00
|
|
|
#include <KWayland/Client/connection_thread.h>
|
2016-03-03 12:32:50 +00:00
|
|
|
#include <KWayland/Client/event_queue.h>
|
|
|
|
#include <KWayland/Client/keyboard.h>
|
|
|
|
#include <KWayland/Client/pointer.h>
|
2022-03-23 10:13:38 +00:00
|
|
|
#include <KWayland/Client/registry.h>
|
2016-03-03 12:32:50 +00:00
|
|
|
#include <KWayland/Client/seat.h>
|
|
|
|
#include <KWayland/Client/shm_pool.h>
|
|
|
|
#include <KWayland/Client/surface.h>
|
|
|
|
#include <KWayland/Client/touch.h>
|
|
|
|
|
2023-07-03 19:28:19 +00:00
|
|
|
#include <QSignalSpy>
|
|
|
|
|
2021-05-11 05:26:51 +00:00
|
|
|
struct PopupLayout
|
|
|
|
{
|
|
|
|
QRect anchorRect;
|
|
|
|
QSize size;
|
|
|
|
quint32 anchor = 0;
|
|
|
|
quint32 gravity = 0;
|
|
|
|
quint32 constraint = 0;
|
|
|
|
};
|
|
|
|
Q_DECLARE_METATYPE(PopupLayout)
|
|
|
|
|
2016-03-03 12:32:50 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
static const QString s_socketName = QStringLiteral("wayland_test_kwin_transient_placement-0");
|
|
|
|
|
|
|
|
class TransientPlacementTest : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
private Q_SLOTS:
|
|
|
|
void initTestCase();
|
|
|
|
void init();
|
|
|
|
void cleanup();
|
2018-10-19 22:21:54 +00:00
|
|
|
void testXdgPopup_data();
|
|
|
|
void testXdgPopup();
|
2018-12-27 19:22:53 +00:00
|
|
|
void testXdgPopupWithPanel();
|
2016-03-03 12:32:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void TransientPlacementTest::initTestCase()
|
|
|
|
{
|
2022-04-22 17:39:12 +00:00
|
|
|
qRegisterMetaType<KWin::Window *>();
|
2020-07-07 09:32:29 +00:00
|
|
|
QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
|
2020-12-09 13:06:15 +00:00
|
|
|
QVERIFY(waylandServer()->init(s_socketName));
|
2023-05-08 10:16:00 +00:00
|
|
|
Test::setOutputConfig({
|
|
|
|
QRect(0, 0, 1280, 1024),
|
|
|
|
QRect(1280, 0, 1280, 1024),
|
|
|
|
});
|
2016-03-03 12:32:50 +00:00
|
|
|
|
|
|
|
kwinApp()->start();
|
2020-07-07 09:32:29 +00:00
|
|
|
QVERIFY(applicationStartedSpy.wait());
|
2022-07-11 10:41:15 +00:00
|
|
|
const auto outputs = workspace()->outputs();
|
2021-08-31 07:03:05 +00:00
|
|
|
QCOMPARE(outputs.count(), 2);
|
|
|
|
QCOMPARE(outputs[0]->geometry(), QRect(0, 0, 1280, 1024));
|
|
|
|
QCOMPARE(outputs[1]->geometry(), QRect(1280, 0, 1280, 1024));
|
2016-03-03 12:32:50 +00:00
|
|
|
setenv("QT_QPA_PLATFORM", "wayland", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransientPlacementTest::init()
|
|
|
|
{
|
2023-09-24 07:34:38 +00:00
|
|
|
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::LayerShellV1));
|
2016-03-03 12:32:50 +00:00
|
|
|
|
2021-08-28 18:58:29 +00:00
|
|
|
workspace()->setActiveOutput(QPoint(640, 512));
|
2023-02-09 13:07:56 +00:00
|
|
|
input()->pointer()->warp(QPoint(640, 512));
|
2016-03-03 12:32:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TransientPlacementTest::cleanup()
|
|
|
|
{
|
2016-06-30 11:32:54 +00:00
|
|
|
Test::destroyWaylandConnection();
|
2016-03-03 12:32:50 +00:00
|
|
|
}
|
|
|
|
|
2018-10-19 22:21:54 +00:00
|
|
|
void TransientPlacementTest::testXdgPopup_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QSize>("parentSize");
|
|
|
|
QTest::addColumn<QPoint>("parentPosition");
|
2021-05-11 05:26:51 +00:00
|
|
|
QTest::addColumn<PopupLayout>("layout");
|
2018-10-19 22:21:54 +00:00
|
|
|
QTest::addColumn<QRect>("expectedGeometry");
|
|
|
|
|
|
|
|
// parent window is 500,500, starting at 300,300, anchorRect is therefore between 350->750 in both dirs
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------
|
2021-05-11 05:26:51 +00:00
|
|
|
// window in the middle, plenty of room either side: Changing anchor
|
2018-10-19 22:21:54 +00:00
|
|
|
|
2023-03-02 08:53:54 +00:00
|
|
|
const PopupLayout layoutNone{
|
|
|
|
.anchorRect = QRect(50, 50, 400, 400),
|
|
|
|
.size = QSize(200, 200),
|
|
|
|
.anchor = Test::XdgPositioner::anchor_top_left,
|
|
|
|
.gravity = Test::XdgPositioner::gravity_top_left,
|
|
|
|
};
|
|
|
|
QTest::newRow("no constraint adjustments") << QSize(500, 500) << QPoint(0, 0) << layoutNone << QRect(50 - 200, 50 - 200, 200, 200);
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
const PopupLayout layoutAnchorCenter{
|
2021-05-11 05:26:51 +00:00
|
|
|
.anchorRect = QRect(50, 50, 400, 400),
|
|
|
|
.size = QSize(200, 200),
|
|
|
|
.anchor = Test::XdgPositioner::anchor_none,
|
|
|
|
.gravity = Test::XdgPositioner::gravity_bottom_right,
|
|
|
|
};
|
2022-03-23 10:13:38 +00:00
|
|
|
QTest::newRow("anchorCentre") << QSize(500, 500) << QPoint(300, 300) << layoutAnchorCenter << QRect(550, 550, 200, 200);
|
2021-05-11 05:26:51 +00:00
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
const PopupLayout layoutAnchorTopLeft{
|
2021-05-11 05:26:51 +00:00
|
|
|
.anchorRect = QRect(50, 50, 400, 400),
|
|
|
|
.size = QSize(200, 200),
|
|
|
|
.anchor = Test::XdgPositioner::anchor_top_left,
|
|
|
|
.gravity = Test::XdgPositioner::gravity_bottom_right,
|
|
|
|
};
|
2022-03-23 10:13:38 +00:00
|
|
|
QTest::newRow("anchorTopLeft") << QSize(500, 500) << QPoint(300, 300) << layoutAnchorTopLeft << QRect(350, 350, 200, 200);
|
2021-05-11 05:26:51 +00:00
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
const PopupLayout layoutAnchorTop{
|
2021-05-11 05:26:51 +00:00
|
|
|
.anchorRect = QRect(50, 50, 400, 400),
|
|
|
|
.size = QSize(200, 200),
|
|
|
|
.anchor = Test::XdgPositioner::anchor_top,
|
|
|
|
.gravity = Test::XdgPositioner::gravity_bottom_right,
|
|
|
|
};
|
2022-03-23 10:13:38 +00:00
|
|
|
QTest::newRow("anchorTop") << QSize(500, 500) << QPoint(300, 300) << layoutAnchorTop << QRect(550, 350, 200, 200);
|
2021-05-11 05:26:51 +00:00
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
const PopupLayout layoutAnchorTopRight{
|
2021-05-11 05:26:51 +00:00
|
|
|
.anchorRect = QRect(50, 50, 400, 400),
|
|
|
|
.size = QSize(200, 200),
|
|
|
|
.anchor = Test::XdgPositioner::anchor_top_right,
|
|
|
|
.gravity = Test::XdgPositioner::gravity_bottom_right,
|
|
|
|
};
|
2022-03-23 10:13:38 +00:00
|
|
|
QTest::newRow("anchorTopRight") << QSize(500, 500) << QPoint(300, 300) << layoutAnchorTopRight << QRect(750, 350, 200, 200);
|
2021-05-11 05:26:51 +00:00
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
const PopupLayout layoutAnchorRight{
|
2021-05-11 05:26:51 +00:00
|
|
|
.anchorRect = QRect(50, 50, 400, 400),
|
|
|
|
.size = QSize(200, 200),
|
|
|
|
.anchor = Test::XdgPositioner::anchor_right,
|
|
|
|
.gravity = Test::XdgPositioner::gravity_bottom_right,
|
|
|
|
};
|
2022-03-23 10:13:38 +00:00
|
|
|
QTest::newRow("anchorRight") << QSize(500, 500) << QPoint(300, 300) << layoutAnchorRight << QRect(750, 550, 200, 200);
|
2021-05-11 05:26:51 +00:00
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
const PopupLayout layoutAnchorBottomRight{
|
2021-05-11 05:26:51 +00:00
|
|
|
.anchorRect = QRect(50, 50, 400, 400),
|
|
|
|
.size = QSize(200, 200),
|
|
|
|
.anchor = Test::XdgPositioner::anchor_bottom_right,
|
|
|
|
.gravity = Test::XdgPositioner::gravity_bottom_right,
|
|
|
|
};
|
2022-03-23 10:13:38 +00:00
|
|
|
QTest::newRow("anchorBottomRight") << QSize(500, 500) << QPoint(300, 300) << layoutAnchorBottomRight << QRect(750, 750, 200, 200);
|
2021-05-11 05:26:51 +00:00
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
const PopupLayout layoutAnchorBottom{
|
2021-05-11 05:26:51 +00:00
|
|
|
.anchorRect = QRect(50, 50, 400, 400),
|
|
|
|
.size = QSize(200, 200),
|
|
|
|
.anchor = Test::XdgPositioner::anchor_bottom,
|
|
|
|
.gravity = Test::XdgPositioner::gravity_bottom_right,
|
|
|
|
};
|
2022-03-23 10:13:38 +00:00
|
|
|
QTest::newRow("anchorBottom") << QSize(500, 500) << QPoint(300, 300) << layoutAnchorBottom << QRect(550, 750, 200, 200);
|
2021-05-11 05:26:51 +00:00
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
const PopupLayout layoutAnchorBottomLeft{
|
2021-05-11 05:26:51 +00:00
|
|
|
.anchorRect = QRect(50, 50, 400, 400),
|
|
|
|
.size = QSize(200, 200),
|
|
|
|
.anchor = Test::XdgPositioner::anchor_bottom_left,
|
|
|
|
.gravity = Test::XdgPositioner::gravity_bottom_right,
|
|
|
|
};
|
2022-03-23 10:13:38 +00:00
|
|
|
QTest::newRow("anchorBottomLeft") << QSize(500, 500) << QPoint(300, 300) << layoutAnchorBottomLeft << QRect(350, 750, 200, 200);
|
2021-05-11 05:26:51 +00:00
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
const PopupLayout layoutAnchorLeft{
|
2021-05-11 05:26:51 +00:00
|
|
|
.anchorRect = QRect(50, 50, 400, 400),
|
|
|
|
.size = QSize(200, 200),
|
|
|
|
.anchor = Test::XdgPositioner::anchor_left,
|
|
|
|
.gravity = Test::XdgPositioner::gravity_bottom_right,
|
|
|
|
};
|
2022-03-23 10:13:38 +00:00
|
|
|
QTest::newRow("anchorLeft") << QSize(500, 500) << QPoint(300, 300) << layoutAnchorLeft << QRect(350, 550, 200, 200);
|
2018-10-19 22:21:54 +00:00
|
|
|
|
2021-05-11 05:26:51 +00:00
|
|
|
// ----------------------------------------------------------------
|
|
|
|
// window in the middle, plenty of room either side: Changing gravity around the bottom right anchor
|
2018-10-19 22:21:54 +00:00
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
const PopupLayout layoutGravityCenter{
|
2021-05-11 05:26:51 +00:00
|
|
|
.anchorRect = QRect(50, 50, 400, 400),
|
|
|
|
.size = QSize(200, 200),
|
|
|
|
.anchor = Test::XdgPositioner::anchor_bottom_right,
|
|
|
|
.gravity = Test::XdgPositioner::gravity_none,
|
|
|
|
};
|
|
|
|
QTest::newRow("gravityCentre") << QSize(500, 500) << QPoint(300, 300) << layoutGravityCenter << QRect(650, 650, 200, 200);
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
const PopupLayout layoutGravityTopLeft{
|
2021-05-11 05:26:51 +00:00
|
|
|
.anchorRect = QRect(50, 50, 400, 400),
|
|
|
|
.size = QSize(200, 200),
|
|
|
|
.anchor = Test::XdgPositioner::anchor_bottom_right,
|
|
|
|
.gravity = Test::XdgPositioner::gravity_top_left,
|
|
|
|
};
|
|
|
|
QTest::newRow("gravityTopLeft") << QSize(500, 500) << QPoint(300, 300) << layoutGravityTopLeft << QRect(550, 550, 200, 200);
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
const PopupLayout layoutGravityTop{
|
2021-05-11 05:26:51 +00:00
|
|
|
.anchorRect = QRect(50, 50, 400, 400),
|
|
|
|
.size = QSize(200, 200),
|
|
|
|
.anchor = Test::XdgPositioner::anchor_bottom_right,
|
|
|
|
.gravity = Test::XdgPositioner::gravity_top,
|
|
|
|
};
|
|
|
|
QTest::newRow("gravityTop") << QSize(500, 500) << QPoint(300, 300) << layoutGravityTop << QRect(650, 550, 200, 200);
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
const PopupLayout layoutGravityTopRight{
|
2021-05-11 05:26:51 +00:00
|
|
|
.anchorRect = QRect(50, 50, 400, 400),
|
|
|
|
.size = QSize(200, 200),
|
|
|
|
.anchor = Test::XdgPositioner::anchor_bottom_right,
|
|
|
|
.gravity = Test::XdgPositioner::gravity_top_right,
|
|
|
|
};
|
|
|
|
QTest::newRow("gravityTopRight") << QSize(500, 500) << QPoint(300, 300) << layoutGravityTopRight << QRect(750, 550, 200, 200);
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
const PopupLayout layoutGravityRight{
|
2021-05-11 05:26:51 +00:00
|
|
|
.anchorRect = QRect(50, 50, 400, 400),
|
|
|
|
.size = QSize(200, 200),
|
|
|
|
.anchor = Test::XdgPositioner::anchor_bottom_right,
|
|
|
|
.gravity = Test::XdgPositioner::gravity_right,
|
|
|
|
};
|
|
|
|
QTest::newRow("gravityRight") << QSize(500, 500) << QPoint(300, 300) << layoutGravityRight << QRect(750, 650, 200, 200);
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
const PopupLayout layoutGravityBottomRight{
|
2021-05-11 05:26:51 +00:00
|
|
|
.anchorRect = QRect(50, 50, 400, 400),
|
|
|
|
.size = QSize(200, 200),
|
|
|
|
.anchor = Test::XdgPositioner::anchor_bottom_right,
|
|
|
|
.gravity = Test::XdgPositioner::gravity_bottom_right,
|
|
|
|
};
|
|
|
|
QTest::newRow("gravityBottomRight") << QSize(500, 500) << QPoint(300, 300) << layoutGravityBottomRight << QRect(750, 750, 200, 200);
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
const PopupLayout layoutGravityBottom{
|
2021-05-11 05:26:51 +00:00
|
|
|
.anchorRect = QRect(50, 50, 400, 400),
|
|
|
|
.size = QSize(200, 200),
|
|
|
|
.anchor = Test::XdgPositioner::anchor_bottom_right,
|
|
|
|
.gravity = Test::XdgPositioner::gravity_bottom,
|
|
|
|
};
|
|
|
|
QTest::newRow("gravityBottom") << QSize(500, 500) << QPoint(300, 300) << layoutGravityBottom << QRect(650, 750, 200, 200);
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
const PopupLayout layoutGravityBottomLeft{
|
2021-05-11 05:26:51 +00:00
|
|
|
.anchorRect = QRect(50, 50, 400, 400),
|
|
|
|
.size = QSize(200, 200),
|
|
|
|
.anchor = Test::XdgPositioner::anchor_bottom_right,
|
|
|
|
.gravity = Test::XdgPositioner::gravity_bottom_left,
|
|
|
|
};
|
|
|
|
QTest::newRow("gravityBottomLeft") << QSize(500, 500) << QPoint(300, 300) << layoutGravityBottomLeft << QRect(550, 750, 200, 200);
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
const PopupLayout layoutGravityLeft{
|
2021-05-11 05:26:51 +00:00
|
|
|
.anchorRect = QRect(50, 50, 400, 400),
|
|
|
|
.size = QSize(200, 200),
|
|
|
|
.anchor = Test::XdgPositioner::anchor_bottom_right,
|
|
|
|
.gravity = Test::XdgPositioner::gravity_left,
|
|
|
|
};
|
|
|
|
QTest::newRow("gravityLeft") << QSize(500, 500) << QPoint(300, 300) << layoutGravityLeft << QRect(550, 650, 200, 200);
|
2018-10-19 22:21:54 +00:00
|
|
|
|
2021-05-11 05:26:51 +00:00
|
|
|
// ----------------------------------------------------------------
|
|
|
|
// constrain and slide
|
|
|
|
// popup is still 200,200. window moved near edge of screen, popup always comes out towards the screen edge
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
const PopupLayout layoutSlideTop{
|
2021-05-11 05:26:51 +00:00
|
|
|
.anchorRect = QRect(50, 50, 400, 400),
|
|
|
|
.size = QSize(200, 200),
|
|
|
|
.anchor = Test::XdgPositioner::anchor_top,
|
|
|
|
.gravity = Test::XdgPositioner::gravity_top,
|
|
|
|
.constraint = Test::XdgPositioner::constraint_adjustment_slide_x | Test::XdgPositioner::constraint_adjustment_slide_y,
|
|
|
|
};
|
|
|
|
QTest::newRow("constraintSlideTop") << QSize(500, 500) << QPoint(80, 80) << layoutSlideTop << QRect(80 + 250 - 100, 0, 200, 200);
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
const PopupLayout layoutSlideLeft{
|
2021-05-11 05:26:51 +00:00
|
|
|
.anchorRect = QRect(50, 50, 400, 400),
|
|
|
|
.size = QSize(200, 200),
|
|
|
|
.anchor = Test::XdgPositioner::anchor_left,
|
|
|
|
.gravity = Test::XdgPositioner::gravity_left,
|
|
|
|
.constraint = Test::XdgPositioner::constraint_adjustment_slide_x | Test::XdgPositioner::constraint_adjustment_slide_y,
|
|
|
|
};
|
|
|
|
QTest::newRow("constraintSlideLeft") << QSize(500, 500) << QPoint(80, 80) << layoutSlideLeft << QRect(0, 80 + 250 - 100, 200, 200);
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
const PopupLayout layoutSlideRight{
|
2021-05-11 05:26:51 +00:00
|
|
|
.anchorRect = QRect(50, 50, 400, 400),
|
|
|
|
.size = QSize(200, 200),
|
|
|
|
.anchor = Test::XdgPositioner::anchor_right,
|
|
|
|
.gravity = Test::XdgPositioner::gravity_right,
|
|
|
|
.constraint = Test::XdgPositioner::constraint_adjustment_slide_x | Test::XdgPositioner::constraint_adjustment_slide_y,
|
|
|
|
};
|
|
|
|
QTest::newRow("constraintSlideRight") << QSize(500, 500) << QPoint(700, 80) << layoutSlideRight << QRect(1280 - 200, 80 + 250 - 100, 200, 200);
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
const PopupLayout layoutSlideBottom{
|
2021-05-11 05:26:51 +00:00
|
|
|
.anchorRect = QRect(50, 50, 400, 400),
|
|
|
|
.size = QSize(200, 200),
|
|
|
|
.anchor = Test::XdgPositioner::anchor_bottom,
|
|
|
|
.gravity = Test::XdgPositioner::gravity_bottom,
|
|
|
|
.constraint = Test::XdgPositioner::constraint_adjustment_slide_x | Test::XdgPositioner::constraint_adjustment_slide_y,
|
|
|
|
};
|
|
|
|
QTest::newRow("constraintSlideBottom") << QSize(500, 500) << QPoint(80, 500) << layoutSlideBottom << QRect(80 + 250 - 100, 1024 - 200, 200, 200);
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
const PopupLayout layoutSlideBottomRight{
|
2021-05-11 05:26:51 +00:00
|
|
|
.anchorRect = QRect(50, 50, 400, 400),
|
|
|
|
.size = QSize(200, 200),
|
|
|
|
.anchor = Test::XdgPositioner::anchor_bottom_right,
|
|
|
|
.gravity = Test::XdgPositioner::gravity_bottom_right,
|
|
|
|
.constraint = Test::XdgPositioner::constraint_adjustment_slide_x | Test::XdgPositioner::constraint_adjustment_slide_y,
|
|
|
|
};
|
|
|
|
QTest::newRow("constraintSlideBottomRight") << QSize(500, 500) << QPoint(700, 1000) << layoutSlideBottomRight << QRect(1280 - 200, 1024 - 200, 200, 200);
|
2018-10-19 22:21:54 +00:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------
|
|
|
|
// constrain and flip
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
const PopupLayout layoutFlipTop{
|
2021-05-11 05:26:51 +00:00
|
|
|
.anchorRect = QRect(50, 50, 400, 400),
|
|
|
|
.size = QSize(200, 200),
|
|
|
|
.anchor = Test::XdgPositioner::anchor_top,
|
|
|
|
.gravity = Test::XdgPositioner::gravity_top,
|
|
|
|
.constraint = Test::XdgPositioner::constraint_adjustment_flip_x | Test::XdgPositioner::constraint_adjustment_flip_y,
|
|
|
|
};
|
|
|
|
QTest::newRow("constraintFlipTop") << QSize(500, 500) << QPoint(80, 80) << layoutFlipTop << QRect(230, 80 + 500 - 50, 200, 200);
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
const PopupLayout layoutFlipLeft{
|
2021-05-11 05:26:51 +00:00
|
|
|
.anchorRect = QRect(50, 50, 400, 400),
|
|
|
|
.size = QSize(200, 200),
|
|
|
|
.anchor = Test::XdgPositioner::anchor_left,
|
|
|
|
.gravity = Test::XdgPositioner::gravity_left,
|
|
|
|
.constraint = Test::XdgPositioner::constraint_adjustment_flip_x | Test::XdgPositioner::constraint_adjustment_flip_y,
|
|
|
|
};
|
|
|
|
QTest::newRow("constraintFlipLeft") << QSize(500, 500) << QPoint(80, 80) << layoutFlipLeft << QRect(80 + 500 - 50, 230, 200, 200);
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
const PopupLayout layoutFlipRight{
|
2021-05-11 05:26:51 +00:00
|
|
|
.anchorRect = QRect(50, 50, 400, 400),
|
|
|
|
.size = QSize(200, 200),
|
|
|
|
.anchor = Test::XdgPositioner::anchor_right,
|
|
|
|
.gravity = Test::XdgPositioner::gravity_right,
|
|
|
|
.constraint = Test::XdgPositioner::constraint_adjustment_flip_x | Test::XdgPositioner::constraint_adjustment_flip_y,
|
|
|
|
};
|
|
|
|
QTest::newRow("constraintFlipRight") << QSize(500, 500) << QPoint(700, 80) << layoutFlipRight << QRect(700 + 50 - 200, 230, 200, 200);
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
const PopupLayout layoutFlipBottom{
|
2021-05-11 05:26:51 +00:00
|
|
|
.anchorRect = QRect(50, 50, 400, 400),
|
|
|
|
.size = QSize(200, 200),
|
|
|
|
.anchor = Test::XdgPositioner::anchor_bottom,
|
|
|
|
.gravity = Test::XdgPositioner::gravity_bottom,
|
|
|
|
.constraint = Test::XdgPositioner::constraint_adjustment_flip_x | Test::XdgPositioner::constraint_adjustment_flip_y,
|
|
|
|
};
|
|
|
|
QTest::newRow("constraintFlipBottom") << QSize(500, 500) << QPoint(80, 500) << layoutFlipBottom << QRect(230, 500 + 50 - 200, 200, 200);
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
const PopupLayout layoutFlipBottomRight{
|
2021-05-11 05:26:51 +00:00
|
|
|
.anchorRect = QRect(50, 50, 400, 400),
|
|
|
|
.size = QSize(200, 200),
|
|
|
|
.anchor = Test::XdgPositioner::anchor_bottom_right,
|
|
|
|
.gravity = Test::XdgPositioner::gravity_bottom_right,
|
|
|
|
.constraint = Test::XdgPositioner::constraint_adjustment_flip_x | Test::XdgPositioner::constraint_adjustment_flip_y,
|
|
|
|
};
|
|
|
|
QTest::newRow("constraintFlipBottomRight") << QSize(500, 500) << QPoint(700, 500) << layoutFlipBottomRight << QRect(700 + 50 - 200, 500 + 50 - 200, 200, 200);
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
const PopupLayout layoutFlipRightNoAnchor{
|
2021-05-11 05:26:51 +00:00
|
|
|
.anchorRect = QRect(50, 50, 400, 400),
|
2022-03-23 10:13:38 +00:00
|
|
|
// as popup is positioned in the middle of the parent we need a massive popup to be able to overflow
|
2021-05-11 05:26:51 +00:00
|
|
|
.size = QSize(400, 400),
|
|
|
|
.anchor = Test::XdgPositioner::anchor_top,
|
|
|
|
.gravity = Test::XdgPositioner::gravity_right,
|
|
|
|
.constraint = Test::XdgPositioner::constraint_adjustment_flip_x | Test::XdgPositioner::constraint_adjustment_flip_y,
|
|
|
|
};
|
|
|
|
QTest::newRow("constraintFlipRightNoAnchor") << QSize(500, 500) << QPoint(700, 80) << layoutFlipRightNoAnchor << QRect(700 + 250 - 400, 330, 400, 400);
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
const PopupLayout layoutFlipRightNoGravity{
|
2021-05-11 05:26:51 +00:00
|
|
|
.anchorRect = QRect(50, 50, 400, 400),
|
|
|
|
.size = QSize(300, 200),
|
|
|
|
.anchor = Test::XdgPositioner::anchor_right,
|
|
|
|
.gravity = Test::XdgPositioner::gravity_top,
|
|
|
|
.constraint = Test::XdgPositioner::constraint_adjustment_flip_x | Test::XdgPositioner::constraint_adjustment_flip_y,
|
|
|
|
};
|
|
|
|
QTest::newRow("constraintFlipRightNoGravity") << QSize(500, 500) << QPoint(700, 80) << layoutFlipRightNoGravity << QRect(700 + 50 - 150, 130, 300, 200);
|
2020-01-31 02:36:45 +00:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------
|
|
|
|
// resize
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
const PopupLayout layoutResizeTop{
|
2021-05-11 05:26:51 +00:00
|
|
|
.anchorRect = QRect(50, 50, 400, 400),
|
|
|
|
.size = QSize(200, 200),
|
|
|
|
.anchor = Test::XdgPositioner::anchor_top,
|
|
|
|
.gravity = Test::XdgPositioner::gravity_top,
|
|
|
|
.constraint = Test::XdgPositioner::constraint_adjustment_resize_x | Test::XdgPositioner::constraint_adjustment_resize_y,
|
|
|
|
};
|
|
|
|
QTest::newRow("resizeTop") << QSize(500, 500) << QPoint(80, 80) << layoutResizeTop << QRect(80 + 250 - 100, 0, 200, 130);
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
const PopupLayout layoutResizeLeft{
|
2021-05-11 05:26:51 +00:00
|
|
|
.anchorRect = QRect(50, 50, 400, 400),
|
|
|
|
.size = QSize(200, 200),
|
|
|
|
.anchor = Test::XdgPositioner::anchor_left,
|
|
|
|
.gravity = Test::XdgPositioner::gravity_left,
|
|
|
|
.constraint = Test::XdgPositioner::constraint_adjustment_resize_x | Test::XdgPositioner::constraint_adjustment_resize_y,
|
|
|
|
};
|
|
|
|
QTest::newRow("resizeLeft") << QSize(500, 500) << QPoint(80, 80) << layoutResizeLeft << QRect(0, 80 + 250 - 100, 130, 200);
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
const PopupLayout layoutResizeRight{
|
2021-05-11 05:26:51 +00:00
|
|
|
.anchorRect = QRect(50, 50, 400, 400),
|
|
|
|
.size = QSize(200, 200),
|
|
|
|
.anchor = Test::XdgPositioner::anchor_right,
|
|
|
|
.gravity = Test::XdgPositioner::gravity_right,
|
|
|
|
.constraint = Test::XdgPositioner::constraint_adjustment_resize_x | Test::XdgPositioner::constraint_adjustment_resize_y,
|
|
|
|
};
|
|
|
|
QTest::newRow("resizeRight") << QSize(500, 500) << QPoint(700, 80) << layoutResizeRight << QRect(700 + 50 + 400, 80 + 250 - 100, 130, 200);
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
const PopupLayout layoutResizeBottom{
|
2021-05-11 05:26:51 +00:00
|
|
|
.anchorRect = QRect(50, 50, 400, 400),
|
|
|
|
.size = QSize(200, 200),
|
|
|
|
.anchor = Test::XdgPositioner::anchor_bottom,
|
|
|
|
.gravity = Test::XdgPositioner::gravity_bottom,
|
|
|
|
.constraint = Test::XdgPositioner::constraint_adjustment_resize_x | Test::XdgPositioner::constraint_adjustment_resize_y,
|
|
|
|
};
|
|
|
|
QTest::newRow("resizeBottom") << QSize(500, 500) << QPoint(80, 500) << layoutResizeBottom << QRect(80 + 250 - 100, 500 + 50 + 400, 200, 74);
|
2018-10-19 22:21:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TransientPlacementTest::testXdgPopup()
|
|
|
|
{
|
|
|
|
// this test verifies that the position of a transient window is taken from the passed position
|
|
|
|
// there are no further constraints like window too large to fit screen, cascading transients, etc
|
|
|
|
// some test cases also verify that the transient fits on the screen
|
|
|
|
QFETCH(QSize, parentSize);
|
2019-02-26 13:41:00 +00:00
|
|
|
QFETCH(QPoint, parentPosition);
|
|
|
|
QFETCH(QRect, expectedGeometry);
|
|
|
|
const QRect expectedRelativeGeometry = expectedGeometry.translated(-parentPosition);
|
2018-10-19 22:21:54 +00:00
|
|
|
|
2022-08-16 11:43:33 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface = Test::createSurface();
|
2018-10-19 22:21:54 +00:00
|
|
|
QVERIFY(surface);
|
2022-08-16 11:43:33 +00:00
|
|
|
auto parentShellSurface = Test::createXdgToplevelSurface(surface.get(), Test::waylandCompositor());
|
2018-10-19 22:21:54 +00:00
|
|
|
QVERIFY(parentShellSurface);
|
2022-08-16 11:43:33 +00:00
|
|
|
auto parent = Test::renderAndWaitForShown(surface.get(), parentSize, Qt::blue);
|
2018-10-19 22:21:54 +00:00
|
|
|
QVERIFY(parent);
|
|
|
|
|
|
|
|
QVERIFY(!parent->isDecorated());
|
|
|
|
parent->move(parentPosition);
|
2019-09-27 10:01:10 +00:00
|
|
|
QCOMPARE(parent->frameGeometry(), QRect(parentPosition, parentSize));
|
2018-10-19 22:21:54 +00:00
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
// create popup
|
2021-05-11 05:26:51 +00:00
|
|
|
QFETCH(PopupLayout, layout);
|
2018-10-19 22:21:54 +00:00
|
|
|
|
2022-08-16 11:43:33 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> transientSurface = Test::createSurface();
|
2018-10-19 22:21:54 +00:00
|
|
|
QVERIFY(transientSurface);
|
|
|
|
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<Test::XdgPositioner> positioner(Test::createXdgPositioner());
|
2021-05-11 05:26:51 +00:00
|
|
|
positioner->set_anchor_rect(layout.anchorRect.x(), layout.anchorRect.y(), layout.anchorRect.width(), layout.anchorRect.height());
|
|
|
|
positioner->set_size(layout.size.width(), layout.size.height());
|
|
|
|
positioner->set_anchor(layout.anchor);
|
|
|
|
positioner->set_gravity(layout.gravity);
|
|
|
|
positioner->set_constraint_adjustment(layout.constraint);
|
2022-08-16 11:43:33 +00:00
|
|
|
std::unique_ptr<Test::XdgPopup> popup(Test::createXdgPopupSurface(transientSurface.get(), parentShellSurface->xdgSurface(), positioner.get(), Test::CreationSetup::CreateOnly));
|
2022-08-01 21:29:02 +00:00
|
|
|
QSignalSpy popupConfigureRequestedSpy(popup.get(), &Test::XdgPopup::configureRequested);
|
2021-05-11 05:26:51 +00:00
|
|
|
QSignalSpy surfaceConfigureRequestedSpy(popup->xdgSurface(), &Test::XdgSurface::configureRequested);
|
2021-09-03 17:54:03 +00:00
|
|
|
transientSurface->commit(KWayland::Client::Surface::CommitFlag::None);
|
2019-02-26 13:41:00 +00:00
|
|
|
|
2021-05-11 05:26:51 +00:00
|
|
|
QVERIFY(surfaceConfigureRequestedSpy.wait());
|
|
|
|
QCOMPARE(surfaceConfigureRequestedSpy.count(), 1);
|
|
|
|
QCOMPARE(popupConfigureRequestedSpy.last()[0].value<QRect>(), expectedRelativeGeometry);
|
|
|
|
popup->xdgSurface()->ack_configure(surfaceConfigureRequestedSpy.last()[0].toUInt());
|
2019-02-26 13:41:00 +00:00
|
|
|
|
2022-08-16 11:43:33 +00:00
|
|
|
auto transient = Test::renderAndWaitForShown(transientSurface.get(), expectedRelativeGeometry.size(), Qt::red);
|
2018-10-19 22:21:54 +00:00
|
|
|
QVERIFY(transient);
|
|
|
|
|
|
|
|
QVERIFY(!transient->isDecorated());
|
|
|
|
QVERIFY(transient->hasTransientPlacementHint());
|
2019-09-27 10:01:10 +00:00
|
|
|
QCOMPARE(transient->frameGeometry(), expectedGeometry);
|
2019-02-26 13:41:00 +00:00
|
|
|
|
2021-05-11 05:26:51 +00:00
|
|
|
QCOMPARE(surfaceConfigureRequestedSpy.count(), 1); // check that we did not get reconfigured
|
2018-10-19 22:21:54 +00:00
|
|
|
}
|
|
|
|
|
2018-12-27 19:22:53 +00:00
|
|
|
void TransientPlacementTest::testXdgPopupWithPanel()
|
|
|
|
{
|
2022-07-11 12:20:35 +00:00
|
|
|
const Output *output = workspace()->activeOutput();
|
|
|
|
|
2023-05-19 11:58:32 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> dockSurface{Test::createSurface()};
|
|
|
|
std::unique_ptr<Test::LayerSurfaceV1> dockShellSurface{Test::createLayerSurfaceV1(dockSurface.get(), QStringLiteral("dock"))};
|
|
|
|
dockShellSurface->set_size(1280, 50);
|
|
|
|
dockShellSurface->set_anchor(Test::LayerSurfaceV1::anchor_bottom);
|
|
|
|
dockShellSurface->set_exclusive_zone(50);
|
|
|
|
dockSurface->commit(KWayland::Client::Surface::CommitFlag::None);
|
2018-12-27 19:22:53 +00:00
|
|
|
|
|
|
|
// now render and map the window
|
2023-05-19 11:58:32 +00:00
|
|
|
QSignalSpy dockConfigureRequestedSpy(dockShellSurface.get(), &Test::LayerSurfaceV1::configureRequested);
|
|
|
|
QVERIFY(dockConfigureRequestedSpy.wait());
|
|
|
|
auto dock = Test::renderAndWaitForShown(dockSurface.get(), dockConfigureRequestedSpy.last().at(1).toSize(), Qt::blue);
|
2018-12-27 19:22:53 +00:00
|
|
|
QVERIFY(dock);
|
2024-02-20 18:04:06 +00:00
|
|
|
QCOMPARE(dock->windowType(), WindowType::Dock);
|
2018-12-27 19:22:53 +00:00
|
|
|
QVERIFY(dock->isDock());
|
2022-07-11 12:20:35 +00:00
|
|
|
QCOMPARE(dock->frameGeometry(), QRect(0, output->geometry().height() - 50, 1280, 50));
|
2018-12-27 19:22:53 +00:00
|
|
|
QCOMPARE(dock->hasStrut(), true);
|
2022-03-29 09:59:02 +00:00
|
|
|
QCOMPARE(workspace()->clientArea(PlacementArea, dock), QRect(0, 0, 1280, 1024 - 50));
|
|
|
|
QCOMPARE(workspace()->clientArea(FullScreenArea, dock), QRect(0, 0, 1280, 1024));
|
2018-12-27 19:22:53 +00:00
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
// create parent
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> parentSurface(Test::createSurface());
|
2018-12-27 19:22:53 +00:00
|
|
|
QVERIFY(parentSurface);
|
2022-08-01 21:29:02 +00:00
|
|
|
auto parentShellSurface = Test::createXdgToplevelSurface(parentSurface.get());
|
2018-12-27 19:22:53 +00:00
|
|
|
QVERIFY(parentShellSurface);
|
2022-08-01 21:29:02 +00:00
|
|
|
auto parent = Test::renderAndWaitForShown(parentSurface.get(), {800, 600}, Qt::blue);
|
2018-12-27 19:22:53 +00:00
|
|
|
QVERIFY(parent);
|
|
|
|
|
|
|
|
QVERIFY(!parent->isDecorated());
|
2022-05-16 20:13:39 +00:00
|
|
|
parent->move(QPointF(0, output->geometry().height() - 600));
|
2018-12-27 19:22:53 +00:00
|
|
|
parent->keepInArea(workspace()->clientArea(PlacementArea, parent));
|
2022-07-11 12:20:35 +00:00
|
|
|
QCOMPARE(parent->frameGeometry(), QRect(0, output->geometry().height() - 600 - 50, 800, 600));
|
2018-12-27 19:22:53 +00:00
|
|
|
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> transientSurface(Test::createSurface());
|
2018-12-27 19:22:53 +00:00
|
|
|
QVERIFY(transientSurface);
|
|
|
|
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<Test::XdgPositioner> positioner(Test::createXdgPositioner());
|
2021-05-11 05:26:51 +00:00
|
|
|
positioner->set_size(200, 200);
|
|
|
|
positioner->set_anchor_rect(50, 500, 200, 200);
|
2023-03-02 08:53:54 +00:00
|
|
|
positioner->set_constraint_adjustment(Test::XdgPositioner::constraint_adjustment_slide_x | Test::XdgPositioner::constraint_adjustment_slide_y);
|
2021-05-11 05:26:51 +00:00
|
|
|
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<Test::XdgPopup> transientShellSurface(Test::createXdgPopupSurface(transientSurface.get(), parentShellSurface->xdgSurface(), positioner.get()));
|
|
|
|
auto transient = Test::renderAndWaitForShown(transientSurface.get(), QSize(200, 200), Qt::red);
|
2018-12-27 19:22:53 +00:00
|
|
|
QVERIFY(transient);
|
|
|
|
|
|
|
|
QVERIFY(!transient->isDecorated());
|
|
|
|
QVERIFY(transient->hasTransientPlacementHint());
|
|
|
|
|
2022-07-11 12:20:35 +00:00
|
|
|
QCOMPARE(transient->frameGeometry(), QRect(50, output->geometry().height() - 200 - 50, 200, 200));
|
2018-12-27 19:22:53 +00:00
|
|
|
|
2021-12-09 07:47:55 +00:00
|
|
|
transientShellSurface.reset();
|
|
|
|
transientSurface.reset();
|
2023-04-21 20:28:48 +00:00
|
|
|
QVERIFY(Test::waitForWindowClosed(transient));
|
2018-12-27 19:22:53 +00:00
|
|
|
|
|
|
|
// now parent to fullscreen - on fullscreen the panel is ignored
|
2021-05-11 05:26:51 +00:00
|
|
|
QSignalSpy toplevelConfigureRequestedSpy(parentShellSurface, &Test::XdgToplevel::configureRequested);
|
|
|
|
QSignalSpy surfaceConfigureRequestedSpy(parentShellSurface->xdgSurface(), &Test::XdgSurface::configureRequested);
|
2018-12-27 19:22:53 +00:00
|
|
|
parent->setFullScreen(true);
|
2021-05-11 05:26:51 +00:00
|
|
|
QVERIFY(surfaceConfigureRequestedSpy.wait());
|
|
|
|
parentShellSurface->xdgSurface()->ack_configure(surfaceConfigureRequestedSpy.last().at(0).value<quint32>());
|
2022-04-22 17:39:12 +00:00
|
|
|
QSignalSpy frameGeometryChangedSpy{parent, &Window::frameGeometryChanged};
|
2022-08-01 21:29:02 +00:00
|
|
|
Test::render(parentSurface.get(), toplevelConfigureRequestedSpy.last().at(0).toSize(), Qt::red);
|
2020-02-05 09:28:50 +00:00
|
|
|
QVERIFY(frameGeometryChangedSpy.wait());
|
2022-07-11 12:20:35 +00:00
|
|
|
QCOMPARE(parent->frameGeometry(), output->geometry());
|
2018-12-27 19:22:53 +00:00
|
|
|
QVERIFY(parent->isFullScreen());
|
|
|
|
|
|
|
|
// another transient, with same hints as before from bottom of window
|
2022-08-16 11:43:33 +00:00
|
|
|
transientSurface = Test::createSurface();
|
2018-12-27 19:22:53 +00:00
|
|
|
QVERIFY(transientSurface);
|
|
|
|
|
2022-07-11 12:20:35 +00:00
|
|
|
const QRect anchorRect2(50, output->geometry().height() - 100, 200, 200);
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<Test::XdgPositioner> positioner2(Test::createXdgPositioner());
|
2021-05-11 05:26:51 +00:00
|
|
|
positioner2->set_size(200, 200);
|
|
|
|
positioner2->set_anchor_rect(anchorRect2.x(), anchorRect2.y(), anchorRect2.width(), anchorRect2.height());
|
2023-03-02 08:53:54 +00:00
|
|
|
positioner2->set_constraint_adjustment(Test::XdgPositioner::constraint_adjustment_slide_x | Test::XdgPositioner::constraint_adjustment_slide_y);
|
2022-08-01 21:29:02 +00:00
|
|
|
transientShellSurface.reset(Test::createXdgPopupSurface(transientSurface.get(), parentShellSurface->xdgSurface(), positioner2.get()));
|
|
|
|
transient = Test::renderAndWaitForShown(transientSurface.get(), QSize(200, 200), Qt::red);
|
2018-12-27 19:22:53 +00:00
|
|
|
QVERIFY(transient);
|
|
|
|
|
|
|
|
QVERIFY(!transient->isDecorated());
|
|
|
|
QVERIFY(transient->hasTransientPlacementHint());
|
|
|
|
|
2022-07-11 12:20:35 +00:00
|
|
|
QCOMPARE(transient->frameGeometry(), QRect(50, output->geometry().height() - 200, 200, 200));
|
2018-12-27 19:22:53 +00:00
|
|
|
}
|
|
|
|
|
2016-03-03 12:32:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WAYLANDTEST_MAIN(KWin::TransientPlacementTest)
|
|
|
|
#include "transient_placement.moc"
|