Replace resize edges flag with an enum

It's more typesafe.
This commit is contained in:
Vlad Zahorodnii 2022-01-12 14:06:37 +02:00
parent ee1ea077ba
commit f06e83f241
3 changed files with 28 additions and 29 deletions

View file

@ -382,16 +382,17 @@ void XdgShellTest::testMove()
void XdgShellTest::testResize_data()
{
QTest::addColumn<Qt::Edges>("edges");
QTest::addColumn<XdgToplevelInterface::ResizeAnchor>("anchor");
QTest::newRow("none") << Qt::Edges();
QTest::newRow("top") << Qt::Edges(Qt::TopEdge);
QTest::newRow("bottom") << Qt::Edges(Qt::BottomEdge);
QTest::newRow("left") << Qt::Edges(Qt::LeftEdge);
QTest::newRow("top left") << Qt::Edges(Qt::TopEdge | Qt::LeftEdge);
QTest::newRow("bottom left") << Qt::Edges(Qt::BottomEdge | Qt::LeftEdge);
QTest::newRow("right") << Qt::Edges(Qt::RightEdge);
QTest::newRow("top right") << Qt::Edges(Qt::TopEdge | Qt::RightEdge);
QTest::newRow("bottom right") << Qt::Edges(Qt::BottomEdge | Qt::RightEdge);
QTest::newRow("none") << Qt::Edges() << XdgToplevelInterface::ResizeAnchor::None;
QTest::newRow("top") << Qt::Edges(Qt::TopEdge) << XdgToplevelInterface::ResizeAnchor::Top;
QTest::newRow("bottom") << Qt::Edges(Qt::BottomEdge) << XdgToplevelInterface::ResizeAnchor::Bottom;
QTest::newRow("left") << Qt::Edges(Qt::LeftEdge) << XdgToplevelInterface::ResizeAnchor::Left;
QTest::newRow("top left") << Qt::Edges(Qt::TopEdge | Qt::LeftEdge) << XdgToplevelInterface::ResizeAnchor::TopLeft;
QTest::newRow("bottom left") << Qt::Edges(Qt::BottomEdge | Qt::LeftEdge) << XdgToplevelInterface::ResizeAnchor::BottomLeft;
QTest::newRow("right") << Qt::Edges(Qt::RightEdge) << XdgToplevelInterface::ResizeAnchor::Right;
QTest::newRow("top right") << Qt::Edges(Qt::TopEdge | Qt::RightEdge) << XdgToplevelInterface::ResizeAnchor::TopRight;
QTest::newRow("bottom right") << Qt::Edges(Qt::BottomEdge | Qt::RightEdge) << XdgToplevelInterface::ResizeAnchor::BottomRight;
}
void XdgShellTest::testResize()
@ -412,7 +413,7 @@ void XdgShellTest::testResize()
QVERIFY(resizeSpy.wait());
QCOMPARE(resizeSpy.count(), 1);
QCOMPARE(resizeSpy.first().at(0).value<SeatInterface *>(), m_seatInterface);
QCOMPARE(resizeSpy.first().at(1).value<Qt::Edges>(), edges);
QTEST(resizeSpy.first().at(1).value<XdgToplevelInterface::ResizeAnchor>(), "anchor");
QCOMPARE(resizeSpy.first().at(2).value<quint32>(), 60u);
}

View file

@ -430,22 +430,7 @@ void XdgToplevelInterfacePrivate::xdg_toplevel_resize(Resource *resource, ::wl_r
}
SeatInterface *seat = SeatInterface::get(seatResource);
Qt::Edges edges;
if (xdgEdges & XDG_TOPLEVEL_RESIZE_EDGE_TOP) {
edges |= Qt::TopEdge;
}
if (xdgEdges & XDG_TOPLEVEL_RESIZE_EDGE_RIGHT) {
edges |= Qt::RightEdge;
}
if (xdgEdges & XDG_TOPLEVEL_RESIZE_EDGE_BOTTOM) {
edges |= Qt::BottomEdge;
}
if (xdgEdges & XDG_TOPLEVEL_RESIZE_EDGE_LEFT) {
edges |= Qt::LeftEdge;
}
Q_EMIT q->resizeRequested(seat, edges, serial);
Q_EMIT q->resizeRequested(seat, XdgToplevelInterface::ResizeAnchor(xdgEdges), serial);
}
void XdgToplevelInterfacePrivate::xdg_toplevel_set_max_size(Resource *resource, int32_t width, int32_t height)

View file

@ -210,6 +210,19 @@ public:
};
Q_DECLARE_FLAGS(States, State)
enum class ResizeAnchor {
None = 0,
Top = 1,
Bottom = 2,
Left = 4,
TopLeft = 5,
BottomLeft = 6,
Right = 8,
TopRight = 9,
BottomRight = 10,
};
Q_ENUM(ResizeAnchor)
/**
* Constructs an XdgToplevelInterface for the given xdg-surface \a surface.
*/
@ -332,11 +345,11 @@ Q_SIGNALS:
void moveRequested(KWaylandServer::SeatInterface *seat, quint32 serial);
/**
* This signal is emitted when the toplevel wants to be interactively resized along the
* specified window edges \a edges. The \a seat and the \a serial indicate the user action
* This signal is emitted when the toplevel wants to be interactively resized by dragging
* the specified \a anchor. The \a seat and the \a serial indicate the user action
* in response to which this request has been issued.
*/
void resizeRequested(KWaylandServer::SeatInterface *seat, Qt::Edges edges, quint32 serial);
void resizeRequested(KWaylandServer::SeatInterface *seat, KWaylandServer::XdgToplevelInterface::ResizeAnchor anchor, quint32 serial);
/**
* This signal is emitted when the toplevel surface wants to become maximized.