From 1f5823cec08791af9059d8ae076d931518f76940 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sat, 18 Jan 2025 15:08:50 +0000 Subject: [PATCH] Always open the user details dialog in the focused window This fixes some odd UX where you tap on someone's user in a search or pinned messages window, but it opens in the NeoChat main window instead. Fixes #681 (cherry picked from commit 590fba7deb0978ce1b8a676e5e2de404c34bd910) Co-authored-by: Joshua Goins --- src/qml/Main.qml | 8 +++++--- src/utils.cpp | 11 +++++++++++ src/utils.h | 2 ++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/qml/Main.qml b/src/qml/Main.qml index 4757465b1..c1c6b8607 100644 --- a/src/qml/Main.qml +++ b/src/qml/Main.qml @@ -318,11 +318,13 @@ Kirigami.ApplicationWindow { }) } function showUserDetail(user, room) { - Qt.createComponent("org.kde.neochat", "UserDetailDialog").createObject(root.QQC2.ApplicationWindow.window, { + const dialog = Qt.createComponent("org.kde.neochat", "UserDetailDialog").createObject(root, { room: room, user: user, - connection: root.connection - }).open(); + connection: root.connection, + }); + dialog.parent = QmlUtils.focusedWindowItem(); // Kirigami Dialogs overwrite the parent, so we need to set it again + dialog.open(); } function load() { diff --git a/src/utils.cpp b/src/utils.cpp index 1e44a8dc2..9a14adfa4 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -13,6 +13,7 @@ #include #include +#include using namespace Quotient; @@ -37,6 +38,16 @@ QColor QmlUtils::getUserColor(qreal hueF) return QColor::fromHslF(hueF, 1, -0.7 * lightness + 0.9, 1); } +QQuickItem *QmlUtils::focusedWindowItem() +{ + const auto window = qobject_cast(QGuiApplication::focusWindow()); + if (window) { + return window->contentItem(); + } else { + return nullptr; + } +} + bool Utils::isEmoji(const QString &text) { #ifdef HAVE_ICU diff --git a/src/utils.h b/src/utils.h index 3447310eb..b9ddb2ce5 100644 --- a/src/utils.h +++ b/src/utils.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -34,6 +35,7 @@ public: Q_INVOKABLE bool isValidJson(const QByteArray &json); Q_INVOKABLE QString escapeString(const QString &string); Q_INVOKABLE QColor getUserColor(qreal hueF); + Q_INVOKABLE QQuickItem *focusedWindowItem(); private: QmlUtils() = default;