Skip to content

Commit

Permalink
Allow setting a node's splitting type
Browse files Browse the repository at this point in the history
Closes #1291.
  • Loading branch information
baskerville committed Jun 1, 2021
1 parent e21ab5b commit 25f2cd1
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 3 deletions.
1 change: 1 addition & 0 deletions contrib/zsh_completion
Original file line number Diff line number Diff line change
Expand Up @@ -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'\
Expand Down
11 changes: 8 additions & 3 deletions doc/bspwm.1
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
.\" Title: bspwm
.\" Author: [see the "Author" section]
.\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
.\" 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
.\" -----------------------------------------------------------------
Expand Down Expand Up @@ -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 <
Expand Down
3 changes: 3 additions & 0 deletions doc/bspwm.1.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
18 changes: 18 additions & 0 deletions src/messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 11 additions & 0 deletions src/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 25f2cd1

Please sign in to comment.