summaryrefslogtreecommitdiffstats
path: root/src/client/qwaylandwindow.cpp
diff options
context:
space:
mode:
authorJohan Klokkhammer Helsing <johan.helsing@qt.io>2018-03-06 13:06:11 +0100
committerJohan Helsing <johan.helsing@qt.io>2018-05-07 11:34:41 +0000
commitc5ab40d2573fde27a14d7c05d8693966c65a400c (patch)
treed93c4647c90b0d72059b9148a6b4ca1d3f7cc272 /src/client/qwaylandwindow.cpp
parent9db98c7e0a2656988d5c549f0618b2ba882f1fc9 (diff)
Client: Add acked configure support and implement it for xdg-shell v6
The problem: The code in QWaylandWindow::setWindowStateInternal made many assumptions about how the shell surface responded to new window states, and when and if they were applied. Particularly: - The shell integrations support different subsets of Qt::WindowStates, so it doesn't make sense to map from states to setFullscreen, setNormal, etc. in QWaylandWindow because it really depends on the shell integration how it should be handled. - Some states are not supported/unknown on some shells and should immediately be rejected. - On some shells, particularly those where the current state is unknown, flags need to be resent even though they didn't change. - Should handleWindowStatesChanged be called immediately (client decides) or should it wait for a configure event (compositor decides)? I.e. the mState variable only makes sense for some shells. Furthermore, when state changes come from the compositors, some shell integrations require that a configure event is acked by the client and that the next committed buffer's size and content matches that configure event. Previously, we would just ack immediately and still send a buffer with the old size before a correct frame was drawn. i.e. sending incorrect acks, which would lead to protocol errors on some compositors. Additionally, QWaylandWindow::createDecoration() also assumed that windows should have decorations unless they are fullscreen. This is not always the case, particularly on ivi-application and probably on future shell integrations for embedded or tiling window managers etc. The Solution: The responsibility of mapping requested window states to Wayland requests have been moved to the QWaylandShellSurface implementation. QWaylandWindow now calls a new virtual, QWaylandShellSurface::requestWindowStates(Qt::WindowStates), instead of trying to be smart about it. The virtual getters and setters for window states have now been removed from the QWaylandShellSurface interface. It's now also the shell surface implementation's responsibility to call QWaylandWindow::handleWindowStatesChanged if and when it knows a new state is effective. QWaylandWindow::configure has been replaced with QWaylandWindow::applyConfigureWhenPossible(), which causes another new virtual, QWaylandShellSurface::applyConfigure(), to be called whenever we're free to resize and change the states of the next buffer (this is when states should be acked). This means that shells that use acked states need to store the pending states themselves, call applyConfigureWhenPossible(), wait for applyConfigure() to be called, call resizeFromApplyConfigure() and handleWindowStatesChanged(), and finally ack the applied state. Acked state for xdg-shell v5 and v6 has now been implemented, which also means we've now: [ChangeLog][QPA plugin] Implemented support for maximizing, minimizing, and setting fullscreen with xdg-shell unstable v6. [ChangeLog][QPA plugin] QWindow::isActive now follows configure events on xdg-shell unstable v6 (like v5). QWaylandWindow::createDecoration queries QWaylandShellSurface::wantsDecoration before creating window decorations, instead of using the previously unreliable QWaylandWindow::isFullscreen(). [ChangeLog][QPA plugin] Window decorations are now automatically disabled for ivi-application. The refactor also removes a couple of hacks: - QWindowSystemInterface::flushWindowSystemEvents() was called in QWaylandWindow::setWindowStates. Since this hack was introduced, the events now have oldState and newState members, and their values seem to make sense (ensured in the tests). - The hack for unminimizing on xdg-shell v5 in QWaylandWindow::createDecoration was not needed anymore. Finally, tests have been added for xdg-shell v6 to ensure that the right Wayland requests are sent, that we respond to configure events from the compositor, and that the Qt events and signals emitted on the client side make sense. Task-number: QTBUG-53702 Task-number: QTBUG-63417 Task-number: QTBUG-63748 Task-number: QTBUG-66928 Change-Id: Ib4c36b69105750f9dbdcc78adcf71e2e994cc70d Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
Diffstat (limited to 'src/client/qwaylandwindow.cpp')
-rw-r--r--src/client/qwaylandwindow.cpp120
1 files changed, 35 insertions, 85 deletions
diff --git a/src/client/qwaylandwindow.cpp b/src/client/qwaylandwindow.cpp
index 6154689df..21c9f82b0 100644
--- a/src/client/qwaylandwindow.cpp
+++ b/src/client/qwaylandwindow.cpp
@@ -200,11 +200,8 @@ void QWaylandWindow::initWindow()
else
setGeometry_helper(window()->geometry());
setMask(window()->mask());
- // setWindowStateInternal is a no-op if the argument is equal to mState,
- // but since we're creating the shellsurface only now we reset mState to
- // make sure the state gets sent out to the compositor
- mState = Qt::WindowNoState;
- setWindowStateInternal(window()->windowStates());
+ if (mShellSurface)
+ mShellSurface->requestWindowStates(window()->windowStates());
handleContentOrientationChange(window()->contentOrientation());
mFlags = window()->flags();
}
@@ -333,7 +330,16 @@ void QWaylandWindow::setGeometry(const QRect &rect)
sendExposeEvent(QRect(QPoint(), geometry().size()));
}
+void QWaylandWindow::resizeFromApplyConfigure(const QSize &sizeWithMargins, const QPoint &offset)
+{
+ QMargins margins = frameMargins();
+ int widthWithoutMargins = qMax(sizeWithMargins.width() - (margins.left()+margins.right()), 1);
+ int heightWithoutMargins = qMax(sizeWithMargins.height() - (margins.top()+margins.bottom()), 1);
+ QRect geometry(QPoint(), QSize(widthWithoutMargins, heightWithoutMargins));
+ mOffset += offset;
+ setGeometry(geometry);
+}
void QWaylandWindow::sendExposeEvent(const QRect &rect)
{
@@ -421,46 +427,24 @@ void QWaylandWindow::setMask(const QRegion &mask)
wl_surface::commit();
}
-void QWaylandWindow::configure(uint32_t edges, int32_t width, int32_t height)
+void QWaylandWindow::applyConfigureWhenPossible()
{
QMutexLocker resizeLocker(&mResizeLock);
- mConfigure.edges |= edges;
- mConfigure.width = width;
- mConfigure.height = height;
-
- if (!mRequestResizeSent && !mConfigure.isEmpty()) {
- mRequestResizeSent= true;
- QMetaObject::invokeMethod(this, "requestResize", Qt::QueuedConnection);
+ if (!mWaitingToApplyConfigure) {
+ mWaitingToApplyConfigure = true;
+ QMetaObject::invokeMethod(this, "applyConfigure", Qt::QueuedConnection);
}
}
-void QWaylandWindow::doResize()
+void QWaylandWindow::doApplyConfigure()
{
- if (mConfigure.isEmpty()) {
+ if (!mWaitingToApplyConfigure)
return;
- }
-
- int widthWithoutMargins = qMax(mConfigure.width-(frameMargins().left() +frameMargins().right()),1);
- int heightWithoutMargins = qMax(mConfigure.height-(frameMargins().top()+frameMargins().bottom()),1);
- widthWithoutMargins = qMax(widthWithoutMargins, window()->minimumSize().width());
- heightWithoutMargins = qMax(heightWithoutMargins, window()->minimumSize().height());
- QRect geometry = QRect(0,0, widthWithoutMargins, heightWithoutMargins);
-
- int x = 0;
- int y = 0;
- QSize size = this->geometry().size();
- if (mConfigure.edges & WL_SHELL_SURFACE_RESIZE_LEFT) {
- x = size.width() - geometry.width();
- }
- if (mConfigure.edges & WL_SHELL_SURFACE_RESIZE_TOP) {
- y = size.height() - geometry.height();
- }
- mOffset += QPoint(x, y);
-
- setGeometry(geometry);
+ if (mShellSurface)
+ mShellSurface->applyConfigure();
- mConfigure.clear();
+ mWaitingToApplyConfigure = false;
}
void QWaylandWindow::setCanResize(bool canResize)
@@ -472,8 +456,8 @@ void QWaylandWindow::setCanResize(bool canResize)
if (mResizeDirty) {
QWindowSystemInterface::handleGeometryChange(window(), geometry());
}
- if (!mConfigure.isEmpty()) {
- doResize();
+ if (mWaitingToApplyConfigure) {
+ doApplyConfigure();
sendExposeEvent(QRect(QPoint(), geometry().size()));
} else if (mResizeDirty) {
mResizeDirty = false;
@@ -482,15 +466,13 @@ void QWaylandWindow::setCanResize(bool canResize)
}
}
-void QWaylandWindow::requestResize()
+void QWaylandWindow::applyConfigure()
{
QMutexLocker lock(&mResizeLock);
- if (mCanResize || !mSentInitialResize) {
- doResize();
- }
+ if (mCanResize || !mSentInitialResize)
+ doApplyConfigure();
- mRequestResizeSent = false;
lock.unlock();
sendExposeEvent(QRect(QPoint(), geometry().size()));
QWindowSystemInterface::flushWindowSystemEvents();
@@ -672,10 +654,10 @@ void QWaylandWindow::setOrientationMask(Qt::ScreenOrientations mask)
mShellSurface->setContentOrientationMask(mask);
}
-void QWaylandWindow::setWindowState(Qt::WindowStates state)
+void QWaylandWindow::setWindowState(Qt::WindowStates states)
{
- if (setWindowStateInternal(state))
- QWindowSystemInterface::flushWindowSystemEvents(); // Required for oldState to work on WindowStateChanged
+ if (mShellSurface)
+ mShellSurface->requestWindowStates(states);
}
void QWaylandWindow::setWindowFlags(Qt::WindowFlags flags)
@@ -689,20 +671,6 @@ void QWaylandWindow::setWindowFlags(Qt::WindowFlags flags)
bool QWaylandWindow::createDecoration()
{
- // so far only xdg-shell support this "unminimize" trick, may be moved elsewhere
- if (mState & Qt::WindowMinimized) {
- QWaylandXdgSurface *xdgSurface = qobject_cast<QWaylandXdgSurface *>(mShellSurface);
- if ( xdgSurface ) {
- Qt::WindowStates states;
- if (xdgSurface->isFullscreen())
- states |= Qt::WindowFullScreen;
- if (xdgSurface->isMaximized())
- states |= Qt::WindowMaximized;
-
- setWindowStateInternal(states);
- }
- }
-
if (!mDisplay->supportsWindowDecoration())
return false;
@@ -719,12 +687,14 @@ bool QWaylandWindow::createDecoration()
default:
break;
}
- if (mFlags & Qt::FramelessWindowHint || isFullscreen())
+ if (mFlags & Qt::FramelessWindowHint)
decoration = false;
if (mFlags & Qt::BypassWindowManagerHint)
decoration = false;
if (mSubSurfaceWindow)
decoration = false;
+ if (mShellSurface && !mShellSurface->wantsDecorations())
+ decoration = false;
bool hadDecoration = mWindowDecoration;
if (decoration && !decorationPluginFailed) {
@@ -970,31 +940,11 @@ bool QWaylandWindow::setMouseGrabEnabled(bool grab)
return true;
}
-bool QWaylandWindow::setWindowStateInternal(Qt::WindowStates state)
+void QWaylandWindow::handleWindowStatesChanged(Qt::WindowStates states)
{
- if (mState == state) {
- return false;
- }
-
- // As of february 2013 QWindow::setWindowState sets the new state value after
- // QPlatformWindow::setWindowState returns, so we cannot rely on QWindow::windowState
- // here. We use then this mState variable.
- mState = state;
-
- if (mShellSurface) {
- createDecoration();
- if (state & Qt::WindowMaximized)
- mShellSurface->setMaximized();
- if (state & Qt::WindowFullScreen)
- mShellSurface->setFullscreen();
- if (state & Qt::WindowMinimized)
- mShellSurface->setMinimized();
- if (!state)
- mShellSurface->setNormal();
- }
-
- QWindowSystemInterface::handleWindowStateChanged(window(), mState);
- return true;
+ createDecoration();
+ QWindowSystemInterface::handleWindowStateChanged(window(), states, mLastReportedWindowStates);
+ mLastReportedWindowStates = states;
}
void QWaylandWindow::sendProperty(const QString &name, const QVariant &value)