Commit b19da3cb authored by Martin Flöser's avatar Martin Flöser

Move implementation of Client::packTo to AbstractClient

Method no longer virtual and only implemented in AbstractClient.
The implementaton works in a generic way nowadyas.

Added an autotest for the basic packTo behavior for packing against
a screen border. Packing towards other clients still needs adjustments
in the Placement code.
parent 1a664724
......@@ -109,12 +109,6 @@ void AbstractClient::shrinkVertical()
{
}
void AbstractClient::packTo(int left, int top)
{
Q_UNUSED(left)
Q_UNUSED(top)
}
xcb_timestamp_t AbstractClient::userTime() const
{
return XCB_TIME_CURRENT_TIME;
......
......@@ -384,7 +384,7 @@ public:
Position titlebarPosition() const;
// a helper for the workspace window packing. tests for screen validity and updates since in maximization case as with normal moving
virtual void packTo(int left, int top);
void packTo(int left, int top);
enum QuickTileFlag {
QuickTileNone = 0,
......
......@@ -52,6 +52,8 @@ private Q_SLOTS:
void init();
void cleanup();
void testMove();
void testPackTo_data();
void testPackTo();
private:
KWayland::Client::ConnectionThread *m_connection = nullptr;
......@@ -236,6 +238,54 @@ void MoveResizeWindowTest::testMove()
QVERIFY(workspace()->getMovingClient() == nullptr);
}
void MoveResizeWindowTest::testPackTo_data()
{
QTest::addColumn<QString>("methodCall");
QTest::addColumn<QRect>("expectedGeometry");
QTest::newRow("left") << QStringLiteral("slotWindowPackLeft") << QRect(0, 487, 100, 50);
QTest::newRow("up") << QStringLiteral("slotWindowPackUp") << QRect(590, 0, 100, 50);
QTest::newRow("right") << QStringLiteral("slotWindowPackRight") << QRect(1180, 487, 100, 50);
QTest::newRow("down") << QStringLiteral("slotWindowPackDown") << QRect(590, 974, 100, 50);
}
void MoveResizeWindowTest::testPackTo()
{
using namespace KWayland::Client;
QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded);
QVERIFY(clientAddedSpy.isValid());
QScopedPointer<Surface> surface(m_compositor->createSurface());
QVERIFY(!surface.isNull());
QScopedPointer<ShellSurface> shellSurface(m_shell->createSurface(surface.data()));
QVERIFY(!shellSurface.isNull());
QSignalSpy sizeChangeSpy(shellSurface.data(), &ShellSurface::sizeChanged);
QVERIFY(sizeChangeSpy.isValid());
// let's render
QImage img(QSize(100, 50), QImage::Format_ARGB32);
img.fill(Qt::blue);
surface->attachBuffer(m_shm->createBuffer(img));
surface->damage(QRect(0, 0, 100, 50));
surface->commit(Surface::CommitFlag::None);
m_connection->flush();
QVERIFY(clientAddedSpy.wait());
AbstractClient *c = workspace()->activeClient();
QVERIFY(c);
QCOMPARE(clientAddedSpy.first().first().value<ShellClient*>(), c);
QCOMPARE(c->geometry(), QRect(0, 0, 100, 50));
// let's place it centered
Placement::self()->placeCentered(c, QRect(0, 0, 1280, 1024));
QCOMPARE(c->geometry(), QRect(590, 487, 100, 50));
QFETCH(QString, methodCall);
QMetaObject::invokeMethod(workspace(), methodCall.toLocal8Bit().constData());
QTEST(c->geometry(), "expectedGeometry");
}
}
WAYLANTEST_MAIN(KWin::MoveResizeWindowTest)
......
......@@ -400,8 +400,6 @@ public:
//sets whether the client should be treated as a SessionInteract window
void setSessionInteract(bool needed);
virtual bool isClient() const;
// a helper for the workspace window packing. tests for screen validity and updates since in maximization case as with normal moving
void packTo(int left, int top) override;
template <typename T>
void print(T &stream) const;
......
......@@ -671,7 +671,7 @@ const char* Placement::policyToString(Policy policy)
// Workspace
// ********************
void Client::packTo(int left, int top)
void AbstractClient::packTo(int left, int top)
{
workspace()->updateFocusMousePosition(Cursor::pos()); // may cause leave event;
......
......@@ -37,7 +37,7 @@ namespace KWin
class AbstractClient;
class Client;
class Placement
class KWIN_EXPORT Placement
{
public:
virtual ~Placement();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment