Skip to content

Commit

Permalink
Account for vacant nodes when adjusting ratios
Browse files Browse the repository at this point in the history
  • Loading branch information
emanuele6 authored and baskerville committed Apr 5, 2023
1 parent fcfdbb0 commit 7848e7f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,8 @@ int balance_tree(node_t *n)
* despite the potential alteration of their rectangle. */
void adjust_ratios(node_t *n, xcb_rectangle_t rect)
{
if (n == NULL) {
#define NULL_OR_VACANT(n) ((n) == NULL || (n)->vacant)
if (NULL_OR_VACANT(n)) {
return;
}

Expand All @@ -1302,6 +1303,16 @@ void adjust_ratios(node_t *n, xcb_rectangle_t rect)
xcb_rectangle_t second_rect;
unsigned int fence;

if (NULL_OR_VACANT(n->first_child)) {
adjust_ratios(n->second_child, rect);
return;
}
if (NULL_OR_VACANT(n->second_child)) {
adjust_ratios(n->first_child, rect);
return;
}
#undef NULL_OR_VACANT

if (n->split_type == TYPE_VERTICAL) {
fence = rect.width * n->split_ratio;
first_rect = (xcb_rectangle_t) {rect.x, rect.y, fence, rect.height};
Expand Down

0 comments on commit 7848e7f

Please sign in to comment.