-
Notifications
You must be signed in to change notification settings - Fork 70
core/window: add parentWindow property to FloatingWindow #378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |
| #include <qnamespace.h> | ||
| #include <qobject.h> | ||
| #include <qqmlengine.h> | ||
| #include <qqmllist.h> | ||
| #include <qqmlinfo.h> | ||
| #include <qtmetamacros.h> | ||
| #include <qtypes.h> | ||
| #include <qwindow.h> | ||
|
|
@@ -19,6 +19,41 @@ void ProxyFloatingWindow::connectWindow() { | |
| this->window->setMaximumSize(this->bMaximumSize); | ||
| } | ||
|
|
||
| void ProxyFloatingWindow::setVisible(bool visible) { | ||
| if (!visible) { | ||
| QObject::disconnect(this->mParentVisibleConn); | ||
| this->ProxyWindowBase::setVisible(false); | ||
| return; | ||
| } | ||
|
|
||
| // If there's a parent, set transient before showing | ||
| if (this->mParentProxyWindow) { | ||
| auto* pw = this->mParentProxyWindow->backingWindow(); | ||
| if (pw && pw->isVisible()) { | ||
| if (this->window) this->window->setTransientParent(pw); | ||
| } else { | ||
| // Parent not visible yet - wait for it. | ||
| QObject::disconnect(this->mParentVisibleConn); | ||
| this->mParentVisibleConn = QObject::connect( | ||
| this->mParentProxyWindow, | ||
| &ProxyWindowBase::backerVisibilityChanged, | ||
| this, | ||
| [this]() { | ||
| auto* pw = | ||
| this->mParentProxyWindow ? this->mParentProxyWindow->backingWindow() : nullptr; | ||
| if (!pw || !pw->isVisible() || !this->window) return; | ||
| this->window->setTransientParent(pw); | ||
| QObject::disconnect(this->mParentVisibleConn); | ||
| this->ProxyWindowBase::setVisible(true); | ||
| } | ||
| ); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| this->ProxyWindowBase::setVisible(true); | ||
| } | ||
|
|
||
| void ProxyFloatingWindow::trySetWidth(qint32 implicitWidth) { | ||
| if (!this->window->isVisible()) { | ||
| this->ProxyWindowBase::trySetWidth(implicitWidth); | ||
|
|
@@ -46,6 +81,33 @@ void ProxyFloatingWindow::onMaximumSizeChanged() { | |
| emit this->maximumSizeChanged(); | ||
| } | ||
|
|
||
| QObject* ProxyFloatingWindow::parentWindow() const { return this->mParentWindow; } | ||
|
|
||
| void ProxyFloatingWindow::setParentWindow(QObject* window) { | ||
| if (window == this->mParentWindow) return; | ||
|
|
||
| if (this->window && this->window->isVisible()) { | ||
| qmlWarning(this) << "parentWindow cannot be changed after the window is visible."; | ||
| return; | ||
| } | ||
|
|
||
| QObject::disconnect(this->mParentVisibleConn); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a nullptr, nullptr disconnect should be used when completely disconnecting an object |
||
| this->mParentWindow = nullptr; | ||
| this->mParentProxyWindow = nullptr; | ||
|
|
||
| if (window) { | ||
| if (auto* proxy = qobject_cast<ProxyWindowBase*>(window)) { | ||
| this->mParentProxyWindow = proxy; | ||
| } else if (auto* iface = qobject_cast<WindowInterface*>(window)) { | ||
| this->mParentProxyWindow = iface->proxyWindow(); | ||
| } else { | ||
| qmlWarning(this) << "parentWindow must be a quickshell window."; | ||
| return; | ||
| } | ||
| this->mParentWindow = window; | ||
| } | ||
|
Comment on lines
+98
to
+108
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing a QObject::destroyed handler which should act similarly to a removal. |
||
| } | ||
|
|
||
| // FloatingWindowInterface | ||
|
|
||
| FloatingWindowInterface::FloatingWindowInterface(QObject* parent) | ||
|
|
@@ -169,3 +231,9 @@ bool FloatingWindowInterface::startSystemResize(Qt::Edges edges) const { | |
| if (!qw) return false; | ||
| return qw->startSystemResize(edges); | ||
| } | ||
|
|
||
| QObject* FloatingWindowInterface::parentWindow() const { return this->window->parentWindow(); } | ||
|
|
||
| void FloatingWindowInterface::setParentWindow(QObject* window) { | ||
| this->window->setParentWindow(window); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
disconnect via filters is preferred where possible (move the lambda in setVisible to its own slot method, then disconnect with
QObject::disconnect(this->mParentProxyWindow, backingwindowvisible, ... ).