|
3 | 3 | #include <private/qquickwindow_p.h> |
4 | 4 | #include <qcoreevent.h> |
5 | 5 | #include <qevent.h> |
| 6 | +#include <qguiapplication.h> |
6 | 7 | #include <qnamespace.h> |
7 | 8 | #include <qobject.h> |
8 | 9 | #include <qqmlcontext.h> |
@@ -200,9 +201,6 @@ void ProxyWindowBase::completeWindow() { |
200 | 201 | if (this->mScreen != nullptr && this->window->screen() != this->mScreen) { |
201 | 202 | if (this->window->isVisible()) this->window->setVisible(false); |
202 | 203 | 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); |
206 | 204 | } |
207 | 205 |
|
208 | 206 | this->setWidth(this->mWidth); |
@@ -327,39 +325,39 @@ void ProxyWindowBase::setHeight(qint32 height) { |
327 | 325 |
|
328 | 326 | void ProxyWindowBase::setScreen(QuickshellScreenInfo* screen) { |
329 | 327 | auto* qscreen = screen == nullptr ? nullptr : screen->screen; |
330 | | - if (qscreen == this->mScreen) return; |
| 328 | + auto newMScreen = this->mScreen != qscreen; |
331 | 329 |
|
332 | | - if (this->mScreen != nullptr) { |
| 330 | + if (this->mScreen && newMScreen) { |
333 | 331 | QObject::disconnect(this->mScreen, nullptr, this, nullptr); |
334 | 332 | } |
335 | 333 |
|
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 | + } |
343 | 344 | } |
344 | 345 |
|
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 | + } |
349 | 349 | } |
350 | 350 |
|
351 | 351 | void ProxyWindowBase::onScreenDestroyed() { this->mScreen = nullptr; } |
352 | 352 |
|
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 | +} |
361 | 358 |
|
362 | | - return QuickshellTracked::instance()->screenInfo(qscreen); |
| 359 | +QuickshellScreenInfo* ProxyWindowBase::screen() const { |
| 360 | + return QuickshellTracked::instance()->screenInfo(this->qscreen()); |
363 | 361 | } |
364 | 362 |
|
365 | 363 | QColor ProxyWindowBase::color() const { return this->mColor; } |
|
0 commit comments