Skip to content

Commit c6791cf

Browse files
committed
core/window: fix screen assignments being completely broken
1 parent b73eff0 commit c6791cf

File tree

3 files changed

+26
-27
lines changed

3 files changed

+26
-27
lines changed

src/wayland/wlr_layershell.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ void WlrLayershell::setHeight(qint32 height) {
9090
}
9191

9292
void WlrLayershell::setScreen(QuickshellScreenInfo* screen) {
93-
this->ProxyWindowBase::setScreen(screen);
9493
this->ext->setUseWindowScreen(screen != nullptr);
94+
this->ProxyWindowBase::setScreen(screen);
9595
}
9696

9797
// NOLINTBEGIN

src/window/proxywindow.cpp

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <private/qquickwindow_p.h>
44
#include <qcoreevent.h>
55
#include <qevent.h>
6+
#include <qguiapplication.h>
67
#include <qnamespace.h>
78
#include <qobject.h>
89
#include <qqmlcontext.h>
@@ -200,9 +201,6 @@ void ProxyWindowBase::completeWindow() {
200201
if (this->mScreen != nullptr && this->window->screen() != this->mScreen) {
201202
if (this->window->isVisible()) this->window->setVisible(false);
202203
this->window->setScreen(this->mScreen);
203-
} else if (this->mScreen == nullptr) {
204-
this->mScreen = this->window->screen();
205-
QObject::connect(this->mScreen, &QObject::destroyed, this, &ProxyWindowBase::onScreenDestroyed);
206204
}
207205

208206
this->setWidth(this->mWidth);
@@ -327,39 +325,39 @@ void ProxyWindowBase::setHeight(qint32 height) {
327325

328326
void ProxyWindowBase::setScreen(QuickshellScreenInfo* screen) {
329327
auto* qscreen = screen == nullptr ? nullptr : screen->screen;
330-
if (qscreen == this->mScreen) return;
328+
auto newMScreen = this->mScreen != qscreen;
331329

332-
if (this->mScreen != nullptr) {
330+
if (this->mScreen && newMScreen) {
333331
QObject::disconnect(this->mScreen, nullptr, this, nullptr);
334332
}
335333

336-
if (this->window == nullptr) {
337-
emit this->screenChanged();
338-
} else {
339-
auto reshow = this->isVisibleDirect();
340-
if (reshow) this->setVisibleDirect(false);
341-
if (this->window != nullptr) this->window->setScreen(qscreen);
342-
if (reshow) this->setVisibleDirect(true);
334+
if (this->qscreen() != qscreen) {
335+
this->mScreen = qscreen;
336+
if (this->window == nullptr) {
337+
emit this->screenChanged();
338+
} else if (qscreen) {
339+
auto reshow = this->isVisibleDirect();
340+
if (reshow) this->setVisibleDirect(false);
341+
if (this->window != nullptr) this->window->setScreen(qscreen);
342+
if (reshow) this->setVisibleDirect(true);
343+
}
343344
}
344345

345-
if (qscreen) this->mScreen = qscreen;
346-
else this->mScreen = this->window->screen();
347-
348-
QObject::connect(this->mScreen, &QObject::destroyed, this, &ProxyWindowBase::onScreenDestroyed);
346+
if (qscreen && newMScreen) {
347+
QObject::connect(this->mScreen, &QObject::destroyed, this, &ProxyWindowBase::onScreenDestroyed);
348+
}
349349
}
350350

351351
void ProxyWindowBase::onScreenDestroyed() { this->mScreen = nullptr; }
352352

353-
QuickshellScreenInfo* ProxyWindowBase::screen() const {
354-
QScreen* qscreen = nullptr;
355-
356-
if (this->window == nullptr) {
357-
if (this->mScreen != nullptr) qscreen = this->mScreen;
358-
} else {
359-
qscreen = this->window->screen();
360-
}
353+
QScreen* ProxyWindowBase::qscreen() const {
354+
if (this->window) return this->window->screen();
355+
if (this->mScreen) return this->mScreen;
356+
return QGuiApplication::primaryScreen();
357+
}
361358

362-
return QuickshellTracked::instance()->screenInfo(qscreen);
359+
QuickshellScreenInfo* ProxyWindowBase::screen() const {
360+
return QuickshellTracked::instance()->screenInfo(this->qscreen());
363361
}
364362

365363
QColor ProxyWindowBase::color() const { return this->mColor; }

src/window/proxywindow.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ class ProxyWindowBase: public Reloadable {
100100

101101
[[nodiscard]] qreal devicePixelRatio() const;
102102

103-
[[nodiscard]] virtual QuickshellScreenInfo* screen() const;
103+
[[nodiscard]] QScreen* qscreen() const;
104+
[[nodiscard]] QuickshellScreenInfo* screen() const;
104105
virtual void setScreen(QuickshellScreenInfo* screen);
105106

106107
[[nodiscard]] QColor color() const;

0 commit comments

Comments
 (0)