diff --git a/src/View.cpp b/src/View.cpp index 863691fa..906d1867 100644 --- a/src/View.cpp +++ b/src/View.cpp @@ -183,3 +183,13 @@ Controllers::FloatingWindow *View::asFloatingWindowController() const return nullptr; } + +bool View::equals(const View *other) const +{ + return other && handle() == other->handle(); +} + +bool View::equals(const std::unique_ptr &other) const +{ + return other && handle() == other->handle(); +} diff --git a/src/View.h b/src/View.h index 2db71a9e..bc7c9630 100644 --- a/src/View.h +++ b/src/View.h @@ -38,6 +38,8 @@ namespace Controllers { class FloatingWindow; } +using HANDLE = const void *; + class DOCKS_EXPORT View { public: @@ -71,6 +73,16 @@ public: /// as the implementation of free() is free to delay it (with deleteLater() for example) bool inDtor() const; + /// @brief Returns whether this view represents the same GUI element as the other + bool equals(const View *other) const; + bool equals(const std::unique_ptr &) const; + + /// @brief Returns a handle for the GUI element + /// This value only makes sense to the frontend. For example, for QtQuick it might be a + /// QtQuickItem, while for QtWidgets it's a QWidget *. Can be whatever the frontend developer wants, + /// as long as it uniquely identifies the GUI element. KDDW backend only uses it for comparison purposes + virtual HANDLE handle() const = 0; + /// @brief Called by the layouting engine /// Override it in case your widget needs to know where it is in the layout. Usually only needed by Frame.s virtual void setLayoutItem(Layouting::Item *) {}; diff --git a/src/controllers/Frame.cpp b/src/controllers/Frame.cpp index 5a495271..96737013 100644 --- a/src/controllers/Frame.cpp +++ b/src/controllers/Frame.cpp @@ -566,7 +566,7 @@ FloatingWindow *Frame::floatingWindow() const if (auto fw = p->asFloatingWindowController()) return fw; - if (p->asQWidget() == view()->window()->asQWidget()) { + if (p->equals(view()->window())) { // We stop at the window. (top-levels can have parent, but we're not interested) return nullptr; } diff --git a/src/views_qtwidgets/ViewWrapper_qtwidgets.cpp b/src/views_qtwidgets/ViewWrapper_qtwidgets.cpp index dee3940e..ae735ce3 100644 --- a/src/views_qtwidgets/ViewWrapper_qtwidgets.cpp +++ b/src/views_qtwidgets/ViewWrapper_qtwidgets.cpp @@ -213,3 +213,8 @@ std::unique_ptr ViewWrapper_qtwidgets::parentView() const { return std::unique_ptr(new ViewWrapper_qtwidgets(m_widget->parentWidget())); } + +HANDLE ViewWrapper_qtwidgets::handle() const +{ + return reinterpret_cast(m_widget); +} diff --git a/src/views_qtwidgets/ViewWrapper_qtwidgets.h b/src/views_qtwidgets/ViewWrapper_qtwidgets.h index a73a6b50..9c8ec169 100644 --- a/src/views_qtwidgets/ViewWrapper_qtwidgets.h +++ b/src/views_qtwidgets/ViewWrapper_qtwidgets.h @@ -43,6 +43,7 @@ public: bool is(Type) const override; std::unique_ptr window() const override; std::unique_ptr parentView() const override; + HANDLE handle() const override; private: QWidget *const m_widget; diff --git a/src/views_qtwidgets/View_qtwidgets.h b/src/views_qtwidgets/View_qtwidgets.h index 542480b6..2d27936b 100644 --- a/src/views_qtwidgets/View_qtwidgets.h +++ b/src/views_qtwidgets/View_qtwidgets.h @@ -311,6 +311,11 @@ public: return QWidget::windowHandle(); } + HANDLE handle() const override + { + return reinterpret_cast(this); + } + std::unique_ptr window() const override { ViewWrapper *wrapper = new ViewWrapper_qtwidgets(QWidget::window());