diff --git a/flake.lock b/flake.lock index d4b336c..bb5cb70 100644 --- a/flake.lock +++ b/flake.lock @@ -3,17 +3,18 @@ "hyprland": { "inputs": { "hyprland-protocols": "hyprland-protocols", + "hyprlang": "hyprlang", "nixpkgs": "nixpkgs", "systems": "systems", "wlroots": "wlroots", "xdph": "xdph" }, "locked": { - "lastModified": 1707847639, - "narHash": "sha256-mBmt1lFImpIK8VwHkJIenzVS95wD67dsfH1oRk2RiEg=", + "lastModified": 1707952083, + "narHash": "sha256-DYt7APLnlG28Cj+KigYtlQrQ1W6DcHw5z7QXW+RDpa4=", "owner": "hyprwm", "repo": "Hyprland", - "rev": "2a3429d4cfdc01794b9d6fc1b49be1da019b5606", + "rev": "3a6451b6026a5f38987e61ee07b442910b5432f5", "type": "github" }, "original": { @@ -48,6 +49,27 @@ } }, "hyprlang": { + "inputs": { + "nixpkgs": [ + "hyprland", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1707842572, + "narHash": "sha256-dYGkJycYJ0RjfkKE98XtppQukr6AHkR5bPJN0GsJeTI=", + "owner": "hyprwm", + "repo": "hyprlang", + "rev": "4a464738e2d12bf3a9735831f784969c7568a4af", + "type": "github" + }, + "original": { + "owner": "hyprwm", + "repo": "hyprlang", + "type": "github" + } + }, + "hyprlang_2": { "inputs": { "nixpkgs": [ "hyprland", @@ -130,7 +152,7 @@ "hyprland", "hyprland-protocols" ], - "hyprlang": "hyprlang", + "hyprlang": "hyprlang_2", "nixpkgs": [ "hyprland", "nixpkgs" diff --git a/src/Hy3Layout.cpp b/src/Hy3Layout.cpp index a99dd96..dde4c31 100644 --- a/src/Hy3Layout.cpp +++ b/src/Hy3Layout.cpp @@ -179,8 +179,8 @@ void Hy3Layout::insertNode(Hy3Node& node) { opening_into = opening_after->parent; } else { if ((opening_into = this->getWorkspaceRootGroup(node.workspace_id)) == nullptr) { - static const auto* tab_first_window = - &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tab_first_window")->intValue; + static const auto tab_first_window = + ConfigValue("plugin:hy3:tab_first_window"); auto width = monitor->vecSize.x - monitor->vecReservedBottomRight.x - monitor->vecReservedTopLeft.x; @@ -233,10 +233,10 @@ void Hy3Layout::insertNode(Hy3Node& node) { { // clang-format off - static const auto* at_enable = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:autotile:enable")->intValue; - static const auto* at_ephemeral = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:autotile:ephemeral_groups")->intValue; - static const auto* at_trigger_width = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:autotile:trigger_width")->intValue; - static const auto* at_trigger_height = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:autotile:trigger_height")->intValue; + static const auto at_enable = ConfigValue("plugin:hy3:autotile:enable"); + static const auto at_ephemeral = ConfigValue("plugin:hy3:autotile:ephemeral_groups"); + static const auto at_trigger_width = ConfigValue("plugin:hy3:autotile:trigger_width"); + static const auto at_trigger_height = ConfigValue("plugin:hy3:autotile:trigger_height"); // clang-format on this->updateAutotileWorkspaces(); @@ -287,8 +287,8 @@ void Hy3Layout::insertNode(Hy3Node& node) { } 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 = + ConfigValue("plugin:hy3:node_collapse_policy"); auto* node = this->getNodeFromWindow(window); @@ -398,8 +398,7 @@ void Hy3Layout::recalculateWindow(CWindow* window) { } ShiftDirection reverse(ShiftDirection direction) { - switch (direction) - { + switch (direction) { case ShiftDirection::Left: return ShiftDirection::Right; case ShiftDirection::Right: return ShiftDirection::Left; case ShiftDirection::Up: return ShiftDirection::Down; @@ -414,53 +413,56 @@ void Hy3Layout::resizeActiveWindow(const Vector2D& delta, eRectCorner corner, CW auto* node = this->getNodeFromWindow(window); - if(node != nullptr) { + if (node != nullptr) { node = &node->getExpandActor(); auto monitor = g_pCompositor->getMonitorFromID(window->m_iMonitorID); const bool display_left = - STICKS(node->position.x, monitor->vecPosition.x + monitor->vecReservedTopLeft.x); + 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 + 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); + 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 + node->position.y + node->size.y, + monitor->vecPosition.y + monitor->vecSize.y - monitor->vecReservedBottomRight.y ); Vector2D resize_delta = delta; bool node_is_root = (node->data.type == Hy3NodeType::Group && node->parent == nullptr) - || (node->data.type == Hy3NodeType::Window && (node->parent == nullptr || node->parent->parent == nullptr)); + || (node->data.type == Hy3NodeType::Window + && (node->parent == nullptr || node->parent->parent == nullptr)); - if(node_is_root) { + if (node_is_root) { if (display_left && display_right) resize_delta.x = 0; if (display_top && display_bottom) resize_delta.y = 0; } // Don't execute the logic unless there's something to do - if(resize_delta.x != 0 || resize_delta.y != 0) { + if (resize_delta.x != 0 || resize_delta.y != 0) { ShiftDirection target_edge_x; ShiftDirection target_edge_y; // Determine the direction in which we're going to look for the neighbor node // that will be resized - if(corner == CORNER_NONE) { // It's probably a keyboard event. + if (corner == CORNER_NONE) { // It's probably a keyboard event. target_edge_x = display_right ? ShiftDirection::Left : ShiftDirection::Right; target_edge_y = display_bottom ? ShiftDirection::Up : ShiftDirection::Down; // If the anchor is not at the top/left then reverse the delta - if(target_edge_x == ShiftDirection::Left) resize_delta.x = -resize_delta.x; - if(target_edge_y == ShiftDirection::Up) resize_delta.y = -resize_delta.y; - } else { // It's probably a mouse event + if (target_edge_x == ShiftDirection::Left) resize_delta.x = -resize_delta.x; + if (target_edge_y == ShiftDirection::Up) resize_delta.y = -resize_delta.y; + } else { // It's probably a mouse event // Resize against the edges corresponding to the selected corner target_edge_x = corner == CORNER_TOPLEFT || corner == CORNER_BOTTOMLEFT - ? ShiftDirection::Left : ShiftDirection::Right; + ? ShiftDirection::Left + : ShiftDirection::Right; target_edge_y = corner == CORNER_TOPLEFT || corner == CORNER_TOPRIGHT - ? ShiftDirection::Up : ShiftDirection::Down; + ? ShiftDirection::Up + : ShiftDirection::Down; } // Find the neighboring node in each axis, which will be either above or at the @@ -470,24 +472,23 @@ void Hy3Layout::resizeActiveWindow(const Vector2D& delta, eRectCorner corner, CW auto horizontal_neighbor = node->findNeighbor(target_edge_x); auto vertical_neighbor = node->findNeighbor(target_edge_y); - const auto animate = - &g_pConfigManager->getConfigValuePtr("misc:animate_manual_resizes")->intValue; + static const auto animate = ConfigValue("misc:animate_manual_resizes"); // Note that the resize direction is reversed, because from the neighbor's perspective // the edge to be moved is the opposite way round. However, the delta is still the same. - if(horizontal_neighbor) { + if (horizontal_neighbor) { horizontal_neighbor->resize(reverse(target_edge_x), resize_delta.x, *animate == 0); } - if(vertical_neighbor) { + if (vertical_neighbor) { vertical_neighbor->resize(reverse(target_edge_y), resize_delta.y, *animate == 0); } } - } else if(window->m_bIsFloating) { + } else if (window->m_bIsFloating) { // No parent node - is this a floating window? If so, use the same logic as the `main` layout const auto required_size = Vector2D( - std::max((window->m_vRealSize.goalv() + delta).x, 20.0), - std::max((window->m_vRealSize.goalv() + delta).y, 20.0) + std::max((window->m_vRealSize.goalv() + delta).x, 20.0), + std::max((window->m_vRealSize.goalv() + delta).y, 20.0) ); window->m_vRealSize = required_size; } @@ -542,8 +543,8 @@ void Hy3Layout::fullscreenRequestForWindow( // Copy of vaxry's massive hack // clang-format off - 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 gaps_in = ConfigValue("general:gaps_in"); + static const auto gaps_out = ConfigValue("general:gaps_out"); // clang-format on int outer_gaps = -(*gaps_in - *gaps_out); @@ -982,8 +983,8 @@ void Hy3Layout::moveNodeToWorkspace(int origin, std::string wsname, bool follow) monitor->changeWorkspace(workspace); - static auto* const allow_workspace_cycles = - &g_pConfigManager->getConfigValuePtr("binds:allow_workspace_cycles")->intValue; + static const auto allow_workspace_cycles = + ConfigValue("binds:allow_workspace_cycles"); if (*allow_workspace_cycles) workspace->rememberPrevWorkspace(origin_ws); } } @@ -1048,10 +1049,10 @@ bottom: Hy3Node* findTabBarAt(Hy3Node& node, Vector2D pos, Hy3Node** focused_node) { // clang-format off - 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* tab_bar_height = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:height")->intValue; - static const auto* tab_bar_padding = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:padding")->intValue; + static const auto gaps_in = ConfigValue("general:gaps_in"); + static const auto gaps_out = ConfigValue("general:gaps_out"); + static const auto tab_bar_height = ConfigValue("plugin:hy3:tabs:height"); + static const auto tab_bar_padding = ConfigValue("plugin:hy3:tabs:padding"); // clang-format on auto inset = *tab_bar_height + *tab_bar_padding; @@ -1467,8 +1468,8 @@ void Hy3Layout::applyNodeDataToWindow(Hy3Node* node, bool no_animation) { } // clang-format off - static const auto* gaps_in = &HyprlandAPI::getConfigValue(PHANDLE, "general:gaps_in")->intValue; - static const auto* single_window_no_gaps = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:no_gaps_when_only")->intValue; + static const auto gaps_in = ConfigValue("general:gaps_in"); + static const auto single_window_no_gaps = ConfigValue("plugin:hy3:no_gaps_when_only"); // clang-format on if (!g_pCompositor->windowExists(window) || !window->m_bIsMapped) { @@ -1788,8 +1789,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 = + ConfigValue("plugin:hy3:autotile:workspaces"); if (*autotile_raw_workspaces == this->autotile.raw_workspaces) { return; diff --git a/src/Hy3Layout.hpp b/src/Hy3Layout.hpp index f912849..766d0bb 100644 --- a/src/Hy3Layout.hpp +++ b/src/Hy3Layout.hpp @@ -20,11 +20,7 @@ enum class ShiftDirection { Right, }; -enum class Axis { - None, - Horizontal, - Vertical -}; +enum class Axis { None, Horizontal, Vertical }; #include "Hy3Node.hpp" #include "TabGroup.hpp" diff --git a/src/Hy3Node.cpp b/src/Hy3Node.cpp index d666d48..59264f2 100644 --- a/src/Hy3Node.cpp +++ b/src/Hy3Node.cpp @@ -270,11 +270,11 @@ Hy3Node& Hy3Node::getExpandActor() { void Hy3Node::recalcSizePosRecursive(bool no_animation) { // clang-format off - 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* group_inset = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:group_inset")->intValue; - static const auto* tab_bar_height = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:height")->intValue; - static const auto* tab_bar_padding = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:padding")->intValue; + static const auto gaps_in = ConfigValue("general:gaps_in"); + static const auto gaps_out = ConfigValue("general:gaps_out"); + static const auto group_inset = ConfigValue("plugin:hy3:group_inset"); + static const auto tab_bar_height = ConfigValue("plugin:hy3:tabs:height"); + static const auto tab_bar_padding = ConfigValue("plugin:hy3:tabs:padding"); // clang-format on if (this->data.type == Hy3NodeType::Window && this->data.as_window->m_bIsFullscreen) { @@ -810,18 +810,13 @@ bool Hy3Node::swallowGroups(Hy3Node* into) { return true; } -Hy3Node* getOuterChild(Hy3GroupData &group, ShiftDirection direction) { +Hy3Node* getOuterChild(Hy3GroupData& group, ShiftDirection direction) { switch (direction) { - case ShiftDirection::Left: - case ShiftDirection::Up: - return group.children.front(); - break; - case ShiftDirection::Right: - case ShiftDirection::Down: - return group.children.back(); - break; - default: - return nullptr; + case ShiftDirection::Left: + case ShiftDirection::Up: return group.children.front(); break; + case ShiftDirection::Right: + case ShiftDirection::Down: return group.children.back(); break; + default: return nullptr; } } @@ -830,22 +825,17 @@ Hy3Node* Hy3Node::getImmediateSibling(ShiftDirection direction) { auto iter = std::find(group.children.begin(), group.children.end(), this); - std::__cxx11::list::const_iterator list_sibling; + std::__cxx11::list::const_iterator list_sibling; switch (direction) { - case ShiftDirection::Left: - case ShiftDirection::Up: - list_sibling = std::prev(iter); - break; - case ShiftDirection::Right: - case ShiftDirection::Down: - list_sibling = std::next(iter); - break; - default: - list_sibling = iter; + case ShiftDirection::Left: + case ShiftDirection::Up: list_sibling = std::prev(iter); break; + case ShiftDirection::Right: + case ShiftDirection::Down: list_sibling = std::next(iter); break; + default: list_sibling = iter; } - if(list_sibling == group.children.end()) { + if (list_sibling == group.children.end()) { hy3_log(WARN, "getImmediateSibling: sibling not found"); list_sibling = iter; } @@ -854,28 +844,20 @@ Hy3Node* Hy3Node::getImmediateSibling(ShiftDirection direction) { } Axis getAxis(Hy3GroupLayout layout) { - switch (layout) - { - case Hy3GroupLayout::SplitH: - return Axis::Horizontal; - case Hy3GroupLayout::SplitV: - return Axis::Vertical; - default: - return Axis::None; + switch (layout) { + case Hy3GroupLayout::SplitH: return Axis::Horizontal; + case Hy3GroupLayout::SplitV: return Axis::Vertical; + default: return Axis::None; } } Axis getAxis(ShiftDirection direction) { - switch (direction) - { + switch (direction) { case ShiftDirection::Left: - case ShiftDirection::Right: - return Axis::Horizontal; + case ShiftDirection::Right: return Axis::Horizontal; case ShiftDirection::Down: - case ShiftDirection::Up: - return Axis::Vertical; - default: - return Axis::None; + case ShiftDirection::Up: return Axis::Vertical; + default: return Axis::None; } } @@ -886,11 +868,13 @@ Hy3Node* Hy3Node::findNeighbor(ShiftDirection direction) { while (sibling == nullptr && current_node->parent != nullptr) { auto& parent_group = current_node->parent->data.as_group; - if(parent_group.layout != Hy3GroupLayout::Tabbed && getAxis(parent_group.layout) == getAxis(direction)) { + if (parent_group.layout != Hy3GroupLayout::Tabbed + && getAxis(parent_group.layout) == getAxis(direction)) + { // If the current node is the outermost child of its parent group then proceed // then we need to look at the parent - otherwise, the sibling is simply the immediate // sibling in the child collection - if(getOuterChild(parent_group, direction) != current_node) { + if (getOuterChild(parent_group, direction) != current_node) { sibling = current_node->getImmediateSibling(direction); } } @@ -902,51 +886,43 @@ Hy3Node* Hy3Node::findNeighbor(ShiftDirection direction) { } int directionToIteratorIncrement(ShiftDirection direction) { - switch (direction) - { - case ShiftDirection::Left: - case ShiftDirection::Up: - return -1; - case ShiftDirection::Right: - case ShiftDirection::Down: - return 1; - default: - hy3_log(WARN, "Unknown ShiftDirection enum value: {}", (int)direction); - return 1; + switch (direction) { + case ShiftDirection::Left: + case ShiftDirection::Up: return -1; + case ShiftDirection::Right: + case ShiftDirection::Down: return 1; + default: hy3_log(WARN, "Unknown ShiftDirection enum value: {}", (int) direction); return 1; } } -void Hy3Node::resize( - ShiftDirection direction, - double delta, - bool no_animation -) { +void Hy3Node::resize(ShiftDirection direction, double delta, bool no_animation) { auto& parent_node = this->parent; auto& containing_group = parent_node->data.as_group; - if(containing_group.layout != Hy3GroupLayout::Tabbed && getAxis(direction) == getAxis(containing_group.layout)) { - double parent_size = getAxis(direction) == Axis::Horizontal ? parent_node->size.x - : parent_node->size.y; + if (containing_group.layout != Hy3GroupLayout::Tabbed + && getAxis(direction) == getAxis(containing_group.layout)) + { + double parent_size = + getAxis(direction) == Axis::Horizontal ? parent_node->size.x : parent_node->size.y; auto ratio_mod = delta * (float) containing_group.children.size() / parent_size; const auto end_of_children = containing_group.children.end(); auto iter = std::find(containing_group.children.begin(), end_of_children, this); - if(iter != end_of_children) { + if (iter != end_of_children) { const auto outermost_node_in_group = getOuterChild(containing_group, direction); - if(this != outermost_node_in_group) { + if (this != outermost_node_in_group) { auto inc = directionToIteratorIncrement(direction); iter = std::next(iter, inc); ratio_mod *= inc; } - if(iter != end_of_children) { + if (iter != end_of_children) { auto* neighbor = *iter; auto requested_size_ratio = this->size_ratio + ratio_mod; - auto requested_neighbor_size_ratio = neighbor->size_ratio -ratio_mod; + auto requested_neighbor_size_ratio = neighbor->size_ratio - ratio_mod; - if(requested_size_ratio >= MIN_RATIO - && requested_neighbor_size_ratio >= MIN_RATIO) { + if (requested_size_ratio >= MIN_RATIO && requested_neighbor_size_ratio >= MIN_RATIO) { this->size_ratio = requested_size_ratio; neighbor->size_ratio = requested_neighbor_size_ratio; diff --git a/src/TabGroup.cpp b/src/TabGroup.cpp index af2d989..b48a784 100644 --- a/src/TabGroup.cpp +++ b/src/TabGroup.cpp @@ -126,18 +126,18 @@ bool Hy3TabBarEntry::shouldRemove() { void Hy3TabBarEntry::prepareTexture(float scale, CBox& box) { // clang-format off - static const auto* s_rounding = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:rounding")->intValue; - static const auto* render_text = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:render_text")->intValue; - static const auto* text_center = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:text_center")->intValue; - static const auto* text_font = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:text_font")->strValue; - static const auto* text_height = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:text_height")->intValue; - static const auto* text_padding = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:text_padding")->intValue; - static const auto* col_active = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:col.active")->intValue; - static const auto* col_urgent = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:col.urgent")->intValue; - static const auto* col_inactive = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:col.inactive")->intValue; - static const auto* col_text_active = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:col.text.active")->intValue; - static const auto* col_text_urgent = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:col.text.urgent")->intValue; - static const auto* col_text_inactive = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:col.text.inactive")->intValue; + static const auto s_rounding = ConfigValue("plugin:hy3:tabs:rounding"); + static const auto render_text = ConfigValue("plugin:hy3:tabs:render_text"); + static const auto text_center = ConfigValue("plugin:hy3:tabs:text_center"); + static const auto text_font = ConfigValue("plugin:hy3:tabs:text_font"); + static const auto text_height = ConfigValue("plugin:hy3:tabs:text_height"); + static const auto text_padding = ConfigValue("plugin:hy3:tabs:text_padding"); + static const auto col_active = ConfigValue("plugin:hy3:tabs:col.active"); + static const auto col_urgent = ConfigValue("plugin:hy3:tabs:col.urgent"); + static const auto col_inactive = ConfigValue("plugin:hy3:tabs:col.inactive"); + static const auto col_text_active = ConfigValue("plugin:hy3:tabs:col.text.active"); + static const auto col_text_urgent = ConfigValue("plugin:hy3:tabs:col.text.urgent"); + static const auto col_text_inactive = ConfigValue("plugin:hy3:tabs:col.text.inactive"); // clang-format on auto width = box.width; @@ -227,7 +227,7 @@ void Hy3TabBarEntry::prepareTexture(float scale, CBox& box) { if (*text_center) pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER); - PangoFontDescription* font_desc = pango_font_description_from_string(text_font->c_str()); + PangoFontDescription* font_desc = pango_font_description_from_string(*text_font); pango_font_description_set_size(font_desc, *text_height * scale * PANGO_SCALE); pango_layout_set_font_description(layout, font_desc); pango_font_description_free(font_desc); @@ -452,10 +452,9 @@ 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 gaps_in = ConfigValue("general:gaps_in"); + static const auto gaps_out = ConfigValue("general:gaps_out"); + static const auto bar_height = ConfigValue("plugin:hy3:tabs:height"); auto gaps = node.parent == nullptr ? *gaps_out : *gaps_in; auto tpos = node.position + Vector2D(gaps, gaps) + node.gap_topleft_offset; @@ -484,10 +483,8 @@ 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 = ConfigValue("plugin:hy3:tabs:from_top"); + static const auto padding = ConfigValue("plugin:hy3:tabs:padding"); auto* workspace = g_pCompositor->getWorkspaceByID(this->workspace_id); this->bar.tick(); @@ -528,12 +525,9 @@ 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 = ConfigValue("decoration:rounding"); + static const auto enter_from_top = ConfigValue("plugin:hy3:tabs:from_top"); + static const auto padding = ConfigValue("plugin:hy3:tabs:padding"); auto* monitor = g_pHyprOpenGL->m_RenderData.pMonitor; auto* workspace = g_pCompositor->getWorkspaceByID(this->workspace_id); diff --git a/src/globals.hpp b/src/globals.hpp index f2032d9..fbaabe5 100644 --- a/src/globals.hpp +++ b/src/globals.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include "Hy3Layout.hpp" #include "log.hpp" @@ -19,3 +20,24 @@ inline void errorNotif() { } ); } + +template +class ConfigValue { +public: + ConfigValue(const std::string& option) { + this->static_data_ptr = HyprlandAPI::getConfigValue(PHANDLE, option)->getDataStaticPtr(); + } + + const T& get() const { return *(T*) *this->static_data_ptr; } + + const T& operator*() const { return this->get(); } + +private: + void* const* static_data_ptr; +}; + +// Bullshit undocumented microptimization case for strings +template <> +inline const Hyprlang::STRING& ConfigValue::get() const { + return *(char* const*) this->static_data_ptr; +} diff --git a/src/main.cpp b/src/main.cpp index 249e14c..a7f69a9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,3 @@ -#include -#include - #include #include #include @@ -30,37 +27,41 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) { selection_hook::init(); #define CONF(NAME, TYPE, VALUE) \ - HyprlandAPI::addConfigValue(PHANDLE, "plugin:hy3:" NAME, SConfigValue {.TYPE##Value = VALUE}) + HyprlandAPI::addConfigValue( \ + PHANDLE, \ + "plugin:hy3:" NAME, \ + Hyprlang::CConfigValue((Hyprlang::TYPE) VALUE) \ + ) // general - CONF("no_gaps_when_only", int, 0); - CONF("node_collapse_policy", int, 2); - CONF("group_inset", int, 10); - CONF("tab_first_window", int, 0); + CONF("no_gaps_when_only", INT, 0); + CONF("node_collapse_policy", INT, 2); + CONF("group_inset", INT, 10); + CONF("tab_first_window", INT, 0); // tabs - CONF("tabs:height", int, 15); - CONF("tabs:padding", int, 5); - CONF("tabs:from_top", int, 0); - CONF("tabs:rounding", int, 3); - CONF("tabs:render_text", int, 1); - CONF("tabs:text_center", int, 0); - CONF("tabs:text_font", str, "Sans"); - CONF("tabs:text_height", int, 8); - CONF("tabs:text_padding", int, 3); - CONF("tabs:col.active", int, 0xff32b4ff); - CONF("tabs:col.urgent", int, 0xffff4f4f); - CONF("tabs:col.inactive", int, 0x80808080); - CONF("tabs:col.text.active", int, 0xff000000); - CONF("tabs:col.text.urgent", int, 0xff000000); - CONF("tabs:col.text.inactive", int, 0xff000000); + CONF("tabs:height", INT, 15); + CONF("tabs:padding", INT, 5); + CONF("tabs:from_top", INT, 0); + CONF("tabs:rounding", INT, 3); + CONF("tabs:render_text", INT, 1); + CONF("tabs:text_center", INT, 0); + CONF("tabs:text_font", STRING, "Sans"); + CONF("tabs:text_height", INT, 8); + CONF("tabs:text_padding", INT, 3); + CONF("tabs:col.active", INT, 0xff32b4ff); + CONF("tabs:col.urgent", INT, 0xffff4f4f); + CONF("tabs:col.inactive", INT, 0x80808080); + CONF("tabs:col.text.active", INT, 0xff000000); + CONF("tabs:col.text.urgent", INT, 0xff000000); + CONF("tabs:col.text.inactive", INT, 0xff000000); // autotiling - CONF("autotile:enable", int, 0); - CONF("autotile:ephemeral_groups", int, 1); - CONF("autotile:trigger_height", int, 0); - CONF("autotile:trigger_width", int, 0); - CONF("autotile:workspaces", str, "all"); + CONF("autotile:enable", INT, 0); + CONF("autotile:ephemeral_groups", INT, 1); + CONF("autotile:trigger_height", INT, 0); + CONF("autotile:trigger_width", INT, 0); + CONF("autotile:workspaces", STRING, "all"); #undef CONF