summary refs log tree commit diff
path: root/src/MainWindow.cpp
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2022-05-07 18:53:16 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2022-05-07 18:53:16 +0200
commit62bf1b253e3b09d516af432d8bd3b34c6979141f (patch)
tree4d463eff503d6f4b296c0bb13112e730b948cfbc /src/MainWindow.cpp
parentFix notification for focus room in main window (diff)
downloadnheko-62bf1b253e3b09d516af432d8bd3b34c6979141f.tar.xz
Rework focus handling
Diffstat (limited to 'src/MainWindow.cpp')
-rw-r--r--src/MainWindow.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp
index ffc3c6c1..7f62b23b 100644
--- a/src/MainWindow.cpp
+++ b/src/MainWindow.cpp
@@ -434,3 +434,50 @@ MainWindow::showDialog(QWidget *dialog)
     utils::centerWidget(dialog, this);
     dialog->window()->windowHandle()->setTransientParent(this);
 }
+
+void
+MainWindow::addPerRoomWindow(const QString &room, QWindow *window)
+{
+    roomWindows_.insert(room, window);
+}
+void
+MainWindow::removePerRoomWindow(const QString &room, QWindow *window)
+{
+    roomWindows_.remove(room, window);
+}
+const QWindow *
+MainWindow::windowForRoom(const QString &room) const
+{
+    auto currMainWindowRoom = ChatPage::instance()->timelineManager()->rooms()->currentRoom();
+    if ((currMainWindowRoom && currMainWindowRoom->roomId() == room) ||
+        ChatPage::instance()->timelineManager()->rooms()->currentRoomPreview().roomid_ == room)
+        return this;
+    else if (auto res = roomWindows_.find(room); res != roomWindows_.end())
+        return res.value();
+    return nullptr;
+}
+
+QString
+MainWindow::focusedRoom() const
+{
+    auto focus = QGuiApplication::focusWindow();
+    if (!focus)
+        return {};
+
+    if (focus == this) {
+        auto currMainWindowRoom = ChatPage::instance()->timelineManager()->rooms()->currentRoom();
+        if (currMainWindowRoom)
+            return currMainWindowRoom->roomId();
+        else
+            return ChatPage::instance()->timelineManager()->rooms()->currentRoomPreview().roomid_;
+    }
+
+    auto i = roomWindows_.constBegin();
+    while (i != roomWindows_.constEnd()) {
+        if (i.value() == focus)
+            return i.key();
+        ++i;
+    }
+
+    return nullptr;
+}