diff options
author | Johan Klokkhammer Helsing <johan.helsing@qt.io> | 2018-08-02 15:41:52 +0200 |
---|---|---|
committer | Johan Helsing <johan.helsing@qt.io> | 2018-08-14 08:16:22 +0000 |
commit | 4d0ae358dd646c369829bb38c099eb47bd04db4a (patch) | |
tree | 0b6e9c283301c5f1444b2b4ce48d1eaa26623965 /src/plugins | |
parent | 0d568553ee849f9273bbd3675f4ceae200b3acd9 (diff) |
Client: Implement xdg-decoration-unstable-v1 for SSD support
[ChangeLog][QPA plugin] Added client-side support for the
xdg-decoration-unstable-v1 Wayland extension. Qt clients will now let the
compositor draw the window decorations if configured through this extension.
Note: The env var QT_WAYLAND_DISABLE_WINDOWDECORATION is still supported, but
works on a higher level, and for all shell integrations, while xdg-decoration
only works with xdg-shell stable.
Task-number: QTBUG-69746
Change-Id: I9dd0331bbd8d624c6be54ed23ee3b96446d5820d
Reviewed-by: Pier Luigi Fiorini <pierluigi.fiorini@liri.io>
Diffstat (limited to 'src/plugins')
6 files changed, 273 insertions, 8 deletions
diff --git a/src/plugins/shellintegration/xdg-shell/qwaylandxdgdecorationv1.cpp b/src/plugins/shellintegration/xdg-shell/qwaylandxdgdecorationv1.cpp new file mode 100644 index 000000000..345ff32ad --- /dev/null +++ b/src/plugins/shellintegration/xdg-shell/qwaylandxdgdecorationv1.cpp @@ -0,0 +1,105 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the config.tests of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qwaylandxdgdecorationv1_p.h" +#include "qwaylandxdgshell_p.h" + +QT_BEGIN_NAMESPACE + +namespace QtWaylandClient { + +QWaylandXdgDecorationManagerV1::QWaylandXdgDecorationManagerV1(wl_registry *registry, uint32_t id, uint32_t availableVersion) + : QtWayland::zxdg_decoration_manager_v1(registry, id, qMin(availableVersion, 1u)) +{ +} + +QWaylandXdgDecorationManagerV1::~QWaylandXdgDecorationManagerV1() +{ + Q_ASSERT(isInitialized()); + destroy(); +} + +QWaylandXdgToplevelDecorationV1 *QWaylandXdgDecorationManagerV1::createToplevelDecoration(::xdg_toplevel *toplevel) +{ + Q_ASSERT(toplevel); + return new QWaylandXdgToplevelDecorationV1(get_toplevel_decoration(toplevel)); +} + +QWaylandXdgToplevelDecorationV1::QWaylandXdgToplevelDecorationV1(::zxdg_toplevel_decoration_v1 *decoration) + : QtWayland::zxdg_toplevel_decoration_v1(decoration) +{ +} + +QWaylandXdgToplevelDecorationV1::~QWaylandXdgToplevelDecorationV1() +{ + Q_ASSERT(isInitialized()); + destroy(); +} + +void QWaylandXdgToplevelDecorationV1::requestMode(QtWayland::zxdg_toplevel_decoration_v1::mode mode) +{ + // According to the spec the client is responsible for not requesting a mode repeatedly. + if (m_modeSet && m_requested == mode) + return; + + set_mode(mode); + m_requested = mode; + m_modeSet = true; +} + +void QWaylandXdgToplevelDecorationV1::unsetMode() +{ + unset_mode(); + m_modeSet = false; + m_requested = mode_client_side; +} + +QWaylandXdgToplevelDecorationV1::mode QWaylandXdgToplevelDecorationV1::pending() const +{ + return m_pending; +} + +void QtWaylandClient::QWaylandXdgToplevelDecorationV1::zxdg_toplevel_decoration_v1_configure(uint32_t mode) +{ + m_pending = zxdg_toplevel_decoration_v1::mode(mode); +} + +} + +QT_END_NAMESPACE diff --git a/src/plugins/shellintegration/xdg-shell/qwaylandxdgdecorationv1_p.h b/src/plugins/shellintegration/xdg-shell/qwaylandxdgdecorationv1_p.h new file mode 100644 index 000000000..d6d8ce94e --- /dev/null +++ b/src/plugins/shellintegration/xdg-shell/qwaylandxdgdecorationv1_p.h @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the config.tests of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWAYLANDXDGDECORATIONV1_P_H +#define QWAYLANDXDGDECORATIONV1_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qwayland-xdg-decoration-unstable-v1.h" + +#include <QtWaylandClient/qtwaylandclientglobal.h> + +QT_BEGIN_NAMESPACE + +class QWindow; + +namespace QtWaylandClient { + +class QWaylandXdgToplevel; +class QWaylandXdgToplevelDecorationV1; + +class Q_WAYLAND_CLIENT_EXPORT QWaylandXdgDecorationManagerV1 : public QtWayland::zxdg_decoration_manager_v1 +{ +public: + QWaylandXdgDecorationManagerV1(struct ::wl_registry *registry, uint32_t id, uint32_t availableVersion); + ~QWaylandXdgDecorationManagerV1() override; + QWaylandXdgToplevelDecorationV1 *createToplevelDecoration(::xdg_toplevel *toplevel); +}; + +class Q_WAYLAND_CLIENT_EXPORT QWaylandXdgToplevelDecorationV1 : public QtWayland::zxdg_toplevel_decoration_v1 +{ +public: + QWaylandXdgToplevelDecorationV1(::zxdg_toplevel_decoration_v1 *decoration); + ~QWaylandXdgToplevelDecorationV1() override; + void requestMode(mode mode); + void unsetMode(); + mode pending() const; + +protected: + void zxdg_toplevel_decoration_v1_configure(uint32_t mode) override; + +private: + mode m_pending = mode_client_side; + mode m_requested = mode_client_side; + bool m_modeSet = false; +}; + +QT_END_NAMESPACE + +} + +#endif // QWAYLANDXDGDECORATIONV1_P_H diff --git a/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp b/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp index 12c77d80d..7dabd96f2 100644 --- a/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp +++ b/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp @@ -54,7 +54,12 @@ QWaylandXdgSurface::Toplevel::Toplevel(QWaylandXdgSurface *xdgSurface) : QtWayland::xdg_toplevel(xdgSurface->get_toplevel()) , m_xdgSurface(xdgSurface) { - requestWindowStates(xdgSurface->window()->window()->windowStates()); + if (auto *decorationManager = m_xdgSurface->m_shell->decorationManager()) + m_decoration = decorationManager->createToplevelDecoration(object()); + + QWindow *window = xdgSurface->window()->window(); + requestWindowStates(window->windowStates()); + requestWindowFlags(window->flags()); } QWaylandXdgSurface::Toplevel::~Toplevel() @@ -63,6 +68,11 @@ QWaylandXdgSurface::Toplevel::~Toplevel() QWaylandWindow *window = m_xdgSurface->window(); window->display()->handleWindowDeactivated(window); } + + // The protocol spec requires that the decoration object is deleted before xdg_toplevel. + delete m_decoration; + m_decoration = nullptr; + if (isInitialized()) destroy(); } @@ -91,6 +101,14 @@ void QWaylandXdgSurface::Toplevel::applyConfigure() m_applied = m_pending; } +bool QWaylandXdgSurface::Toplevel::wantsDecorations() +{ + if (m_decoration && m_decoration->pending() == QWaylandXdgToplevelDecorationV1::mode_server_side) + return false; + + return !(m_pending.states & Qt::WindowFullScreen); +} + void QWaylandXdgSurface::Toplevel::xdg_toplevel_configure(int32_t width, int32_t height, wl_array *states) { m_pending.size = QSize(width, height); @@ -124,6 +142,16 @@ void QWaylandXdgSurface::Toplevel::xdg_toplevel_close() m_xdgSurface->m_window->window()->close(); } +void QWaylandXdgSurface::Toplevel::requestWindowFlags(Qt::WindowFlags flags) +{ + if (m_decoration) { + if (flags & Qt::FramelessWindowHint) + m_decoration->requestMode(QWaylandXdgToplevelDecorationV1::mode_client_side); + else + m_decoration->unsetMode(); + } +} + void QWaylandXdgSurface::Toplevel::requestWindowStates(Qt::WindowStates states) { // Re-send what's different from the applied state @@ -237,6 +265,12 @@ void QWaylandXdgSurface::setAppId(const QString &appId) m_toplevel->set_app_id(appId); } +void QWaylandXdgSurface::setWindowFlags(Qt::WindowFlags flags) +{ + if (m_toplevel) + m_toplevel->requestWindowFlags(flags); +} + bool QWaylandXdgSurface::handleExpose(const QRegion ®ion) { if (!m_configured && !region.isEmpty()) { @@ -261,7 +295,7 @@ void QWaylandXdgSurface::applyConfigure() bool QWaylandXdgSurface::wantsDecorations() const { - return m_toplevel && !(m_toplevel->m_pending.states & Qt::WindowFullScreen); + return m_toplevel && m_toplevel->wantsDecorations(); } void QWaylandXdgSurface::requestWindowStates(Qt::WindowStates states) @@ -313,13 +347,16 @@ void QWaylandXdgSurface::xdg_surface_configure(uint32_t serial) } } -QWaylandXdgShell::QWaylandXdgShell(struct ::wl_registry *registry, uint32_t id, uint32_t availableVersion) - : QtWayland::xdg_wm_base(registry, id, qMin(availableVersion, 1u)) +QWaylandXdgShell::QWaylandXdgShell(QWaylandDisplay *display, uint32_t id, uint32_t availableVersion) + : QtWayland::xdg_wm_base(display->wl_registry(), id, qMin(availableVersion, 1u)) + , m_display(display) { + display->addRegistryListener(&QWaylandXdgShell::handleRegistryGlobal, this); } QWaylandXdgShell::~QWaylandXdgShell() { + m_display->removeListener(&QWaylandXdgShell::handleRegistryGlobal, this); destroy(); } @@ -333,6 +370,14 @@ void QWaylandXdgShell::xdg_wm_base_ping(uint32_t serial) pong(serial); } +void QWaylandXdgShell::handleRegistryGlobal(void *data, wl_registry *registry, uint id, + const QString &interface, uint version) +{ + QWaylandXdgShell *xdgShell = static_cast<QWaylandXdgShell *>(data); + if (interface == QLatin1String(QWaylandXdgDecorationManagerV1::interface()->name)) + xdgShell->m_xdgDecorationManager.reset(new QWaylandXdgDecorationManagerV1(registry, id, version)); +} + } QT_END_NAMESPACE diff --git a/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell_p.h b/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell_p.h index 7fb851315..37a4a8a4c 100644 --- a/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell_p.h +++ b/src/plugins/shellintegration/xdg-shell/qwaylandxdgshell_p.h @@ -54,6 +54,8 @@ #include "qwayland-xdg-shell.h" +#include "qwaylandxdgdecorationv1_p.h" + #include <QtWaylandClient/qtwaylandclientglobal.h> #include <QtWaylandClient/private/qwaylandshellsurface_p.h> @@ -68,6 +70,7 @@ class QWindow; namespace QtWaylandClient { +class QWaylandDisplay; class QWaylandWindow; class QWaylandInputDevice; class QWaylandXdgShell; @@ -84,6 +87,7 @@ public: bool move(QWaylandInputDevice *inputDevice) override; void setTitle(const QString &title) override; void setAppId(const QString &appId) override; + void setWindowFlags(Qt::WindowFlags flags) override; bool isExposed() const override { return m_configured; } bool handleExpose(const QRegion &) override; @@ -103,10 +107,12 @@ private: ~Toplevel() override; void applyConfigure(); + bool wantsDecorations(); void xdg_toplevel_configure(int32_t width, int32_t height, wl_array *states) override; void xdg_toplevel_close() override; + void requestWindowFlags(Qt::WindowFlags flags); void requestWindowStates(Qt::WindowStates states); struct { QSize size = {0, 0}; @@ -115,6 +121,7 @@ private: QSize m_normalSize; QWaylandXdgSurface *m_xdgSurface = nullptr; + QWaylandXdgToplevelDecorationV1 *m_decoration = nullptr; }; class Popup : public QtWayland::xdg_popup { @@ -142,14 +149,21 @@ private: class Q_WAYLAND_CLIENT_EXPORT QWaylandXdgShell : public QtWayland::xdg_wm_base { public: - QWaylandXdgShell(struct ::wl_registry *registry, uint32_t id, uint32_t availableVersion); + QWaylandXdgShell(QWaylandDisplay *display, uint32_t id, uint32_t availableVersion); + ~QWaylandXdgShell() override; + QWaylandXdgDecorationManagerV1 *decorationManager() { return m_xdgDecorationManager.data(); } QWaylandXdgSurface *getXdgSurface(QWaylandWindow *window); - ~QWaylandXdgShell() override; +protected: + void xdg_wm_base_ping(uint32_t serial) override; private: - void xdg_wm_base_ping(uint32_t serial) override; + static void handleRegistryGlobal(void *data, ::wl_registry *registry, uint id, + const QString &interface, uint version); + + QWaylandDisplay *m_display = nullptr; + QScopedPointer<QWaylandXdgDecorationManagerV1> m_xdgDecorationManager; }; QT_END_NAMESPACE diff --git a/src/plugins/shellintegration/xdg-shell/qwaylandxdgshellintegration.cpp b/src/plugins/shellintegration/xdg-shell/qwaylandxdgshellintegration.cpp index 54d5b55ed..8769d9716 100644 --- a/src/plugins/shellintegration/xdg-shell/qwaylandxdgshellintegration.cpp +++ b/src/plugins/shellintegration/xdg-shell/qwaylandxdgshellintegration.cpp @@ -38,6 +38,7 @@ ****************************************************************************/ #include "qwaylandxdgshellintegration_p.h" +#include "qwaylandxdgdecorationv1_p.h" #include <QtWaylandClient/private/qwaylandwindow_p.h> #include <QtWaylandClient/private/qwaylanddisplay_p.h> @@ -50,7 +51,7 @@ bool QWaylandXdgShellIntegration::initialize(QWaylandDisplay *display) { for (QWaylandDisplay::RegistryGlobal global : display->globals()) { if (global.interface == QLatin1String("xdg_wm_base")) { - m_xdgShell.reset(new QWaylandXdgShell(display->wl_registry(), global.id, global.version)); + m_xdgShell.reset(new QWaylandXdgShell(display, global.id, global.version)); break; } } diff --git a/src/plugins/shellintegration/xdg-shell/xdg-shell.pro b/src/plugins/shellintegration/xdg-shell/xdg-shell.pro index 1fabf2c64..2b1191af0 100644 --- a/src/plugins/shellintegration/xdg-shell/xdg-shell.pro +++ b/src/plugins/shellintegration/xdg-shell/xdg-shell.pro @@ -6,14 +6,17 @@ qtConfig(xkbcommon-evdev): \ QMAKE_USE_PRIVATE += xkbcommon_evdev WAYLANDCLIENTSOURCES += \ + ../../../3rdparty/protocol/xdg-decoration-unstable-v1.xml \ ../../../3rdparty/protocol/xdg-shell.xml HEADERS += \ + qwaylandxdgdecorationv1_p.h \ qwaylandxdgshell_p.h \ qwaylandxdgshellintegration_p.h \ SOURCES += \ main.cpp \ + qwaylandxdgdecorationv1.cpp \ qwaylandxdgshell.cpp \ qwaylandxdgshellintegration.cpp \ |