]> git.lizzy.rs Git - bspwm.git/commitdiff
New message: 'flip'
authorBastien Dejean <nihilhill@gmail.com>
Tue, 26 Feb 2013 11:54:01 +0000 (12:54 +0100)
committerBastien Dejean <nihilhill@gmail.com>
Tue, 26 Feb 2013 11:54:01 +0000 (12:54 +0100)
README.md
bspwm.1
messages.c
messages.h
tree.c
tree.h
types.h

index c54ebd04cfd4ecddf11f51ceed0b9a8fbdb3e2f7..cb84e30db52157620acdb87bb3e6880402aa8d9a 100644 (file)
--- a/README.md
+++ b/README.md
@@ -167,7 +167,9 @@ The following messages are handled:
 
 - `cycle_layout` — Cycle the layout of the current desktop.
 
-- `rotate clockwise|counter_clockwise|full_cycle` — Rotate the tree of the current desktop.
+- `rotate clockwise|counter_clockwise|full_cycle` — Rotate the window tree.
+
+- `flip horizontal|vertical` — Flip the window tree.
 
 - `rule PATTERN [DESKTOP_NAME] [floating]` — Create a new rule (`PATTERN` must match the class or instance name).
 
diff --git a/bspwm.1 b/bspwm.1
index a72f5470d68d62a3d0ead2e4d82dd44d85ec0c39..84125f2f4d399047e8daf215741351c4352da777 100644 (file)
--- a/bspwm.1
+++ b/bspwm.1
@@ -240,7 +240,10 @@ Set the layout of the given desktops (current if none given).
 Cycle the layout of the current desktop.
 .TP
 .BI rotate " clockwise|counter_clockwise|full_cycle"
-Rotate the tree of the current desktop.
+Rotate the window tree.
+.TP
+.BI flip " horizontal|vertical"
+Flip the window tree.
 .TP
 .BI rule " PATTERN [DESKTOP_NAME] [floating]"
 Create a new rule (PATTERN must match the class or instance name).
index 7597e6c785f47c794e808b8cc60043e5f659f1bc..530670451a9d4d97080f8ae8d6f1c22d95670aa6 100644 (file)
@@ -66,9 +66,15 @@ void process_message(char *msg, char *rsp)
         char *deg = strtok(NULL, TOK_SEP);
         if (deg != NULL) {
             rotate_t r;
-            if (parse_rotate(deg, &r)) {
+            if (parse_rotate(deg, &r))
                 rotate_tree(mon->desk->root, r);
-            }
+        }
+    } else if (strcmp(cmd, "flip") == 0) {
+        char *flp = strtok(NULL, TOK_SEP);
+        if (flp != NULL) {
+            flip_t f;
+            if (parse_flip(flp, &f))
+                flip_tree(mon->desk->root, f);
         }
     } else if (strcmp(cmd, "grab_pointer") == 0) {
         char *pac = strtok(NULL, TOK_SEP);
@@ -724,6 +730,18 @@ bool parse_rotate(char *s, rotate_t *r)
     return false;
 }
 
+bool parse_flip(char *s, flip_t *f)
+{
+    if (strcmp(s, "horizontal") == 0) {
+        *f = FLIP_HORIZONTAL;
+        return true;
+    } else if (strcmp(s, "vertical") == 0) {
+        *f = FLIP_VERTICAL;
+        return true;
+    }
+    return false;
+}
+
 bool parse_fence_move(char *s, fence_move_t *m)
 {
     if (strcmp(s, "push") == 0) {
index 8f97de0a800dc6c1cb0b3fea086dd4bc488b93aa..8f7d5d6d7296c32e161526e7a0656c6c4156f9c0 100644 (file)
@@ -19,6 +19,7 @@ bool parse_send_option(char *, send_option_t *);
 bool parse_skip_client(char *, skip_client_t *);
 bool parse_skip_desktop(char *, skip_desktop_t *);
 bool parse_rotate(char *, rotate_t *);
+bool parse_flip(char *, flip_t *);
 bool parse_fence_move(char *, fence_move_t *);
 bool parse_pointer_action(char *, pointer_action_t *);
 
diff --git a/tree.c b/tree.c
index 6df52c832e068a2799b62b61a535b48cd09885bb..6d41fb665e2781b292ac95b702e9d16044a76337 100644 (file)
--- a/tree.c
+++ b/tree.c
@@ -201,6 +201,24 @@ void rotate_tree(node_t *n, rotate_t rot)
     rotate_tree(n->second_child, rot);
 }
 
+void flip_tree(node_t *n, flip_t flp)
+{
+    if (n == NULL || is_leaf(n))
+        return;
+
+    node_t *tmp;
+
+    if ((flp == FLIP_HORIZONTAL && n->split_type == TYPE_HORIZONTAL)
+            || (flp == FLIP_VERTICAL && n->split_type == TYPE_VERTICAL)) {
+        tmp = n->first_child;
+        n->first_child = n->second_child;
+        n->second_child = tmp;
+        n->split_ratio = 1.0 - n->split_ratio;
+    }
+
+    flip_tree(n->first_child, flp);
+    flip_tree(n->second_child, flp);
+}
 
 void arrange(monitor_t *m, desktop_t *d)
 {
diff --git a/tree.h b/tree.h
index 00486e6aa6572d21a5ebb010fab46b7516666da4..b5b2802328dd4891ff951b00f29b56a1232a241e 100644 (file)
--- a/tree.h
+++ b/tree.h
@@ -20,6 +20,7 @@ void move_fence(node_t *, direction_t, fence_move_t);
 unsigned int distance_to_fence(xcb_point_t, node_t *);
 fence_distance_t nearest_fence(xcb_point_t, node_t *);
 void rotate_tree(node_t *, rotate_t);
+void flip_tree(node_t *, flip_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 *);
diff --git a/types.h b/types.h
index efc36a12a0790043442b22250bd198e01723bfc8..683ca8b4cb98c70833b8290d6fdfb7c049bb48d0 100644 (file)
--- a/types.h
+++ b/types.h
@@ -81,6 +81,11 @@ typedef enum {
     ROTATE_FULL_CYCLE
 } rotate_t;
 
+typedef enum {
+    FLIP_HORIZONTAL,
+    FLIP_VERTICAL
+} flip_t;
+
 typedef enum {
     DIR_LEFT,
     DIR_RIGHT,