From 9e5c32e1ab2faa80f84e92f7f2c3b292100b529b Mon Sep 17 00:00:00 2001 From: Fabian Vogt Date: Tue, 21 Feb 2023 16:03:51 +0100 Subject: [PATCH] Use the QScreen of the QWindow as default output If the Window::setDesiredOutput API was not called for the QWindow, use QWindow::screen(). This allows assigning QWindows to specific screens using the plain Qt API. Passing nullptr to Window::setDesiredOutput explicitly results in nil as desired output for the layer, which lets the compositor select a screen. --- src/interfaces/window.cpp | 10 ++++++++-- src/interfaces/window.h | 1 + src/qwaylandlayersurface.cpp | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/interfaces/window.cpp b/src/interfaces/window.cpp index 477b74e..eba46db 100644 --- a/src/interfaces/window.cpp +++ b/src/interfaces/window.cpp @@ -8,6 +8,7 @@ #include #include +#include using namespace LayerShellQt; @@ -26,7 +27,7 @@ public: Window::KeyboardInteractivity keyboardInteractivity = Window::KeyboardInteractivityExclusive; Window::Layer layer = Window::LayerTop; QMargins margins; - QPointer desiredOutput; + std::optional> desiredOutput; }; static QMap s_map; @@ -103,7 +104,7 @@ Window::Layer Window::layer() const QScreen *Window::desiredOutput() const { - return d->desiredOutput; + return d->desiredOutput.value_or(nullptr); } void Window::setDesiredOutput(QScreen *output) @@ -111,6 +112,11 @@ void Window::setDesiredOutput(QScreen *output) d->desiredOutput = output; } +bool Window::desiredOutputSet() const +{ + return d->desiredOutput.has_value(); +} + Window::Window(QWindow *window) : QObject(window) , d(new WindowPrivate(window)) diff --git a/src/interfaces/window.h b/src/interfaces/window.h index 5ebc9b1..81ff603 100644 --- a/src/interfaces/window.h +++ b/src/interfaces/window.h @@ -76,6 +76,7 @@ public: */ void setDesiredOutput(QScreen *output); QScreen *desiredOutput() const; + bool desiredOutputSet() const; /** * Sets a string based identifier for this window. diff --git a/src/qwaylandlayersurface.cpp b/src/qwaylandlayersurface.cpp index dd17aa0..a355845 100644 --- a/src/qwaylandlayersurface.cpp +++ b/src/qwaylandlayersurface.cpp @@ -24,7 +24,7 @@ QWaylandLayerSurface::QWaylandLayerSurface(QWaylandLayerShell *shell, QtWaylandC Q_ASSERT(interface); wl_output *output = nullptr; - QScreen *screen = interface->desiredOutput(); + QScreen *screen = interface->desiredOutputSet() ? interface->desiredOutput() : window->window()->screen(); if (screen) { auto waylandScreen = dynamic_cast(screen->handle()); // Qt will always assign a screen to a window, but if the compositor has no screens available a dummy QScreen object is created