summarylogtreecommitdiffstats
path: root/0003-Fix_blank_browser_dock_titles.patch
blob: d841c6421421880c24e391243e550ff46b42cf91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
From db9719ebfe9ccf4de8ca35cff1de1331ef240c36 Mon Sep 17 00:00:00 2001
From: Matt Gajownik <matt@obsproject.com>
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<QCefWidget> 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 <ryan@obsproject.com>
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<QAction> extraBrowserMenuDocksSeparator;
 
 	QList<QSharedPointer<QDockWidget>> 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<BrowserDock *>(
-			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<QDockWidget>(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 <ryan@obsproject.com>
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 <ryan@obsproject.com>
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