22
33#include < qobject.h>
44#include < qqmlengine.h>
5- #include < qqmllist .h>
5+ #include < qqmlinfo .h>
66#include < qtmetamacros.h>
77#include < qtypes.h>
88
@@ -15,6 +15,9 @@ void ProxyFloatingWindow::connectWindow() {
1515 this ->window ->setTitle (this ->bTitle );
1616 this ->window ->setMinimumSize (this ->bMinimumSize );
1717 this ->window ->setMaximumSize (this ->bMaximumSize );
18+
19+ // Apply transient parent now that our backing window exists
20+ this ->updateTransientParent ();
1821}
1922
2023void ProxyFloatingWindow::trySetWidth (qint32 implicitWidth) {
@@ -44,6 +47,65 @@ void ProxyFloatingWindow::onMaximumSizeChanged() {
4447 emit this ->maximumSizeChanged ();
4548}
4649
50+ QObject* ProxyFloatingWindow::parentWindow () const { return this ->mParentWindow ; }
51+
52+ void ProxyFloatingWindow::setParentWindow (QObject* window) {
53+ if (window == this ->mParentWindow ) return ;
54+
55+ if (this ->mParentWindow ) {
56+ QObject::disconnect (this ->mParentWindow , nullptr , this , nullptr );
57+ QObject::disconnect (this ->mParentProxyWindow , nullptr , this , nullptr );
58+ }
59+
60+ if (window) {
61+ if (auto * proxy = qobject_cast<ProxyWindowBase*>(window)) {
62+ this ->mParentProxyWindow = proxy;
63+ } else if (auto * interface = qobject_cast<WindowInterface*>(window)) {
64+ this ->mParentProxyWindow = interface->proxyWindow ();
65+ } else {
66+ qmlWarning (this ) << " parentWindow must be a quickshell window." ;
67+ return ;
68+ }
69+
70+ this ->mParentWindow = window;
71+ QObject::connect (
72+ this ->mParentWindow ,
73+ &QObject::destroyed,
74+ this ,
75+ &ProxyFloatingWindow::onParentDestroyed
76+ );
77+
78+ QObject::connect (
79+ this ->mParentProxyWindow ,
80+ &ProxyWindowBase::backingWindowChanged,
81+ this ,
82+ &ProxyFloatingWindow::updateTransientParent
83+ );
84+ } else {
85+ this ->mParentWindow = nullptr ;
86+ this ->mParentProxyWindow = nullptr ;
87+ }
88+
89+ this ->updateTransientParent ();
90+ emit this ->parentWindowChanged ();
91+ }
92+
93+ void ProxyFloatingWindow::onParentDestroyed () {
94+ this ->mParentWindow = nullptr ;
95+ this ->mParentProxyWindow = nullptr ;
96+ this ->updateTransientParent ();
97+ emit this ->parentWindowChanged ();
98+ }
99+
100+ void ProxyFloatingWindow::updateTransientParent () {
101+ if (!this ->window ) return ;
102+
103+ auto * parentBacking =
104+ this ->mParentProxyWindow ? this ->mParentProxyWindow ->backingWindow () : nullptr ;
105+
106+ this ->window ->setTransientParent (parentBacking);
107+ }
108+
47109// FloatingWindowInterface
48110
49111FloatingWindowInterface::FloatingWindowInterface (QObject* parent)
@@ -55,6 +117,7 @@ FloatingWindowInterface::FloatingWindowInterface(QObject* parent)
55117 QObject::connect (this ->window , &ProxyFloatingWindow::titleChanged, this , &FloatingWindowInterface::titleChanged);
56118 QObject::connect (this ->window , &ProxyFloatingWindow::minimumSizeChanged, this , &FloatingWindowInterface::minimumSizeChanged);
57119 QObject::connect (this ->window , &ProxyFloatingWindow::maximumSizeChanged, this , &FloatingWindowInterface::maximumSizeChanged);
120+ QObject::connect (this ->window , &ProxyFloatingWindow::parentWindowChanged, this , &FloatingWindowInterface::parentWindowChanged);
58121 // clang-format on
59122}
60123
@@ -66,3 +129,9 @@ void FloatingWindowInterface::onReload(QObject* oldInstance) {
66129}
67130
68131ProxyWindowBase* FloatingWindowInterface::proxyWindow () const { return this ->window ; }
132+
133+ QObject* FloatingWindowInterface::parentWindow () const { return this ->window ->parentWindow (); }
134+
135+ void FloatingWindowInterface::setParentWindow (QObject* window) {
136+ this ->window ->setParentWindow (window);
137+ }
0 commit comments