From f79697754361c9bbf7a30cadd06b81b560c0228f Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Fri, 27 Oct 2023 04:08:07 -0700 Subject: [PATCH] Update code style --- .clang-format | 18 +++++++-- src/Hy3Layout.cpp | 86 ++++++++++++++++++++++--------------------- src/Hy3Node.cpp | 19 +++++----- src/SelectionHook.cpp | 4 +- src/TabGroup.cpp | 41 ++++++++++----------- src/TabGroup.hpp | 1 + src/globals.hpp | 4 +- src/main.cpp | 2 +- 8 files changed, 93 insertions(+), 82 deletions(-) diff --git a/.clang-format b/.clang-format index 89917c2..faedbee 100644 --- a/.clang-format +++ b/.clang-format @@ -1,4 +1,3 @@ ---- AlignArrayOfStructures: None AlignAfterOpenBracket: BlockIndent AllowShortBlocksOnASingleLine: Always @@ -30,9 +29,9 @@ SpaceBeforeCpp11BracedList: true SpaceBeforeCtorInitializerColon: false SpaceBeforeInheritanceColon: false SpaceBeforeParens: ControlStatementsExceptControlMacros -SortIncludes: CaseInsensitive +SortIncludes: CaseSensitive PointerAlignment: Left -PackConstructorInitializers: CurrentLine +PackConstructorInitializers: NextLine LineEnding: LF InsertBraces: false BreakConstructorInitializers: AfterColon @@ -59,7 +58,7 @@ BraceWrapping: SplitEmptyRecord: false SplitEmptyNamespace: false AfterControlStatement: MultiLine -BreakBeforeBinaryOperators: All +BreakBeforeBinaryOperators: NonAssignment BreakBeforeTernaryOperators: true AlignOperands: AlignAfterOperator InsertTrailingCommas: Wrapped @@ -70,3 +69,14 @@ IndentWidth: 2 TabWidth: 2 AllowAllConstructorInitializersOnNextLine: false ConstructorInitializerAllOnOneLineOrOnePerLine: true +NamespaceIndentation: None +IncludeBlocks: Regroup +IncludeCategories: + - Regex: '^<(cassert|cctype|cerrno|cfenv|cfloat|cinttypes|climits|clocale|cmath|csetjmp|csignal|cstdarg|cstdbool|cstddef|cstdint|cstdio|cstdlib|cstring|ctime|cuchar|cwchar|cwctype|algorithm|any|array|atomic|bitset|chrono|codecvt|complex|condition_variable|deque|exception|filesystem|forward_list|fstream|functional|future|initializer_list|iomanip|ios|iosfwd|iostream|istream|iterator|latch|limits|list|locale|map|memory|mutex|new|numeric|optional|ostream|queue|random|ratio|regex|scoped_allocator|set|shared_mutex|sstream|stack|stdexcept|streambuf|string|string_view|strstream|syncstream|system_error|thread|tuple|type_traits|typeindex|typeinfo|unordered_map|unordered_set|utility|valarray|variant|vector|version|assert.h|ctype.h|errno.h|fenv.h|float.h|inttypes.h|limits.h|locale.h|math.h|setjmp.h|signal.h|stdarg.h|stddef.h|stdint.h|stdio.h|stdlib.h|string.h|time.h|uchar.h|wchar.h|wctype.h)>$' + Priority: 0 + - Regex: '^<.*>$' + Priority: 1 + - Regex: '^".*"$' + Priority: 2 + - Regex: '.+' + Priority: 3 diff --git a/src/Hy3Layout.cpp b/src/Hy3Layout.cpp index d34a0b2..617e22d 100644 --- a/src/Hy3Layout.cpp +++ b/src/Hy3Layout.cpp @@ -1,20 +1,21 @@ -#include -#include #include #include -#include "globals.hpp" +#include +#include + #include "Hy3Layout.hpp" #include "SelectionHook.hpp" +#include "globals.hpp" -std::unique_ptr renderHookPtr - = std::make_unique(Hy3Layout::renderHook); -std::unique_ptr windowTitleHookPtr - = std::make_unique(Hy3Layout::windowGroupUpdateRecursiveHook); -std::unique_ptr urgentHookPtr - = std::make_unique(Hy3Layout::windowGroupUrgentHook); -std::unique_ptr tickHookPtr - = std::make_unique(Hy3Layout::tickHook); +std::unique_ptr renderHookPtr = + std::make_unique(Hy3Layout::renderHook); +std::unique_ptr windowTitleHookPtr = + std::make_unique(Hy3Layout::windowGroupUpdateRecursiveHook); +std::unique_ptr urgentHookPtr = + std::make_unique(Hy3Layout::windowGroupUrgentHook); +std::unique_ptr tickHookPtr = + std::make_unique(Hy3Layout::tickHook); bool performContainment(Hy3Node& node, bool contained, CWindow* window) { if (node.data.type == Hy3NodeType::Group) { @@ -102,8 +103,8 @@ void Hy3Layout::onWindowCreatedTiling(CWindow* window, eDirection) { // opening_after->parent cannot be nullptr if (opening_after == root) { - opening_after - = opening_after->intoGroup(Hy3GroupLayout::SplitH, GroupEphemeralityOption::Standard); + opening_after = + opening_after->intoGroup(Hy3GroupLayout::SplitH, GroupEphemeralityOption::Standard); } } } @@ -130,7 +131,8 @@ void Hy3Layout::onWindowCreatedTiling(CWindow* window, eDirection) { opening_into = opening_after->parent; } else { if ((opening_into = this->getWorkspaceRootGroup(window->m_iWorkspaceID)) == nullptr) { - static const auto* tab_first_window = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tab_first_window")->intValue; + static const auto* tab_first_window = + &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tab_first_window")->intValue; this->nodes.push_back({ .data = Hy3GroupLayout::SplitH, @@ -144,12 +146,12 @@ void Hy3Layout::onWindowCreatedTiling(CWindow* window, eDirection) { auto& parent = this->nodes.back(); this->nodes.push_back({ - .parent = &parent, - .data = Hy3GroupLayout::Tabbed, - .position = parent.position, - .size = parent.size, - .workspace_id = window->m_iWorkspaceID, - .layout = this, + .parent = &parent, + .data = Hy3GroupLayout::Tabbed, + .position = parent.position, + .size = parent.size, + .workspace_id = window->m_iWorkspaceID, + .layout = this, }); parent.data.as_group.children.push_back(&this->nodes.back()); @@ -239,8 +241,8 @@ void Hy3Layout::onWindowCreatedTiling(CWindow* window, eDirection) { } void Hy3Layout::onWindowRemovedTiling(CWindow* window) { - static const auto* node_collapse_policy - = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:node_collapse_policy")->intValue; + static const auto* node_collapse_policy = + &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:node_collapse_policy")->intValue; auto* node = this->getNodeFromWindow(window); @@ -329,8 +331,8 @@ void Hy3Layout::recalculateMonitor(const int& monitor_id) { if (top_node != nullptr) { top_node->position = monitor->vecPosition + monitor->vecReservedTopLeft; - top_node->size - = monitor->vecSize - monitor->vecReservedTopLeft - monitor->vecReservedBottomRight; + top_node->size = + monitor->vecSize - monitor->vecReservedTopLeft - monitor->vecReservedBottomRight; top_node->recalcSizePosRecursive(); } } @@ -369,8 +371,8 @@ void Hy3Layout::recalculateMonitor(const int& monitor_id) { if (top_node != nullptr) { top_node->position = monitor->vecPosition + monitor->vecReservedTopLeft; - top_node->size - = monitor->vecSize - monitor->vecReservedTopLeft - monitor->vecReservedBottomRight; + top_node->size = + monitor->vecSize - monitor->vecReservedTopLeft - monitor->vecReservedBottomRight; top_node->recalcSizePosRecursive(); } } @@ -402,19 +404,19 @@ void Hy3Layout::resizeActiveWindow(const Vector2D& delta, eRectCorner corner, CW drag_y = corner == CORNER_BOTTOMLEFT || corner == CORNER_BOTTOMRIGHT; } - const auto animate - = &g_pConfigManager->getConfigValuePtr("misc:animate_manual_resizes")->intValue; + const auto animate = + &g_pConfigManager->getConfigValuePtr("misc:animate_manual_resizes")->intValue; auto monitor = g_pCompositor->getMonitorFromID(window->m_iMonitorID); - const bool display_left - = STICKS(node->position.x, monitor->vecPosition.x + monitor->vecReservedTopLeft.x); + const bool display_left = + STICKS(node->position.x, monitor->vecPosition.x + monitor->vecReservedTopLeft.x); const bool display_right = STICKS( node->position.x + node->size.x, monitor->vecPosition.x + monitor->vecSize.x - monitor->vecReservedBottomRight.x ); - const bool display_top - = STICKS(node->position.y, monitor->vecPosition.y + monitor->vecReservedTopLeft.y); + const bool display_top = + STICKS(node->position.y, monitor->vecPosition.y + monitor->vecReservedTopLeft.y); const bool display_bottom = STICKS( node->position.y + node->size.y, monitor->vecPosition.y + monitor->vecSize.y - monitor->vecReservedBottomRight.y @@ -498,8 +500,8 @@ void Hy3Layout::resizeActiveWindow(const Vector2D& delta, eRectCorner corner, CW // adjust the inner node switch (inner_group.layout) { case Hy3GroupLayout::SplitH: { - auto ratio_mod - = allowed_movement.x * (float) inner_group.children.size() / inner_parent->size.x; + auto ratio_mod = + allowed_movement.x * (float) inner_group.children.size() / inner_parent->size.x; auto iter = std::find(inner_group.children.begin(), inner_group.children.end(), inner_node); @@ -548,8 +550,8 @@ void Hy3Layout::resizeActiveWindow(const Vector2D& delta, eRectCorner corner, CW // adjust the outer node switch (outer_group.layout) { case Hy3GroupLayout::SplitH: { - auto ratio_mod - = allowed_movement.x * (float) outer_group.children.size() / outer_parent->size.x; + auto ratio_mod = + allowed_movement.x * (float) outer_group.children.size() / outer_parent->size.x; auto iter = std::find(outer_group.children.begin(), outer_group.children.end(), outer_node); @@ -857,8 +859,8 @@ void Hy3Layout::makeOppositeGroupOn(Hy3Node* node, GroupEphemeralityOption ephem } auto& group = node->parent->data.as_group; - auto layout - = group.layout == Hy3GroupLayout::SplitH ? Hy3GroupLayout::SplitV : Hy3GroupLayout::SplitH; + auto layout = + group.layout == Hy3GroupLayout::SplitH ? Hy3GroupLayout::SplitV : Hy3GroupLayout::SplitH; if (group.children.size() == 1) { group.setLayout(layout); @@ -1131,8 +1133,8 @@ void Hy3Layout::focusTab( return; cont:; } else { - auto node_iter - = std::find(children.begin(), children.end(), tab_node->data.as_group.focused_child); + auto node_iter = + std::find(children.begin(), children.end(), tab_node->data.as_group.focused_child); if (node_iter == children.end()) return; if (target == TabFocus::Left) { if (node_iter == children.begin()) { @@ -1743,8 +1745,8 @@ Hy3Node* Hy3Layout::shiftOrGetFocus( } void Hy3Layout::updateAutotileWorkspaces() { - static const auto* autotile_raw_workspaces - = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:autotile:workspaces")->strValue; + static const auto* autotile_raw_workspaces = + &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:autotile:workspaces")->strValue; if (*autotile_raw_workspaces == this->autotile.raw_workspaces) { return; diff --git a/src/Hy3Node.cpp b/src/Hy3Node.cpp index 9ed6add..f4304de 100644 --- a/src/Hy3Node.cpp +++ b/src/Hy3Node.cpp @@ -3,8 +3,8 @@ #include #include -#include "globals.hpp" #include "Hy3Node.hpp" +#include "globals.hpp" // Hy3GroupData // @@ -310,15 +310,14 @@ void Hy3Node::recalcSizePosRecursive(bool no_animation) { } auto expand_focused = group->expand_focused != ExpandFocusType::NotExpanded; - bool directly_contains_expanded - = expand_focused - && (group->focused_child->data.type == Hy3NodeType::Window - || group->focused_child->data.as_group.expand_focused == ExpandFocusType::NotExpanded); + bool directly_contains_expanded = + expand_focused + && (group->focused_child->data.type == Hy3NodeType::Window + || group->focused_child->data.as_group.expand_focused == ExpandFocusType::NotExpanded); auto child_count = group->children.size(); - double ratio_mul = group->layout != Hy3GroupLayout::Tabbed - ? child_count <= 0 ? 0 : constraint / child_count - : 0; + double ratio_mul = + group->layout != Hy3GroupLayout::Tabbed ? child_count <= 0 ? 0 : constraint / child_count : 0; double offset = 0; @@ -435,8 +434,8 @@ void Hy3Node::recalcSizePosRecursive(bool no_animation) { child->size = tsize; child->hidden = this->hidden || expand_focused || group->focused_child != child; - child->gap_topleft_offset - = Vector2D(gap_topleft_offset.x, gap_topleft_offset.y + tab_height_offset); + child->gap_topleft_offset = + Vector2D(gap_topleft_offset.x, gap_topleft_offset.y + tab_height_offset); child->gap_bottomright_offset = gap_bottomright_offset; child->recalcSizePosRecursive(no_animation); diff --git a/src/SelectionHook.cpp b/src/SelectionHook.cpp index 29bffc0..603ede6 100644 --- a/src/SelectionHook.cpp +++ b/src/SelectionHook.cpp @@ -22,8 +22,8 @@ void hook_updateDecos(void* thisptr, CWindow* window) { } void init() { - static const auto decoUpdateCandidates - = HyprlandAPI::findFunctionsByName(PHANDLE, "updateWindowAnimatedDecorationValues"); + static const auto decoUpdateCandidates = + HyprlandAPI::findFunctionsByName(PHANDLE, "updateWindowAnimatedDecorationValues"); if (decoUpdateCandidates.size() != 1) { g_LastSelectionHook = nullptr; diff --git a/src/TabGroup.cpp b/src/TabGroup.cpp index bbfcc5b..8c03303 100644 --- a/src/TabGroup.cpp +++ b/src/TabGroup.cpp @@ -1,14 +1,13 @@ +#include "TabGroup.hpp" + #include #include #include -#include #include #include #include #include "globals.hpp" -#include "Hy3Layout.hpp" -#include "TabGroup.hpp" Hy3TabBarEntry::Hy3TabBarEntry(Hy3TabBar& tab_bar, Hy3Node& node): tab_bar(tab_bar), node(node) { this->focused.create( @@ -342,10 +341,10 @@ void Hy3TabBar::updateNodeList(std::list& nodes) { continue; } - auto moved - = std::find_if(removed_entries.begin(), removed_entries.end(), [&node](auto entry) { - return **node == *entry; - }); + auto moved = + std::find_if(removed_entries.begin(), removed_entries.end(), [&node](auto entry) { + return **node == *entry; + }); if (moved != removed_entries.end()) { this->entries.splice(entry, this->entries, *moved); @@ -451,8 +450,8 @@ Hy3TabGroup::Hy3TabGroup(Hy3Node& node) { void Hy3TabGroup::updateWithGroup(Hy3Node& node, bool warp) { static const auto* gaps_in = &HyprlandAPI::getConfigValue(PHANDLE, "general:gaps_in")->intValue; static const auto* gaps_out = &HyprlandAPI::getConfigValue(PHANDLE, "general:gaps_out")->intValue; - static const auto* bar_height - = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:height")->intValue; + static const auto* bar_height = + &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:height")->intValue; auto gaps = node.parent == nullptr ? *gaps_out : *gaps_in; auto tpos = node.position + Vector2D(gaps, gaps) + node.gap_topleft_offset; @@ -478,10 +477,10 @@ void Hy3TabGroup::updateWithGroup(Hy3Node& node, bool warp) { } void Hy3TabGroup::tick() { - static const auto* enter_from_top - = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:from_top")->intValue; - static const auto* padding - = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:padding")->intValue; + static const auto* enter_from_top = + &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:from_top")->intValue; + static const auto* padding = + &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:padding")->intValue; auto* workspace = g_pCompositor->getWorkspaceByID(this->workspace_id); this->bar.tick(); @@ -522,12 +521,12 @@ void Hy3TabGroup::tick() { } void Hy3TabGroup::renderTabBar() { - static const auto* window_rounding - = &HyprlandAPI::getConfigValue(PHANDLE, "decoration:rounding")->intValue; - static const auto* enter_from_top - = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:from_top")->intValue; - static const auto* padding - = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:padding")->intValue; + static const auto* window_rounding = + &HyprlandAPI::getConfigValue(PHANDLE, "decoration:rounding")->intValue; + static const auto* enter_from_top = + &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:from_top")->intValue; + static const auto* padding = + &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:padding")->intValue; auto* monitor = g_pHyprOpenGL->m_RenderData.pMonitor; auto* workspace = g_pCompositor->getWorkspaceByID(this->workspace_id); @@ -601,8 +600,8 @@ void Hy3TabGroup::renderTabBar() { glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); } - auto fade_opacity - = this->bar.fade_opacity.fl() * (workspace == nullptr ? 1.0 : workspace->m_fAlpha.fl()); + auto fade_opacity = + this->bar.fade_opacity.fl() * (workspace == nullptr ? 1.0 : workspace->m_fAlpha.fl()); auto render_entry = [&](Hy3TabBarEntry& entry) { Vector2D entry_pos = { diff --git a/src/TabGroup.hpp b/src/TabGroup.hpp index 0495276..e0deb48 100644 --- a/src/TabGroup.hpp +++ b/src/TabGroup.hpp @@ -7,6 +7,7 @@ class Hy3TabBar; #include #include +#include #include #include "Hy3Node.hpp" diff --git a/src/globals.hpp b/src/globals.hpp index 87b6296..f2032d9 100644 --- a/src/globals.hpp +++ b/src/globals.hpp @@ -1,10 +1,10 @@ #pragma once +#include + #include "Hy3Layout.hpp" #include "log.hpp" -#include - inline HANDLE PHANDLE = nullptr; inline std::unique_ptr g_Hy3Layout; diff --git a/src/main.cpp b/src/main.cpp index 12944a2..f4e9c9e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,9 +3,9 @@ #include #include +#include "SelectionHook.hpp" #include "dispatchers.hpp" #include "globals.hpp" -#include "SelectionHook.hpp" APICALL EXPORT std::string PLUGIN_API_VERSION() { return HYPRLAND_API_VERSION; }