debug: run lints after window expose

Ensures items are at their final sizes before checking them,
fixing some false positives.
This commit is contained in:
outfoxxed 2024-11-19 15:58:55 -08:00
parent 98516cf0b2
commit 8c37bd191b
Signed by: outfoxxed
GPG key ID: 4C88A185FB89301E
4 changed files with 38 additions and 12 deletions

View file

@ -18,7 +18,7 @@ WlrLayershell::WlrLayershell(QObject* parent)
: ProxyWindowBase(parent) : ProxyWindowBase(parent)
, ext(new LayershellWindowExtension(this)) {} , ext(new LayershellWindowExtension(this)) {}
QQuickWindow* WlrLayershell::retrieveWindow(QObject* oldInstance) { ProxiedWindow* WlrLayershell::retrieveWindow(QObject* oldInstance) {
auto* old = qobject_cast<WlrLayershell*>(oldInstance); auto* old = qobject_cast<WlrLayershell*>(oldInstance);
auto* window = old == nullptr ? nullptr : old->disownWindow(); auto* window = old == nullptr ? nullptr : old->disownWindow();
@ -33,8 +33,8 @@ QQuickWindow* WlrLayershell::retrieveWindow(QObject* oldInstance) {
return this->createQQuickWindow(); return this->createQQuickWindow();
} }
QQuickWindow* WlrLayershell::createQQuickWindow() { ProxiedWindow* WlrLayershell::createQQuickWindow() {
auto* window = new QQuickWindow(); auto* window = this->ProxyWindowBase::createQQuickWindow();
if (!this->ext->attach(window)) { if (!this->ext->attach(window)) {
qWarning() << "Could not attach Layershell extension to new QQuickWindow. Layer will not " qWarning() << "Could not attach Layershell extension to new QQuickWindow. Layer will not "

View file

@ -64,8 +64,8 @@ class WlrLayershell: public ProxyWindowBase {
public: public:
explicit WlrLayershell(QObject* parent = nullptr); explicit WlrLayershell(QObject* parent = nullptr);
QQuickWindow* retrieveWindow(QObject* oldInstance) override; ProxiedWindow* retrieveWindow(QObject* oldInstance) override;
QQuickWindow* createQQuickWindow() override; ProxiedWindow* createQQuickWindow() override;
void connectWindow() override; void connectWindow() override;
[[nodiscard]] bool deleteOnInvisible() const override; [[nodiscard]] bool deleteOnInvisible() const override;

View file

@ -1,6 +1,7 @@
#include "proxywindow.hpp" #include "proxywindow.hpp"
#include <private/qquickwindow_p.h> #include <private/qquickwindow_p.h>
#include <qevent.h>
#include <qnamespace.h> #include <qnamespace.h>
#include <qobject.h> #include <qobject.h>
#include <qqmlcontext.h> #include <qqmlcontext.h>
@ -80,7 +81,7 @@ void ProxyWindowBase::onReload(QObject* oldInstance) {
void ProxyWindowBase::postCompleteWindow() { this->setVisible(this->mVisible); } void ProxyWindowBase::postCompleteWindow() { this->setVisible(this->mVisible); }
QQuickWindow* ProxyWindowBase::createQQuickWindow() { return new QQuickWindow(); } ProxiedWindow* ProxyWindowBase::createQQuickWindow() { return new ProxiedWindow(); }
void ProxyWindowBase::createWindow() { void ProxyWindowBase::createWindow() {
if (this->window != nullptr) return; if (this->window != nullptr) return;
@ -102,7 +103,7 @@ void ProxyWindowBase::deleteWindow(bool keepItemOwnership) {
} }
} }
QQuickWindow* ProxyWindowBase::disownWindow(bool keepItemOwnership) { ProxiedWindow* ProxyWindowBase::disownWindow(bool keepItemOwnership) {
if (this->window == nullptr) return nullptr; if (this->window == nullptr) return nullptr;
QObject::disconnect(this->window, nullptr, this, nullptr); QObject::disconnect(this->window, nullptr, this, nullptr);
@ -116,7 +117,7 @@ QQuickWindow* ProxyWindowBase::disownWindow(bool keepItemOwnership) {
return window; return window;
} }
QQuickWindow* ProxyWindowBase::retrieveWindow(QObject* oldInstance) { ProxiedWindow* ProxyWindowBase::retrieveWindow(QObject* oldInstance) {
auto* old = qobject_cast<ProxyWindowBase*>(oldInstance); auto* old = qobject_cast<ProxyWindowBase*>(oldInstance);
return old == nullptr ? nullptr : old->disownWindow(); return old == nullptr ? nullptr : old->disownWindow();
} }
@ -136,6 +137,7 @@ void ProxyWindowBase::connectWindow() {
QObject::connect(this->window, &QWindow::heightChanged, this, &ProxyWindowBase::heightChanged); QObject::connect(this->window, &QWindow::heightChanged, this, &ProxyWindowBase::heightChanged);
QObject::connect(this->window, &QWindow::screenChanged, this, &ProxyWindowBase::screenChanged); QObject::connect(this->window, &QWindow::screenChanged, this, &ProxyWindowBase::screenChanged);
QObject::connect(this->window, &QQuickWindow::colorChanged, this, &ProxyWindowBase::colorChanged); QObject::connect(this->window, &QQuickWindow::colorChanged, this, &ProxyWindowBase::colorChanged);
QObject::connect(this->window, &ProxiedWindow::exposed, this, &ProxyWindowBase::onWindowExposeEvent);
// clang-format on // clang-format on
} }
@ -215,7 +217,9 @@ void ProxyWindowBase::polishItems() {
// This hack manually polishes the item tree right before showing the window so it will // This hack manually polishes the item tree right before showing the window so it will
// always be created with the correct size. // always be created with the correct size.
QQuickWindowPrivate::get(this->window)->polishItems(); QQuickWindowPrivate::get(this->window)->polishItems();
}
void ProxyWindowBase::onWindowExposeEvent() {
if (!this->ranLints) { if (!this->ranLints) {
qs::debug::lintItemTree(this->mContentItem); qs::debug::lintItemTree(this->mContentItem);
this->ranLints = true; this->ranLints = true;
@ -368,3 +372,8 @@ void ProxyWindowBase::onHeightChanged() { this->mContentItem->setHeight(this->he
QObject* ProxyWindowAttached::window() const { return this->mWindow; } QObject* ProxyWindowAttached::window() const { return this->mWindow; }
QQuickItem* ProxyWindowAttached::contentItem() const { return this->mWindow->contentItem(); } QQuickItem* ProxyWindowAttached::contentItem() const { return this->mWindow->contentItem(); }
void ProxiedWindow::exposeEvent(QExposeEvent* event) {
this->QQuickWindow::exposeEvent(event);
emit this->exposed();
}

View file

@ -11,12 +11,15 @@
#include <qquickwindow.h> #include <qquickwindow.h>
#include <qtmetamacros.h> #include <qtmetamacros.h>
#include <qtypes.h> #include <qtypes.h>
#include <qwindow.h>
#include "../core/qmlscreen.hpp" #include "../core/qmlscreen.hpp"
#include "../core/region.hpp" #include "../core/region.hpp"
#include "../core/reload.hpp" #include "../core/reload.hpp"
#include "windowinterface.hpp" #include "windowinterface.hpp"
class ProxiedWindow;
// Proxy to an actual window exposing a limited property set with the ability to // Proxy to an actual window exposing a limited property set with the ability to
// transfer it to a new window. // transfer it to a new window.
@ -60,10 +63,10 @@ public:
void deleteWindow(bool keepItemOwnership = false); void deleteWindow(bool keepItemOwnership = false);
// Disown the backing window and delete all its children. // Disown the backing window and delete all its children.
virtual QQuickWindow* disownWindow(bool keepItemOwnership = false); virtual ProxiedWindow* disownWindow(bool keepItemOwnership = false);
virtual QQuickWindow* retrieveWindow(QObject* oldInstance); virtual ProxiedWindow* retrieveWindow(QObject* oldInstance);
virtual QQuickWindow* createQQuickWindow(); virtual ProxiedWindow* createQQuickWindow();
virtual void connectWindow(); virtual void connectWindow();
virtual void completeWindow(); virtual void completeWindow();
virtual void postCompleteWindow(); virtual void postCompleteWindow();
@ -119,6 +122,7 @@ protected slots:
void onMaskChanged(); void onMaskChanged();
void onMaskDestroyed(); void onMaskDestroyed();
void onScreenDestroyed(); void onScreenDestroyed();
void onWindowExposeEvent();
protected: protected:
bool mVisible = true; bool mVisible = true;
@ -127,7 +131,7 @@ protected:
QScreen* mScreen = nullptr; QScreen* mScreen = nullptr;
QColor mColor = Qt::white; QColor mColor = Qt::white;
PendingRegion* mMask = nullptr; PendingRegion* mMask = nullptr;
QQuickWindow* window = nullptr; ProxiedWindow* window = nullptr;
QQuickItem* mContentItem = nullptr; QQuickItem* mContentItem = nullptr;
bool reloadComplete = false; bool reloadComplete = false;
bool ranLints = false; bool ranLints = false;
@ -151,3 +155,16 @@ public:
private: private:
ProxyWindowBase* mWindow; ProxyWindowBase* mWindow;
}; };
class ProxiedWindow: public QQuickWindow {
Q_OBJECT;
public:
explicit ProxiedWindow(QWindow* parent = nullptr): QQuickWindow(parent) {}
signals:
void exposed();
protected:
void exposeEvent(QExposeEvent* event) override;
};