Move implementation of (shrow|grow)(Horizontal|Vertical) to AbstractClient
Methods are no longer virtual. The only x11 specific usage in these methods (resizeInc) is replaced by a virtual method. Default resize increments is QSize(1,1) for AbstractClient.
This commit is contained in:
parent
8f2b01b549
commit
f1215e44d4
6 changed files with 100 additions and 33 deletions
|
@ -93,22 +93,6 @@ bool AbstractClient::isCurrentTab() const
|
|||
return true;
|
||||
}
|
||||
|
||||
void AbstractClient::growHorizontal()
|
||||
{
|
||||
}
|
||||
|
||||
void AbstractClient::growVertical()
|
||||
{
|
||||
}
|
||||
|
||||
void AbstractClient::shrinkHorizontal()
|
||||
{
|
||||
}
|
||||
|
||||
void AbstractClient::shrinkVertical()
|
||||
{
|
||||
}
|
||||
|
||||
xcb_timestamp_t AbstractClient::userTime() const
|
||||
{
|
||||
return XCB_TIME_CURRENT_TIME;
|
||||
|
@ -1302,4 +1286,9 @@ void AbstractClient::keyPressEvent(uint key_code)
|
|||
Cursor::setPos(pos);
|
||||
}
|
||||
|
||||
QSize AbstractClient::resizeIncrements() const
|
||||
{
|
||||
return QSize(1, 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -359,10 +359,10 @@ public:
|
|||
virtual xcb_timestamp_t userTime() const;
|
||||
virtual void updateWindowRules(Rules::Types selection) = 0;
|
||||
|
||||
virtual void growHorizontal();
|
||||
virtual void shrinkHorizontal();
|
||||
virtual void growVertical();
|
||||
virtual void shrinkVertical();
|
||||
void growHorizontal();
|
||||
void shrinkHorizontal();
|
||||
void growVertical();
|
||||
void shrinkVertical();
|
||||
void updateMoveResize(const QPointF ¤tGlobalCursor);
|
||||
void keyPressEvent(uint key_code);
|
||||
|
||||
|
@ -746,6 +746,8 @@ protected:
|
|||
void handleMoveResize(int x, int y, int x_root, int y_root);
|
||||
void handleMoveResize(const QPoint &local, const QPoint &global);
|
||||
|
||||
virtual QSize resizeIncrements() const;
|
||||
|
||||
static bool haveResizeEffect() {
|
||||
return s_haveResizeEffect;
|
||||
}
|
||||
|
|
|
@ -56,6 +56,8 @@ private Q_SLOTS:
|
|||
void testPackTo();
|
||||
void testPackAgainstClient_data();
|
||||
void testPackAgainstClient();
|
||||
void testGrowShrink_data();
|
||||
void testGrowShrink();
|
||||
|
||||
private:
|
||||
KWayland::Client::ConnectionThread *m_connection = nullptr;
|
||||
|
@ -373,6 +375,79 @@ void MoveResizeWindowTest::testPackAgainstClient()
|
|||
QTEST(c->geometry(), "expectedGeometry");
|
||||
}
|
||||
|
||||
void MoveResizeWindowTest::testGrowShrink_data()
|
||||
{
|
||||
QTest::addColumn<QString>("methodCall");
|
||||
QTest::addColumn<QRect>("expectedGeometry");
|
||||
|
||||
QTest::newRow("grow vertical") << QStringLiteral("slotWindowGrowVertical") << QRect(590, 487, 100, 537);
|
||||
QTest::newRow("grow horizontal") << QStringLiteral("slotWindowGrowHorizontal") << QRect(590, 487, 690, 50);
|
||||
QTest::newRow("shrink vertical") << QStringLiteral("slotWindowShrinkVertical") << QRect(590, 487, 100, 23);
|
||||
QTest::newRow("shrink horizontal") << QStringLiteral("slotWindowShrinkHorizontal") << QRect(590, 487, 40, 50);
|
||||
}
|
||||
|
||||
void MoveResizeWindowTest::testGrowShrink()
|
||||
{
|
||||
using namespace KWayland::Client;
|
||||
QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded);
|
||||
QVERIFY(clientAddedSpy.isValid());
|
||||
|
||||
// block geometry helper
|
||||
QScopedPointer<Surface> surface1(m_compositor->createSurface());
|
||||
QVERIFY(!surface1.isNull());
|
||||
QScopedPointer<ShellSurface> shellSurface1(m_shell->createSurface(surface1.data()));
|
||||
QVERIFY(!shellSurface1.isNull());
|
||||
QImage img1(QSize(650, 514), QImage::Format_ARGB32);
|
||||
img1.fill(Qt::blue);
|
||||
surface1->attachBuffer(m_shm->createBuffer(img1));
|
||||
surface1->damage(QRect(0, 0, 650, 514));
|
||||
surface1->commit(Surface::CommitFlag::None);
|
||||
m_connection->flush();
|
||||
QVERIFY(clientAddedSpy.wait());
|
||||
clientAddedSpy.clear();
|
||||
workspace()->slotWindowPackRight();
|
||||
workspace()->slotWindowPackDown();
|
||||
|
||||
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);
|
||||
|
||||
// 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());
|
||||
QVERIFY(sizeChangeSpy.wait());
|
||||
QImage img2(shellSurface->size(), QImage::Format_ARGB32);
|
||||
img2.fill(Qt::red);
|
||||
surface->attachBuffer(m_shm->createBuffer(img2));
|
||||
surface->damage(QRect(QPoint(0, 0), shellSurface->size()));
|
||||
surface->commit(Surface::CommitFlag::None);
|
||||
|
||||
QSignalSpy geometryChangedSpy(c, &AbstractClient::geometryChanged);
|
||||
QVERIFY(geometryChangedSpy.isValid());
|
||||
m_connection->flush();
|
||||
QVERIFY(geometryChangedSpy.wait());
|
||||
QTEST(c->geometry(), "expectedGeometry");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
WAYLANTEST_MAIN(KWin::MoveResizeWindowTest)
|
||||
|
|
|
@ -2250,6 +2250,11 @@ void Client::updateTabGroupStates(TabGroup::States states)
|
|||
}
|
||||
}
|
||||
|
||||
QSize Client::resizeIncrements() const
|
||||
{
|
||||
return m_geometryHints.resizeIncrements();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
#include "client.moc"
|
||||
|
|
6
client.h
6
client.h
|
@ -263,11 +263,6 @@ public:
|
|||
void resizeWithChecks(const QSize& s, xcb_gravity_t gravity, ForceGeometry_t force = NormalGeometrySet);
|
||||
QSize sizeForClientSize(const QSize&, Sizemode mode = SizemodeAny, bool noframe = false) const override;
|
||||
|
||||
void growHorizontal() override;
|
||||
void shrinkHorizontal() override;
|
||||
void growVertical() override;
|
||||
void shrinkVertical() override;
|
||||
|
||||
bool providesContextHelp() const;
|
||||
const QKeySequence &shortcut() const override;
|
||||
void setShortcut(const QString& cut) override;
|
||||
|
@ -468,6 +463,7 @@ protected:
|
|||
void doPerformMoveResize() override;
|
||||
bool isWaitingForMoveResizeSync() const override;
|
||||
void doResizeSync() override;
|
||||
QSize resizeIncrements() const override;
|
||||
|
||||
private Q_SLOTS:
|
||||
void delayedSetShortcut();
|
||||
|
|
|
@ -721,15 +721,15 @@ void Workspace::slotWindowGrowHorizontal()
|
|||
active_client->growHorizontal();
|
||||
}
|
||||
|
||||
void Client::growHorizontal()
|
||||
void AbstractClient::growHorizontal()
|
||||
{
|
||||
if (!isResizable() || isShade())
|
||||
return;
|
||||
QRect geom = geometry();
|
||||
geom.setRight(workspace()->packPositionRight(this, geom.right(), true));
|
||||
QSize adjsize = adjustedSize(geom.size(), SizemodeFixedW);
|
||||
if (geometry().size() == adjsize && geom.size() != adjsize && m_geometryHints.resizeIncrements().width() > 1) { // take care of size increments
|
||||
int newright = workspace()->packPositionRight(this, geom.right() + m_geometryHints.resizeIncrements().width() - 1, true);
|
||||
if (geometry().size() == adjsize && geom.size() != adjsize && resizeIncrements().width() > 1) { // take care of size increments
|
||||
int newright = workspace()->packPositionRight(this, geom.right() + resizeIncrements().width() - 1, true);
|
||||
// check that it hasn't grown outside of the area, due to size increments
|
||||
// TODO this may be wrong?
|
||||
if (workspace()->clientArea(MovementArea,
|
||||
|
@ -748,7 +748,7 @@ void Workspace::slotWindowShrinkHorizontal()
|
|||
active_client->shrinkHorizontal();
|
||||
}
|
||||
|
||||
void Client::shrinkHorizontal()
|
||||
void AbstractClient::shrinkHorizontal()
|
||||
{
|
||||
if (!isResizable() || isShade())
|
||||
return;
|
||||
|
@ -769,15 +769,15 @@ void Workspace::slotWindowGrowVertical()
|
|||
active_client->growVertical();
|
||||
}
|
||||
|
||||
void Client::growVertical()
|
||||
void AbstractClient::growVertical()
|
||||
{
|
||||
if (!isResizable() || isShade())
|
||||
return;
|
||||
QRect geom = geometry();
|
||||
geom.setBottom(workspace()->packPositionDown(this, geom.bottom(), true));
|
||||
QSize adjsize = adjustedSize(geom.size(), SizemodeFixedH);
|
||||
if (geometry().size() == adjsize && geom.size() != adjsize && m_geometryHints.resizeIncrements().height() > 1) { // take care of size increments
|
||||
int newbottom = workspace()->packPositionDown(this, geom.bottom() + m_geometryHints.resizeIncrements().height() - 1, true);
|
||||
if (geometry().size() == adjsize && geom.size() != adjsize && resizeIncrements().height() > 1) { // take care of size increments
|
||||
int newbottom = workspace()->packPositionDown(this, geom.bottom() + resizeIncrements().height() - 1, true);
|
||||
// check that it hasn't grown outside of the area, due to size increments
|
||||
if (workspace()->clientArea(MovementArea,
|
||||
QPoint(geometry().center().x(), (y() + newbottom) / 2), desktop()).bottom() >= newbottom)
|
||||
|
@ -795,7 +795,7 @@ void Workspace::slotWindowShrinkVertical()
|
|||
active_client->shrinkVertical();
|
||||
}
|
||||
|
||||
void Client::shrinkVertical()
|
||||
void AbstractClient::shrinkVertical()
|
||||
{
|
||||
if (!isResizable() || isShade())
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue