diff --git a/src/interfaces/window.cpp b/src/interfaces/window.cpp index 7aa39f4..8d69bd8 100644 --- a/src/interfaces/window.cpp +++ b/src/interfaces/window.cpp @@ -27,7 +27,7 @@ public: Window::KeyboardInteractivity keyboardInteractivity = Window::KeyboardInteractivityExclusive; Window::Layer layer = Window::LayerTop; QMargins margins; - std::optional> desiredOutput; + Window::ScreenConfiguration screenConfiguration = Window::ScreenFromQWindow; }; static QMap s_map; @@ -102,19 +102,14 @@ Window::Layer Window::layer() const return d->layer; } -QScreen *Window::desiredOutput() const +Window::ScreenConfiguration Window::screenConfiguration() const { - // Don't use .value_or here to avoid a temporary QPointer - if (d->desiredOutput.has_value()) { - return d->desiredOutput.value(); - } - - return d->parentWindow->screen(); + return d->screenConfiguration; } -void Window::setDesiredOutput(QScreen *output) +void Window::setScreenConfiguration(Window::ScreenConfiguration screenConfiguration) { - d->desiredOutput = output; + d->screenConfiguration = screenConfiguration; } Window::Window(QWindow *window) diff --git a/src/interfaces/window.h b/src/interfaces/window.h index 5ebc9b1..f75e1ce 100644 --- a/src/interfaces/window.h +++ b/src/interfaces/window.h @@ -54,6 +54,17 @@ public: }; Q_ENUM(KeyboardInteractivity) + /** + * This enum type is used to specify which screen to place the surface on. + * ScreenFromQWindow (the default) reads QWindow::screen() while ScreenFromCompositor + * passes nil and lets the compositor decide. + */ + enum ScreenConfiguration { + ScreenFromQWindow = 0, + ScreenFromCompositor = 1, + }; + Q_ENUM(ScreenConfiguration) + void setAnchors(Anchors anchor); Anchors anchors() const; @@ -69,13 +80,8 @@ public: void setLayer(Layer layer); Layer layer() const; - /** - * If set, the compositor will try to put the window on the given screen. - * If its not set, then the compositor will decide where to put the window. - * Under normal circumstances, this should be the active output. - */ - void setDesiredOutput(QScreen *output); - QScreen *desiredOutput() const; + void setScreenConfiguration(ScreenConfiguration screenConfiguration); + ScreenConfiguration screenConfiguration() const; /** * Sets a string based identifier for this window. diff --git a/src/qwaylandlayersurface.cpp b/src/qwaylandlayersurface.cpp index dd17aa0..994c28f 100644 --- a/src/qwaylandlayersurface.cpp +++ b/src/qwaylandlayersurface.cpp @@ -24,9 +24,8 @@ QWaylandLayerSurface::QWaylandLayerSurface(QWaylandLayerShell *shell, QtWaylandC Q_ASSERT(interface); wl_output *output = nullptr; - QScreen *screen = interface->desiredOutput(); - if (screen) { - auto waylandScreen = dynamic_cast(screen->handle()); + if (interface->screenConfiguration() == Window::ScreenFromQWindow) { + auto waylandScreen = dynamic_cast(window->window()->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 // this will not cast to a QWaylandScreen if (!waylandScreen) {