diff options
author | Bernd Weimer <bernd.weimer@pelagicore.com> | 2020-09-16 11:05:04 +0200 |
---|---|---|
committer | Bernd Weimer <bernd.weimer@pelagicore.com> | 2020-09-21 13:26:33 +0200 |
commit | 5820ee2dc4f0dcf1a1d2679351cfae293a5143f3 (patch) | |
tree | 0e8195840466152f67a31701756cc99f094bfb5b | |
parent | c77202bd69d9589fac1be14b4e32e09b8e23d061 (diff) |
Fix window properties (show-hide-show)
With QtWayand patch e18cfb5 we cannot rely any more on the fake
PlatformSurface SurfaceCreated event for sending window properties
from client to server, when the window is made visible again. We need
to attach to the Expose event instead. To reduce IPC, redundant
Expose events are ignored. Unfortunately, the Show event cannot be
used since there might not be a mapping from the window to the
Wayland surface.
Change-Id: I476fd6ae2968f90f25aef6533e6eb5c3b26a613b
Reviewed-by: Robert Griebl <robert.griebl@qt.io>
-rw-r--r-- | src/launcher-lib/waylandqtamclientextension.cpp | 53 | ||||
-rw-r--r-- | src/launcher-lib/waylandqtamclientextension_p.h | 2 |
2 files changed, 30 insertions, 25 deletions
diff --git a/src/launcher-lib/waylandqtamclientextension.cpp b/src/launcher-lib/waylandqtamclientextension.cpp index 69cd7dac..b58fe676 100644 --- a/src/launcher-lib/waylandqtamclientextension.cpp +++ b/src/launcher-lib/waylandqtamclientextension.cpp @@ -44,7 +44,7 @@ #include <QWindow> #include <QGuiApplication> -#include <QPlatformSurfaceEvent> +#include <QEvent> #include <qpa/qplatformnativeinterface.h> #include <QtAppManCommon/logging.h> @@ -64,29 +64,31 @@ WaylandQtAMClientExtension::~WaylandQtAMClientExtension() bool WaylandQtAMClientExtension::eventFilter(QObject *o, QEvent *e) { - if (e->type() == QEvent::PlatformSurface) { - QWindow *window = qobject_cast<QWindow *>(o); - if (!window) - return false; + if (e->type() == QEvent::Expose) { if (!isActive()) { - qCWarning(LogGraphics) << "Tried to (un)register a Wayland qtam_extended_surface, but the extension itself is not active"; + qCWarning(LogGraphics) << "WaylandQtAMClientExtension is not active"; return false; } - switch (static_cast<QPlatformSurfaceEvent *>(e)->surfaceEventType()) { - case QPlatformSurfaceEvent::SurfaceCreated: { - auto surface = static_cast<struct ::wl_surface *>(QGuiApplication::platformNativeInterface()->nativeResourceForWindow("surface", window)); - m_windows.insert(surface, window); - const QVariantMap wp = windowProperties(window); - for (auto it = wp.cbegin(); it != wp.cend(); ++it) - sendPropertyToServer(surface, it.key(), it.value()); - break; - } - case QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed: - // NOOP - break; - } + if (static_cast<QExposeEvent *>(e)->region().isNull()) + return false; + + QWindow *window = qobject_cast<QWindow *>(o); + Q_ASSERT(window); + + if (m_windowToSurface.contains(window)) + return false; + + auto surface = static_cast<struct ::wl_surface *> + (QGuiApplication::platformNativeInterface()->nativeResourceForWindow("surface", window)); + m_windowToSurface.insert(window, surface); + const QVariantMap wp = windowProperties(window); + for (auto it = wp.cbegin(); it != wp.cend(); ++it) + sendPropertyToServer(surface, it.key(), it.value()); + } else if (e->type() == QEvent::Hide) { + m_windowToSurface.remove(qobject_cast<QWindow *>(o)); } + return false; } @@ -95,7 +97,8 @@ QVariantMap WaylandQtAMClientExtension::windowProperties(QWindow *window) const return m_windowProperties.value(window); } -void WaylandQtAMClientExtension::sendPropertyToServer(struct ::wl_surface *surface, const QString &name, const QVariant &value) +void WaylandQtAMClientExtension::sendPropertyToServer(struct ::wl_surface *surface, const QString &name, + const QVariant &value) { QByteArray byteValue; QDataStream ds(&byteValue, QIODevice::WriteOnly); @@ -106,8 +109,9 @@ void WaylandQtAMClientExtension::sendPropertyToServer(struct ::wl_surface *surfa void WaylandQtAMClientExtension::setWindowProperty(QWindow *window, const QString &name, const QVariant &value) { - if (setWindowPropertyHelper(window, name, value)) { - auto surface = static_cast<struct ::wl_surface *>(QGuiApplication::platformNativeInterface()->nativeResourceForWindow("surface", window)); + if (setWindowPropertyHelper(window, name, value) && m_windowToSurface.contains(window)) { + auto surface = static_cast<struct ::wl_surface *> + (QGuiApplication::platformNativeInterface()->nativeResourceForWindow("surface", window)); if (surface) sendPropertyToServer(surface, name, value); } @@ -133,14 +137,15 @@ void WaylandQtAMClientExtension::clearWindowPropertyCache(QWindow *window) m_windowProperties.remove(window); } -void WaylandQtAMClientExtension::qtam_extension_window_property_changed(wl_surface *surface, const QString &name, wl_array *value) +void WaylandQtAMClientExtension::qtam_extension_window_property_changed(wl_surface *surface, const QString &name, + wl_array *value) { const QByteArray data = QByteArray::fromRawData(static_cast<char *>(value->data), int(value->size)); QDataStream ds(data); QVariant variantValue; ds >> variantValue; - QWindow *window = m_windows.value(surface); + QWindow *window = m_windowToSurface.key(surface); qCDebug(LogWaylandDebug) << "CLIENT <<prop<<" << window << name << variantValue; if (!window) return; diff --git a/src/launcher-lib/waylandqtamclientextension_p.h b/src/launcher-lib/waylandqtamclientextension_p.h index c2814855..086cb44c 100644 --- a/src/launcher-lib/waylandqtamclientextension_p.h +++ b/src/launcher-lib/waylandqtamclientextension_p.h @@ -88,7 +88,7 @@ private: void qtam_extension_window_property_changed(wl_surface *surface, const QString &name, wl_array *value) override; QMap<QWindow *, QVariantMap> m_windowProperties; - QMap<::wl_surface *, QWindow *> m_windows; + QMap<QWindow *, ::wl_surface *> m_windowToSurface; }; QT_END_NAMESPACE_AM |