From df928c7053666a551dfe0cde06659c78d9ad9f02 Mon Sep 17 00:00:00 2001 From: Bastien Dejean Date: Tue, 26 Feb 2013 12:54:01 +0100 Subject: [PATCH] New message: 'flip' --- README.md | 4 +++- bspwm.1 | 5 ++++- messages.c | 22 ++++++++++++++++++++-- messages.h | 1 + tree.c | 18 ++++++++++++++++++ tree.h | 1 + types.h | 5 +++++ 7 files changed, 52 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c54ebd0..cb84e30 100644 --- 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 a72f547..84125f2 100644 --- 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). diff --git a/messages.c b/messages.c index 7597e6c..5306704 100644 --- a/messages.c +++ b/messages.c @@ -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) { diff --git a/messages.h b/messages.h index 8f97de0..8f7d5d6 100644 --- a/messages.h +++ b/messages.h @@ -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 6df52c8..6d41fb6 100644 --- 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 00486e6..b5b2802 100644 --- 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 efc36a1..683ca8b 100644 --- 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, -- 2.44.0