Decorations: Don't depend on wl_shell

[ChangeLog][QPA plugin] The private window decoration API method,
QWaylandAbstractDecoration::startResize, now takes Qt::Edges argument instead
of a wl_shell_surface_resize enum. This will break window decoration plugins
written for older versions of Qt Wayland.

Change-Id: I4fc9aab949e91efd48a4943f8e116f51dfc373b8
Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
Reviewed-by: Pier Luigi Fiorini <pierluigi.fiorini@liri.io>
This commit is contained in:
Johan Klokkhammer Helsing 2018-09-12 15:02:09 +02:00 committed by Johan Helsing
parent 6252a08923
commit 088dc0556d
12 changed files with 68 additions and 51 deletions

View File

@ -315,19 +315,19 @@ void QWaylandBradientDecoration::processMouseTop(QWaylandInputDevice *inputDevic
#if QT_CONFIG(cursor)
waylandWindow()->setMouseCursor(inputDevice, Qt::SizeFDiagCursor);
#endif
startResize(inputDevice,WL_SHELL_SURFACE_RESIZE_TOP_LEFT,b);
startResize(inputDevice, Qt::TopEdge | Qt::LeftEdge, b);
} else if (local.x() > window()->width() + margins().left()) {
//top right bit
#if QT_CONFIG(cursor)
waylandWindow()->setMouseCursor(inputDevice, Qt::SizeBDiagCursor);
#endif
startResize(inputDevice,WL_SHELL_SURFACE_RESIZE_TOP_RIGHT,b);
startResize(inputDevice, Qt::TopEdge | Qt::RightEdge, b);
} else {
//top resize bit
#if QT_CONFIG(cursor)
waylandWindow()->setMouseCursor(inputDevice, Qt::SplitVCursor);
#endif
startResize(inputDevice,WL_SHELL_SURFACE_RESIZE_TOP,b);
startResize(inputDevice, Qt::TopEdge, b);
}
} else if (local.x() <= margins().left()) {
processMouseLeft(inputDevice, local, b, mods);
@ -358,19 +358,19 @@ void QWaylandBradientDecoration::processMouseBottom(QWaylandInputDevice *inputDe
#if QT_CONFIG(cursor)
waylandWindow()->setMouseCursor(inputDevice, Qt::SizeBDiagCursor);
#endif
startResize(inputDevice, WL_SHELL_SURFACE_RESIZE_BOTTOM_LEFT,b);
startResize(inputDevice, Qt::BottomEdge | Qt::LeftEdge, b);
} else if (local.x() > window()->width() + margins().left()) {
//bottom right bit
#if QT_CONFIG(cursor)
waylandWindow()->setMouseCursor(inputDevice, Qt::SizeFDiagCursor);
#endif
startResize(inputDevice, WL_SHELL_SURFACE_RESIZE_BOTTOM_RIGHT,b);
startResize(inputDevice, Qt::BottomEdge | Qt::RightEdge, b);
} else {
//bottom bit
#if QT_CONFIG(cursor)
waylandWindow()->setMouseCursor(inputDevice, Qt::SplitVCursor);
#endif
startResize(inputDevice,WL_SHELL_SURFACE_RESIZE_BOTTOM,b);
startResize(inputDevice, Qt::BottomEdge, b);
}
}
@ -381,7 +381,7 @@ void QWaylandBradientDecoration::processMouseLeft(QWaylandInputDevice *inputDevi
#if QT_CONFIG(cursor)
waylandWindow()->setMouseCursor(inputDevice, Qt::SplitHCursor);
#endif
startResize(inputDevice,WL_SHELL_SURFACE_RESIZE_LEFT,b);
startResize(inputDevice, Qt::LeftEdge, b);
}
void QWaylandBradientDecoration::processMouseRight(QWaylandInputDevice *inputDevice, const QPointF &local, Qt::MouseButtons b, Qt::KeyboardModifiers mods)
@ -391,7 +391,7 @@ void QWaylandBradientDecoration::processMouseRight(QWaylandInputDevice *inputDev
#if QT_CONFIG(cursor)
waylandWindow()->setMouseCursor(inputDevice, Qt::SplitHCursor);
#endif
startResize(inputDevice, WL_SHELL_SURFACE_RESIZE_RIGHT,b);
startResize(inputDevice, Qt::RightEdge, b);
}
class QWaylandBradientDecorationPlugin : public QWaylandDecorationPlugin

