]> git.lizzy.rs Git - bspwm.git/commitdiff
New message: `balance`
authorBastien Dejean <nihilhill@gmail.com>
Sun, 10 Mar 2013 17:28:30 +0000 (18:28 +0100)
committerBastien Dejean <nihilhill@gmail.com>
Sun, 10 Mar 2013 17:28:30 +0000 (18:28 +0100)
README.md
bspwm.1
messages.c
tree.c
tree.h

index 5564bf3bcb4c70d575bf4d7c1e209878634a37d3..610d808e7109dbdd32f5efd75b8019ac15ec26aa 100644 (file)
--- a/README.md
+++ b/README.md
@@ -171,6 +171,8 @@ The following messages are handled:
 
 - `flip horizontal|vertical` — Flip the window tree.
 
+- `balance` — Adjust the split ratios so that all windows occupy the same area.
+
 - `rule PATTERN [DESKTOP_NAME] [floating]` — Create a new rule (`PATTERN` must match the class or instance name).
 
 - `remove_rule UID ...` — Remove the rules with the given UIDs.
diff --git a/bspwm.1 b/bspwm.1
index f3aa4a666c93a821c6dba19876bc4d5a253fd533..fa607902eccab909ce70f5b928f2ea9de187cbe1 100644 (file)
--- a/bspwm.1
+++ b/bspwm.1
@@ -245,6 +245,9 @@ Rotate the window tree.
 .BI flip " horizontal|vertical"
 Flip the window tree.
 .TP
+.B balance
+Adjust the split ratios so that all windows occupy the same area.
+.TP
 .BI rule " PATTERN [DESKTOP_NAME] [floating]"
 Create a new rule (PATTERN must match the class or instance name).
 .TP
index 57b9c7ff1af72b074f1f9e27ef9dabf8e5c07bff..285702dd6f1ab93fe9a7d6a969bc2eaa843e824b 100644 (file)
@@ -76,6 +76,8 @@ void process_message(char *msg, char *rsp)
             if (parse_flip(flp, &f))
                 flip_tree(mon->desk->root, f);
         }
+    } else if (strcmp(cmd, "balance") == 0) {
+        balance_tree(mon->desk->root);
     } else if (strcmp(cmd, "grab_pointer") == 0) {
         char *pac = strtok(NULL, TOK_SEP);
         if (pac != NULL) {
diff --git a/tree.c b/tree.c
index 130df1ca9323eab77d4a7dbcab0d09b347fc8f97..3a51c16abc35e3ae0339725371b6a13e62c12b67 100644 (file)
--- a/tree.c
+++ b/tree.c
@@ -186,6 +186,22 @@ void flip_tree(node_t *n, flip_t flp)
     flip_tree(n->second_child, flp);
 }
 
+int balance_tree(node_t *n)
+{
+    if (n == NULL || n->vacant) {
+        return 0;
+    } else if (is_leaf(n)) {
+        return 1;
+    } else {
+        int b1 = balance_tree(n->first_child);
+        int b2 = balance_tree(n->second_child);
+        int b = b1 + b2;
+        if (b1 > 0 && b2 > 0)
+            n->split_ratio = (double) b1 / b;
+        return b;
+    }
+}
+
 void arrange(monitor_t *m, desktop_t *d)
 {
     PRINTF("arrange %s%s%s\n", (num_monitors > 1 ? m->name : ""), (num_monitors > 1 ? " " : ""), d->name);
diff --git a/tree.h b/tree.h
index 6e380cfc8ce732da4659884a17a91aa3df2c4ce8..a3ecb20916fc91feb4b3c7749947e019b87195a7 100644 (file)
--- a/tree.h
+++ b/tree.h
@@ -19,6 +19,7 @@ node_t *find_neighbor(node_t *, direction_t);
 void move_fence(node_t *, direction_t, fence_move_t);
 void rotate_tree(node_t *, rotate_t);
 void flip_tree(node_t *, flip_t);
+int balance_tree(node_t *);
 void arrange(monitor_t *, desktop_t *);
 void apply_layout(monitor_t *, desktop_t *, node_t *, xcb_rectangle_t, xcb_rectangle_t);
 void insert_node(monitor_t *, desktop_t *, node_t *);