From 25f2cd17011d4032d255de41f70581b87c90cbcc Mon Sep 17 00:00:00 2001 From: Bastien Dejean Date: Tue, 1 Jun 2021 13:41:44 +0200 Subject: [PATCH] Allow setting a node's splitting type Closes #1291. --- contrib/zsh_completion | 1 + doc/bspwm.1 | 11 ++++++++--- doc/bspwm.1.asciidoc | 3 +++ src/messages.c | 18 ++++++++++++++++++ src/tree.c | 11 +++++++++++ src/tree.h | 1 + 6 files changed, 42 insertions(+), 3 deletions(-) diff --git a/contrib/zsh_completion b/contrib/zsh_completion index c3d0b47..106997f 100644 --- a/contrib/zsh_completion +++ b/contrib/zsh_completion @@ -178,6 +178,7 @@ _bspc() { '*'{-n,--to-node}'[Transplant the selected node to the given node]:node selector:_bspc_selector -- node'\ '*'{-o,--presel-ratio}'[Set the splitting ratio of the preselection area]:preselect ratio: ( )'\ '*'{-p,--presel-dir}'[Preselect the splitting area of the selected node or cancel the preselection]: :_bspc_prefix -- "~" preselect presel_dir'\ + '*'{-y,--type}'[Set the splitting type of the selected node]: :(horizontal vertical)'\ '*'{-r,--ratio}'[Set the splitting ratio of the selected node (0 < ratio < 1)]: :( )'\ '*'{-R,--rotate}'[Rotate the tree rooted at the selected node]:angle:(90 270 180)'\ '*'{-s,--swap}'[Swap the selected node with the given node]:node selector:_bspc_selector -- node'\ diff --git a/doc/bspwm.1 b/doc/bspwm.1 index 9b58951..59b0faa 100644 --- a/doc/bspwm.1 +++ b/doc/bspwm.1 @@ -2,12 +2,12 @@ .\" Title: bspwm .\" Author: [see the "Author" section] .\" Generator: DocBook XSL Stylesheets vsnapshot -.\" Date: 05/28/2021 +.\" Date: 06/01/2021 .\" Manual: Bspwm Manual -.\" Source: Bspwm 0.9.10-26-gbadfd6c +.\" Source: Bspwm 0.9.10-31-ge21ab5b .\" Language: English .\" -.TH "BSPWM" "1" "05/28/2021" "Bspwm 0\&.9\&.10\-26\-gbadfd6c" "Bspwm Manual" +.TH "BSPWM" "1" "06/01/2021" "Bspwm 0\&.9\&.10\-31\-ge21ab5b" "Bspwm Manual" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- @@ -706,6 +706,11 @@ pixels horizontally and pixels vertically\&. .RE .PP +\fB\-y\fR, \fB\-\-type\fR \fIhorizontal|vertical\fR +.RS 4 +Set the splitting type of the selected node\&. +.RE +.PP \fB\-r\fR, \fB\-\-ratio\fR \fIRATIO\fR|(+|\-)(\fIPIXELS\fR|\fIFRACTION\fR) .RS 4 Set the splitting ratio of the selected node (0 < diff --git a/doc/bspwm.1.asciidoc b/doc/bspwm.1.asciidoc index 1874f24..6e86413 100644 --- a/doc/bspwm.1.asciidoc +++ b/doc/bspwm.1.asciidoc @@ -434,6 +434,9 @@ Commands *-z*, *--resize* top|left|bottom|right|top_left|top_right|bottom_right|bottom_left 'dx' 'dy':: Resize the selected window by moving the given handle by 'dx' pixels horizontally and 'dy' pixels vertically. +*-y*, *--type* 'horizontal|vertical':: + Set the splitting type of the selected node. + *-r*, *--ratio* 'RATIO'|(+|-)('PIXELS'|'FRACTION'):: Set the splitting ratio of the selected node (0 < 'RATIO' < 1). diff --git a/src/messages.c b/src/messages.c index 5b6e608..bca55c9 100644 --- a/src/messages.c +++ b/src/messages.c @@ -458,6 +458,24 @@ void cmd_node(char **args, int num, FILE *rsp) fail(rsp, "node %s: Invalid resize handle argument: '%s'.\n", *(args - 1), *args); break; } + } else if (streq("-y", *args) || streq("--type", *args)) { + num--, args++; + if (num < 1) { + fail(rsp, "node %s: Not enough arguments.\n", *(args - 1)); + break; + } + if (trg.node == NULL) { + fail(rsp, ""); + break; + } + split_type_t typ; + if (parse_split_type(*args, &typ)) { + set_type(trg.node, typ); + changed = true; + } else { + fail(rsp, ""); + break; + } } else if (streq("-r", *args) || streq("--ratio", *args)) { num--, args++; if (num < 1) { diff --git a/src/tree.c b/src/tree.c index e6faadd..6f75dc3 100644 --- a/src/tree.c +++ b/src/tree.c @@ -190,6 +190,17 @@ presel_t *make_presel(void) return p; } +void set_type(node_t *n, split_type_t typ) +{ + if (n == NULL) { + return; + } + + n->split_type = typ; + update_constraints(n); + rebuild_constraints_towards_root(n); +} + void set_ratio(node_t *n, double rat) { if (n == NULL) { diff --git a/src/tree.h b/src/tree.h index 1acc4bb..aa04cde 100644 --- a/src/tree.h +++ b/src/tree.h @@ -31,6 +31,7 @@ void arrange(monitor_t *m, desktop_t *d); void apply_layout(monitor_t *m, desktop_t *d, node_t *n, xcb_rectangle_t rect, xcb_rectangle_t root_rect); presel_t *make_presel(void); +void set_type(node_t *n, split_type_t typ); void set_ratio(node_t *n, double rat); void presel_dir(monitor_t *m, desktop_t *d, node_t *n, direction_t dir); void presel_ratio(monitor_t *m, desktop_t *d, node_t *n, double ratio); -- 2.44.0