Skip to content

Commit eb5a5b8

Browse files
committed
debug: run lints after window expose
Ensures items are at their final sizes before checking them, fixing some false positives.
1 parent 6ceee06 commit eb5a5b8

File tree

4 files changed

+38
-12
lines changed

4 files changed

+38
-12
lines changed

src/wayland/wlr_layershell.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ WlrLayershell::WlrLayershell(QObject* parent)
1818
: ProxyWindowBase(parent)
1919
, ext(new LayershellWindowExtension(this)) {}
2020

21-
QQuickWindow* WlrLayershell::retrieveWindow(QObject* oldInstance) {
21+
ProxiedWindow* WlrLayershell::retrieveWindow(QObject* oldInstance) {
2222
auto* old = qobject_cast<WlrLayershell*>(oldInstance);
2323
auto* window = old == nullptr ? nullptr : old->disownWindow();
2424

@@ -33,8 +33,8 @@ QQuickWindow* WlrLayershell::retrieveWindow(QObject* oldInstance) {
3333
return this->createQQuickWindow();
3434
}
3535

36-
QQuickWindow* WlrLayershell::createQQuickWindow() {
37-
auto* window = new QQuickWindow();
36+
ProxiedWindow* WlrLayershell::createQQuickWindow() {
37+
auto* window = this->ProxyWindowBase::createQQuickWindow();
3838

3939
if (!this->ext->attach(window)) {
4040
qWarning() << "Could not attach Layershell extension to new QQuickWindow. Layer will not "

src/wayland/wlr_layershell.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ class WlrLayershell: public ProxyWindowBase {
6464
public:
6565
explicit WlrLayershell(QObject* parent = nullptr);
6666

67-
QQuickWindow* retrieveWindow(QObject* oldInstance) override;
68-
QQuickWindow* createQQuickWindow() override;
67+
ProxiedWindow* retrieveWindow(QObject* oldInstance) override;
68+
ProxiedWindow* createQQuickWindow() override;
6969
void connectWindow() override;
7070
[[nodiscard]] bool deleteOnInvisible() const override;
7171

src/window/proxywindow.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "proxywindow.hpp"
22

33
#include <private/qquickwindow_p.h>
4+
#include <qevent.h>
45
#include <qnamespace.h>
56
#include <qobject.h>
67
#include <qqmlcontext.h>
@@ -80,7 +81,7 @@ void ProxyWindowBase::onReload(QObject* oldInstance) {
8081

8182
void ProxyWindowBase::postCompleteWindow() { this->setVisible(this->mVisible); }
8283

83-
QQuickWindow* ProxyWindowBase::createQQuickWindow() { return new QQuickWindow(); }
84+
ProxiedWindow* ProxyWindowBase::createQQuickWindow() { return new ProxiedWindow(); }
8485

8586
void ProxyWindowBase::createWindow() {
8687
if (this->window != nullptr) return;
@@ -102,7 +103,7 @@ void ProxyWindowBase::deleteWindow(bool keepItemOwnership) {
102103
}
103104
}
104105

105-
QQuickWindow* ProxyWindowBase::disownWindow(bool keepItemOwnership) {
106+
ProxiedWindow* ProxyWindowBase::disownWindow(bool keepItemOwnership) {
106107
if (this->window == nullptr) return nullptr;
107108

108109
QObject::disconnect(this->window, nullptr, this, nullptr);
@@ -116,7 +117,7 @@ QQuickWindow* ProxyWindowBase::disownWindow(bool keepItemOwnership) {
116117
return window;
117118
}
118119

119-
QQuickWindow* ProxyWindowBase::retrieveWindow(QObject* oldInstance) {
120+
ProxiedWindow* ProxyWindowBase::retrieveWindow(QObject* oldInstance) {
120121
auto* old = qobject_cast<ProxyWindowBase*>(oldInstance);
121122
return old == nullptr ? nullptr : old->disownWindow();
122123
}
@@ -136,6 +137,7 @@ void ProxyWindowBase::connectWindow() {
136137
QObject::connect(this->window, &QWindow::heightChanged, this, &ProxyWindowBase::heightChanged);
137138
QObject::connect(this->window, &QWindow::screenChanged, this, &ProxyWindowBase::screenChanged);
138139
QObject::connect(this->window, &QQuickWindow::colorChanged, this, &ProxyWindowBase::colorChanged);
140+
QObject::connect(this->window, &ProxiedWindow::exposed, this, &ProxyWindowBase::onWindowExposeEvent);
139141
// clang-format on
140142
}
141143

@@ -215,7 +217,9 @@ void ProxyWindowBase::polishItems() {
215217
// This hack manually polishes the item tree right before showing the window so it will
216218
// always be created with the correct size.
217219
QQuickWindowPrivate::get(this->window)->polishItems();
220+
}
218221

222+
void ProxyWindowBase::onWindowExposeEvent() {
219223
if (!this->ranLints) {
220224
qs::debug::lintItemTree(this->mContentItem);
221225
this->ranLints = true;
@@ -368,3 +372,8 @@ void ProxyWindowBase::onHeightChanged() { this->mContentItem->setHeight(this->he
368372

369373
QObject* ProxyWindowAttached::window() const { return this->mWindow; }
370374
QQuickItem* ProxyWindowAttached::contentItem() const { return this->mWindow->contentItem(); }
375+
376+
void ProxiedWindow::exposeEvent(QExposeEvent* event) {
377+
this->QQuickWindow::exposeEvent(event);
378+
emit this->exposed();
379+
}

src/window/proxywindow.hpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@
1111
#include <qquickwindow.h>
1212
#include <qtmetamacros.h>
1313
#include <qtypes.h>
14+
#include <qwindow.h>
1415

1516
#include "../core/qmlscreen.hpp"
1617
#include "../core/region.hpp"
1718
#include "../core/reload.hpp"
1819
#include "windowinterface.hpp"
1920

21+
class ProxiedWindow;
22+
2023
// Proxy to an actual window exposing a limited property set with the ability to
2124
// transfer it to a new window.
2225

@@ -60,10 +63,10 @@ class ProxyWindowBase: public Reloadable {
6063
void deleteWindow(bool keepItemOwnership = false);
6164

6265
// Disown the backing window and delete all its children.
63-
virtual QQuickWindow* disownWindow(bool keepItemOwnership = false);
66+
virtual ProxiedWindow* disownWindow(bool keepItemOwnership = false);
6467

65-
virtual QQuickWindow* retrieveWindow(QObject* oldInstance);
66-
virtual QQuickWindow* createQQuickWindow();
68+
virtual ProxiedWindow* retrieveWindow(QObject* oldInstance);
69+
virtual ProxiedWindow* createQQuickWindow();
6770
virtual void connectWindow();
6871
virtual void completeWindow();
6972
virtual void postCompleteWindow();
@@ -119,6 +122,7 @@ protected slots:
119122
void onMaskChanged();
120123
void onMaskDestroyed();
121124
void onScreenDestroyed();
125+
void onWindowExposeEvent();
122126

123127
protected:
124128
bool mVisible = true;
@@ -127,7 +131,7 @@ protected slots:
127131
QScreen* mScreen = nullptr;
128132
QColor mColor = Qt::white;
129133
PendingRegion* mMask = nullptr;
130-
QQuickWindow* window = nullptr;
134+
ProxiedWindow* window = nullptr;
131135
QQuickItem* mContentItem = nullptr;
132136
bool reloadComplete = false;
133137
bool ranLints = false;
@@ -151,3 +155,16 @@ class ProxyWindowAttached: public QsWindowAttached {
151155
private:
152156
ProxyWindowBase* mWindow;
153157
};
158+
159+
class ProxiedWindow: public QQuickWindow {
160+
Q_OBJECT;
161+
162+
public:
163+
explicit ProxiedWindow(QWindow* parent = nullptr): QQuickWindow(parent) {}
164+
165+
signals:
166+
void exposed();
167+
168+
protected:
169+
void exposeEvent(QExposeEvent* event) override;
170+
};

0 commit comments

Comments
 (0)