Skip to content

Commit

Permalink
qt5-wayland: Backport patch from Qt6 for QAdwaitaDecorations
Browse files Browse the repository at this point in the history
  • Loading branch information
joebonrichie committed Mar 25, 2024
1 parent b13be2a commit 78fcee0
Show file tree
Hide file tree
Showing 5 changed files with 242 additions and 11 deletions.
4 changes: 3 additions & 1 deletion packages/q/qt5-wayland/abi_symbols
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ libQt5WaylandClient.so.5:_ZN15QtWaylandClient14QWaylandWindow25handleWindowState
libQt5WaylandClient.so.5:_ZN15QtWaylandClient14QWaylandWindow26applyConfigureWhenPossibleEv
libQt5WaylandClient.so.5:_ZN15QtWaylandClient14QWaylandWindow30handleContentOrientationChangeEN2Qt17ScreenOrientationE
libQt5WaylandClient.so.5:_ZN15QtWaylandClient14QWaylandWindow30handleMouseEventWithDecorationEPNS_19QWaylandInputDeviceERKNS_20QWaylandPointerEventE
libQt5WaylandClient.so.5:_ZN15QtWaylandClient14QWaylandWindow39handleToplevelWindowTilingStatesChangedE6QFlagsINS0_25ToplevelWindowTilingStateEE
libQt5WaylandClient.so.5:_ZN15QtWaylandClient14QWaylandWindow5lowerEv
libQt5WaylandClient.so.5:_ZN15QtWaylandClient14QWaylandWindow5raiseEv
libQt5WaylandClient.so.5:_ZN15QtWaylandClient14QWaylandWindow5resetEv
Expand Down Expand Up @@ -1589,6 +1590,7 @@ libQt5WaylandClient.so.5:_ZNK15QtWaylandClient14QWaylandWindow16subSurfaceWindow
libQt5WaylandClient.so.5:_ZNK15QtWaylandClient14QWaylandWindow21windowContentGeometryEv
libQt5WaylandClient.so.5:_ZNK15QtWaylandClient14QWaylandWindow22shouldCreateSubSurfaceEv
libQt5WaylandClient.so.5:_ZNK15QtWaylandClient14QWaylandWindow24shouldCreateShellSurfaceEv
libQt5WaylandClient.so.5:_ZNK15QtWaylandClient14QWaylandWindow26toplevelWindowTilingStatesEv
libQt5WaylandClient.so.5:_ZNK15QtWaylandClient14QWaylandWindow32calculateScreenFromSurfaceEventsEv
libQt5WaylandClient.so.5:_ZNK15QtWaylandClient14QWaylandWindow5scaleEv
libQt5WaylandClient.so.5:_ZNK15QtWaylandClient14QWaylandWindow5winIdEv
Expand Down Expand Up @@ -6599,7 +6601,7 @@ libbradient.so:_ZN15QtWaylandClient26QWaylandBradientDecorationC2Ev
libbradient.so:_ZNK15QtWaylandClient26QWaylandBradientDecoration15closeButtonRectEv
libbradient.so:_ZNK15QtWaylandClient26QWaylandBradientDecoration18maximizeButtonRectEv
libbradient.so:_ZNK15QtWaylandClient26QWaylandBradientDecoration18minimizeButtonRectEv
libbradient.so:_ZNK15QtWaylandClient26QWaylandBradientDecoration7marginsEv
libbradient.so:_ZNK15QtWaylandClient26QWaylandBradientDecoration7marginsENS_26QWaylandAbstractDecoration11MarginsTypeE
libbradient.so:_ZTIN15QtWaylandClient26QWaylandBradientDecorationE
libbradient.so:_ZTSN15QtWaylandClient26QWaylandBradientDecorationE
libbradient.so:_ZTVN15QtWaylandClient26QWaylandBradientDecorationE
Expand Down
1 change: 0 additions & 1 deletion packages/q/qt5-wayland/abi_used_symbols
Original file line number Diff line number Diff line change
Expand Up @@ -1966,7 +1966,6 @@ libwayland-server.so.0:wl_event_loop_dispatch
libwayland-server.so.0:wl_event_loop_get_fd
libwayland-server.so.0:wl_global_create
libwayland-server.so.0:wl_global_destroy
libwayland-server.so.0:wl_list_init
libwayland-server.so.0:wl_list_remove
libwayland-server.so.0:wl_resource_add_destroy_listener
libwayland-server.so.0:wl_resource_create
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
# Required by qadwaitadecorations
diff --git a/src/client/qwaylandabstractdecoration_p.h b/src/client/qwaylandabstractdecoration_p.h
index 81c8e17..61cbde7 100644
--- a/src/client/qwaylandabstractdecoration_p.h
+++ b/src/client/qwaylandabstractdecoration_p.h
@@ -82,6 +82,12 @@ class Q_WAYLAND_CLIENT_EXPORT QWaylandAbstractDecoration : public QObject
Q_OBJECT
Q_DECLARE_PRIVATE(QWaylandAbstractDecoration)
public:
+ enum MarginsType {
+ Full,
+ ShadowsExcluded,
+ ShadowsOnly
+ };
+
QWaylandAbstractDecoration();
~QWaylandAbstractDecoration() override;

