Skip to content

Commit

Permalink
Update code style
Browse files Browse the repository at this point in the history
  • Loading branch information
outfoxxed committed Oct 27, 2023
1 parent 1222764 commit f796977
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 82 deletions.
18 changes: 14 additions & 4 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
AlignArrayOfStructures: None
AlignAfterOpenBracket: BlockIndent
AllowShortBlocksOnASingleLine: Always
Expand Down Expand Up @@ -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
Expand All @@ -59,7 +58,7 @@ BraceWrapping:
SplitEmptyRecord: false
SplitEmptyNamespace: false
AfterControlStatement: MultiLine
BreakBeforeBinaryOperators: All
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeTernaryOperators: true
AlignOperands: AlignAfterOperator
InsertTrailingCommas: Wrapped
Expand All @@ -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
86 changes: 44 additions & 42 deletions src/Hy3Layout.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
#include <hyprland/src/Compositor.hpp>
#include <hyprland/src/plugins/PluginAPI.hpp>
#include <regex>
#include <set>

#include "globals.hpp"
#include <hyprland/src/Compositor.hpp>
#include <hyprland/src/plugins/PluginAPI.hpp>

#include "Hy3Layout.hpp"
#include "SelectionHook.hpp"
#include "globals.hpp"

std::unique_ptr<HOOK_CALLBACK_FN> renderHookPtr
= std::make_unique<HOOK_CALLBACK_FN>(Hy3Layout::renderHook);
std::unique_ptr<HOOK_CALLBACK_FN> windowTitleHookPtr
= std::make_unique<HOOK_CALLBACK_FN>(Hy3Layout::windowGroupUpdateRecursiveHook);
std::unique_ptr<HOOK_CALLBACK_FN> urgentHookPtr
= std::make_unique<HOOK_CALLBACK_FN>(Hy3Layout::windowGroupUrgentHook);
std::unique_ptr<HOOK_CALLBACK_FN> tickHookPtr
= std::make_unique<HOOK_CALLBACK_FN>(Hy3Layout::tickHook);
std::unique_ptr<HOOK_CALLBACK_FN> renderHookPtr =
std::make_unique<HOOK_CALLBACK_FN>(Hy3Layout::renderHook);
std::unique_ptr<HOOK_CALLBACK_FN> windowTitleHookPtr =
std::make_unique<HOOK_CALLBACK_FN>(Hy3Layout::windowGroupUpdateRecursiveHook);
std::unique_ptr<HOOK_CALLBACK_FN> urgentHookPtr =
std::make_unique<HOOK_CALLBACK_FN>(Hy3Layout::windowGroupUrgentHook);
std::unique_ptr<HOOK_CALLBACK_FN> tickHookPtr =
std::make_unique<HOOK_CALLBACK_FN>(Hy3Layout::tickHook);

bool performContainment(Hy3Node& node, bool contained, CWindow* window) {
if (node.data.type == Hy3NodeType::Group) {
Expand Down Expand Up @@ -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);
}
}
}
Expand All @@ -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,
Expand All @@ -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());
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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;
Expand Down
19 changes: 9 additions & 10 deletions src/Hy3Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include <hyprland/src/Compositor.hpp>
#include <hyprland/src/plugins/PluginAPI.hpp>

#include "globals.hpp"
#include "Hy3Node.hpp"
#include "globals.hpp"

// Hy3GroupData //

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/SelectionHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
41 changes: 20 additions & 21 deletions src/TabGroup.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#include "TabGroup.hpp"

#include <cairo/cairo.h>
#include <hyprland/src/Compositor.hpp>
#include <hyprland/src/helpers/Color.hpp>
#include <hyprland/src/plugins/PluginAPI.hpp>
#include <hyprland/src/render/OpenGL.hpp>
#include <pango/pangocairo.h>
#include <pixman.h>

#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(
Expand Down Expand Up @@ -342,10 +341,10 @@ void Hy3TabBar::updateNodeList(std::list<Hy3Node*>& 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);
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 = {
Expand Down
1 change: 1 addition & 0 deletions src/TabGroup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Hy3TabBar;
#include <memory>
#include <vector>

#include <hyprland/src/plugins/PluginAPI.hpp>
#include <hyprland/src/render/Texture.hpp>

#include "Hy3Node.hpp"
Expand Down
4 changes: 2 additions & 2 deletions src/globals.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#pragma once

#include <hyprland/src/plugins/PluginAPI.hpp>

#include "Hy3Layout.hpp"
#include "log.hpp"

#include <hyprland/src/plugins/PluginAPI.hpp>

inline HANDLE PHANDLE = nullptr;
inline std::unique_ptr<Hy3Layout> g_Hy3Layout;

Expand Down
Loading

0 comments on commit f796977

Please sign in to comment.