Fix incorrect logical positioning of windows

Logical window positions, used for mouse interaction, previously did
not match up with real window positions, leaving areas near the edges
of windows impossible to select with the mouse with window gaps active
or tab bars onscreen.
This commit is contained in:
outfoxxed 2023-08-19 03:56:34 -07:00
parent bfd56ab940
commit 6938d88ae0
No known key found for this signature in database
GPG key ID: 4C88A185FB89301E
4 changed files with 57 additions and 49 deletions

View file

@ -320,16 +320,16 @@ void Hy3Layout::recalculateMonitor(const int& monitor_id) {
// 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);
auto gap_topleft_offset = Vector2D(outer_gaps, outer_gaps);
auto gap_bottomright_offset = Vector2D(outer_gaps, outer_gaps);
Debug::log(LOG, "FS gaps: %d", outer_gaps);
Hy3Node fakeNode = {
.data = window,
.position = monitor->vecPosition + monitor->vecReservedTopLeft,
.size = monitor->vecSize - monitor->vecReservedTopLeft - monitor->vecReservedBottomRight,
.gap_pos_offset = gap_pos_offset,
.gap_size_offset = gap_size_offset,
.gap_topleft_offset = gap_topleft_offset,
.gap_bottomright_offset = gap_bottomright_offset,
.workspace_id = window->m_iWorkspaceID,
};
@ -629,8 +629,8 @@ void Hy3Layout::fullscreenRequestForWindow(
.data = window,
.position = monitor->vecPosition + monitor->vecReservedTopLeft,
.size = monitor->vecSize - monitor->vecReservedTopLeft - monitor->vecReservedBottomRight,
.gap_pos_offset = gap_pos_offset,
.gap_size_offset = gap_size_offset,
.gap_topleft_offset = gap_pos_offset,
.gap_bottomright_offset = gap_size_offset,
.workspace_id = window->m_iWorkspaceID,
};
@ -909,7 +909,7 @@ Hy3Node* findTabBarAt(Hy3Node& node, Vector2D pos, Hy3Node** focused_node) {
if (node.data.as_group.layout == Hy3GroupLayout::Tabbed
&& node.data.as_group.tab_bar != nullptr)
{
if (pos.y < node.position.y + node.gap_pos_offset.y + inset) {
if (pos.y < node.position.y + node.gap_topleft_offset.y + inset) {
auto& children = node.data.as_group.children;
auto& tab_bar = *node.data.as_group.tab_bar;
@ -1333,8 +1333,9 @@ void Hy3Layout::applyNodeDataToWindow(Hy3Node* node, bool no_animation) {
window->m_sSpecialRenderData.border = true;
window->m_sSpecialRenderData.decorate = true;
auto gaps_offset_topleft = Vector2D(*gaps_in, *gaps_in) + node->gap_pos_offset;
auto gaps_offset_bottomright = Vector2D(*gaps_in * 2, *gaps_in * 2) + node->gap_size_offset;
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;
calcPos = calcPos + gaps_offset_topleft;
calcSize = calcSize - gaps_offset_bottomright;

View file

@ -269,16 +269,16 @@ void Hy3Node::recalcSizePosRecursive(bool no_animation) {
// clang-format on
int outer_gaps = 0;
Vector2D gap_pos_offset;
Vector2D gap_size_offset;
Vector2D gap_topleft_offset;
Vector2D gap_bottomright_offset;
if (this->parent == nullptr) {
outer_gaps = -(*gaps_in - *gaps_out);
gap_pos_offset = Vector2D(outer_gaps, outer_gaps);
gap_size_offset = Vector2D(outer_gaps * 2, outer_gaps * 2);
gap_topleft_offset = Vector2D(outer_gaps, outer_gaps);
gap_bottomright_offset = Vector2D(outer_gaps, outer_gaps);
} else {
gap_pos_offset = this->gap_pos_offset;
gap_size_offset = this->gap_size_offset;
gap_topleft_offset = this->gap_topleft_offset;
gap_bottomright_offset = this->gap_bottomright_offset;
}
auto tpos = this->position;
@ -296,8 +296,12 @@ void Hy3Node::recalcSizePosRecursive(bool no_animation) {
double constraint;
switch (group->layout) {
case Hy3GroupLayout::SplitH: constraint = tsize.x - gap_size_offset.x; break;
case Hy3GroupLayout::SplitV: constraint = tsize.y - gap_size_offset.y; break;
case Hy3GroupLayout::SplitH:
constraint = tsize.x - gap_topleft_offset.x - gap_bottomright_offset.x;
break;
case Hy3GroupLayout::SplitV:
constraint = tsize.y - gap_topleft_offset.y - gap_bottomright_offset.y;
break;
case Hy3GroupLayout::Tabbed: break;
}
@ -341,8 +345,8 @@ void Hy3Node::recalcSizePosRecursive(bool no_animation) {
expanded_node->size = tsize;
expanded_node->setHidden(this->hidden);
expanded_node->gap_pos_offset = gap_pos_offset;
expanded_node->gap_size_offset = gap_size_offset;
expanded_node->gap_topleft_offset = gap_topleft_offset;
expanded_node->gap_bottomright_offset = gap_bottomright_offset;
expanded_node->recalcSizePosRecursive(no_animation);
}
@ -368,21 +372,22 @@ void Hy3Node::recalcSizePosRecursive(bool no_animation) {
child->hidden = this->hidden || expand_focused;
if (group->children.size() == 1) {
child->gap_pos_offset = gap_pos_offset;
child->gap_size_offset = gap_size_offset;
if (this->parent != nullptr) child->gap_size_offset.x += *group_inset;
child->size.x += gap_size_offset.x;
child->gap_topleft_offset = gap_topleft_offset;
child->gap_bottomright_offset = gap_bottomright_offset;
child->size.x = tsize.x;
if (this->parent != nullptr) child->gap_bottomright_offset.x += *group_inset;
} else if (child == group->children.front()) {
child->gap_pos_offset = gap_pos_offset;
child->gap_size_offset = Vector2D(0, gap_size_offset.y);
offset += gap_pos_offset.x;
child->gap_topleft_offset = gap_topleft_offset;
child->gap_bottomright_offset = Vector2D(0, gap_bottomright_offset.y);
child->size.x += gap_topleft_offset.x;
offset += gap_topleft_offset.x;
} else if (child == group->children.back()) {
child->gap_pos_offset = Vector2D(0, gap_pos_offset.y);
child->gap_size_offset = gap_size_offset;
child->size.x += gap_size_offset.x;
child->gap_topleft_offset = Vector2D(0, gap_topleft_offset.y);
child->gap_bottomright_offset = gap_bottomright_offset;
child->size.x += gap_bottomright_offset.x;
} else {
child->gap_pos_offset = Vector2D(0, gap_pos_offset.y);
child->gap_size_offset = Vector2D(0, gap_size_offset.y);
child->gap_topleft_offset = Vector2D(0, gap_topleft_offset.y);
child->gap_bottomright_offset = Vector2D(0, gap_bottomright_offset.y);
}
child->recalcSizePosRecursive(no_animation);
@ -396,21 +401,22 @@ void Hy3Node::recalcSizePosRecursive(bool no_animation) {
child->hidden = this->hidden || expand_focused;
if (group->children.size() == 1) {
child->gap_pos_offset = gap_pos_offset;
child->gap_size_offset = gap_size_offset;
if (this->parent != nullptr) child->gap_size_offset.y += *group_inset;
child->size.y += gap_size_offset.y;
child->gap_topleft_offset = gap_topleft_offset;
child->gap_bottomright_offset = gap_bottomright_offset;
child->size.y = tsize.y;
if (this->parent != nullptr) child->gap_bottomright_offset.y += *group_inset;
} else if (child == group->children.front()) {
child->gap_pos_offset = gap_pos_offset;
child->gap_size_offset = Vector2D(gap_size_offset.x, 0);
offset += gap_pos_offset.y;
child->gap_topleft_offset = gap_topleft_offset;
child->gap_bottomright_offset = Vector2D(gap_bottomright_offset.x, 0);
child->size.y += gap_topleft_offset.y;
offset += gap_topleft_offset.y;
} else if (child == group->children.back()) {
child->gap_pos_offset = Vector2D(gap_pos_offset.x, 0);
child->gap_size_offset = gap_size_offset;
child->size.y += gap_size_offset.y;
child->gap_topleft_offset = Vector2D(gap_topleft_offset.x, 0);
child->gap_bottomright_offset = gap_bottomright_offset;
child->size.y += gap_bottomright_offset.y;
} else {
child->gap_pos_offset = Vector2D(gap_pos_offset.x, 0);
child->gap_size_offset = Vector2D(gap_size_offset.x, 0);
child->gap_topleft_offset = Vector2D(gap_topleft_offset.x, 0);
child->gap_bottomright_offset = Vector2D(gap_bottomright_offset.x, 0);
}
child->recalcSizePosRecursive(no_animation);
@ -420,8 +426,9 @@ void Hy3Node::recalcSizePosRecursive(bool no_animation) {
child->size = tsize;
child->hidden = this->hidden || expand_focused || group->focused_child != child;
child->gap_pos_offset = Vector2D(gap_pos_offset.x, gap_pos_offset.y + tab_height_offset);
child->gap_size_offset = Vector2D(gap_size_offset.x, gap_size_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);
break;

View file

@ -79,8 +79,8 @@ struct Hy3Node {
Hy3NodeData data;
Vector2D position;
Vector2D size;
Vector2D gap_pos_offset;
Vector2D gap_size_offset;
Vector2D gap_topleft_offset;
Vector2D gap_bottomright_offset;
float size_ratio = 1.0;
int workspace_id = -1;
bool hidden = false;

View file

@ -456,8 +456,8 @@ void Hy3TabGroup::updateWithGroup(Hy3Node& node, bool warp) {
= &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_pos_offset;
auto tsize = Vector2D(node.size.x - node.gap_size_offset.x - gaps * 2, *bar_height);
auto tpos = node.position + Vector2D(gaps, gaps) + node.gap_topleft_offset;
auto tsize = Vector2D(node.size.x - node.gap_bottomright_offset.x - gaps * 2, *bar_height);
this->hidden = node.hidden;
if (this->pos.goalv() != tpos) {