@@ -91,7 +97,8 @@ public:
void update();
bool isDirty() const;

- virtual QMargins margins() const = 0;
+ virtual QMargins margins(MarginsType marginsType = Full) const = 0;
+
QWindow *window() const;
const QImage &contentImage();

diff --git a/src/client/qwaylandwindow.cpp b/src/client/qwaylandwindow.cpp
index ec232cd..54b27f1 100644
--- a/src/client/qwaylandwindow.cpp
+++ b/src/client/qwaylandwindow.cpp
@@ -383,6 +383,16 @@ void QWaylandWindow::setGeometry(const QRect &r)
void QWaylandWindow::resizeFromApplyConfigure(const QSize &sizeWithMargins, const QPoint &offset)
{
QMargins margins = frameMargins();
+
+ // Exclude shadows from margins once they are excluded from window geometry
+ // 1) First resizeFromApplyConfigure() call will have sizeWithMargins equal to surfaceSize()
+ // which has full margins (shadows included).
+ // 2) Following resizeFromApplyConfigure() calls should have sizeWithMargins equal to
+ // windowContentGeometry() which excludes shadows, therefore in this case we have to
+ // exclude them too in order not to accidentally apply smaller size to the window.
+ if (mWindowDecoration && (sizeWithMargins != surfaceSize()))
+ margins = mWindowDecoration->margins(QWaylandAbstractDecoration::ShadowsExcluded);
+
int widthWithoutMargins = qMax(sizeWithMargins.width() - (margins.left() + margins.right()), 1);
int heightWithoutMargins = qMax(sizeWithMargins.height() - (margins.top() + margins.bottom()), 1);
QRect geometry(windowGeometry().topLeft(), QSize(widthWithoutMargins, heightWithoutMargins));
@@ -710,7 +720,12 @@ QSize QWaylandWindow::surfaceSize() const
*/
QRect QWaylandWindow::windowContentGeometry() const
{
- return QRect(QPoint(), surfaceSize());
+ QMargins shadowMargins;
+
+ if (mWindowDecoration)
+ shadowMargins = mWindowDecoration->margins(QWaylandAbstractDecoration::ShadowsOnly);
+
+ return QRect(QPoint(shadowMargins.left(), shadowMargins.top()), surfaceSize().shrunkBy(shadowMargins));
}

/*!
@@ -1111,6 +1126,16 @@ Qt::WindowStates QWaylandWindow::windowStates() const
return mLastReportedWindowStates;
}

+QWaylandWindow::ToplevelWindowTilingStates QWaylandWindow::toplevelWindowTilingStates() const
+{
+ return mLastReportedToplevelWindowTilingStates;
+}
+
+void QWaylandWindow::handleToplevelWindowTilingStatesChanged(ToplevelWindowTilingStates states)
+{
+ mLastReportedToplevelWindowTilingStates = states;
+}
+
void QWaylandWindow::handleWindowStatesChanged(Qt::WindowStates states)
{
createDecoration();
diff --git a/src/client/qwaylandwindow_p.h b/src/client/qwaylandwindow_p.h
index 1907f10..33a3b83 100644
--- a/src/client/qwaylandwindow_p.h
+++ b/src/client/qwaylandwindow_p.h
@@ -95,6 +95,15 @@ public:
Vulkan
};

+ enum ToplevelWindowTilingState {
+ WindowNoState = 0,
+ WindowTiledLeft = 1,
+ WindowTiledRight = 2,
+ WindowTiledTop = 4,
+ WindowTiledBottom = 8
+ };
+ Q_DECLARE_FLAGS(ToplevelWindowTilingStates, ToplevelWindowTilingState)
+
QWaylandWindow(QWindow *window, QWaylandDisplay *display);
~QWaylandWindow() override;

@@ -148,6 +157,9 @@ public:
void handleContentOrientationChange(Qt::ScreenOrientation orientation) override;
void setOrientationMask(Qt::ScreenOrientations mask);

+ ToplevelWindowTilingStates toplevelWindowTilingStates() const;
+ void handleToplevelWindowTilingStatesChanged(ToplevelWindowTilingStates states);
+
void setWindowState(Qt::WindowStates states) override;
void setWindowFlags(Qt::WindowFlags flags) override;
void handleWindowStatesChanged(Qt::WindowStates states);
@@ -260,6 +272,7 @@ protected:
QRegion mMask;
QRegion mOpaqueArea;
Qt::WindowStates mLastReportedWindowStates = Qt::WindowNoState;
+ ToplevelWindowTilingStates mLastReportedToplevelWindowTilingStates = WindowNoState;

QWaylandShmBackingStore *mBackingStore = nullptr;
QWaylandBuffer *mQueuedBuffer = nullptr;
@@ -296,6 +309,8 @@ private:
friend class QWaylandSubSurface;
};

+Q_DECLARE_OPERATORS_FOR_FLAGS(QWaylandWindow::ToplevelWindowTilingStates)
+
inline QIcon QWaylandWindow::windowIcon() const
{
return mWindowIcon;
diff --git a/src/plugins/decorations/bradient/main.cpp b/src/plugins/decorations/bradient/main.cpp
index e75fda3..72dda67 100644
--- a/src/plugins/decorations/bradient/main.cpp
+++ b/src/plugins/decorations/bradient/main.cpp
@@ -72,7 +72,7 @@ class Q_WAYLAND_CLIENT_EXPORT QWaylandBradientDecoration : public QWaylandAbstra
public:
QWaylandBradientDecoration();
protected:
- QMargins margins() const override;
+ QMargins margins(MarginsType marginsType = Full) const override;
void paint(QPaintDevice *device) override;
bool handleMouse(QWaylandInputDevice *inputDevice, const QPointF &local, const QPointF &global,Qt::MouseButtons b,Qt::KeyboardModifiers mods) override;
bool handleTouch(QWaylandInputDevice *inputDevice, const QPointF &local, const QPointF &global, Qt::TouchPointState state, Qt::KeyboardModifiers mods) override;
@@ -129,8 +129,11 @@ QRectF QWaylandBradientDecoration::minimizeButtonRect() const
(margins().top() - BUTTON_WIDTH) / 2, BUTTON_WIDTH, BUTTON_WIDTH);
}

-QMargins QWaylandBradientDecoration::margins() const
+QMargins QWaylandBradientDecoration::margins(MarginsType marginsType) const
{
+ if (marginsType == ShadowsOnly)
+ return QMargins();
+
return QMargins(3, 30, 3, 3);
}

diff --git a/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp b/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp
index 2666df2..8d8ac85 100644
--- a/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp
+++ b/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp
@@ -88,6 +88,7 @@ void QWaylandXdgSurface::Toplevel::applyConfigure()
&& !m_xdgSurface->m_window->display()->isKeyboardAvailable())
m_xdgSurface->m_window->display()->handleWindowDeactivated(m_xdgSurface->m_window);

+ m_xdgSurface->m_window->handleToplevelWindowTilingStatesChanged(m_toplevelStates);
m_xdgSurface->m_window->handleWindowStatesChanged(m_pending.states);

if (m_pending.size.isEmpty()) {
@@ -120,6 +121,7 @@ void QWaylandXdgSurface::Toplevel::xdg_toplevel_configure(int32_t width, int32_t
size_t numStates = states->size / sizeof(uint32_t);

m_pending.states = Qt::WindowNoState;
+ m_toplevelStates = QWaylandWindow::WindowNoState;

for (size_t i = 0; i < numStates; i++) {
switch (xdgStates[i]) {
@@ -132,6 +134,18 @@ void QWaylandXdgSurface::Toplevel::xdg_toplevel_configure(int32_t width, int32_t
case XDG_TOPLEVEL_STATE_FULLSCREEN:
m_pending.states |= Qt::WindowFullScreen;
break;
+ case XDG_TOPLEVEL_STATE_TILED_LEFT:
+ m_toplevelStates |= QWaylandWindow::WindowTiledLeft;
+ break;
+ case XDG_TOPLEVEL_STATE_TILED_RIGHT:
+ m_toplevelStates |= QWaylandWindow::WindowTiledRight;
+ break;
+ case XDG_TOPLEVEL_STATE_TILED_TOP:
+ m_toplevelStates |= QWaylandWindow::WindowTiledTop;
+ break;
+ case XDG_TOPLEVEL_STATE_TILED_BOTTOM:
+ m_toplevelStates |= QWaylandWindow::WindowTiledBottom;
+ break;
default:
break;
}
@@ -458,7 +472,7 @@ void QWaylandXdgSurface::xdg_surface_configure(uint32_t serial)
}

QWaylandXdgShell::QWaylandXdgShell(QWaylandDisplay *display, uint32_t id, uint32_t availableVersion)
- : QtWayland::xdg_wm_base(display->wl_registry(), id, qMin(availableVersion, 1u))
+ : QtWayland::xdg_wm_base(display->wl_registry(), id, qMin(availableVersion, 2u))
, m_display(display)
{
display->addRegistryListener(&QWaylandXdgShell::handleRegistryGlobal, this);
diff --git a/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell_p.h b/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell_p.h
index 0c98be3..d791213 100644
--- a/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell_p.h
+++ b/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell_p.h
@@ -58,6 +58,7 @@

#include <QtWaylandClient/qtwaylandclientglobal.h>
#include <QtWaylandClient/private/qwaylandshellsurface_p.h>
+#include <QtWaylandClient/private/qwaylandwindow_p.h>

#include <QtCore/QSize>
#include <QtGui/QRegion>
@@ -69,7 +70,6 @@ class QWindow;
namespace QtWaylandClient {

class QWaylandDisplay;
-class QWaylandWindow;
class QWaylandInputDevice;
class QWaylandXdgShell;

@@ -123,6 +123,7 @@ private:
QSize size = {0, 0};
Qt::WindowStates states = Qt::WindowNoState;
} m_pending, m_applied;
+ QWaylandWindow::ToplevelWindowTilingStates m_toplevelStates = QWaylandWindow::WindowNoState;
QSize m_normalSize;

QWaylandXdgSurface *m_xdgSurface = nullptr;
3 changes: 2 additions & 1 deletion packages/q/qt5-wayland/package.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name : qt5-wayland
version : 5.15.13
release : 51
release : 52
source :
- git|https://invent.kde.org/qt/qt/qtwayland.git : 9c82b5461736f59a06923ab68c6f7584ecab4f77
homepage : https://www.qt.io
Expand Down Expand Up @@ -39,6 +39,7 @@ patterns :
- devel :
- /usr/bin
setup : |
%patch -p1 -i $pkgfiles/qtwayland-decoration-support-backports-from-qt6.patch
%qmake CONFIG+="release wayland-compositor" qtwayland.pro
build : |
%make
Expand Down
16 changes: 8 additions & 8 deletions packages/q/qt5-wayland/pspec_x86_64.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<Name>qt5-wayland</Name>
<Homepage>https://www.qt.io</Homepage>
<Packager>
<Name>Reilly Brogan</Name>
<Email>solus@reillybrogan.com</Email>
<Name>Joey Riches</Name>
<Email>josephriches@gmail.com</Email>
</Packager>
<License>LGPL-2.1-or-later</License>
<License>LGPL-3.0-or-later</License>
Expand Down Expand Up @@ -84,7 +84,7 @@ own Wayland compositors.
</Description>
<PartOf>programming.library</PartOf>
<RuntimeDependencies>
<Dependency release="51">qt5-wayland</Dependency>
<Dependency release="52">qt5-wayland</Dependency>
</RuntimeDependencies>
<Files>
<Path fileType="library">/usr/lib64/qt5/examples/wayland/custom-extension/compositor/compositor.pro</Path>
Expand Down Expand Up @@ -247,7 +247,7 @@ own Wayland compositors.
</Description>
<PartOf>programming.devel</PartOf>
<RuntimeDependencies>
<Dependency release="51">qt5-wayland</Dependency>
<Dependency release="52">qt5-wayland</Dependency>
</RuntimeDependencies>
<Files>
<Path fileType="executable">/usr/bin/qtwaylandscanner</Path>
Expand Down Expand Up @@ -575,12 +575,12 @@ own Wayland compositors.
</Files>
</Package>
<History>
<Update release="51">
<Date>2024-03-14</Date>
<Update release="52">
<Date>2024-03-24</Date>
<Version>5.15.13</Version>
<Comment>Packaging update</Comment>
<Name>Reilly Brogan</Name>
<Email>solus@reillybrogan.com</Email>
<Name>Joey Riches</Name>
<Email>josephriches@gmail.com</Email>
</Update>
</History>
</PISI>

0 comments on commit 78fcee0

Please sign in to comment.