From 66a0d3dd7a2813f44244e16ffcbd78d4223dcba9 Mon Sep 17 00:00:00 2001 From: Ryan Foster Date: Fri, 11 Oct 2024 14:27:29 -0400 Subject: [PATCH] clang-format: Update to clang-format 17.0.3 Also port clang-format settings from obs-studio. Use these settings for consistency with obs-studio code style. --- .clang-format | 136 ++++++++++++++++++++++++++++----- browser-app.hpp | 3 +- obs-browser-plugin.cpp | 44 ++++++++--- panel/browser-panel-client.cpp | 4 +- panel/browser-panel-client.hpp | 4 +- panel/browser-panel.cpp | 7 +- 6 files changed, 164 insertions(+), 34 deletions(-) diff --git a/.clang-format b/.clang-format index 5c7b99e5a..a10cf9586 100644 --- a/.clang-format +++ b/.clang-format @@ -1,7 +1,6 @@ +# please use clang-format version 16 or later -# please use clang-format version 8 or later - -Standard: Cpp11 +Standard: c++17 AccessModifierOffset: -8 AlignAfterOpenBracket: Align AlignConsecutiveAssignments: false @@ -9,14 +8,14 @@ AlignConsecutiveDeclarations: false AlignEscapedNewlines: Left AlignOperands: true AlignTrailingComments: true -#AllowAllArgumentsOnNextLine: false # requires clang-format 9 -#AllowAllConstructorInitializersOnNextLine: false # requires clang-format 9 +AllowAllArgumentsOnNextLine: false +AllowAllConstructorInitializersOnNextLine: false AllowAllParametersOfDeclarationOnNextLine: false AllowShortBlocksOnASingleLine: false AllowShortCaseLabelsOnASingleLine: false AllowShortFunctionsOnASingleLine: Inline AllowShortIfStatementsOnASingleLine: false -#AllowShortLambdasOnASingleLine: Inline # requires clang-format 9 +AllowShortLambdasOnASingleLine: Inline AllowShortLoopsOnASingleLine: false AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakAfterReturnType: None @@ -53,11 +52,12 @@ ContinuationIndentWidth: 8 Cpp11BracedListStyle: true DerivePointerAlignment: false DisableFormat: false -FixNamespaceComments: false -ForEachMacros: +FixNamespaceComments: true +ForEachMacros: - 'json_object_foreach' - 'json_object_foreach_safe' - 'json_array_foreach' + - 'HASH_ITER' IncludeBlocks: Preserve IndentCaseLabels: false IndentPPDirectives: None @@ -66,7 +66,7 @@ IndentWrappedFunctionNames: false KeepEmptyLinesAtTheStartOfBlocks: true MaxEmptyLinesToKeep: 1 NamespaceIndentation: None -#ObjCBinPackProtocolList: Auto # requires clang-format 7 +ObjCBinPackProtocolList: Auto ObjCBlockIndentWidth: 8 ObjCSpaceAfterProperty: true ObjCSpaceBeforeProtocolList: true @@ -84,13 +84,13 @@ ReflowComments: false SortIncludes: false SortUsingDeclarations: false SpaceAfterCStyleCast: false -#SpaceAfterLogicalNot: false # requires clang-format 9 +SpaceAfterLogicalNot: false SpaceAfterTemplateKeyword: false SpaceBeforeAssignmentOperators: true -#SpaceBeforeCtorInitializerColon: true # requires clang-format 7 -#SpaceBeforeInheritanceColon: true # requires clang-format 7 +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true SpaceBeforeParens: ControlStatements -#SpaceBeforeRangeBasedForLoopColon: true # requires clang-format 7 +SpaceBeforeRangeBasedForLoopColon: true SpaceInEmptyParentheses: false SpacesBeforeTrailingComments: 1 SpacesInAngles: false @@ -98,11 +98,111 @@ SpacesInCStyleCastParentheses: false SpacesInContainerLiterals: false SpacesInParentheses: false SpacesInSquareBrackets: false -#StatementMacros: # requires clang-format 8 -# - 'Q_OBJECT' +StatementMacros: + - 'Q_OBJECT' TabWidth: 8 -#TypenameMacros: # requires clang-format 9 -# - 'DARRAY' +TypenameMacros: + - 'DARRAY' UseTab: ForContinuationAndIndentation --- -Language: ObjC \ No newline at end of file +Language: ObjC +AccessModifierOffset: 2 +AlignArrayOfStructures: Right +AlignConsecutiveAssignments: None +AlignConsecutiveBitFields: None +AlignConsecutiveDeclarations: None +AlignConsecutiveMacros: + Enabled: true + AcrossEmptyLines: false + AcrossComments: true +AllowShortBlocksOnASingleLine: Never +AllowShortEnumsOnASingleLine: false +AllowShortFunctionsOnASingleLine: Empty +AllowShortIfStatementsOnASingleLine: Never +AllowShortLambdasOnASingleLine: None +AttributeMacros: ['__unused', '__autoreleasing', '_Nonnull', '__bridge'] +BitFieldColonSpacing: Both +#BreakBeforeBraces: Webkit +BreakBeforeBraces: Custom +BraceWrapping: + AfterCaseLabel: false + AfterClass: true + AfterControlStatement: Never + AfterEnum: false + AfterFunction: true + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: false + SplitEmptyNamespace: true +BreakAfterAttributes: Never +BreakArrays: false +BreakBeforeConceptDeclarations: Allowed +BreakBeforeInlineASMColon: OnlyMultiline +BreakConstructorInitializers: AfterColon +BreakInheritanceList: AfterComma +ColumnLimit: 120 +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: LogicalBlock +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +IndentAccessModifiers: false +IndentCaseBlocks: false +IndentCaseLabels: true +IndentExternBlock: Indent +IndentGotoLabels: false +IndentRequiresClause: true +IndentWidth: 4 +IndentWrappedFunctionNames: true +InsertBraces: false +InsertNewlineAtEOF: true +KeepEmptyLinesAtTheStartOfBlocks: false +LambdaBodyIndentation: Signature +NamespaceIndentation: All +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 4 +ObjCBreakBeforeNestedBlockParam: false +ObjCSpaceAfterProperty: true +ObjCSpaceBeforeProtocolList: true +PPIndentWidth: -1 +PackConstructorInitializers: NextLine +QualifierAlignment: Leave +ReferenceAlignment: Right +RemoveSemicolon: false +RequiresClausePosition: WithPreceding +RequiresExpressionIndentation: OuterScope +SeparateDefinitionBlocks: Leave +ShortNamespaceLines: 1 +SortIncludes: false +#SortUsingDeclarations: LexicographicNumeric +SortUsingDeclarations: true +SpaceAfterCStyleCast: true +SpaceAfterLogicalNot: false +SpaceAroundPointerQualifiers: Default +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: true +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 2 +SpacesInConditionalStatement: false +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 +Standard: c++17 +TabWidth: 4 +UseTab: Never diff --git a/browser-app.hpp b/browser-app.hpp index db1202b0c..57d2b84ca 100644 --- a/browser-app.hpp +++ b/browser-app.hpp @@ -77,7 +77,8 @@ class BrowserApp : public CefApp, public CefRenderProcessHandler, public CefBrow inline BrowserApp(bool shared_texture_available_ = false) : shared_texture_available(shared_texture_available_) #else inline BrowserApp(bool shared_texture_available_ = false, bool wayland_ = false) - : shared_texture_available(shared_texture_available_), wayland(wayland_) + : shared_texture_available(shared_texture_available_), + wayland(wayland_) #endif { } diff --git a/obs-browser-plugin.cpp b/obs-browser-plugin.cpp index 7d27c3936..3e6999eb3 100644 --- a/obs-browser-plugin.cpp +++ b/obs-browser-plugin.cpp @@ -435,18 +435,32 @@ void RegisterBrowserSource() info.get_defaults = browser_source_get_defaults; info.icon_type = OBS_ICON_TYPE_BROWSER; - info.get_name = [](void *) { return obs_module_text("BrowserSource"); }; + info.get_name = [](void *) { + return obs_module_text("BrowserSource"); + }; info.create = [](obs_data_t *settings, obs_source_t *source) -> void * { obs_browser_initialize(); return new BrowserSource(settings, source); }; - info.destroy = [](void *data) { static_cast(data)->Destroy(); }; + info.destroy = [](void *data) { + static_cast(data)->Destroy(); + }; info.missing_files = browser_source_missingfiles; - info.update = [](void *data, obs_data_t *settings) { static_cast(data)->Update(settings); }; - info.get_width = [](void *data) { return (uint32_t) static_cast(data)->width; }; - info.get_height = [](void *data) { return (uint32_t) static_cast(data)->height; }; - info.video_tick = [](void *data, float) { static_cast(data)->Tick(); }; - info.video_render = [](void *data, gs_effect_t *) { static_cast(data)->Render(); }; + info.update = [](void *data, obs_data_t *settings) { + static_cast(data)->Update(settings); + }; + info.get_width = [](void *data) { + return (uint32_t) static_cast(data)->width; + }; + info.get_height = [](void *data) { + return (uint32_t) static_cast(data)->height; + }; + info.video_tick = [](void *data, float) { + static_cast(data)->Tick(); + }; + info.video_render = [](void *data, gs_effect_t *) { + static_cast(data)->Render(); + }; #if CHROME_VERSION_BUILD < 4103 info.audio_mix = [](void *data, uint64_t *ts_out, struct audio_output_data *audio_output, size_t channels, size_t sample_rate) { @@ -466,19 +480,27 @@ void RegisterBrowserSource() info.mouse_wheel = [](void *data, const struct obs_mouse_event *event, int x_delta, int y_delta) { static_cast(data)->SendMouseWheel(event, x_delta, y_delta); }; - info.focus = [](void *data, bool focus) { static_cast(data)->SendFocus(focus); }; + info.focus = [](void *data, bool focus) { + static_cast(data)->SendFocus(focus); + }; info.key_click = [](void *data, const struct obs_key_event *event, bool key_up) { static_cast(data)->SendKeyClick(event, key_up); }; - info.show = [](void *data) { static_cast(data)->SetShowing(true); }; - info.hide = [](void *data) { static_cast(data)->SetShowing(false); }; + info.show = [](void *data) { + static_cast(data)->SetShowing(true); + }; + info.hide = [](void *data) { + static_cast(data)->SetShowing(false); + }; info.activate = [](void *data) { BrowserSource *bs = static_cast(data); if (bs->restart) bs->Refresh(); bs->SetActive(true); }; - info.deactivate = [](void *data) { static_cast(data)->SetActive(false); }; + info.deactivate = [](void *data) { + static_cast(data)->SetActive(false); + }; obs_register_source(&info); } diff --git a/panel/browser-panel-client.cpp b/panel/browser-panel-client.cpp index d982e979b..d3744b400 100644 --- a/panel/browser-panel-client.cpp +++ b/panel/browser-panel-client.cpp @@ -440,7 +440,9 @@ bool QCefBrowserClient::OnJSDialog(CefRefPtr, const CefString &, title << ": " << obs_module_text("Dialog.BrowserDock"); dlg->setWindowTitle(title.str().c_str()); - auto finished = [callback](int result) { callback.get()->Continue(result == QMessageBox::Ok, ""); }; + auto finished = [callback](int result) { + callback.get()->Continue(result == QMessageBox::Ok, ""); + }; QWidget::connect(dlg, &QMessageBox::finished, finished); diff --git a/panel/browser-panel-client.hpp b/panel/browser-panel-client.hpp index dc81177d4..2ec7320bf 100644 --- a/panel/browser-panel-client.hpp +++ b/panel/browser-panel-client.hpp @@ -17,7 +17,9 @@ class QCefBrowserClient : public CefClient, public: inline QCefBrowserClient(QCefWidgetInternal *widget_, const std::string &script_, bool allowAllPopups_) - : widget(widget_), script(script_), allowAllPopups(allowAllPopups_) + : widget(widget_), + script(script_), + allowAllPopups(allowAllPopups_) { } diff --git a/panel/browser-panel.cpp b/panel/browser-panel.cpp index c50ffb79b..0d999cefa 100644 --- a/panel/browser-panel.cpp +++ b/panel/browser-panel.cpp @@ -44,7 +44,8 @@ class CookieCheck : public CefCookieVisitor { bool cookie_found = false; inline CookieCheck(QCefCookieManager::cookie_exists_cb callback_, const std::string target_) - : callback(callback_), target(target_) + : callback(callback_), + target(target_) { } @@ -131,7 +132,9 @@ struct QCefCookieManagerInternal : QCefCookieManager { /* ------------------------------------------------------------------------- */ QCefWidgetInternal::QCefWidgetInternal(QWidget *parent, const std::string &url_, CefRefPtr rqc_) - : QCefWidget(parent), url(url_), rqc(rqc_) + : QCefWidget(parent), + url(url_), + rqc(rqc_) { setAttribute(Qt::WA_PaintOnScreen); setAttribute(Qt::WA_StaticContents);