View File

@ -76,11 +76,10 @@ QWaylandWlShellSurface::~QWaylandWlShellSurface()
delete m_extendedWindow;
}
void QWaylandWlShellSurface::resize(QWaylandInputDevice *inputDevice, enum wl_shell_surface_resize edges)
void QWaylandWlShellSurface::resize(QWaylandInputDevice *inputDevice, Qt::Edges edges)
{
resize(inputDevice->wl_seat(),
inputDevice->serial(),
edges);
enum resize resizeEdges = convertToResizeEdges(edges);
resize(inputDevice->wl_seat(), inputDevice->serial(), resizeEdges);
}
bool QWaylandWlShellSurface::move(QWaylandInputDevice *inputDevice)
@ -193,6 +192,14 @@ void QWaylandWlShellSurface::requestWindowStates(Qt::WindowStates states)
m_pending.states = states & ~Qt::WindowMinimized;
}
enum QWaylandWlShellSurface::resize QWaylandWlShellSurface::convertToResizeEdges(Qt::Edges edges)
{
return static_cast<enum resize>(
((edges & Qt::TopEdge) ? resize_top : 0)
| ((edges & Qt::BottomEdge) ? resize_bottom : 0)
| ((edges & Qt::LeftEdge) ? resize_left : 0)
| ((edges & Qt::RightEdge) ? resize_right : 0));
}
void QWaylandWlShellSurface::setTopLevel()
{

View File

@ -78,7 +78,7 @@ public:
~QWaylandWlShellSurface() override;
using QtWayland::wl_shell_surface::resize;
void resize(QWaylandInputDevice *inputDevice, enum wl_shell_surface_resize edges) override;
void resize(QWaylandInputDevice *inputDevice, Qt::Edges edges) override;
using QtWayland::wl_shell_surface::move;
bool move(QWaylandInputDevice *inputDevice) override;
@ -99,6 +99,7 @@ protected:
void requestWindowStates(Qt::WindowStates states) override;
private:
static enum resize convertToResizeEdges(Qt::Edges edges);
void setTopLevel();
void updateTransientParent(QWindow *parent);
void setPopup(QWaylandWindow *parent, QWaylandInputDevice *device, uint serial);

View File

@ -73,18 +73,19 @@ QWaylandXdgSurfaceV5::~QWaylandXdgSurfaceV5()
delete m_extendedWindow;
}
void QWaylandXdgSurfaceV5::resize(QWaylandInputDevice *inputDevice, enum wl_shell_surface_resize edges)
QtWayland::xdg_surface_v5::resize_edge QWaylandXdgSurfaceV5::convertToResizeEdges(Qt::Edges edges)
{
// May need some conversion if types get incompatibles, ATM they're identical
enum resize_edge const * const arg = reinterpret_cast<enum resize_edge const *>(&edges);
resize(inputDevice, *arg);
return static_cast<enum resize_edge>(
((edges & Qt::TopEdge) ? resize_edge_top : 0)
| ((edges & Qt::BottomEdge) ? resize_edge_bottom : 0)
| ((edges & Qt::LeftEdge) ? resize_edge_left : 0)
| ((edges & Qt::RightEdge) ? resize_edge_right : 0));
}
void QWaylandXdgSurfaceV5::resize(QWaylandInputDevice *inputDevice, enum resize_edge edges)
void QWaylandXdgSurfaceV5::resize(QWaylandInputDevice *inputDevice, Qt::Edges edges)
{
resize(inputDevice->wl_seat(),
inputDevice->serial(),
edges);
resize_edge resizeEdges = convertToResizeEdges(edges);
resize(inputDevice->wl_seat(), inputDevice->serial(), resizeEdges);
}
bool QWaylandXdgSurfaceV5::move(QWaylandInputDevice *inputDevice)

View File

@ -81,9 +81,8 @@ public:
~QWaylandXdgSurfaceV5() override;
using QtWayland::xdg_surface_v5::resize;
void resize(QWaylandInputDevice *inputDevice, enum resize_edge edges);
void resize(QWaylandInputDevice *inputDevice, enum wl_shell_surface_resize edges) override;
static resize_edge convertToResizeEdges(Qt::Edges edges);
void resize(QWaylandInputDevice *inputDevice, Qt::Edges edges) override;
using QtWayland::xdg_surface_v5::move;
bool move(QWaylandInputDevice *inputDevice) override;

