Adjust nearby ratios when moving a fence

Fixes #902.
This commit is contained in:
Bastien Dejean 2019-01-21 12:02:43 +01:00
parent ab7e5abc26
commit 644b20028f
3 changed files with 43 additions and 0 deletions

View file

@ -1173,6 +1173,46 @@ int balance_tree(node_t *n)
}
}
/* Adjust the split ratios so that they keep their position
* despite the potential alteration of their rectangle. */
void adjust_ratios(node_t *n, xcb_rectangle_t rect)
{
if (n == NULL) {
return;
}
double ratio;
if (n->split_type == TYPE_VERTICAL) {
double position = (double) n->rectangle.x + n->split_ratio * (double) n->rectangle.width;
ratio = (position - (double) rect.x) / (double) rect.width;
} else {
double position = (double) n->rectangle.y + n->split_ratio * (double) n->rectangle.height;
ratio = (position - (double) rect.y) / (double) rect.height;
}
ratio = MAX(0.0, ratio);
ratio = MIN(1.0, ratio);
n->split_ratio = ratio;
xcb_rectangle_t first_rect;
xcb_rectangle_t second_rect;
unsigned int fence;
if (n->split_type == TYPE_VERTICAL) {
fence = rect.width * n->split_ratio;
first_rect = (xcb_rectangle_t) {rect.x, rect.y, fence, rect.height};
second_rect = (xcb_rectangle_t) {rect.x + fence, rect.y, rect.width - fence, rect.height};
} else {
fence = rect.height * n->split_ratio;
first_rect = (xcb_rectangle_t) {rect.x, rect.y, rect.width, fence};
second_rect = (xcb_rectangle_t) {rect.x, rect.y + fence, rect.width, rect.height - fence};
}
adjust_ratios(n->first_child, first_rect);
adjust_ratios(n->second_child, second_rect);
}
void unlink_node(monitor_t *m, desktop_t *d, node_t *n)
{
if (d == NULL || n == NULL) {

View file

@ -77,6 +77,7 @@ void rotate_tree_rec(node_t *n, int deg);
void flip_tree(node_t *n, flip_t flp);
void equalize_tree(node_t *n);
int balance_tree(node_t *n);
void adjust_ratios(node_t *n, xcb_rectangle_t rect);
void unlink_node(monitor_t *m, desktop_t *d, node_t *n);
void close_node(node_t *n);
void kill_node(monitor_t *m, desktop_t *d, node_t *n);

View file

@ -582,6 +582,8 @@ bool resize_client(coordinates_t *loc, resize_handle_t rh, int dx, int dy, bool
sr = MIN(1, sr);
horizontal_fence->split_ratio = sr;
}
node_t *target_fence = horizontal_fence != NULL ? horizontal_fence : vertical_fence;
adjust_ratios(target_fence, target_fence->rectangle);
arrange(loc->monitor, loc->desktop);
} else {
int w = width, h = height;