Skip to content

Commit f48a5ca

Browse files
committed
core/window: add closed() signal to all window types
1 parent 5706c09 commit f48a5ca

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

src/window/proxywindow.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ void ProxyWindowBase::connectWindow() {
188188
this->window->setProxy(this);
189189

190190
// clang-format off
191-
QObject::connect(this->window, &QWindow::visibilityChanged, this, &ProxyWindowBase::visibleChanged);
191+
QObject::connect(this->window, &QWindow::visibilityChanged, this, &ProxyWindowBase::onVisibleChanged);
192192
QObject::connect(this->window, &QWindow::xChanged, this, &ProxyWindowBase::xChanged);
193193
QObject::connect(this->window, &QWindow::yChanged, this, &ProxyWindowBase::yChanged);
194194
QObject::connect(this->window, &QWindow::widthChanged, this, &ProxyWindowBase::widthChanged);
@@ -226,6 +226,16 @@ void ProxyWindowBase::completeWindow() {
226226
emit this->screenChanged();
227227
}
228228

229+
void ProxyWindowBase::onVisibleChanged() {
230+
if (this->mVisible && !this->window->isVisible()) {
231+
this->mVisible = false;
232+
this->setVisibleDirect(false);
233+
emit this->closed();
234+
}
235+
236+
emit this->visibleChanged();
237+
}
238+
229239
bool ProxyWindowBase::deleteOnInvisible() const { return false; }
230240

231241
QQuickWindow* ProxyWindowBase::backingWindow() const { return this->window; }

src/window/proxywindow.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ class ProxyWindowBase: public Reloadable {
141141
[[nodiscard]] QQmlListProperty<QObject> data();
142142

143143
signals:
144+
void closed();
144145
void windowConnected();
145146
void windowDestroyed();
146147
void visibleChanged();

src/window/windowinterface.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ QQmlListProperty<QObject> WindowInterface::data() const { return this->proxyWind
133133
void WindowInterface::connectSignals() const {
134134
auto* window = this->proxyWindow();
135135
// clang-format off
136+
QObject::connect(window, &ProxyWindowBase::closed, this, &WindowInterface::closed);
136137
QObject::connect(window, &ProxyWindowBase::windowConnected, this, &WindowInterface::windowConnected);
137138
QObject::connect(window, &ProxyWindowBase::visibleChanged, this, &WindowInterface::visibleChanged);
138139
QObject::connect(window, &ProxyWindowBase::backerVisibilityChanged, this, &WindowInterface::backingWindowVisibleChanged);

src/window/windowinterface.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@ class WindowInterface: public Reloadable {
236236
static QsWindowAttached* qmlAttachedProperties(QObject* object);
237237

238238
signals:
239+
/// This signal is emitted when the window is closed by the user, the display server,
240+
/// or an error. It is not emitted when @@visible is set to false.
241+
void closed();
239242
void windowConnected();
240243
void visibleChanged();
241244
void backingWindowVisibleChanged();

0 commit comments

Comments
 (0)