From d436a779d7f8dab974137324e2af3166edff2634 Mon Sep 17 00:00:00 2001 From: Kai Uwe Broulik Date: Wed, 23 Jul 2025 17:00:24 +0200 Subject: [PATCH] Request activate on show Unless the window doesn't have keyboard interactivity or the caller wants it not to. To match XDG Shell behavior and general Qt window behavior. --- src/interfaces/window.cpp | 11 +++++++++++ src/interfaces/window.h | 13 +++++++++++++ src/qwaylandlayersurface.cpp | 17 +++++++++++++++++ src/qwaylandlayersurface_p.h | 1 + 4 files changed, 42 insertions(+) diff --git a/src/interfaces/window.cpp b/src/interfaces/window.cpp index 4071977..2ef96da 100644 --- a/src/interfaces/window.cpp +++ b/src/interfaces/window.cpp @@ -35,6 +35,7 @@ public: QSize desiredSize = QSize(0, 0); Window::ScreenConfiguration screenConfiguration = Window::ScreenFromQWindow; bool closeOnDismissed = true; + bool activateOnShow = true; }; static QMap s_map; @@ -170,6 +171,16 @@ void Window::setCloseOnDismissed(bool close) d->closeOnDismissed = close; } +bool Window::activateOnShow() const +{ + return d->activateOnShow; +} + +void Window::setActivateOnShow(bool activateOnShow) +{ + d->activateOnShow = activateOnShow; +} + Window::Window(QWindow *window) : QObject(window) , d(new WindowPrivate(window)) diff --git a/src/interfaces/window.h b/src/interfaces/window.h index 40a9ca3..f2dd573 100644 --- a/src/interfaces/window.h +++ b/src/interfaces/window.h @@ -28,6 +28,7 @@ class LAYERSHELLQT_EXPORT Window : public QObject Q_PROPERTY(Layer layer READ layer WRITE setLayer NOTIFY layerChanged) Q_PROPERTY(KeyboardInteractivity keyboardInteractivity READ keyboardInteractivity WRITE setKeyboardInteractivity NOTIFY keyboardInteractivityChanged) Q_PROPERTY(ScreenConfiguration screenConfiguration READ screenConfiguration WRITE setScreenConfiguration) + Q_PROPERTY(bool activateOnShow READ activateOnShow WRITE setActivateOnShow) public: ~Window() override; @@ -117,6 +118,18 @@ public: void setCloseOnDismissed(bool close); bool closeOnDismissed() const; + /** + * Whether the window should requestActivate on show. + * + * Normally, you want this enabled but in case of e.g. a desktop window, this can be disabled. + * + * It does nothing when KeyboardInteractivity is KeyboardInteractivityNone. + * + * The default is true. + */ + void setActivateOnShow(bool activateOnShow); + bool activateOnShow() const; + /** * Gets the LayerShell Window for a given Qt Window * Ownership is not transferred diff --git a/src/qwaylandlayersurface.cpp b/src/qwaylandlayersurface.cpp index 3355c17..2a38456 100644 --- a/src/qwaylandlayersurface.cpp +++ b/src/qwaylandlayersurface.cpp @@ -230,6 +230,23 @@ bool QWaylandLayerSurface::requestActivate() return false; } +bool QWaylandLayerSurface::requestActivateOnShow() +{ + if (!m_interface->activateOnShow()) { + return false; + } + + if (m_interface->keyboardInteractivity() == Window::KeyboardInteractivityNone) { + return false; + } + + if (m_window->window()->property("_q_showWithoutActivating").toBool()) { + return false; + } + + return requestActivate(); +} + void QWaylandLayerSurface::setXdgActivationToken(const QString &token) { m_activationToken = token; diff --git a/src/qwaylandlayersurface_p.h b/src/qwaylandlayersurface_p.h index 079a295..acf502b 100644 --- a/src/qwaylandlayersurface_p.h +++ b/src/qwaylandlayersurface_p.h @@ -50,6 +50,7 @@ public: #endif bool requestActivate() override; + bool requestActivateOnShow() override; void setXdgActivationToken(const QString &token) override; void requestXdgActivationToken(quint32 serial) override;