From 91dbee4c6eb2dcb1c16bf02f2571001726ba6eb1 Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Wed, 12 Sep 2018 15:02:09 +0200 Subject: 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 Reviewed-by: Pier Luigi Fiorini --- src/client/qwaylandabstractdecoration.cpp | 4 ++-- src/client/qwaylandabstractdecoration_p.h | 2 +- src/client/qwaylandshellsurface_p.h | 3 +-- src/plugins/decorations/bradient/main.cpp | 16 ++++++++-------- .../wl-shell/qwaylandwlshellsurface.cpp | 15 +++++++++++---- .../wl-shell/qwaylandwlshellsurface_p.h | 3 ++- .../xdg-shell-v5/qwaylandxdgsurfacev5.cpp | 17 +++++++++-------- .../xdg-shell-v5/qwaylandxdgsurfacev5_p.h | 5 ++--- .../xdg-shell-v6/qwaylandxdgshellv6.cpp | 21 ++++++++++++--------- .../xdg-shell-v6/qwaylandxdgshellv6_p.h | 6 ++++-- .../shellintegration/xdg-shell/qwaylandxdgshell.cpp | 21 ++++++++++++--------- .../shellintegration/xdg-shell/qwaylandxdgshell_p.h | 6 ++++-- 12 files changed, 68 insertions(+), 51 deletions(-) diff --git a/src/client/qwaylandabstractdecoration.cpp b/src/client/qwaylandabstractdecoration.cpp index 479a85750..503ad41fc 100644 --- a/src/client/qwaylandabstractdecoration.cpp +++ b/src/client/qwaylandabstractdecoration.cpp @@ -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); } } diff --git a/src/client/qwaylandabstractdecoration_p.h b/src/client/qwaylandabstractdecoration_p.h index 84a6d4dd7..d1b11928a 100644 --- a/src/client/qwaylandabstractdecoration_p.h +++ b/src/client/qwaylandabstractdecoration_p.h @@ -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); diff --git a/src/client/qwaylandshellsurface_p.h b/src/client/qwaylandshellsurface_p.h index 6bc3258c7..f034e1bdb 100644 --- a/src/client/qwaylandshellsurface_p.h +++ b/src/client/qwaylandshellsurface_p.h @@ -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*/) {} diff --git a/src/plugins/decorations/bradient/main.cpp b/src/plugins/decorations/bradient/main.cpp index 3fa723446..83dc8604b 100644 --- a/src/plugins/decorations/bradient/main.cpp +++ b/src/plugins/decorations/bradient/main.cpp @@ -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 diff --git a/src/plugins/shellintegration/wl-shell/qwaylandwlshellsurface.cpp b/src/plugins/shellintegration/wl-shell/qwaylandwlshellsurface.cpp index d9bc83059..ccab131d8 100644 --- a/src/plugins/shellintegration/wl-shell/qwaylandwlshellsurface.cpp +++ b/src/plugins/shellintegration/wl-shell/qwaylandwlshellsurface.cpp @@ -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( + ((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() { diff --git a/src/plugins/shellintegration/wl-shell/qwaylandwlshellsurface_p.h b/src/plugins/shellintegration/wl-shell/qwaylandwlshellsurface_p.h index 57e06525a..86305e4e5 100644 --- a/src/plugins/shellintegration/wl-shell/qwaylandwlshellsurface_p.h +++ b/src/plugins/shellintegration/wl-shell/qwaylandwlshellsurface_p.h @@ -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); diff --git a/src/plugins/shellintegration/xdg-shell-v5/qwaylandxdgsurfacev5.cpp b/src/plugins/shellintegration/xdg-shell-v5/qwaylandxdgsurfacev5.cpp index 61a865cb2..b691ee747 100644 --- a/src/plugins/shellintegration/xdg-shell-v5/qwaylandxdgsurfacev5.cpp +++ b/src/plugins/shellintegration/xdg-shell-v5/qwaylandxdgsurfacev5.cpp @@ -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(&edges); - resize(inputDevice, *arg); + return static_cast( + ((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) diff --git a/src/plugins/shellintegration/xdg-shell-v5/qwaylandxdgsurfacev5_p.h b/src/plugins/shellintegration/xdg-shell-v5/qwaylandxdgsurfacev5_p.h index b938047ec..741366fb5 100644 --- a/src/plugins/shellintegration/xdg-shell-v5/qwaylandxdgsurfacev5_p.h +++ b/src/plugins/shellintegration/xdg-shell-v5/qwaylandxdgsurfacev5_p.h @@ -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; diff --git a/src/plugins/shellintegration/xdg-shell-v6/qwaylandxdgshellv6.cpp b/src/plugins/shellintegration/xdg-shell-v6/qwaylandxdgshellv6.cpp index 1dc43b371..f43df36cb 100644 --- a/src/plugins/shellintegration/xdg-shell-v6/qwaylandxdgshellv6.cpp +++ b/src/plugins/shellintegration/xdg-shell-v6/qwaylandxdgshellv6.cpp @@ -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( + ((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(&edges); - resize(inputDevice, *xdgEdges); -} - - bool QWaylandXdgSurfaceV6::move(QWaylandInputDevice *inputDevice) { if (m_toplevel && m_toplevel->isInitialized()) { diff --git a/src/plugins/shellintegration/xdg-shell-v6/qwaylandxdgshellv6_p.h b/src/plugins/shellintegration/xdg-shell-v6/qwaylandxdgshellv6_p.h index 38b711f88..c6e898121 100644 --- a/src/plugins/shellintegration/xdg-shell-v6/qwaylandxdgshellv6_p.h +++ b/src/plugins/shellintegration/xdg-shell-v6/qwaylandxdgshellv6_p.h @@ -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; diff --git a/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp b/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp index 8b3d07481..07067e120 100644 --- a/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp +++ b/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp @@ -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( + ((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(&edges); - resize(inputDevice, *xdgEdges); -} - - bool QWaylandXdgSurface::move(QWaylandInputDevice *inputDevice) { if (m_toplevel && m_toplevel->isInitialized()) { diff --git a/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell_p.h b/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell_p.h index 45d7d4b0e..591df9ddd 100644 --- a/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell_p.h +++ b/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell_p.h @@ -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; -- cgit v1.2.3