diff --git a/src/private/DockRegistry.cpp b/src/private/DockRegistry.cpp index f980ca37..5ea6c590 100644 --- a/src/private/DockRegistry.cpp +++ b/src/private/DockRegistry.cpp @@ -51,15 +51,14 @@ DockRegistry::DockRegistry(QObject *parent) : QObject(parent) { qApp->installEventFilter(this); - - connect(qApp, &QGuiApplication::focusObjectChanged, - this, &DockRegistry::onFocusObjectChanged); + m_connection = Platform::instance()->focusedViewChanged.connect(&DockRegistry::onFocusedViewChanged, this); initKDDockWidgetResources(); } DockRegistry::~DockRegistry() { + m_connection.disconnect(); } void DockRegistry::maybeDelete() @@ -68,11 +67,11 @@ void DockRegistry::maybeDelete() delete this; } -void DockRegistry::onFocusObjectChanged(QObject *obj) +void DockRegistry::onFocusedViewChanged(std::shared_ptr view) { - auto p = qobject_cast(obj); - while (p) { - if (auto frame = Views::ViewWrapper_qtwidgets(qobject_cast(p)).asFrameController()) { + auto p = view; + while (p && !p->isNull()) { + if (auto frame = p->asFrameController()) { // Special case: The focused widget is inside the frame but not inside the dockwidget. // For example, it's a line edit in the QTabBar. We still need to send the signal for // the current dw in the tab group @@ -83,11 +82,11 @@ void DockRegistry::onFocusObjectChanged(QObject *obj) return; } - if (auto dwView = qobject_cast(p)) { - DockRegistry::self()->setFocusedDockWidget(dwView->dockWidget()); + if (auto dw = p->asDockWidgetController()) { + DockRegistry::self()->setFocusedDockWidget(dw); return; } - p = p->parentWidget(); + p = p->parentView(); } setFocusedDockWidget(nullptr); diff --git a/src/private/DockRegistry_p.h b/src/private/DockRegistry_p.h index 5cca8367..caf5eea0 100644 --- a/src/private/DockRegistry_p.h +++ b/src/private/DockRegistry_p.h @@ -20,6 +20,8 @@ #include #include +#include "kdbindings/signal.h" + /** * DockRegistry is a singleton that knows about all DockWidgets. * It's used so we can restore layouts. @@ -245,7 +247,7 @@ private: friend class FocusScope; explicit DockRegistry(QObject *parent = nullptr); bool onDockWidgetPressed(Controllers::DockWidget *dw, QMouseEvent *); - void onFocusObjectChanged(QObject *obj); + void onFocusedViewChanged(std::shared_ptr view); void maybeDelete(); void setFocusedDockWidget(Controllers::DockWidget *); @@ -256,6 +258,7 @@ private: QVector m_floatingWindows; QVector m_layouts; QPointer m_focusedDockWidget; + KDBindings::ConnectionHandle m_connection; ///@brief Dock widget id remapping, used by LayoutSaver ///