-
-
Notifications
You must be signed in to change notification settings - Fork 8.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UI: Reorganise and refactor entire frontend codebase #11622
base: master
Are you sure you want to change the base?
Conversation
136fe35
to
fa07b37
Compare
frontend/forms/OBSBasic.ui
Outdated
<string>label-preview-title</string> | ||
<string>previewProgramLabels</string> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Warchamp7 might have an opinion on this, but I think CSS/QSS class names should be singular (not plural). Also, if changing this, wouldn't the class rule in the theme files need to be changed? Or was this changed by mistake?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This string is in essence a CSS class name yes. Changing this would necessitate changes to the obt/ovt files and could be a breaking change to any custom themes people have made.
It is pretty common to use kebab-case for CSS classes and I have tried to be consistent about naming schemes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's an automatic change through rebasing though, the only classes that needed to be changed are the actual C++ class names in the customwidgets
tree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I follow.
There's a distinction here between the C++ class the widget is tied to, and the dynamic property class on the widget, which is used for styling purposes.
The thing changed here is a dynamic property that seems like an accidental modification.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what I'm saying, yes. The line should not have changed and the only reason it did was because git was able to apply the change when I rebased it to master.
frontend/docks/YouTubeAppDock.cpp
Outdated
@@ -29,6 +34,7 @@ static constexpr const char *INGESTION_STARTED = "INGESTION_STARTED"; | |||
static constexpr const char *INGESTION_STOPPED = "INGESTION_STOPPED"; | |||
|
|||
YouTubeAppDock::YouTubeAppDock(const QString &title) : BrowserDock(title), dockBrowser(nullptr) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This linebreak seems accidental.
UI/api-interface.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rip the most upsettingly named file in the entire program.
@@ -0,0 +1,27 @@ | |||
include_guard(DIRECTORY) | |||
|
|||
find_package(nlohmann_json REQUIRED) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
find_package(nlohmann_json REQUIRED) | |
find_package(nlohmann_json 3.11 REQUIRED) |
This is the line in the original file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks like a error from rebasing, was too easy for git to just remove it again.
frontend/cmake/os-freebsd.cmake
Outdated
find_package(Python REQUIRED COMPONENTS Interpreter Development) | ||
target_link_libraries(obs-studio PRIVATE Python::Python) | ||
target_link_options(obs-studio PRIVATE LINKER:-no-as-needed) | ||
endif() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
frontend/cmake/os-linux.cmake
Outdated
target_compile_definitions( | ||
obs-studio | ||
PRIVATE OBS_INSTALL_PREFIX="${OBS_INSTALL_PREFIX}" $<$<BOOL:${ENABLE_PORTABLE_CONFIG}>:ENABLE_PORTABLE_CONFIG> | ||
PRIVATE USE_XDG OBS_INSTALL_PREFIX="${OBS_INSTALL_PREFIX}" $<$<BOOL:${ENABLE_PORTABLE_CONFIG}>:ENABLE_PORTABLE_CONFIG> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
frontend/cmake/os-windows.cmake
Outdated
find_package(nlohmann_json 3.11 REQUIRED) | ||
find_package(nlohmann_json REQUIRED) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we removing this version requirement on purpose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above.
frontend/oauth/TwitchAuth.cpp
Outdated
#include <ui-config.h> | ||
#include <qt-wrappers.hpp> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#include <ui-config.h> | |
#include <qt-wrappers.hpp> | |
#include <qt-wrappers.hpp> | |
#include <ui-config.h> |
If alphabetizing, use this order. Otherwise, ignore.
class QWidget; | ||
class QString; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Swap if alphabetizing. Ignore if this order is specific.
frontend/utility/audio-encoders.hpp
Outdated
#include <vector> | ||
#include <string> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#include <vector> | |
#include <string> | |
#include <string> | |
#include <vector> |
frontend/utility/obf.c
Outdated
#include "obf.h" | ||
#include <stdbool.h> | ||
|
||
#include "obf.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought the expected order here was:
- corresponding .h file
- stdlib
See frontend/utility/audio-encoders.cpp
for example.
frontend/widgets/OBSProjector.cpp
Outdated
#include <utility/platform.hpp> | ||
#include <widgets/OBSBasic.hpp> | ||
|
||
#include "OBSProjector.hpp" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this usually be the first include?
class OBSSourceLabel; | ||
class QCheckBox; | ||
|
||
class OBSSourceLabel; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OBSSourceLabel
is here twice.
frontend/wizards/AutoConfig.cpp
Outdated
#include "AutoConfigStreamPage.hpp" | ||
#include "AutoConfigStartPage.hpp" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#include "AutoConfigStreamPage.hpp" | |
#include "AutoConfigStartPage.hpp" | |
#include "AutoConfigStartPage.hpp" | |
#include "AutoConfigStreamPage.hpp" |
If alphabetical. If other order, ignore.
frontend/wizards/AutoConfig.cpp
Outdated
#include "ui_AutoConfigVideoPage.h" | ||
#include "ui_AutoConfigStreamPage.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#include "ui_AutoConfigVideoPage.h" | |
#include "ui_AutoConfigStreamPage.h" | |
#include "ui_AutoConfigStreamPage.h" | |
#include "ui_AutoConfigVideoPage.h" |
If alphabetical. If other order, ignore.
#include <vector> | ||
#include <string> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#include <vector> | |
#include <string> | |
#include <string> | |
#include <vector> |
@@ -0,0 +1,12 @@ | |||
#pragma once |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing license header?
@@ -0,0 +1,15 @@ | |||
#pragma once |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing license headers.
@@ -0,0 +1,18 @@ | |||
#pragma once |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing license headers.
@@ -0,0 +1,33 @@ | |||
#pragma once |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing license header.
@@ -171,6 +136,8 @@ class OBSBasicSettings : public QDialog { | |||
void SaveEncoder(QComboBox *combo, const char *section, const char *value); | |||
|
|||
bool ResFPSValid(obs_service_resolution *res_list, size_t res_count, int max_fps); | |||
|
|||
// TODO: Remove, orphaned method |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just leaving a review note to raise awareness of this todo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finished a first pass of all files.
frontend/oauth/RestreamAuth.cpp
Outdated
#include <ui-config.h> | ||
#include <qt-wrappers.hpp> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#include <ui-config.h> | |
#include <qt-wrappers.hpp> | |
#include <qt-wrappers.hpp> | |
#include <ui-config.h> |
frontend/oauth/YoutubeAuth.cpp
Outdated
#include <ui-config.h> | ||
#include <qt-wrappers.hpp> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#include <ui-config.h> | |
#include <qt-wrappers.hpp> | |
#include <qt-wrappers.hpp> | |
#include <ui-config.h> |
vector<FFmpegFormat> GetSupportedFormats() | ||
{ | ||
vector<FFmpegFormat> formats; | ||
const AVOutputFormat *output_format; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surprised the avformat.h
include wasn't needed for this.
@@ -0,0 +1,18 @@ | |||
#include "OBSTranslator.hpp" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OBSTranslator comes from UI\obs-app.cpp/hpp
which has a license header.
@@ -0,0 +1,14 @@ | |||
#pragma once |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OBSTranslator comes from UI\obs-app.cpp/hpp
which has a license header.
#include <docks/YouTubeAppDock.hpp> | ||
#include <dialogs/OBSYoutubeActions.hpp> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#include <docks/YouTubeAppDock.hpp> | |
#include <dialogs/OBSYoutubeActions.hpp> | |
#include <dialogs/OBSYoutubeActions.hpp> | |
#include <docks/YouTubeAppDock.hpp> |
Unless include order is specific.
#include <utility/OBSEventFilter.hpp> | ||
#include <utility/display-helpers.hpp> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other files seem to do case-insensitive alphabetization. I don't yet have a strong preference, so I just wanted to see if there is an intended order.
frontend/dialogs/OBSWhatsNew.cpp
Outdated
#include <QPushButton> | ||
#include <QHBoxLayout> | ||
#include <QVBoxLayout> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#include <QPushButton> | |
#include <QHBoxLayout> | |
#include <QVBoxLayout> | |
#include <QHBoxLayout> | |
#include <QPushButton> | |
#include <QVBoxLayout> |
If alphabetical is preferred, order like this.
frontend/obs-main.cpp
Outdated
#include <utility/platform.hpp> | ||
#include <dialogs/OBSLogViewer.hpp> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#include <utility/platform.hpp> | |
#include <dialogs/OBSLogViewer.hpp> | |
#include <dialogs/OBSLogViewer.hpp> | |
#include <utility/platform.hpp> |
Alphabetize unless order is intentional.
This commit only contains Qt UI components that are self-contained, i.e. the translation units only contain code for a single class or interface and don't mix implementations.
fa07b37
to
2ef2956
Compare
Description
This PR reorganises the frontend codebase to enable a switch of the project to common good practices for development large GUI applications.
The actual implementations of frontend functionality are unchanged, with the exception of cases where the new organisation of source files required them to get the project in a compilable state again.
Caution
This PR must be merged via a merge commit, as extra effort has been taken to ensure the blame history of the new files will be able to access the history of the old files. A rebase will prohibit git from figuring out these connections.
Motivation and Context
The frontend of OBS Studio is written in C++ and based on Qt6, for which good practices have evolved that are distinct from development practices common in library or pure C-based development. These practices include approaches to file naming, file structuring, class design, and header design, with the goal of improving maintainability and discoverability, as well as speed improvements for incremental builds and compiler performance.
For this refactor, the following set of rules were established and applied to the entire frontend codebase:
CapitalCase
, class methods usecamelCase
Additional rules that should be established but haven't been applied in this PR are:
Important
The following rules should be followed moving forward but have not been applied to this PR yet to keep the amount of actual code changes to a very low level.
Those changes will be applied in a later PR.
static
functionsstatic
function in another translation unit.inline
decoration should be used according to its actual meaning in C++: That a function definition is provided "in line" (it has no direct bearing on the code inlining behaviour of compilers). As such it should never(!) be used in source files and should only ever be used in header files, and even there it should be used with all its associated caveats applied.camelCase
, notsnake_case
(which instead should be used to clearly identify C functions vs C++ functions)AdvAudio
, butAdvancedAudio
).Youtube
andYouTube
in the same codebaseActive
orNudge
, make their purpose explicit by their name itself, e.g.nudgePreviewItem
orisOutputActive
Get
,Set
, andIs
prefixes to clearly communicate whether a method gets, sets, or gets a state/status.extern
symbols that also "magically" have to exist in the global namespace. Encapsulate data with functionality and use APIs to access data or delegate functionality to encapsulated classes entirely.Moving forward the principle to Respect Levels Of Abstraction should be followed not only in code architecture but also method naming.
Notably there is no good reason to update all existing code to these practices, instead they
will need to be applied to any new code and to changes made to existing code.
Note
As this PR does not rename actual classes or change implementations, some idiosyncrasies of the current code base are made more apparent by this change:
Some classes carry an
OBS
orOBSBasic
prefix, some carry no such prefix at all. Some classes have overlay generic names (e.g.DelButton
, orWorkerThread
). This is by design as it will hopefully spur maintainers to clean this up if only to achieve consistency in class naming.Notably these changes also have a positive effect on incremental compile times: Header files should be seen as "class interface definitions" that are needed for code to understand the memory layout and API of another class. Such headers should only be included in other headers sparingly and instead be limited to source files as best as possible.
A single header file per class also avoids the issue of triggering recompilation of a whole set of source code just because one of many class definitions in the same header has been changed. This also improves parallelisation in build tools and improves speed of recompilation efforts by Qt's
moc
precompiler (as source and header files themselves become smaller).Unfortunately the single massive
OBSBasic
class with its equally massive header file persists, which is also included by almost all other frontend code in one form or another. A better architecture for the frontend code could avoid this pitfall, but for the time being a single change inOBSBasic
's header will trigger recompilation of a large amount of frontend code.How Has This Been Tested?
Successfully compiled and ran OBS Studio on macOS 15, Windows 11, and Ubuntu 24.04 with browser sources enabled and disabled and service integrations enabled as well as disabled.
Types of changes
Checklist: