Fix gaps config being read as an int (it is now a customtype)

Fixes breakage introduced in hyprland/ddf022d61c63fb36b4abba392682772690c06b5c
This commit is contained in:
outfoxxed 2024-02-22 18:09:50 -08:00
parent 1a4847456b
commit f5fc457d6b
No known key found for this signature in database
GPG key ID: 4C88A185FB89301E
5 changed files with 84 additions and 51 deletions

14
flake.lock generated
View file

@ -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"
}
},

View file

@ -543,13 +543,21 @@ void Hy3Layout::fullscreenRequestForWindow(
// Copy of vaxry's massive hack
// clang-format off
static const auto gaps_in = ConfigValue<Hyprlang::INT>("general:gaps_in");
static const auto gaps_out = ConfigValue<Hyprlang::INT>("general:gaps_out");
static const auto gaps_in = ConfigValue<Hyprlang::CUSTOMTYPE, CCssGapData>("general:gaps_in");
static const auto gaps_out = ConfigValue<Hyprlang::CUSTOMTYPE, CCssGapData>("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<Hyprlang::INT>("general:gaps_in");
static const auto gaps_out = ConfigValue<Hyprlang::INT>("general:gaps_out");
static const auto gaps_in = ConfigValue<Hyprlang::CUSTOMTYPE, CCssGapData>("general:gaps_in");
static const auto gaps_out = ConfigValue<Hyprlang::CUSTOMTYPE, CCssGapData>("general:gaps_out");
static const auto tab_bar_height = ConfigValue<Hyprlang::INT>("plugin:hy3:tabs:height");
static const auto tab_bar_padding = ConfigValue<Hyprlang::INT>("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<Hyprlang::INT>("general:gaps_in");
static const auto gaps_in = ConfigValue<Hyprlang::CUSTOMTYPE, CCssGapData>("general:gaps_in");
static const auto single_window_no_gaps = ConfigValue<Hyprlang::INT>("plugin:hy3:no_gaps_when_only");
// clang-format on
@ -1517,8 +1525,9 @@ 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)
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;

View file

@ -270,13 +270,25 @@ Hy3Node& Hy3Node::getExpandActor() {
void Hy3Node::recalcSizePosRecursive(bool no_animation) {
// clang-format off
static const auto gaps_in = ConfigValue<Hyprlang::INT>("general:gaps_in");
static const auto gaps_out = ConfigValue<Hyprlang::INT>("general:gaps_out");
static const auto gaps_in = ConfigValue<Hyprlang::CUSTOMTYPE, CCssGapData>("general:gaps_in");
static const auto gaps_out = ConfigValue<Hyprlang::CUSTOMTYPE, CCssGapData>("general:gaps_out");
static const auto group_inset = ConfigValue<Hyprlang::INT>("plugin:hy3:group_inset");
static const auto tab_bar_height = ConfigValue<Hyprlang::INT>("plugin:hy3:tabs:height");
static const auto tab_bar_padding = ConfigValue<Hyprlang::INT>("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;
}

View file

@ -452,16 +452,19 @@ Hy3TabGroup::Hy3TabGroup(Hy3Node& node) {
}
void Hy3TabGroup::updateWithGroup(Hy3Node& node, bool warp) {
static const auto gaps_in = ConfigValue<Hyprlang::INT>("general:gaps_in");
static const auto gaps_out = ConfigValue<Hyprlang::INT>("general:gaps_out");
static const auto gaps_in = ConfigValue<Hyprlang::CUSTOMTYPE, CCssGapData>("general:gaps_in");
static const auto gaps_out = ConfigValue<Hyprlang::CUSTOMTYPE, CCssGapData>("general:gaps_out");
static const auto bar_height = ConfigValue<Hyprlang::INT>("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,
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) {

View file

@ -1,5 +1,7 @@
#pragma once
#include <type_traits>
#include <hyprland/src/plugins/PluginAPI.hpp>
#include <hyprlang.hpp>
@ -21,23 +23,43 @@ inline void errorNotif() {
);
}
template <typename T>
class HyprlangUnspecifiedCustomType {};
// abandon hope all ye who enter here
template <typename T, typename V = HyprlangUnspecifiedCustomType>
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 U = T>
typename std::enable_if<std::is_same<U, Hyprlang::CUSTOMTYPE>::value, const V&>::type
operator*() const {
return *(V*) ((Hyprlang::CUSTOMTYPE*) *this->static_data_ptr)->getData();
}
const T& operator*() const { return this->get(); }
template <typename U = T>
typename std::enable_if<std::is_same<U, Hyprlang::CUSTOMTYPE>::value, const V*>::type
operator->() const {
return &**this;
}
// Bullshit microptimization case for strings
template <typename U = T>
typename std::enable_if<std::is_same<U, Hyprlang::STRING>::value, const char*>::type
operator*() const {
return *(const char**) this->static_data_ptr;
}
template <typename U = T>
typename std::enable_if<
!std::is_same<U, Hyprlang::CUSTOMTYPE>::value && !std::is_same<U, Hyprlang::STRING>::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<Hyprlang::STRING>::get() const {
return *(char* const*) this->static_data_ptr;
}