From f5fc457d6b510ad4eb07ba1e12ea8168085001ec Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Thu, 22 Feb 2024 18:09:50 -0800 Subject: [PATCH] Fix gaps config being read as an int (it is now a customtype) Fixes breakage introduced in hyprland/ddf022d61c63fb36b4abba392682772690c06b5c --- flake.lock | 14 +++++++------- src/Hy3Layout.cpp | 35 ++++++++++++++++++++++------------- src/Hy3Node.cpp | 31 +++++++++++++++---------------- src/TabGroup.cpp | 15 +++++++++------ src/globals.hpp | 40 +++++++++++++++++++++++++++++++--------- 5 files changed, 84 insertions(+), 51 deletions(-) diff --git a/flake.lock b/flake.lock index 5fc180c..0abb1d4 100644 --- a/flake.lock +++ b/flake.lock @@ -10,11 +10,11 @@ "xdph": "xdph" }, "locked": { - "lastModified": 1708272248, - "narHash": "sha256-EMGPzNg9422NEoFJUfidRHPokX2+UWErX9qSghpfS/g=", + "lastModified": 1708650152, + "narHash": "sha256-OZUS5FED7KKAPpNaJYQr4BPGXQzGrDFgkKVg9U2aZh8=", "owner": "hyprwm", "repo": "Hyprland", - "rev": "301b48b74087cc59753ffa144b215540e6f82831", + "rev": "8c3613632a6ccebf9fb797ec756ecfce99514eec", "type": "github" }, "original": { @@ -131,18 +131,18 @@ "flake": false, "locked": { "host": "gitlab.freedesktop.org", - "lastModified": 1706359063, - "narHash": "sha256-5HUTG0p+nCJv3cn73AmFHRZdfRV5AD5N43g8xAePSKM=", + "lastModified": 1708558866, + "narHash": "sha256-Mz6hCtommq7RQfcPnxLINigO4RYSNt23HeJHC6mVmWI=", "owner": "wlroots", "repo": "wlroots", - "rev": "00b869c1a96f300a8f25da95d624524895e0ddf2", + "rev": "0cb091f1a2d345f37d2ee445f4ffd04f7f4ec9e5", "type": "gitlab" }, "original": { "host": "gitlab.freedesktop.org", "owner": "wlroots", "repo": "wlroots", - "rev": "00b869c1a96f300a8f25da95d624524895e0ddf2", + "rev": "0cb091f1a2d345f37d2ee445f4ffd04f7f4ec9e5", "type": "gitlab" } }, diff --git a/src/Hy3Layout.cpp b/src/Hy3Layout.cpp index dde4c31..14b3c9b 100644 --- a/src/Hy3Layout.cpp +++ b/src/Hy3Layout.cpp @@ -543,13 +543,21 @@ void Hy3Layout::fullscreenRequestForWindow( // Copy of vaxry's massive hack // clang-format off - static const auto gaps_in = ConfigValue("general:gaps_in"); - static const auto gaps_out = ConfigValue("general:gaps_out"); + 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); - auto gap_pos_offset = Vector2D(outer_gaps, outer_gaps); - auto gap_size_offset = Vector2D(outer_gaps * 2, outer_gaps * 2); + // clang-format off + auto gap_pos_offset = Vector2D( + -(gaps_in->left - gaps_out->left), + -(gaps_in->top - gaps_out->top) + ); + // clang-format on + + auto gap_size_offset = Vector2D( + -(gaps_in->left - gaps_out->left) + -(gaps_in->right - gaps_out->right), + -(gaps_in->top - gaps_out->top) + -(gaps_in->bottom - gaps_out->bottom) + ); Hy3Node fakeNode = { .data = window, @@ -1049,8 +1057,8 @@ bottom: Hy3Node* findTabBarAt(Hy3Node& node, Vector2D pos, Hy3Node** focused_node) { // clang-format off - static const auto gaps_in = ConfigValue("general:gaps_in"); - static const auto gaps_out = ConfigValue("general:gaps_out"); + 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 @@ -1058,9 +1066,9 @@ Hy3Node* findTabBarAt(Hy3Node& node, Vector2D pos, Hy3Node** focused_node) { auto inset = *tab_bar_height + *tab_bar_padding; if (node.parent == nullptr) { - inset += *gaps_out; + inset += gaps_out->left; } else { - inset += *gaps_in; + inset += gaps_in->left; } if (node.data.type == Hy3NodeType::Group) { @@ -1468,7 +1476,7 @@ void Hy3Layout::applyNodeDataToWindow(Hy3Node* node, bool no_animation) { } // clang-format off - static const auto gaps_in = ConfigValue("general:gaps_in"); + 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 @@ -1517,9 +1525,10 @@ void Hy3Layout::applyNodeDataToWindow(Hy3Node* node, bool no_animation) { auto calcPos = window->m_vPosition; auto calcSize = window->m_vSize; - auto gaps_offset_topleft = Vector2D(*gaps_in, *gaps_in) + node->gap_topleft_offset; - auto gaps_offset_bottomright = Vector2D(*gaps_in * 2, *gaps_in * 2) - + node->gap_bottomright_offset + node->gap_topleft_offset; + auto gaps_offset_topleft = Vector2D(gaps_in->left, gaps_in->top) + node->gap_topleft_offset; + auto gaps_offset_bottomright = + Vector2D(gaps_in->left + gaps_in->right, gaps_in->top + gaps_in->bottom) + + node->gap_bottomright_offset + node->gap_topleft_offset; calcPos = calcPos + gaps_offset_topleft; calcSize = calcSize - gaps_offset_bottomright; diff --git a/src/Hy3Node.cpp b/src/Hy3Node.cpp index 59264f2..5eed0fc 100644 --- a/src/Hy3Node.cpp +++ b/src/Hy3Node.cpp @@ -270,13 +270,25 @@ Hy3Node& Hy3Node::getExpandActor() { void Hy3Node::recalcSizePosRecursive(bool no_animation) { // clang-format off - static const auto gaps_in = ConfigValue("general:gaps_in"); - static const auto gaps_out = ConfigValue("general:gaps_out"); + 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 + // clang-format off + auto gap_topleft_offset = Vector2D( + -(gaps_in->left - gaps_out->left), + -(gaps_in->top - gaps_out->top) + ); + + auto gap_bottomright_offset = Vector2D( + -(gaps_in->right - gaps_out->right), + -(gaps_in->bottom - gaps_out->bottom) + ); + // clang-format on + if (this->data.type == Hy3NodeType::Window && this->data.as_window->m_bIsFullscreen) { auto* workspace = g_pCompositor->getWorkspaceByID(this->workspace_id); auto* monitor = g_pCompositor->getMonitorFromID(workspace->m_iMonitorID); @@ -287,11 +299,6 @@ void Hy3Node::recalcSizePosRecursive(bool no_animation) { return; } - int outer_gaps = -(*gaps_in - *gaps_out); - - auto gap_topleft_offset = Vector2D(outer_gaps, outer_gaps); - auto gap_bottomright_offset = Vector2D(outer_gaps, outer_gaps); - Hy3Node fake_node = { .data = this->data.as_window, .position = monitor->vecPosition + monitor->vecReservedTopLeft, @@ -305,15 +312,7 @@ void Hy3Node::recalcSizePosRecursive(bool no_animation) { return; } - int outer_gaps = 0; - Vector2D gap_topleft_offset; - Vector2D gap_bottomright_offset; - if (this->parent == nullptr) { - outer_gaps = -(*gaps_in - *gaps_out); - - gap_topleft_offset = Vector2D(outer_gaps, outer_gaps); - gap_bottomright_offset = Vector2D(outer_gaps, outer_gaps); - } else { + if (this->parent != nullptr) { gap_topleft_offset = this->gap_topleft_offset; gap_bottomright_offset = this->gap_bottomright_offset; } diff --git a/src/TabGroup.cpp b/src/TabGroup.cpp index b48a784..e7049fb 100644 --- a/src/TabGroup.cpp +++ b/src/TabGroup.cpp @@ -452,16 +452,19 @@ Hy3TabGroup::Hy3TabGroup(Hy3Node& node) { } void Hy3TabGroup::updateWithGroup(Hy3Node& node, bool warp) { - static const auto gaps_in = ConfigValue("general:gaps_in"); - static const auto gaps_out = ConfigValue("general:gaps_out"); + 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; + auto& gaps = node.parent == nullptr ? gaps_out : gaps_in; + auto tpos = node.position + Vector2D(gaps->left, gaps->top) + node.gap_topleft_offset; + + // clang-format off auto tsize = Vector2D( - node.size.x - node.gap_bottomright_offset.x - node.gap_topleft_offset.x - gaps * 2, - *bar_height + node.size.x - node.gap_bottomright_offset.x - node.gap_topleft_offset.x - (gaps->left + gaps->right), + *bar_height ); + // clang-format on this->hidden = node.hidden; if (this->pos.goalv() != tpos) { diff --git a/src/globals.hpp b/src/globals.hpp index fbaabe5..48839ca 100644 --- a/src/globals.hpp +++ b/src/globals.hpp @@ -1,5 +1,7 @@ #pragma once +#include + #include #include @@ -21,23 +23,43 @@ inline void errorNotif() { ); } -template +class HyprlangUnspecifiedCustomType {}; + +// abandon hope all ye who enter here +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; } + template + typename std::enable_if::value, const V&>::type + operator*() const { + return *(V*) ((Hyprlang::CUSTOMTYPE*) *this->static_data_ptr)->getData(); + } - const T& operator*() const { return this->get(); } + template + typename std::enable_if::value, const V*>::type + operator->() const { + return &**this; + } + + // Bullshit microptimization case for strings + template + typename std::enable_if::value, const char*>::type + operator*() const { + return *(const char**) this->static_data_ptr; + } + + template + typename std::enable_if< + !std::is_same::value && !std::is_same::value, + const T&>::type + operator*() const { + return *(T*) *this->static_data_ptr; + } 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; -}