Migrate config to hyprlang

This commit is contained in:
outfoxxed 2024-02-14 22:33:07 -08:00
parent f231373aee
commit cdb2c28df1
No known key found for this signature in database
GPG key ID: 4C88A185FB89301E
7 changed files with 192 additions and 180 deletions

30
flake.lock generated
View file

@ -3,17 +3,18 @@
"hyprland": { "hyprland": {
"inputs": { "inputs": {
"hyprland-protocols": "hyprland-protocols", "hyprland-protocols": "hyprland-protocols",
"hyprlang": "hyprlang",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"systems": "systems", "systems": "systems",
"wlroots": "wlroots", "wlroots": "wlroots",
"xdph": "xdph" "xdph": "xdph"
}, },
"locked": { "locked": {
"lastModified": 1707847639, "lastModified": 1707952083,
"narHash": "sha256-mBmt1lFImpIK8VwHkJIenzVS95wD67dsfH1oRk2RiEg=", "narHash": "sha256-DYt7APLnlG28Cj+KigYtlQrQ1W6DcHw5z7QXW+RDpa4=",
"owner": "hyprwm", "owner": "hyprwm",
"repo": "Hyprland", "repo": "Hyprland",
"rev": "2a3429d4cfdc01794b9d6fc1b49be1da019b5606", "rev": "3a6451b6026a5f38987e61ee07b442910b5432f5",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -48,6 +49,27 @@
} }
}, },
"hyprlang": { "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": { "inputs": {
"nixpkgs": [ "nixpkgs": [
"hyprland", "hyprland",
@ -130,7 +152,7 @@
"hyprland", "hyprland",
"hyprland-protocols" "hyprland-protocols"
], ],
"hyprlang": "hyprlang", "hyprlang": "hyprlang_2",
"nixpkgs": [ "nixpkgs": [
"hyprland", "hyprland",
"nixpkgs" "nixpkgs"

View file

@ -179,8 +179,8 @@ void Hy3Layout::insertNode(Hy3Node& node) {
opening_into = opening_after->parent; opening_into = opening_after->parent;
} else { } else {
if ((opening_into = this->getWorkspaceRootGroup(node.workspace_id)) == nullptr) { if ((opening_into = this->getWorkspaceRootGroup(node.workspace_id)) == nullptr) {
static const auto* tab_first_window = static const auto tab_first_window =
&HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tab_first_window")->intValue; ConfigValue<Hyprlang::INT>("plugin:hy3:tab_first_window");
auto width = auto width =
monitor->vecSize.x - monitor->vecReservedBottomRight.x - monitor->vecReservedTopLeft.x; monitor->vecSize.x - monitor->vecReservedBottomRight.x - monitor->vecReservedTopLeft.x;
@ -233,10 +233,10 @@ void Hy3Layout::insertNode(Hy3Node& node) {
{ {
// clang-format off // clang-format off
static const auto* at_enable = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:autotile:enable")->intValue; static const auto at_enable = ConfigValue<Hyprlang::INT>("plugin:hy3:autotile:enable");
static const auto* at_ephemeral = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:autotile:ephemeral_groups")->intValue; static const auto at_ephemeral = ConfigValue<Hyprlang::INT>("plugin:hy3:autotile:ephemeral_groups");
static const auto* at_trigger_width = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:autotile:trigger_width")->intValue; static const auto at_trigger_width = ConfigValue<Hyprlang::INT>("plugin:hy3:autotile:trigger_width");
static const auto* at_trigger_height = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:autotile:trigger_height")->intValue; static const auto at_trigger_height = ConfigValue<Hyprlang::INT>("plugin:hy3:autotile:trigger_height");
// clang-format on // clang-format on
this->updateAutotileWorkspaces(); this->updateAutotileWorkspaces();
@ -287,8 +287,8 @@ void Hy3Layout::insertNode(Hy3Node& node) {
} }
void Hy3Layout::onWindowRemovedTiling(CWindow* window) { void Hy3Layout::onWindowRemovedTiling(CWindow* window) {
static const auto* node_collapse_policy = static const auto node_collapse_policy =
&HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:node_collapse_policy")->intValue; ConfigValue<Hyprlang::INT>("plugin:hy3:node_collapse_policy");
auto* node = this->getNodeFromWindow(window); auto* node = this->getNodeFromWindow(window);
@ -398,8 +398,7 @@ void Hy3Layout::recalculateWindow(CWindow* window) {
} }
ShiftDirection reverse(ShiftDirection direction) { ShiftDirection reverse(ShiftDirection direction) {
switch (direction) switch (direction) {
{
case ShiftDirection::Left: return ShiftDirection::Right; case ShiftDirection::Left: return ShiftDirection::Right;
case ShiftDirection::Right: return ShiftDirection::Left; case ShiftDirection::Right: return ShiftDirection::Left;
case ShiftDirection::Up: return ShiftDirection::Down; case ShiftDirection::Up: return ShiftDirection::Down;
@ -414,53 +413,56 @@ void Hy3Layout::resizeActiveWindow(const Vector2D& delta, eRectCorner corner, CW
auto* node = this->getNodeFromWindow(window); auto* node = this->getNodeFromWindow(window);
if(node != nullptr) { if (node != nullptr) {
node = &node->getExpandActor(); node = &node->getExpandActor();
auto monitor = g_pCompositor->getMonitorFromID(window->m_iMonitorID); auto monitor = g_pCompositor->getMonitorFromID(window->m_iMonitorID);
const bool display_left = 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( const bool display_right = STICKS(
node->position.x + node->size.x, node->position.x + node->size.x,
monitor->vecPosition.x + monitor->vecSize.x - monitor->vecReservedBottomRight.x monitor->vecPosition.x + monitor->vecSize.x - monitor->vecReservedBottomRight.x
); );
const bool display_top = 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( const bool display_bottom = STICKS(
node->position.y + node->size.y, node->position.y + node->size.y,
monitor->vecPosition.y + monitor->vecSize.y - monitor->vecReservedBottomRight.y monitor->vecPosition.y + monitor->vecSize.y - monitor->vecReservedBottomRight.y
); );
Vector2D resize_delta = delta; Vector2D resize_delta = delta;
bool node_is_root = (node->data.type == Hy3NodeType::Group && node->parent == nullptr) 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_left && display_right) resize_delta.x = 0;
if (display_top && display_bottom) resize_delta.y = 0; if (display_top && display_bottom) resize_delta.y = 0;
} }
// Don't execute the logic unless there's something to do // 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_x;
ShiftDirection target_edge_y; ShiftDirection target_edge_y;
// Determine the direction in which we're going to look for the neighbor node // Determine the direction in which we're going to look for the neighbor node
// that will be resized // 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_x = display_right ? ShiftDirection::Left : ShiftDirection::Right;
target_edge_y = display_bottom ? ShiftDirection::Up : ShiftDirection::Down; target_edge_y = display_bottom ? ShiftDirection::Up : ShiftDirection::Down;
// If the anchor is not at the top/left then reverse the delta // 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_x == ShiftDirection::Left) resize_delta.x = -resize_delta.x;
if(target_edge_y == ShiftDirection::Up) resize_delta.y = -resize_delta.y; if (target_edge_y == ShiftDirection::Up) resize_delta.y = -resize_delta.y;
} else { // It's probably a mouse event } else { // It's probably a mouse event
// Resize against the edges corresponding to the selected corner // Resize against the edges corresponding to the selected corner
target_edge_x = corner == CORNER_TOPLEFT || corner == CORNER_BOTTOMLEFT 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 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 // 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 horizontal_neighbor = node->findNeighbor(target_edge_x);
auto vertical_neighbor = node->findNeighbor(target_edge_y); auto vertical_neighbor = node->findNeighbor(target_edge_y);
const auto animate = static const auto animate = ConfigValue<Hyprlang::INT>("misc:animate_manual_resizes");
&g_pConfigManager->getConfigValuePtr("misc:animate_manual_resizes")->intValue;
// Note that the resize direction is reversed, because from the neighbor's perspective // 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. // 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); 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); 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 // No parent node - is this a floating window? If so, use the same logic as the `main` layout
const auto required_size = Vector2D( const auto required_size = Vector2D(
std::max((window->m_vRealSize.goalv() + delta).x, 20.0), 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).y, 20.0)
); );
window->m_vRealSize = required_size; window->m_vRealSize = required_size;
} }
@ -542,8 +543,8 @@ void Hy3Layout::fullscreenRequestForWindow(
// Copy of vaxry's massive hack // Copy of vaxry's massive hack
// clang-format off // clang-format off
static const auto* gaps_in = &HyprlandAPI::getConfigValue(PHANDLE, "general:gaps_in")->intValue; static const auto gaps_in = ConfigValue<Hyprlang::INT>("general:gaps_in");
static const auto* gaps_out = &HyprlandAPI::getConfigValue(PHANDLE, "general:gaps_out")->intValue; static const auto gaps_out = ConfigValue<Hyprlang::INT>("general:gaps_out");
// clang-format on // clang-format on
int outer_gaps = -(*gaps_in - *gaps_out); int outer_gaps = -(*gaps_in - *gaps_out);
@ -982,8 +983,8 @@ void Hy3Layout::moveNodeToWorkspace(int origin, std::string wsname, bool follow)
monitor->changeWorkspace(workspace); monitor->changeWorkspace(workspace);
static auto* const allow_workspace_cycles = static const auto allow_workspace_cycles =
&g_pConfigManager->getConfigValuePtr("binds:allow_workspace_cycles")->intValue; ConfigValue<Hyprlang::INT>("binds:allow_workspace_cycles");
if (*allow_workspace_cycles) workspace->rememberPrevWorkspace(origin_ws); if (*allow_workspace_cycles) workspace->rememberPrevWorkspace(origin_ws);
} }
} }
@ -1048,10 +1049,10 @@ bottom:
Hy3Node* findTabBarAt(Hy3Node& node, Vector2D pos, Hy3Node** focused_node) { Hy3Node* findTabBarAt(Hy3Node& node, Vector2D pos, Hy3Node** focused_node) {
// clang-format off // clang-format off
static const auto* gaps_in = &HyprlandAPI::getConfigValue(PHANDLE, "general:gaps_in")->intValue; static const auto gaps_in = ConfigValue<Hyprlang::INT>("general:gaps_in");
static const auto* gaps_out = &HyprlandAPI::getConfigValue(PHANDLE, "general:gaps_out")->intValue; static const auto gaps_out = ConfigValue<Hyprlang::INT>("general:gaps_out");
static const auto* tab_bar_height = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:height")->intValue; static const auto tab_bar_height = ConfigValue<Hyprlang::INT>("plugin:hy3:tabs:height");
static const auto* tab_bar_padding = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:padding")->intValue; static const auto tab_bar_padding = ConfigValue<Hyprlang::INT>("plugin:hy3:tabs:padding");
// clang-format on // clang-format on
auto inset = *tab_bar_height + *tab_bar_padding; auto inset = *tab_bar_height + *tab_bar_padding;
@ -1467,8 +1468,8 @@ void Hy3Layout::applyNodeDataToWindow(Hy3Node* node, bool no_animation) {
} }
// clang-format off // clang-format off
static const auto* gaps_in = &HyprlandAPI::getConfigValue(PHANDLE, "general:gaps_in")->intValue; static const auto gaps_in = ConfigValue<Hyprlang::INT>("general:gaps_in");
static const auto* single_window_no_gaps = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:no_gaps_when_only")->intValue; static const auto single_window_no_gaps = ConfigValue<Hyprlang::INT>("plugin:hy3:no_gaps_when_only");
// clang-format on // clang-format on
if (!g_pCompositor->windowExists(window) || !window->m_bIsMapped) { if (!g_pCompositor->windowExists(window) || !window->m_bIsMapped) {
@ -1788,8 +1789,8 @@ Hy3Node* Hy3Layout::shiftOrGetFocus(
} }
void Hy3Layout::updateAutotileWorkspaces() { void Hy3Layout::updateAutotileWorkspaces() {
static const auto* autotile_raw_workspaces = static const auto autotile_raw_workspaces =
&HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:autotile:workspaces")->strValue; ConfigValue<Hyprlang::STRING>("plugin:hy3:autotile:workspaces");
if (*autotile_raw_workspaces == this->autotile.raw_workspaces) { if (*autotile_raw_workspaces == this->autotile.raw_workspaces) {
return; return;

View file

@ -20,11 +20,7 @@ enum class ShiftDirection {
Right, Right,
}; };
enum class Axis { enum class Axis { None, Horizontal, Vertical };
None,
Horizontal,
Vertical
};
#include "Hy3Node.hpp" #include "Hy3Node.hpp"
#include "TabGroup.hpp" #include "TabGroup.hpp"

View file

@ -270,11 +270,11 @@ Hy3Node& Hy3Node::getExpandActor() {
void Hy3Node::recalcSizePosRecursive(bool no_animation) { void Hy3Node::recalcSizePosRecursive(bool no_animation) {
// clang-format off // clang-format off
static const auto* gaps_in = &HyprlandAPI::getConfigValue(PHANDLE, "general:gaps_in")->intValue; static const auto gaps_in = ConfigValue<Hyprlang::INT>("general:gaps_in");
static const auto* gaps_out = &HyprlandAPI::getConfigValue(PHANDLE, "general:gaps_out")->intValue; static const auto gaps_out = ConfigValue<Hyprlang::INT>("general:gaps_out");
static const auto* group_inset = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:group_inset")->intValue; static const auto group_inset = ConfigValue<Hyprlang::INT>("plugin:hy3:group_inset");
static const auto* tab_bar_height = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:height")->intValue; static const auto tab_bar_height = ConfigValue<Hyprlang::INT>("plugin:hy3:tabs:height");
static const auto* tab_bar_padding = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:padding")->intValue; static const auto tab_bar_padding = ConfigValue<Hyprlang::INT>("plugin:hy3:tabs:padding");
// clang-format on // clang-format on
if (this->data.type == Hy3NodeType::Window && this->data.as_window->m_bIsFullscreen) { if (this->data.type == Hy3NodeType::Window && this->data.as_window->m_bIsFullscreen) {
@ -810,18 +810,13 @@ bool Hy3Node::swallowGroups(Hy3Node* into) {
return true; return true;
} }
Hy3Node* getOuterChild(Hy3GroupData &group, ShiftDirection direction) { Hy3Node* getOuterChild(Hy3GroupData& group, ShiftDirection direction) {
switch (direction) { switch (direction) {
case ShiftDirection::Left: case ShiftDirection::Left:
case ShiftDirection::Up: case ShiftDirection::Up: return group.children.front(); break;
return group.children.front(); case ShiftDirection::Right:
break; case ShiftDirection::Down: return group.children.back(); break;
case ShiftDirection::Right: default: return nullptr;
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); auto iter = std::find(group.children.begin(), group.children.end(), this);
std::__cxx11::list<Hy3Node *>::const_iterator list_sibling; std::__cxx11::list<Hy3Node*>::const_iterator list_sibling;
switch (direction) { switch (direction) {
case ShiftDirection::Left: case ShiftDirection::Left:
case ShiftDirection::Up: case ShiftDirection::Up: list_sibling = std::prev(iter); break;
list_sibling = std::prev(iter); case ShiftDirection::Right:
break; case ShiftDirection::Down: list_sibling = std::next(iter); break;
case ShiftDirection::Right: default: list_sibling = iter;
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"); hy3_log(WARN, "getImmediateSibling: sibling not found");
list_sibling = iter; list_sibling = iter;
} }
@ -854,28 +844,20 @@ Hy3Node* Hy3Node::getImmediateSibling(ShiftDirection direction) {
} }
Axis getAxis(Hy3GroupLayout layout) { Axis getAxis(Hy3GroupLayout layout) {
switch (layout) switch (layout) {
{ case Hy3GroupLayout::SplitH: return Axis::Horizontal;
case Hy3GroupLayout::SplitH: case Hy3GroupLayout::SplitV: return Axis::Vertical;
return Axis::Horizontal; default: return Axis::None;
case Hy3GroupLayout::SplitV:
return Axis::Vertical;
default:
return Axis::None;
} }
} }
Axis getAxis(ShiftDirection direction) { Axis getAxis(ShiftDirection direction) {
switch (direction) switch (direction) {
{
case ShiftDirection::Left: case ShiftDirection::Left:
case ShiftDirection::Right: case ShiftDirection::Right: return Axis::Horizontal;
return Axis::Horizontal;
case ShiftDirection::Down: case ShiftDirection::Down:
case ShiftDirection::Up: case ShiftDirection::Up: return Axis::Vertical;
return Axis::Vertical; default: return Axis::None;
default:
return Axis::None;
} }
} }
@ -886,11 +868,13 @@ Hy3Node* Hy3Node::findNeighbor(ShiftDirection direction) {
while (sibling == nullptr && current_node->parent != nullptr) { while (sibling == nullptr && current_node->parent != nullptr) {
auto& parent_group = current_node->parent->data.as_group; 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 // 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 // then we need to look at the parent - otherwise, the sibling is simply the immediate
// sibling in the child collection // sibling in the child collection
if(getOuterChild(parent_group, direction) != current_node) { if (getOuterChild(parent_group, direction) != current_node) {
sibling = current_node->getImmediateSibling(direction); sibling = current_node->getImmediateSibling(direction);
} }
} }
@ -902,51 +886,43 @@ Hy3Node* Hy3Node::findNeighbor(ShiftDirection direction) {
} }
int directionToIteratorIncrement(ShiftDirection direction) { int directionToIteratorIncrement(ShiftDirection direction) {
switch (direction) switch (direction) {
{ case ShiftDirection::Left:
case ShiftDirection::Left: case ShiftDirection::Up: return -1;
case ShiftDirection::Up: case ShiftDirection::Right:
return -1; case ShiftDirection::Down: return 1;
case ShiftDirection::Right: default: hy3_log(WARN, "Unknown ShiftDirection enum value: {}", (int) direction); return 1;
case ShiftDirection::Down:
return 1;
default:
hy3_log(WARN, "Unknown ShiftDirection enum value: {}", (int)direction);
return 1;
} }
} }
void Hy3Node::resize( void Hy3Node::resize(ShiftDirection direction, double delta, bool no_animation) {
ShiftDirection direction,
double delta,
bool no_animation
) {
auto& parent_node = this->parent; auto& parent_node = this->parent;
auto& containing_group = parent_node->data.as_group; auto& containing_group = parent_node->data.as_group;
if(containing_group.layout != Hy3GroupLayout::Tabbed && getAxis(direction) == getAxis(containing_group.layout)) { if (containing_group.layout != Hy3GroupLayout::Tabbed
double parent_size = getAxis(direction) == Axis::Horizontal ? parent_node->size.x && getAxis(direction) == getAxis(containing_group.layout))
: parent_node->size.y; {
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; auto ratio_mod = delta * (float) containing_group.children.size() / parent_size;
const auto end_of_children = containing_group.children.end(); const auto end_of_children = containing_group.children.end();
auto iter = std::find(containing_group.children.begin(), end_of_children, this); 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); 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); auto inc = directionToIteratorIncrement(direction);
iter = std::next(iter, inc); iter = std::next(iter, inc);
ratio_mod *= inc; ratio_mod *= inc;
} }
if(iter != end_of_children) { if (iter != end_of_children) {
auto* neighbor = *iter; auto* neighbor = *iter;
auto requested_size_ratio = this->size_ratio + ratio_mod; 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 if (requested_size_ratio >= MIN_RATIO && requested_neighbor_size_ratio >= MIN_RATIO) {
&& requested_neighbor_size_ratio >= MIN_RATIO) {
this->size_ratio = requested_size_ratio; this->size_ratio = requested_size_ratio;
neighbor->size_ratio = requested_neighbor_size_ratio; neighbor->size_ratio = requested_neighbor_size_ratio;

View file

@ -126,18 +126,18 @@ bool Hy3TabBarEntry::shouldRemove() {
void Hy3TabBarEntry::prepareTexture(float scale, CBox& box) { void Hy3TabBarEntry::prepareTexture(float scale, CBox& box) {
// clang-format off // clang-format off
static const auto* s_rounding = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:rounding")->intValue; static const auto s_rounding = ConfigValue<Hyprlang::INT>("plugin:hy3:tabs:rounding");
static const auto* render_text = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:render_text")->intValue; static const auto render_text = ConfigValue<Hyprlang::INT>("plugin:hy3:tabs:render_text");
static const auto* text_center = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:text_center")->intValue; static const auto text_center = ConfigValue<Hyprlang::INT>("plugin:hy3:tabs:text_center");
static const auto* text_font = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:text_font")->strValue; static const auto text_font = ConfigValue<Hyprlang::STRING>("plugin:hy3:tabs:text_font");
static const auto* text_height = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:text_height")->intValue; static const auto text_height = ConfigValue<Hyprlang::INT>("plugin:hy3:tabs:text_height");
static const auto* text_padding = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:text_padding")->intValue; static const auto text_padding = ConfigValue<Hyprlang::INT>("plugin:hy3:tabs:text_padding");
static const auto* col_active = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:col.active")->intValue; static const auto col_active = ConfigValue<Hyprlang::INT>("plugin:hy3:tabs:col.active");
static const auto* col_urgent = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:col.urgent")->intValue; static const auto col_urgent = ConfigValue<Hyprlang::INT>("plugin:hy3:tabs:col.urgent");
static const auto* col_inactive = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:col.inactive")->intValue; static const auto col_inactive = ConfigValue<Hyprlang::INT>("plugin:hy3:tabs:col.inactive");
static const auto* col_text_active = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:col.text.active")->intValue; static const auto col_text_active = ConfigValue<Hyprlang::INT>("plugin:hy3:tabs:col.text.active");
static const auto* col_text_urgent = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:col.text.urgent")->intValue; static const auto col_text_urgent = ConfigValue<Hyprlang::INT>("plugin:hy3:tabs:col.text.urgent");
static const auto* col_text_inactive = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:col.text.inactive")->intValue; static const auto col_text_inactive = ConfigValue<Hyprlang::INT>("plugin:hy3:tabs:col.text.inactive");
// clang-format on // clang-format on
auto width = box.width; 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); 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_font_description_set_size(font_desc, *text_height * scale * PANGO_SCALE);
pango_layout_set_font_description(layout, font_desc); pango_layout_set_font_description(layout, font_desc);
pango_font_description_free(font_desc); pango_font_description_free(font_desc);
@ -452,10 +452,9 @@ Hy3TabGroup::Hy3TabGroup(Hy3Node& node) {
} }
void Hy3TabGroup::updateWithGroup(Hy3Node& node, bool warp) { void Hy3TabGroup::updateWithGroup(Hy3Node& node, bool warp) {
static const auto* gaps_in = &HyprlandAPI::getConfigValue(PHANDLE, "general:gaps_in")->intValue; static const auto gaps_in = ConfigValue<Hyprlang::INT>("general:gaps_in");
static const auto* gaps_out = &HyprlandAPI::getConfigValue(PHANDLE, "general:gaps_out")->intValue; static const auto gaps_out = ConfigValue<Hyprlang::INT>("general:gaps_out");
static const auto* bar_height = static const auto bar_height = ConfigValue<Hyprlang::INT>("plugin:hy3:tabs:height");
&HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:height")->intValue;
auto gaps = node.parent == nullptr ? *gaps_out : *gaps_in; auto gaps = node.parent == nullptr ? *gaps_out : *gaps_in;
auto tpos = node.position + Vector2D(gaps, gaps) + node.gap_topleft_offset; 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() { void Hy3TabGroup::tick() {
static const auto* enter_from_top = static const auto enter_from_top = ConfigValue<Hyprlang::INT>("plugin:hy3:tabs:from_top");
&HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:from_top")->intValue; static const auto padding = ConfigValue<Hyprlang::INT>("plugin:hy3:tabs:padding");
static const auto* padding =
&HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:tabs:padding")->intValue;
auto* workspace = g_pCompositor->getWorkspaceByID(this->workspace_id); auto* workspace = g_pCompositor->getWorkspaceByID(this->workspace_id);
this->bar.tick(); this->bar.tick();
@ -528,12 +525,9 @@ void Hy3TabGroup::tick() {
} }
void Hy3TabGroup::renderTabBar() { void Hy3TabGroup::renderTabBar() {
static const auto* window_rounding = static const auto window_rounding = ConfigValue<Hyprlang::INT>("decoration:rounding");
&HyprlandAPI::getConfigValue(PHANDLE, "decoration:rounding")->intValue; static const auto enter_from_top = ConfigValue<Hyprlang::INT>("plugin:hy3:tabs:from_top");
static const auto* enter_from_top = static const auto padding = ConfigValue<Hyprlang::INT>("plugin:hy3:tabs:padding");
&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* monitor = g_pHyprOpenGL->m_RenderData.pMonitor;
auto* workspace = g_pCompositor->getWorkspaceByID(this->workspace_id); auto* workspace = g_pCompositor->getWorkspaceByID(this->workspace_id);

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <hyprland/src/plugins/PluginAPI.hpp> #include <hyprland/src/plugins/PluginAPI.hpp>
#include <hyprlang.hpp>
#include "Hy3Layout.hpp" #include "Hy3Layout.hpp"
#include "log.hpp" #include "log.hpp"
@ -19,3 +20,24 @@ inline void errorNotif() {
} }
); );
} }
template <typename T>
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<Hyprlang::STRING>::get() const {
return *(char* const*) this->static_data_ptr;
}

View file

@ -1,6 +1,3 @@
#include <optional>
#include <stdexcept>
#include <hyprland/src/Compositor.hpp> #include <hyprland/src/Compositor.hpp>
#include <hyprland/src/plugins/PluginAPI.hpp> #include <hyprland/src/plugins/PluginAPI.hpp>
#include <hyprland/src/version.h> #include <hyprland/src/version.h>
@ -30,37 +27,41 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
selection_hook::init(); selection_hook::init();
#define CONF(NAME, TYPE, VALUE) \ #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 // general
CONF("no_gaps_when_only", int, 0); CONF("no_gaps_when_only", INT, 0);
CONF("node_collapse_policy", int, 2); CONF("node_collapse_policy", INT, 2);
CONF("group_inset", int, 10); CONF("group_inset", INT, 10);
CONF("tab_first_window", int, 0); CONF("tab_first_window", INT, 0);
// tabs // tabs
CONF("tabs:height", int, 15); CONF("tabs:height", INT, 15);
CONF("tabs:padding", int, 5); CONF("tabs:padding", INT, 5);
CONF("tabs:from_top", int, 0); CONF("tabs:from_top", INT, 0);
CONF("tabs:rounding", int, 3); CONF("tabs:rounding", INT, 3);
CONF("tabs:render_text", int, 1); CONF("tabs:render_text", INT, 1);
CONF("tabs:text_center", int, 0); CONF("tabs:text_center", INT, 0);
CONF("tabs:text_font", str, "Sans"); CONF("tabs:text_font", STRING, "Sans");
CONF("tabs:text_height", int, 8); CONF("tabs:text_height", INT, 8);
CONF("tabs:text_padding", int, 3); CONF("tabs:text_padding", INT, 3);
CONF("tabs:col.active", int, 0xff32b4ff); CONF("tabs:col.active", INT, 0xff32b4ff);
CONF("tabs:col.urgent", int, 0xffff4f4f); CONF("tabs:col.urgent", INT, 0xffff4f4f);
CONF("tabs:col.inactive", int, 0x80808080); CONF("tabs:col.inactive", INT, 0x80808080);
CONF("tabs:col.text.active", int, 0xff000000); CONF("tabs:col.text.active", INT, 0xff000000);
CONF("tabs:col.text.urgent", int, 0xff000000); CONF("tabs:col.text.urgent", INT, 0xff000000);
CONF("tabs:col.text.inactive", int, 0xff000000); CONF("tabs:col.text.inactive", INT, 0xff000000);
// autotiling // autotiling
CONF("autotile:enable", int, 0); CONF("autotile:enable", INT, 0);
CONF("autotile:ephemeral_groups", int, 1); CONF("autotile:ephemeral_groups", INT, 1);
CONF("autotile:trigger_height", int, 0); CONF("autotile:trigger_height", INT, 0);
CONF("autotile:trigger_width", int, 0); CONF("autotile:trigger_width", INT, 0);
CONF("autotile:workspaces", str, "all"); CONF("autotile:workspaces", STRING, "all");
#undef CONF #undef CONF