View File

@ -150,6 +150,15 @@ void QWaylandXdgSurfaceV6::Toplevel::requestWindowStates(Qt::WindowStates states
}
}
QtWayland::zxdg_toplevel_v6::resize_edge QWaylandXdgSurfaceV6::Toplevel::convertToResizeEdges(Qt::Edges edges)
{
return static_cast<enum resize_edge>(
((edges & Qt::TopEdge) ? resize_edge_top : 0)
| ((edges & Qt::BottomEdge) ? resize_edge_bottom : 0)
| ((edges & Qt::LeftEdge) ? resize_edge_left : 0)
| ((edges & Qt::RightEdge) ? resize_edge_right : 0));
}
QWaylandXdgSurfaceV6::Popup::Popup(QWaylandXdgSurfaceV6 *xdgSurface, QWaylandXdgSurfaceV6 *parent,
QtWayland::zxdg_positioner_v6 *positioner)
: zxdg_popup_v6(xdgSurface->get_popup(parent->object(), positioner->object()))
@ -217,19 +226,13 @@ QWaylandXdgSurfaceV6::~QWaylandXdgSurfaceV6()
destroy();
}
void QWaylandXdgSurfaceV6::resize(QWaylandInputDevice *inputDevice, zxdg_toplevel_v6_resize_edge edges)
void QWaylandXdgSurfaceV6::resize(QWaylandInputDevice *inputDevice, Qt::Edges edges)
{
Q_ASSERT(m_toplevel && m_toplevel->isInitialized());
m_toplevel->resize(inputDevice->wl_seat(), inputDevice->serial(), edges);
auto resizeEdges = Toplevel::convertToResizeEdges(edges);
m_toplevel->resize(inputDevice->wl_seat(), inputDevice->serial(), resizeEdges);
}
void QWaylandXdgSurfaceV6::resize(QWaylandInputDevice *inputDevice, enum wl_shell_surface_resize edges)
{
auto xdgEdges = reinterpret_cast<enum zxdg_toplevel_v6_resize_edge const *>(&edges);
resize(inputDevice, *xdgEdges);
}
bool QWaylandXdgSurfaceV6::move(QWaylandInputDevice *inputDevice)
{
if (m_toplevel && m_toplevel->isInitialized()) {

View File

@ -79,8 +79,7 @@ public:
QWaylandXdgSurfaceV6(QWaylandXdgShellV6 *shell, ::zxdg_surface_v6 *surface, QWaylandWindow *window);
~QWaylandXdgSurfaceV6() override;
void resize(QWaylandInputDevice *inputDevice, enum zxdg_toplevel_v6_resize_edge edges);
void resize(QWaylandInputDevice *inputDevice, enum wl_shell_surface_resize edges) override;
void resize(QWaylandInputDevice *inputDevice, Qt::Edges edges) override;
bool move(QWaylandInputDevice *inputDevice) override;
void setTitle(const QString &title) override;
void setAppId(const QString &appId) override;
@ -108,6 +107,9 @@ private:
void zxdg_toplevel_v6_close() override;
void requestWindowStates(Qt::WindowStates states);
static resize_edge convertToResizeEdges(Qt::Edges edges);
struct {
QSize size = {0, 0};
Qt::WindowStates states = Qt::WindowNoState;

View File

@ -178,6 +178,15 @@ void QWaylandXdgSurface::Toplevel::requestWindowStates(Qt::WindowStates states)
}
}
QtWayland::xdg_toplevel::resize_edge QWaylandXdgSurface::Toplevel::convertToResizeEdges(Qt::Edges edges)
{
return static_cast<enum resize_edge>(
((edges & Qt::TopEdge) ? resize_edge_top : 0)
| ((edges & Qt::BottomEdge) ? resize_edge_bottom : 0)
| ((edges & Qt::LeftEdge) ? resize_edge_left : 0)
| ((edges & Qt::RightEdge) ? resize_edge_right : 0));
}
QWaylandXdgSurface::Popup::Popup(QWaylandXdgSurface *xdgSurface, QWaylandXdgSurface *parent,
QtWayland::xdg_positioner *positioner)
: xdg_popup(xdgSurface->get_popup(parent->object(), positioner->object()))
@ -245,19 +254,13 @@ QWaylandXdgSurface::~QWaylandXdgSurface()
destroy();
}
void QWaylandXdgSurface::resize(QWaylandInputDevice *inputDevice, xdg_toplevel_resize_edge edges)
void QWaylandXdgSurface::resize(QWaylandInputDevice *inputDevice, Qt::Edges edges)
{
Q_ASSERT(m_toplevel && m_toplevel->isInitialized());
m_toplevel->resize(inputDevice->wl_seat(), inputDevice->serial(), edges);
auto resizeEdges = Toplevel::convertToResizeEdges(edges);
m_toplevel->resize(inputDevice->wl_seat(), inputDevice->serial(), resizeEdges);
}
void QWaylandXdgSurface::resize(QWaylandInputDevice *inputDevice, enum wl_shell_surface_resize edges)
{
auto xdgEdges = reinterpret_cast<enum xdg_toplevel_resize_edge const *>(&edges);
resize(inputDevice, *xdgEdges);
}
bool QWaylandXdgSurface::move(QWaylandInputDevice *inputDevice)
{
if (m_toplevel && m_toplevel->isInitialized()) {

View File

@ -82,8 +82,7 @@ public:
QWaylandXdgSurface(QWaylandXdgShell *shell, ::xdg_surface *surface, QWaylandWindow *window);
~QWaylandXdgSurface() override;
void resize(QWaylandInputDevice *inputDevice, enum xdg_toplevel_resize_edge edges);
void resize(QWaylandInputDevice *inputDevice, enum wl_shell_surface_resize edges) override;
void resize(QWaylandInputDevice *inputDevice, Qt::Edges edges) override;
bool move(QWaylandInputDevice *inputDevice) override;
void setTitle(const QString &title) override;
void setAppId(const QString &appId) override;
@ -114,6 +113,9 @@ private:
void requestWindowFlags(Qt::WindowFlags flags);
void requestWindowStates(Qt::WindowStates states);
static resize_edge convertToResizeEdges(Qt::Edges edges);
struct {
QSize size = {0, 0};
Qt::WindowStates states = Qt::WindowNoState;

View File

@ -145,11 +145,11 @@ void QWaylandAbstractDecoration::setMouseButtons(Qt::MouseButtons mb)
d->m_mouseButtons = mb;
}
void QWaylandAbstractDecoration::startResize(QWaylandInputDevice *inputDevice, enum wl_shell_surface_resize resize, Qt::MouseButtons buttons)
void QWaylandAbstractDecoration::startResize(QWaylandInputDevice *inputDevice, Qt::Edges edges, Qt::MouseButtons buttons)
{
Q_D(QWaylandAbstractDecoration);
if (isLeftClicked(buttons) && d->m_wayland_window->shellSurface()) {
d->m_wayland_window->shellSurface()->resize(inputDevice, resize);
d->m_wayland_window->shellSurface()->resize(inputDevice, edges);
inputDevice->removeMouseButtonFromState(Qt::LeftButton);
}
}

View File

@ -105,7 +105,7 @@ protected:
void setMouseButtons(Qt::MouseButtons mb);
void startResize(QWaylandInputDevice *inputDevice,enum wl_shell_surface_resize resize, Qt::MouseButtons buttons);
void startResize(QWaylandInputDevice *inputDevice, Qt::Edges edges, Qt::MouseButtons buttons);
void startMove(QWaylandInputDevice *inputDevice, Qt::MouseButtons buttons);
bool isLeftClicked(Qt::MouseButtons newMouseButtonState);

View File

@ -75,8 +75,7 @@ class Q_WAYLAND_CLIENT_EXPORT QWaylandShellSurface : public QObject
public:
explicit QWaylandShellSurface(QWaylandWindow *window);
~QWaylandShellSurface() override {}
virtual void resize(QWaylandInputDevice * /*inputDevice*/, enum wl_shell_surface_resize /*edges*/)
{}
virtual void resize(QWaylandInputDevice * /*inputDevice*/, Qt::Edges /*edges*/) {}
virtual bool move(QWaylandInputDevice *) { return false; }
virtual void setTitle(const QString & /*title*/) {}