forked from quickshell/quickshell
core/proxywindow: improve QsWindowAttached robustness
Can now track window parent window changes. Added tests.
This commit is contained in:
parent
539692bc11
commit
b6a79fe99c
7 changed files with 145 additions and 36 deletions
|
@ -2,33 +2,19 @@
|
|||
|
||||
#include <qobject.h>
|
||||
#include <qquickitem.h>
|
||||
#include <qvariant.h>
|
||||
|
||||
#include "proxywindow.hpp"
|
||||
|
||||
QsWindowAttached* WindowInterface::qmlAttachedProperties(QObject* object) {
|
||||
auto* visualRoot = qobject_cast<QQuickItem*>(object);
|
||||
|
||||
ProxyWindowBase* proxy = nullptr;
|
||||
while (visualRoot != nullptr) {
|
||||
proxy = visualRoot->property("__qs_proxywindow").value<ProxyWindowBase*>();
|
||||
|
||||
if (proxy) break;
|
||||
visualRoot = visualRoot->parentItem();
|
||||
};
|
||||
|
||||
if (!proxy) return nullptr;
|
||||
|
||||
auto v = proxy->property("__qs_window_attached");
|
||||
if (auto* attached = v.value<QsWindowAttached*>()) {
|
||||
return attached;
|
||||
}
|
||||
|
||||
auto* attached = new ProxyWindowAttached(proxy);
|
||||
|
||||
if (attached) {
|
||||
proxy->setProperty("__qs_window_attached", QVariant::fromValue(attached));
|
||||
}
|
||||
|
||||
return attached;
|
||||
QsWindowAttached::QsWindowAttached(QQuickItem* parent): QObject(parent) {
|
||||
QObject::connect(parent, &QQuickItem::windowChanged, this, &QsWindowAttached::updateWindow);
|
||||
}
|
||||
|
||||
QsWindowAttached* WindowInterface::qmlAttachedProperties(QObject* object) {
|
||||
while (object && !qobject_cast<QQuickItem*>(object)) {
|
||||
object = object->parent();
|
||||
}
|
||||
|
||||
if (!object) return nullptr;
|
||||
auto* item = static_cast<QQuickItem*>(object); // NOLINT
|
||||
return new ProxyWindowAttached(item);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue