diff --git a/README.asciidoc b/README.asciidoc index ffb37da..283621c 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -123,7 +123,7 @@ Messages *presel* _left_|_right_|_up_|_down_ [_SPLIT_RATIO_]:: Switch to manual mode and select the splitting direction. -*cancel*:: +*cancel* [*--all*]:: Switch to automatic mode. *ratio* _VALUE_:: diff --git a/doc/bspwm.1 b/doc/bspwm.1 index b15ee6d..2c71ec3 100644 --- a/doc/bspwm.1 +++ b/doc/bspwm.1 @@ -158,7 +158,7 @@ Return the list of rules\&. Switch to manual mode and select the splitting direction\&. .RE .PP -\fBcancel\fR +\fBcancel\fR [\fB\-\-all\fR] .RS 4 Switch to automatic mode\&. .RE diff --git a/doc/bspwm.1.txt b/doc/bspwm.1.txt index 7c00b43..adf7e2c 100644 --- a/doc/bspwm.1.txt +++ b/doc/bspwm.1.txt @@ -121,7 +121,7 @@ Messages *presel* _left_|_right_|_up_|_down_ [_SPLIT_RATIO_]:: Switch to manual mode and select the splitting direction. -*cancel*:: +*cancel* [*--all*]:: Switch to automatic mode. *ratio* _VALUE_:: diff --git a/messages.c b/messages.c index 1e2d834..706b0f1 100644 --- a/messages.c +++ b/messages.c @@ -163,8 +163,10 @@ void process_message(char *msg, char *rsp) } else if (strcmp(cmd, "cancel") == 0) { if (mon->desk->focus == NULL) return; - mon->desk->focus->split_mode = MODE_AUTOMATIC; - window_draw_border(mon->desk->focus, true, true); + char *opt = strtok(NULL, TOK_SEP); + cancel_option_t o; + if (parse_cancel_option(opt, &o)) + reset_mode(mon->desk, mon->desk->focus, o); } else if (strcmp(cmd, "presel") == 0) { if (mon->desk->focus == NULL || !is_tiled(mon->desk->focus->client) || mon->desk->layout != LAYOUT_TILED) return; @@ -802,6 +804,18 @@ bool parse_swap_option(char *s, swap_option_t *o) return false; } +bool parse_cancel_option(char *s, cancel_option_t *o) +{ + if (s == NULL) { + *o = CANCEL_OPTION_FOCUSED; + return true; + } else if (strcmp(s, "--all") == 0) { + *o = CANCEL_OPTION_ALL; + return true; + } + return false; +} + bool parse_rotate(char *s, rotate_t *r) { if (strcmp(s, "clockwise") == 0) { diff --git a/messages.h b/messages.h index 794a73e..ed66fb6 100644 --- a/messages.h +++ b/messages.h @@ -17,6 +17,7 @@ bool parse_circulate_direction(char *, circulate_dir_t *); bool parse_list_option(char *, list_option_t *); bool parse_send_option(char *, send_option_t *); bool parse_swap_option(char *, swap_option_t *); +bool parse_cancel_option(char *, cancel_option_t *); bool parse_skip_client(char *, skip_client_t *); bool parse_skip_desktop(char *, skip_desktop_t *); bool parse_rotate(char *, rotate_t *); diff --git a/tree.c b/tree.c index abcc0cc..c9dcbcd 100644 --- a/tree.c +++ b/tree.c @@ -57,6 +57,19 @@ void change_layout(monitor_t *m, desktop_t *d, layout_t l) put_status(); } +void reset_mode(desktop_t *d, node_t *n, cancel_option_t c) +{ + if (c == CANCEL_OPTION_FOCUSED) { + n->split_mode = MODE_AUTOMATIC; + window_draw_border(mon->desk->focus, d->focus == n, true); + } else if (c == CANCEL_OPTION_ALL) { + for (node_t *a = first_extrema(d->root); a != NULL; a = next_leaf(a, d->root)) { + a->split_mode = MODE_AUTOMATIC; + window_draw_border(a, d->focus == a, true); + } + } +} + node_t *first_extrema(node_t *n) { if (n == NULL) diff --git a/tree.h b/tree.h index 2320f02..b347d9c 100644 --- a/tree.h +++ b/tree.h @@ -11,6 +11,7 @@ bool is_first_child(node_t *); bool is_second_child(node_t *); void change_split_ratio(node_t *, value_change_t); void change_layout(monitor_t *, desktop_t *, layout_t); +void reset_mode(desktop_t *, node_t *, cancel_option_t); node_t *first_extrema(node_t *); node_t *second_extrema(node_t *); node_t *next_leaf(node_t *, node_t *); diff --git a/types.h b/types.h index 7e11e21..5ba942d 100644 --- a/types.h +++ b/types.h @@ -51,6 +51,11 @@ typedef enum { SWAP_OPTION_SWAP_FOCUS } swap_option_t; +typedef enum { + CANCEL_OPTION_FOCUSED, + CANCEL_OPTION_ALL +} cancel_option_t; + typedef enum { CLIENT_SKIP_NONE, CLIENT_SKIP_FLOATING,