]> git.lizzy.rs Git - bspwm.git/commitdiff
Adjust nearby ratios when moving a fence
authorBastien Dejean <nihilhill@gmail.com>
Mon, 21 Jan 2019 11:02:43 +0000 (12:02 +0100)
committerBastien Dejean <nihilhill@gmail.com>
Mon, 21 Jan 2019 11:02:43 +0000 (12:02 +0100)
Fixes #902.

src/tree.c
src/tree.h
src/window.c

index 1a16d05413819cb5ad35a9adb40ce9f5b2d48ca9..cab8c56ed925856903b513afeee80741c2794561 100644 (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) {
index 25e638fb04fcc62f265b7ba77ee783812777d7c5..0334c2e8d92725a89d26d3f4497bf575b32356cc 100644 (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);
index 2641d02079ccc141cc921b2cd568852c3804afcf..9461151840d5967e0e6dfa337939ccdc120b7456 100644 (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;