From db9719ebfe9ccf4de8ca35cff1de1331ef240c36 Mon Sep 17 00:00:00 2001 From: Matt Gajownik Date: Thu, 10 Aug 2023 18:31:19 +1000 Subject: [PATCH 1/4] UI: Set browser dock title in constructor Works around a bug in Qt where setWindowTitle called on a native window that hasn't been initialised yet causes the title data to be lost, resulting in the window's title never being set. --- UI/auth-restream.cpp | 6 +++--- UI/auth-twitch.cpp | 8 ++++---- UI/auth-youtube.cpp | 3 +-- UI/auth-youtube.hpp | 1 + UI/window-dock-browser.hpp | 4 ++++ UI/window-dock.hpp | 4 ++++ UI/window-extra-browsers.cpp | 2 +- 7 files changed, 18 insertions(+), 10 deletions(-) diff --git a/UI/auth-restream.cpp b/UI/auth-restream.cpp index 9188da118..bedc10c70 100644 --- a/UI/auth-restream.cpp +++ b/UI/auth-restream.cpp @@ -150,7 +150,7 @@ void RestreamAuth::LoadUI() QSize size = main->frameSize(); QPoint pos = main->pos(); - BrowserDock *chat = new BrowserDock(); + BrowserDock *chat = new BrowserDock(QTStr("Auth.Chat")); chat->setObjectName(RESTREAM_CHAT_DOCK_NAME); chat->resize(420, 600); chat->setMinimumSize(200, 300); @@ -166,7 +166,7 @@ void RestreamAuth::LoadUI() url = "https://restream.io/titles/embed"; - BrowserDock *info = new BrowserDock(); + BrowserDock *info = new BrowserDock(QTStr("Auth.StreamInfo")); info->setObjectName(RESTREAM_INFO_DOCK_NAME); info->resize(410, 600); info->setMinimumSize(200, 150); @@ -182,7 +182,7 @@ void RestreamAuth::LoadUI() url = "https://restream.io/channel/embed"; - BrowserDock *channels = new BrowserDock(); + BrowserDock *channels = new BrowserDock(QTStr("RestreamAuth.Channels")); channels->setObjectName(RESTREAM_CHANNELS_DOCK_NAME); channels->resize(410, 600); channels->setMinimumSize(410, 300); diff --git a/UI/auth-twitch.cpp b/UI/auth-twitch.cpp index 386a0e927..88e14e0be 100644 --- a/UI/auth-twitch.cpp +++ b/UI/auth-twitch.cpp @@ -251,7 +251,7 @@ void TwitchAuth::LoadUI() QSize size = main->frameSize(); QPoint pos = main->pos(); - BrowserDock *chat = new BrowserDock(); + BrowserDock *chat = new BrowserDock(QTStr("Auth.Chat")); chat->setObjectName(TWITCH_CHAT_DOCK_NAME); chat->resize(300, 600); chat->setMinimumSize(200, 300); @@ -340,7 +340,7 @@ void TwitchAuth::LoadSecondaryUIPanes() url += name; url += "/stream-manager/edit-stream-info"; - BrowserDock *info = new BrowserDock(); + BrowserDock *info = new BrowserDock(QTStr("Auth.StreamInfo")); info->setObjectName(TWITCH_INFO_DOCK_NAME); info->resize(300, 650); info->setMinimumSize(200, 300); @@ -359,7 +359,7 @@ void TwitchAuth::LoadSecondaryUIPanes() url += name; url += "/dashboard/live/stats"; - BrowserDock *stats = new BrowserDock(); + BrowserDock *stats = new BrowserDock(QTStr("TwitchAuth.Stats")); stats->setObjectName(TWITCH_STATS_DOCK_NAME); stats->resize(200, 250); stats->setMinimumSize(200, 150); @@ -379,7 +379,7 @@ void TwitchAuth::LoadSecondaryUIPanes() url += "/stream-manager/activity-feed"; url += "?uuid=" + uuid; - BrowserDock *feed = new BrowserDock(); + BrowserDock *feed = new BrowserDock(QTStr("TwitchAuth.Feed")); feed->setObjectName(TWITCH_FEED_DOCK_NAME); feed->resize(300, 650); feed->setMinimumSize(200, 300); diff --git a/UI/auth-youtube.cpp b/UI/auth-youtube.cpp index 7783fa62d..906481959 100644 --- a/UI/auth-youtube.cpp +++ b/UI/auth-youtube.cpp @@ -154,11 +154,10 @@ void YoutubeAuth::LoadUI() QSize size = main->frameSize(); QPoint pos = main->pos(); - chat = new YoutubeChatDock(); + chat = new YoutubeChatDock(QTStr("Auth.Chat")); chat->setObjectName(YOUTUBE_CHAT_DOCK_NAME); chat->resize(300, 600); chat->setMinimumSize(200, 300); - chat->setWindowTitle(QTStr("Auth.Chat")); chat->setAllowedAreas(Qt::AllDockWidgetAreas); browser = cef->create_widget(chat, YOUTUBE_CHAT_PLACEHOLDER_URL, diff --git a/UI/auth-youtube.hpp b/UI/auth-youtube.hpp index ffe35c25c..5c5015def 100644 --- a/UI/auth-youtube.hpp +++ b/UI/auth-youtube.hpp @@ -21,6 +21,7 @@ private: QHBoxLayout *chatLayout; public: + inline YoutubeChatDock(const QString &title) : BrowserDock(title) {} void SetWidget(QCefWidget *widget_); void SetApiChatId(const std::string &id); diff --git a/UI/window-dock-browser.hpp b/UI/window-dock-browser.hpp index 37583c200..717ff7787 100644 --- a/UI/window-dock-browser.hpp +++ b/UI/window-dock-browser.hpp @@ -10,6 +10,10 @@ extern QCefCookieManager *panel_cookies; class BrowserDock : public OBSDock { public: inline BrowserDock() : OBSDock() { setAttribute(Qt::WA_NativeWindow); } + inline BrowserDock(const QString &title) : OBSDock(title) + { + setAttribute(Qt::WA_NativeWindow); + } QScopedPointer cefWidget; diff --git a/UI/window-dock.hpp b/UI/window-dock.hpp index ccb1cf0ae..2d4062ec7 100644 --- a/UI/window-dock.hpp +++ b/UI/window-dock.hpp @@ -7,6 +7,10 @@ class OBSDock : public QDockWidget { public: inline OBSDock(QWidget *parent = nullptr) : QDockWidget(parent) {} + inline OBSDock(const QString &title, QWidget *parent = nullptr) + : QDockWidget(title, parent) + { + } virtual void closeEvent(QCloseEvent *event); }; diff --git a/UI/window-extra-browsers.cpp b/UI/window-extra-browsers.cpp index a53f66106..d26138756 100644 --- a/UI/window-extra-browsers.cpp +++ b/UI/window-extra-browsers.cpp @@ -527,7 +527,7 @@ void OBSBasic::AddExtraBrowserDock(const QString &title, const QString &url, panel_version = obs_browser_qcef_version(); } - BrowserDock *dock = new BrowserDock(); + BrowserDock *dock = new BrowserDock(title); QString bId(uuid.isEmpty() ? QUuid::createUuid().toString() : uuid); bId.replace(QRegularExpression("[{}-]"), ""); dock->setProperty("uuid", bId); -- 2.42.0 From e30be01b053958f793f748c306a480bdb63e0e96 Mon Sep 17 00:00:00 2001 From: Ryan Foster Date: Fri, 11 Aug 2023 16:27:55 -0400 Subject: [PATCH 2/4] UI: Track custom browser dock names internally This is a workaround for a change in Qt behavior between 6.5.1 and 6.5.2[1] which affected the outcome of attempting to set the window title of a window that is not currently open. In Qt 6.4.3 and 6.5.1, the window title would be set. In Qt 6.5.2, the window title will become NULL/empty. Instead of relying on Qt to have valid titles for custom browser dock windows that we manage, let's track the names ourselves. [1]: https://github.com/qt/qtbase/commit/c153066baaa88718ed45b68230d81285eb436d3d --- UI/window-basic-main.hpp | 1 + UI/window-extra-browsers.cpp | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/UI/window-basic-main.hpp b/UI/window-basic-main.hpp index 55abea8fe..20a02ca1c 100644 --- a/UI/window-basic-main.hpp +++ b/UI/window-basic-main.hpp @@ -560,6 +560,7 @@ private: QPointer extraBrowserMenuDocksSeparator; QList> extraBrowserDocks; + QStringList extraBrowserDockNames; QStringList extraBrowserDockTargets; void ClearExtraBrowserDocks(); diff --git a/UI/window-extra-browsers.cpp b/UI/window-extra-browsers.cpp index d26138756..a8076f1b1 100644 --- a/UI/window-extra-browsers.cpp +++ b/UI/window-extra-browsers.cpp @@ -32,12 +32,9 @@ void ExtraBrowsersModel::Reset() OBSBasic *main = OBSBasic::Get(); for (int i = 0; i < main->extraBrowserDocks.size(); i++) { - BrowserDock *dock = reinterpret_cast( - main->extraBrowserDocks[i].data()); - Item item; item.prevIdx = i; - item.title = dock->windowTitle(); + item.title = main->extraBrowserDockNames[i]; item.url = main->extraBrowserDockTargets[i]; items.push_back(item); } @@ -180,6 +177,10 @@ void ExtraBrowsersModel::UpdateItem(Item &item) dock->setWindowTitle(item.title); dock->setObjectName(item.title + OBJ_NAME_SUFFIX); + if (main->extraBrowserDockNames[idx] != item.title) { + main->extraBrowserDockNames[idx] = item.title; + } + if (main->extraBrowserDockTargets[idx] != item.url) { dock->cefWidget->setURL(QT_TO_UTF8(item.url)); main->extraBrowserDockTargets[idx] = item.url; @@ -234,6 +235,7 @@ void ExtraBrowsersModel::Apply() for (int i = deleted.size() - 1; i >= 0; i--) { int idx = deleted[i]; main->extraBrowserDockTargets.removeAt(idx); + main->extraBrowserDockNames.removeAt(idx); main->extraBrowserDocks.removeAt(idx); } @@ -460,6 +462,7 @@ void OBSExtraBrowsers::on_apply_clicked() void OBSBasic::ClearExtraBrowserDocks() { extraBrowserDockTargets.clear(); + extraBrowserDockNames.clear(); extraBrowserDocks.clear(); } @@ -492,10 +495,11 @@ void OBSBasic::SaveExtraBrowserDocks() Json::array array; for (int i = 0; i < extraBrowserDocks.size(); i++) { QDockWidget *dock = extraBrowserDocks[i].data(); + QString title = extraBrowserDockNames[i]; QString url = extraBrowserDockTargets[i]; QString uuid = dock->property("uuid").toString(); Json::object obj{ - {"title", QT_TO_UTF8(dock->windowTitle())}, + {"title", QT_TO_UTF8(title)}, {"url", QT_TO_UTF8(url)}, {"uuid", QT_TO_UTF8(uuid)}, }; @@ -564,6 +568,7 @@ void OBSBasic::AddExtraBrowserDock(const QString &title, const QString &url, AddDockWidget(dock, Qt::RightDockWidgetArea, true); extraBrowserDocks.push_back(QSharedPointer(dock)); + extraBrowserDockNames.push_back(title); extraBrowserDockTargets.push_back(url); if (firstCreate) { -- 2.42.0 From 1a6858af32bd65fcbafb7927dcf8d988b80bd2e9 Mon Sep 17 00:00:00 2001 From: Ryan Foster Date: Fri, 11 Aug 2023 16:29:57 -0400 Subject: [PATCH 3/4] UI: Update text for custom browser dock menu items manually Instead of relying on the dock's having their window title already set for the menu items to be updated, let's just manually update the menu item text ourselves when updating the item. --- UI/window-extra-browsers.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/UI/window-extra-browsers.cpp b/UI/window-extra-browsers.cpp index a8076f1b1..64741e0a6 100644 --- a/UI/window-extra-browsers.cpp +++ b/UI/window-extra-browsers.cpp @@ -179,6 +179,7 @@ void ExtraBrowsersModel::UpdateItem(Item &item) if (main->extraBrowserDockNames[idx] != item.title) { main->extraBrowserDockNames[idx] = item.title; + dock->toggleViewAction()->setText(item.title); } if (main->extraBrowserDockTargets[idx] != item.url) { -- 2.42.0 From 12ebcec223a8d117a475bf8d2969e615f5fd56f2 Mon Sep 17 00:00:00 2001 From: Ryan Foster Date: Fri, 11 Aug 2023 16:47:29 -0400 Subject: [PATCH 4/4] UI: Store dock titles in BrowserDock instead of relying on Qt Attempting to set the window title of a BrowserDock that is closed, then opening the BrowserDock, would show that BrowserDock with an incorrect title. We can handle this by overriding the showEvent of BrowserDock and manually setting the window title after the showEvent is called, hopefully ensuring that we are only setting the window title on a window that exists. --- UI/window-dock-browser.cpp | 6 ++++++ UI/window-dock-browser.hpp | 9 ++++++++- UI/window-dock.cpp | 5 +++++ UI/window-dock.hpp | 1 + UI/window-extra-browsers.cpp | 1 + 5 files changed, 21 insertions(+), 1 deletion(-) diff --git a/UI/window-dock-browser.cpp b/UI/window-dock-browser.cpp index 7ae55e77c..30e1de1bc 100644 --- a/UI/window-dock-browser.cpp +++ b/UI/window-dock-browser.cpp @@ -18,3 +18,9 @@ void BrowserDock::closeEvent(QCloseEvent *event) cefWidget->closeBrowser(); } } + +void BrowserDock::showEvent(QShowEvent *event) +{ + OBSDock::showEvent(event); + setWindowTitle(title); +} diff --git a/UI/window-dock-browser.hpp b/UI/window-dock-browser.hpp index 717ff7787..750ed42bd 100644 --- a/UI/window-dock-browser.hpp +++ b/UI/window-dock-browser.hpp @@ -8,10 +8,14 @@ extern QCef *cef; extern QCefCookieManager *panel_cookies; class BrowserDock : public OBSDock { +private: + QString title; + public: inline BrowserDock() : OBSDock() { setAttribute(Qt::WA_NativeWindow); } - inline BrowserDock(const QString &title) : OBSDock(title) + inline BrowserDock(const QString &title_) : OBSDock(title_) { + title = title_; setAttribute(Qt::WA_NativeWindow); } @@ -23,5 +27,8 @@ public: cefWidget.reset(widget_); } + inline void setTitle(const QString &title_) { title = title_; } + void closeEvent(QCloseEvent *event) override; + void showEvent(QShowEvent *event) override; }; diff --git a/UI/window-dock.cpp b/UI/window-dock.cpp index ed8e92860..3c3eed995 100644 --- a/UI/window-dock.cpp +++ b/UI/window-dock.cpp @@ -34,3 +34,8 @@ void OBSDock::closeEvent(QCloseEvent *event) QDockWidget::closeEvent(event); } + +void OBSDock::showEvent(QShowEvent *event) +{ + QDockWidget::showEvent(event); +} diff --git a/UI/window-dock.hpp b/UI/window-dock.hpp index 2d4062ec7..e73620a2b 100644 --- a/UI/window-dock.hpp +++ b/UI/window-dock.hpp @@ -13,4 +13,5 @@ public: } virtual void closeEvent(QCloseEvent *event); + virtual void showEvent(QShowEvent *event); }; diff --git a/UI/window-extra-browsers.cpp b/UI/window-extra-browsers.cpp index 64741e0a6..a7f593782 100644 --- a/UI/window-extra-browsers.cpp +++ b/UI/window-extra-browsers.cpp @@ -180,6 +180,7 @@ void ExtraBrowsersModel::UpdateItem(Item &item) if (main->extraBrowserDockNames[idx] != item.title) { main->extraBrowserDockNames[idx] = item.title; dock->toggleViewAction()->setText(item.title); + dock->setTitle(item.title); } if (main->extraBrowserDockTargets[idx] != item.url) { -- 2.42.0