Skip to content

Commit 363fa83

Browse files
committed
Add RFC: Switch to Advanced Docking System
1 parent e5c925b commit 363fa83

File tree

4 files changed

+377
-0
lines changed

4 files changed

+377
-0
lines changed
Lines changed: 377 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,377 @@
1+
# Summary
2+
3+
- Switch main dock system to [ADS][1]
4+
- Make ADS dock state per profile
5+
- Allow the user to switch between pre-made layouts
6+
- Plugins could register their own
7+
- Users could save their own
8+
- Dock added by plugins with the old method are added as "*Legacy dock*"
9+
- Frontend API methods and events about ADS docks
10+
11+
Note: The "central widget" design is kept.
12+
13+
# Motivation
14+
15+
Provide a better dock system to end-users.
16+
17+
# Design
18+
**DISCLAIMER**: The "central widget" design is kept, switching to a non-"central widget" one is not part of this RFC.
19+
20+
## Main window dock separation
21+
To make OBS Studio compatible with ADS, Controls, Transitions, Mixer, Sources, Scenes docks need to be separated from the main window.
22+
23+
And the central widget of main window should also be separated as well to become the central dock.
24+
25+
So the docks will be separated as widget class with their own UI class.
26+
27+
Then those widget are inserted in OBSDock (QDockWidget) and the central widget and put as main window central widget.
28+
29+
And then we switch to ADS, all those widget will become docks and added to the ADS dock manager.
30+
31+
The OBSBasic heavily rely on some UI element from those docks, to resolve that the related code will be refactored to remove this dependance going toward a MVC pattern.
32+
33+
Each widget class will be put as a friend class in OBSBasic to allow access to private slot and avoid moving them as public.
34+
35+
### Controls widget
36+
*Future ADS Controls dock widget*
37+
38+
All the buttons of this dock will be connected through signal and slots to OBSBasic.
39+
40+
Some hotkeys and pause functions rely on UI buttons, so OBS Basic will be refactored to remove this dependance.
41+
42+
### Transistions widget
43+
*Future ADS Transitions dock widget*
44+
45+
Transitions will be stored in OBSBasic and selected through the combo box of the widget.
46+
47+
The transition duration will become an attribute of OBSBasic, and signal and slots will be setup to synchromise it with the dock spinbox.
48+
49+
Buttons for adding, removing and open settings will be connected through signals and slots to OBSBasic.
50+
51+
### Mixer widget
52+
*Future ADS Mixer dock widget*
53+
54+
The base dock is easily separable, but the VolControl class can be refactored (toward MVC) later because this is not a requirement for this RFC.
55+
56+
### Sources widget
57+
*Future ADS Sources dock widget*
58+
59+
OBSBasic heavily rely on the SourceTree from the widget, but a refactoring will not be considered as a requirement for this RFC. So the class of the sources widget will have OBSBasic as a friend class.
60+
61+
### Scenes widget
62+
*Future ADS Scenes dock widget*
63+
64+
OBSBasic heavily rely on the SceneTree from the widget, but a refactoring will not be considered as a requirement for this RFC. So the class of the scenes widget will have OBSBasic as a friend class.
65+
66+
### Central widget
67+
*Future ADS Central dock widget*
68+
69+
Some context bar, preview/program and nudge related code is moved to the central widget class.
70+
71+
This class will have OBSBasicPreview as a friend class.
72+
73+
This class will be a friend class of OBSBasic also to have access to some gs_vertbuffer_t type attributes.
74+
75+
## ADS
76+
The Advanced Docking System, require to add a Dock Manager in the main window and then add the central widget and then add other docks.
77+
78+
Some work on themes CSS will be required.
79+
80+
### About obs-deps
81+
82+
obs-deps already build Qt for macOS and Windows, so adding a ADS script to the Qt tarballs is not a problem.
83+
84+
### Floating docks titlebar on X11
85+
On X11, ADS provide two type of titlebar for floating docks:
86+
87+
- Native
88+
89+
[![Native titlebar under GNOME](./0047-switch-to-advanced-docking-system/linux_native_floating_dock_titlebar.png)]()
90+
91+
- QWidget based (WIP CSS)
92+
93+
[![QWidget titlebar](./0047-switch-to-advanced-docking-system/linux_qwidget_floating_dock_titlebar.png)]()
94+
95+
The QWidget one is used by default when using KWin based Desktop Environement like Plasma. And this titlebar requires some CSS in the themes to match it.
96+
97+
So the QWidget based titlebar usage will be enforced thanks to a flag for the Dock Manager to "unify" experience between desktop environement.
98+
Theme makers may ignore to theme this bar.
99+
100+
### Dock state
101+
*The per profile dock state feature is not taken into account to describe those changes.*
102+
103+
In the global config (`global.ini`).
104+
- `"dockState"` is kept for for backward compatiblity and no longer overwitten. It will be used if the following state is not present.
105+
- `"windowState"` is the state of the main window, since it does not store only the state of legacy docks.
106+
- `"advDockState"` is the state of the dock manager which contain only the states of any ADS dock.
107+
108+
Service integrations only save `"advDockProfile"`
109+
110+
ADS dock state is compressed by default but behind the scene it's XML.
111+
112+
### OBSAdvDock
113+
OBSAdvDock is a class which inherit `ads::CDockWidget` class.
114+
115+
This class has a constructor which require a QWidget and setup some things arround the widget and set some connections.
116+
117+
It adds a warning message when closing a dock from a close dock button.
118+
119+
It allows to reset a dock position after a UI reset or a layout change with a possibility to reset the size if set beforehand.
120+
121+
### Custom Browser docks and BrowserAdvDock
122+
The custom browser docks feature is modified to use BrowserAdvDock which inherit OBSAdvDock.
123+
124+
Those docks are stored in the dock manager and their names is stored in a QStringList for browser docks to be able to get the dock from the manager to modify it like changing the URL.
125+
126+
Each of those browser dock is named `extraBrowser_$UUID` where `$UUID` is replaced by the dock UUID to have a really unique name.
127+
128+
### Service integration docks
129+
130+
Like custom browser docks, those integration are modified to use BrowserAdvDock. But their names is stored in the QStringList for plugins extra docks.
131+
132+
Those docks are named `obs-$SERVICE_$DOCK_NAME` where `$SERVICE` is the service name in lowercase and `$DOCK_NAME` the name of the dock.
133+
134+
`"dockState"` will be imported from the integration config if `"windowState"` is not present.
135+
136+
### Reset UI action
137+
1. Legacy dock are hidden
138+
2. The default state written in XML is applied
139+
3. Each not shown OBSAdvDock/BrowserAdvDock dock have its position and size reseted.
140+
141+
## Legacy dock
142+
143+
If switching to ADS is made at the same as switching to Qt 6. This feature will only concern builds that still use Qt 5 (e.g. Ubuntu 20.04).
144+
145+
The frontend API method `obs_frontend_add_dock()` is put in deprecation. And if dual switch only Qt5 and on Qt 6 the method is removed or does nothing, this is possible because plugin will need to be rebuilt agaisnt Qt6.
146+
147+
And dock added through this method are added to a sub-menu named `Legacy dock` of the Dock menu.
148+
149+
[![Legacy dock menu](./0047-switch-to-advanced-docking-system/legacy_dock.png)]()
150+
151+
When openning a legacy dock, a message will appear explaining that those docks will not meld wery well with "new" docks.
152+
153+
The state of those are saved through `"windowState"` global config.
154+
155+
## Per profile dock state
156+
Move the `"advDockState"` from global config to the profile and integration no longer store their own state. `"windowState"` is kept global.
157+
158+
If a release happen between the switch to ADS and this feature, import the one from the integration service if the profile has one set up.
159+
160+
## Layouts management
161+
Add the feature, to switch between registered/saved dock layouts:
162+
- Though a sub-menu in the dock menu
163+
- Through a hotkey
164+
- Through the frontend API
165+
166+
OBS Studio could provide layouts, the default count as one.
167+
168+
Plugins could also register their own XML layouts through the frontend API.
169+
170+
Users could be able to save their own layouts. Those layouts will have their name prefixed with`user_` to avoid name conflicts.
171+
172+
Note: ADS perspective feature is not directly used because it relies heavily on QSettings.
173+
## Frontend API
174+
Like said earlier, the method `obs_frontend_add_dock()` is put in deprecation.
175+
176+
All add/remove methods related to ADS requiring a name will require the plugin module to be able to prefix the given name with the module name (`mod_name`) to avoid conflicts.
177+
178+
So the following method will be added to libobs to access modules `mod_name`:
179+
```c++
180+
EXPORT const char *obs_get_module_mod_name(obs_module_t *module);
181+
```
182+
183+
### Add a dock
184+
```c++
185+
/* takes QWidget */
186+
#define obs_frontend_add_dock_2(title, unique_name, widget) \
187+
obs_frontend_add_module_dock(obs_current_module(), title, \
188+
unique_name, widget)
189+
EXPORT void obs_frontend_add_module_dock(obs_module_t *module,
190+
const char *title,
191+
const char *unique_name,
192+
void *widget);
193+
```
194+
195+
This allow to add a OBSAdvDock with the given QWidget. Those docks are stored in the Dock Manager and their names is stored in the QStringList for plugins extra docks.
196+
197+
Default height and width would based on the widget actual size except if `"defaultWidth"` and `"defaultHeight"` properties are set with the [`setProperty()`][7] method on the widget.
198+
199+
Minimum sizes used by the dock are based on the widget ones.
200+
201+
### Remove a dock
202+
```c++
203+
#define obs_frontend_remove_dock(unique_name) \
204+
obs_frontend_remove_module_dock(obs_current_module(), unique_name)
205+
EXPORT void obs_frontend_remove_module_dock(obs_module_t *module,
206+
const char *unique_name);
207+
```
208+
209+
This allow the plugin to remove a dock added earlier.
210+
211+
### Add a browser dock
212+
```c++
213+
EXPORT bool obs_frontend_is_browser_available(void);
214+
```
215+
216+
This allow to know if the running OBS Studio has browser feature enabled. So it return false if OBS Studio was built without browser or is running under Wayland.
217+
218+
```c++
219+
#define obs_frontend_add_browser_dock(dock_params, browser_params) \
220+
obs_frontend_add_module_browser_dock(obs_current_module(), \
221+
dock_params, browser_params)
222+
EXPORT void obs_frontend_add_module_browser_dock(obs_module_t *module,
223+
struct obs_frontend_browser_dock_params *dock_params,
224+
struct obs_frontend_browser_params *browser_params);
225+
```
226+
227+
This allow the plugin to add a dock with a QCefWidget as widget.
228+
229+
If browser docks are added in the module load or post load steps, their parameter will be stored and those will be really added later.
230+
231+
The QCefWidget will get parameters from this structure:
232+
233+
```c++
234+
struct obs_frontend_browser_params {
235+
const char *url;
236+
bool enable_cookie;
237+
struct dstr startup_script;
238+
DARRAY(char *) force_popup_urls;
239+
};
240+
```
241+
242+
- `bool enable_cookie`: if true `panel_cookie` will be used. The plugin maker will have to remove the dock the between profile change because the cookie manager is per profile.
243+
- `struct dstr startup_script` allow to set a startup script for the QCefWidget.
244+
- `DARRAY(char *) force_popup_urls` allow to set a list of url forced to popup.
245+
246+
And the dock itself will get parameters from this structure:
247+
248+
```c++
249+
struct obs_frontend_browser_dock_params {
250+
const char *unique_name;
251+
const char *title;
252+
int default_width;
253+
int default_height;
254+
int min_width;
255+
int min_height;
256+
};
257+
```
258+
259+
`obs_frontend_remove_dock()` can be used to remove the browser dock.
260+
261+
### Remove browser cookie
262+
Since enabling cookie is posible, allowing to delete those is required.
263+
264+
```c++
265+
EXPORT void obs_frontend_delete_browser_cookie(const char *url);
266+
```
267+
268+
This will remove cookie related to the given URL.
269+
270+
### Add a dock layouts
271+
```c++
272+
#define obs_frontend_add_dock_layout(title, unique_name, xml_layout) \
273+
obs_frontend_add_module_dock_layout(obs_current_module(), \
274+
title, unique_name, xml_layout)
275+
EXPORT void obs_frontend_add_module_dock_layout(obs_module_t *module,
276+
const char *title,
277+
const char *unique_name,
278+
const char *xml_layout);
279+
```
280+
281+
This allow the plugin to add a dock layouts in XML to the UI. ADS allow to test a layout (state/perspective) without applying it, so the layout will be tested before registering it.
282+
283+
### Get a list of docks layouts
284+
```c++
285+
EXPORT char **obs_frontend_get_dock_layouts(void);
286+
```
287+
288+
This allow the plugin to get a list of registered dock layouts from the UI.
289+
290+
### Set a registered dock layout
291+
```c++
292+
EXPORT void obs_frontend_set_dock_layouts(const char *layout_name);
293+
```
294+
295+
This allow the plugin to set a registered dock layouts to the UI, the asked name should come directly from the get list method.
296+
297+
### Remove a dock layouts
298+
```c++
299+
#define obs_frontend_remove_dock_layout(unique_name) \
300+
obs_frontend_remove_module_dock_layout(obs_current_module(), \
301+
unique_name)
302+
EXPORT void obs_frontend_remove_module_dock_layout(obs_module_t *module,
303+
const char *unique_name);
304+
```
305+
306+
This allow the plugin to remove a dock layouts from the UI.
307+
308+
### Add a entirely custom dock
309+
```c++
310+
/* takes ads::CDockWidget */
311+
#define obs_frontend_add_custom_dock(unique_name, dock) \
312+
obs_frontend_add_module_custom_dock(obs_current_module(), \
313+
unique_name, dock)
314+
EXPORT void obs_frontend_add_module_custom_dock(obs_module_t *module,
315+
const char *unique_name,
316+
void *dock);
317+
```
318+
319+
Some plugin like [Sources Dock][6], do not add their docks to the Dock menu.
320+
321+
So this method allow to do this but requires the plugin to be link against ADS library.
322+
323+
And the dock will not have OBSAdvDock features.
324+
325+
Even if the plugin has the control over the dock, the the name is changed by the frontend API to be prefixed by the module name.
326+
327+
`obs_frontend_remove_dock()` can be used to remove the reference stored in the Dock Manager. Because their names is stored in the QStringList for plugins custom extra docks.
328+
329+
### Get the XML behind a registered dock layout
330+
*Method meant to allow a Dock Layout editor tool to exist*
331+
332+
```c++
333+
EXPORT char *obs_frontend_get_dock_layout(const char *layout_name);
334+
```
335+
336+
This allow the plugin to get a registered dock layouts XML, the asked name should come directly from the get list method.
337+
338+
### Get the XML of the actual dock state
339+
*Method meant to allow a Dock Layout editor tool to exist*
340+
341+
```c++
342+
EXPORT char *obs_frontend_get_current_dock_state(void);
343+
```
344+
345+
This allow the plugin to get the dock states XML of the UI.
346+
347+
### Events addition
348+
- An event before the startup restore dock state and `OBS_FRONTEND_EVENT_FINISHED_LOADING` to allow plugins to load their docks before the restore or redo a restore if the number of extra docks has changed. This event could possibly be emitted when profile is changed before restoring profile dock state and `OBS_FRONTEND_EVENT_PROFILE_CHANGED`.
349+
350+
- An event when the a dock layout is applied (reset or not) to allow plugins to reset the positions of their customs docks, if they want to.
351+
352+
## About making dock states future proof
353+
By default generated state are version 0. If one day we make a breaking change like remove the notion of central widget and so change the version.
354+
355+
We could take the saved `"advDockState"` and uncompress to edit the XML, to make it compatible with the change.
356+
357+
# Drawbacks
358+
We can't convert old `"dockState"` to the new dock system.
359+
360+
# Additional Information
361+
About Wayland support, Qt and ADS docking system have very bad support because of Qt Wayland. The Wayland backend is apparently third-class on Qt's priorities.
362+
363+
My WIP branches:
364+
- [Dock separation][2]
365+
- [Central widget separation][8]
366+
- [Switch to ADS][3]
367+
- [Frontend API to add ADS dock][4]
368+
- [Frontend API to add custom ADS dock][5]
369+
370+
[1]: https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System
371+
[2]: https://github.com/tytan652/obs-studio/tree/dock_separation
372+
[3]: https://github.com/tytan652/obs-studio/tree/advanced_docking
373+
[4]: https://github.com/tytan652/obs-studio/tree/ads_frontend_api
374+
[5]: https://github.com/tytan652/obs-studio/tree/add_custom_dock
375+
[6]: https://obsproject.com/forum/resources/source-dock.1317/
376+
[7]: https://doc.qt.io/qt-5/qobject.html#setProperty
377+
[8]: https://github.com/tytan652/obs-studio/tree/central_widget_separation
9.15 KB
Loading
9.24 KB
Loading
9.02 KB
Loading

0 commit comments

Comments
 (0)