Allow specifying explicit desired screen

If the window position is not specified, which is a reasonable thing to
do when using the layer shell protocol, setWidth() and setHeight() can
unintentionally change the screen() to the wrong one.

This change adds a setScreen() function so it's harder to shoot
yourself in the foot while using the layer shell protocol.

(cherry picked from commit 430ad3630f)
This commit is contained in:
Vlad Zahorodnii
2025-11-19 16:32:04 +02:00
parent 94ac4be08f
commit 3dacd70398
3 changed files with 72 additions and 21 deletions

View File

@ -27,8 +27,13 @@ QWaylandLayerSurface::QWaylandLayerSurface(QWaylandLayerShellIntegration *shell,
, m_window(window)
{
wl_output *output = nullptr;
if (m_interface->screenConfiguration() == Window::ScreenFromQWindow) {
auto waylandScreen = dynamic_cast<QtWaylandClient::QWaylandScreen *>(window->window()->screen()->handle());
if (!m_interface->wantsToBeOnActiveScreen()) {
QScreen *desiredScreen = m_interface->screen();
if (!desiredScreen) {
desiredScreen = window->window()->screen();
}
auto waylandScreen = dynamic_cast<QtWaylandClient::QWaylandScreen *>(desiredScreen->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) {