Skip to content

Commit

Permalink
#190 allow additional options for auto_balance config command
Browse files Browse the repository at this point in the history
  • Loading branch information
koekeishiya committed Jan 4, 2025
1 parent c97357c commit 3547611
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 29 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Update scripting addition for macOS Sonoma 14.7.2 [#2497](https://github.com/koekeishiya/yabai/issues/2497)
- Maybe fix issue with patching macOS space switching animation on macOS 14.7 Intel x86-64 [#2440](https://github.com/koekeishiya/yabai/issues/2440)
- Config *global setting* `split_type` is now categorized as a *space setting* instead [#2479](https://github.com/koekeishiya/yabai/issues/2479)
- Additional options `x-axis` and `y-axis` can now be used with `config auto_balance` command [#190](https://github.com/koekeishiya/yabai/issues/190)

## [7.1.5] - 2024-11-01
### Changed
Expand Down
8 changes: 4 additions & 4 deletions doc/yabai.1
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
.\" Title: yabai
.\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.23
.\" Date: 2025-01-02
.\" Date: 2025-01-04
.\" Manual: Yabai Manual
.\" Source: Yabai
.\" Language: English
.\"
.TH "YABAI" "1" "2025-01-02" "Yabai" "Yabai Manual"
.TH "YABAI" "1" "2025-01-04" "Yabai" "Yabai Manual"
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.ss \n[.ss] 0
Expand Down Expand Up @@ -372,9 +372,9 @@ Padding added at the right side of the selected space.
Size of the gap that separates windows for the selected space.
.RE
.sp
\fBauto_balance\fP [\fI<BOOL_SEL>\fP]
\fBauto_balance\fP [\fI<BOOL_SEL>|x\-axis|y\-axis\fP]
.RS 4
Balance the window tree upon change, so that all windows occupy the same area.
Balance the window tree upon change, so that all windows occupy an equally sized area.
.RE
.SS "Display"
.SS "General Syntax"
Expand Down
4 changes: 2 additions & 2 deletions doc/yabai.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ Space Settings
*window_gap* ['<integer number>']::
Size of the gap that separates windows for the selected space.

*auto_balance* ['<BOOL_SEL>']::
Balance the window tree upon change, so that all windows occupy the same area.
*auto_balance* ['<BOOL_SEL>|x-axis|y-axis']::
Balance the window tree upon change, so that all windows occupy an equally sized area.

Display
~~~~~~~
Expand Down
34 changes: 22 additions & 12 deletions src/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ extern bool g_verbose;
#define COMMAND_SPACE_LAYOUT "--layout"
#define COMMAND_SPACE_LABEL "--label"

#define ARGUMENT_SPACE_AXIS_X "x-axis"
#define ARGUMENT_SPACE_AXIS_Y "y-axis"
#define ARGUMENT_SPACE_ROTATE_90 "90"
#define ARGUMENT_SPACE_ROTATE_180 "180"
#define ARGUMENT_SPACE_ROTATE_270 "270"
Expand Down Expand Up @@ -248,6 +246,8 @@ extern bool g_verbose;
#define ARGUMENT_COMMON_SEL_MOUSE "mouse"
#define ARGUMENT_COMMON_SEL_STACK "stack"
#define ARGUMENT_COMMON_SEL_STACK_PREFIX "stack."
#define ARGUMENT_COMMON_VAL_AXIS_X "x-axis"
#define ARGUMENT_COMMON_VAL_AXIS_Y "y-axis"
/* ----------------------------------------------------------------------------- */

struct token
Expand Down Expand Up @@ -1575,20 +1575,30 @@ static void handle_domain_config(FILE *rsp, struct token domain, char *message)
fprintf(rsp, "%s\n", bool_str[view->auto_balance]);
} else if (token_equals(value, ARGUMENT_COMMON_VAL_OFF)) {
view_set_flag(view, VIEW_AUTO_BALANCE);
view->auto_balance = false;
view->auto_balance = SPLIT_NONE;
} else if (token_equals(value, ARGUMENT_COMMON_VAL_ON)) {
view_set_flag(view, VIEW_AUTO_BALANCE);
view->auto_balance = true;
view->auto_balance = SPLIT_X | SPLIT_Y;
} else if (token_equals(value, ARGUMENT_COMMON_VAL_AXIS_X)) {
view_set_flag(view, VIEW_AUTO_BALANCE);
view->auto_balance = SPLIT_X;
} else if (token_equals(value, ARGUMENT_COMMON_VAL_AXIS_Y)) {
view_set_flag(view, VIEW_AUTO_BALANCE);
view->auto_balance = SPLIT_Y;
} else {
daemon_fail(rsp, "unknown value '%.*s' given to command '%.*s' for domain '%.*s'\n", value.length, value.text, command.length, command.text, domain.length, domain.text);
}
} else {
if (!token_is_valid(value)) {
fprintf(rsp, "%s\n", bool_str[g_space_manager.auto_balance]);
} else if (token_equals(value, ARGUMENT_COMMON_VAL_OFF)) {
space_manager_set_auto_balance_for_all_spaces(&g_space_manager, false);
space_manager_set_auto_balance_for_all_spaces(&g_space_manager, SPLIT_NONE);
} else if (token_equals(value, ARGUMENT_COMMON_VAL_ON)) {
space_manager_set_auto_balance_for_all_spaces(&g_space_manager, true);
space_manager_set_auto_balance_for_all_spaces(&g_space_manager, SPLIT_X | SPLIT_Y);
} else if (token_equals(value, ARGUMENT_COMMON_VAL_AXIS_X)) {
space_manager_set_auto_balance_for_all_spaces(&g_space_manager, SPLIT_X);
} else if (token_equals(value, ARGUMENT_COMMON_VAL_AXIS_Y)) {
space_manager_set_auto_balance_for_all_spaces(&g_space_manager, SPLIT_Y);
} else {
daemon_fail(rsp, "unknown value '%.*s' given to command '%.*s' for domain '%.*s'\n", value.length, value.text, command.length, command.text, domain.length, domain.text);
}
Expand Down Expand Up @@ -1881,11 +1891,11 @@ static void handle_domain_space(FILE *rsp, struct token domain, char *message)
if (!space_manager_equalize_space(&g_space_manager, acting_sid, SPLIT_X | SPLIT_Y)) {
daemon_fail(rsp, "cannot equalize a non-managed space.\n");
}
} else if (token_equals(value, ARGUMENT_SPACE_AXIS_X)) {
} else if (token_equals(value, ARGUMENT_COMMON_VAL_AXIS_X)) {
if (!space_manager_equalize_space(&g_space_manager, acting_sid, SPLIT_X)) {
daemon_fail(rsp, "cannot equalize a non-managed space.\n");
}
} else if (token_equals(value, ARGUMENT_SPACE_AXIS_Y)) {
} else if (token_equals(value, ARGUMENT_COMMON_VAL_AXIS_Y)) {
if (!space_manager_equalize_space(&g_space_manager, acting_sid, SPLIT_Y)) {
daemon_fail(rsp, "cannot equalize a non-managed space.\n");
}
Expand All @@ -1898,11 +1908,11 @@ static void handle_domain_space(FILE *rsp, struct token domain, char *message)
if (!space_manager_balance_space(&g_space_manager, acting_sid, SPLIT_X | SPLIT_Y)) {
daemon_fail(rsp, "cannot balance a non-managed space.\n");
}
} else if (token_equals(value, ARGUMENT_SPACE_AXIS_X)) {
} else if (token_equals(value, ARGUMENT_COMMON_VAL_AXIS_X)) {
if (!space_manager_balance_space(&g_space_manager, acting_sid, SPLIT_X)) {
daemon_fail(rsp, "cannot balance a non-managed space.\n");
}
} else if (token_equals(value, ARGUMENT_SPACE_AXIS_Y)) {
} else if (token_equals(value, ARGUMENT_COMMON_VAL_AXIS_Y)) {
if (!space_manager_balance_space(&g_space_manager, acting_sid, SPLIT_Y)) {
daemon_fail(rsp, "cannot balance a non-managed space.\n");
}
Expand All @@ -1911,11 +1921,11 @@ static void handle_domain_space(FILE *rsp, struct token domain, char *message)
}
} else if (token_equals(command, COMMAND_SPACE_MIRROR)) {
struct token value = get_token(&message);
if (token_equals(value, ARGUMENT_SPACE_AXIS_X)) {
if (token_equals(value, ARGUMENT_COMMON_VAL_AXIS_X)) {
if (!space_manager_mirror_space(&g_space_manager, acting_sid, SPLIT_X)) {
daemon_fail(rsp, "cannot mirror a non-managed space.\n");
}
} else if (token_equals(value, ARGUMENT_SPACE_AXIS_Y)) {
} else if (token_equals(value, ARGUMENT_COMMON_VAL_AXIS_Y)) {
if (!space_manager_mirror_space(&g_space_manager, acting_sid, SPLIT_Y)) {
daemon_fail(rsp, "cannot mirror a non-managed space.\n");
}
Expand Down
8 changes: 4 additions & 4 deletions src/space_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ void space_manager_set_split_type_for_all_spaces(struct space_manager *sm, enum
})
}

void space_manager_set_auto_balance_for_all_spaces(struct space_manager *sm, bool auto_balance)
void space_manager_set_auto_balance_for_all_spaces(struct space_manager *sm, uint32_t auto_balance)
{
sm->auto_balance = auto_balance;
table_for (struct view *view, sm->view, {
Expand Down Expand Up @@ -473,8 +473,8 @@ void space_manager_toggle_window_split(struct space_manager *sm, struct window *
if (node && window_node_is_intermediate(node)) {
node->parent->split = node->parent->split == SPLIT_Y ? SPLIT_X : SPLIT_Y;

if (view->auto_balance) {
window_node_balance(view->root, SPLIT_X | SPLIT_Y);
if (view->auto_balance != SPLIT_NONE) {
window_node_balance(view->root, view->auto_balance);
view_update(view);
view_flush(view);
} else {
Expand Down Expand Up @@ -1122,7 +1122,7 @@ void space_manager_begin(struct space_manager *sm)
{
sm->layout = VIEW_FLOAT;
sm->split_ratio = 0.5f;
sm->auto_balance = false;
sm->auto_balance = SPLIT_NONE;
sm->split_type = SPLIT_AUTO;
sm->window_placement = CHILD_SECOND;
sm->window_insertion_point = INSERT_FOCUSED;
Expand Down
4 changes: 2 additions & 2 deletions src/space_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct space_manager
enum window_node_child window_placement;
enum window_insertion_point window_insertion_point;
bool window_zoom_persist;
bool auto_balance;
uint32_t auto_balance;
struct space_label *labels;
};

Expand Down Expand Up @@ -82,7 +82,7 @@ void space_manager_set_bottom_padding_for_all_spaces(struct space_manager *sm, i
void space_manager_set_left_padding_for_all_spaces(struct space_manager *sm, int left_padding);
void space_manager_set_right_padding_for_all_spaces(struct space_manager *sm, int right_padding);
void space_manager_set_split_type_for_all_spaces(struct space_manager *sm, enum window_node_split split_type);
void space_manager_set_auto_balance_for_all_spaces(struct space_manager *sm, bool auto_balance);
void space_manager_set_auto_balance_for_all_spaces(struct space_manager *sm, uint32_t auto_balance);
bool space_manager_set_padding_for_space(struct space_manager *sm, uint64_t sid, int type, int top, int bottom, int left, int right);
bool space_manager_toggle_padding_for_space(struct space_manager *sm, uint64_t sid);
bool space_manager_rotate_space(struct space_manager *sm, uint64_t sid, int degrees);
Expand Down
8 changes: 4 additions & 4 deletions src/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -712,8 +712,8 @@ struct window_node *view_remove_window_node(struct view *view, struct window *wi
free(child);
free(node);

if (view->auto_balance) {
window_node_balance(view->root, SPLIT_X | SPLIT_Y);
if (view->auto_balance != SPLIT_NONE) {
window_node_balance(view->root, view->auto_balance);
view_update(view);
return view->root;
}
Expand Down Expand Up @@ -790,8 +790,8 @@ struct window_node *view_add_window_node_with_insertion_point(struct view *view,

window_node_split(view, leaf, window);

if (view->auto_balance) {
window_node_balance(view->root, SPLIT_X | SPLIT_Y);
if (view->auto_balance != SPLIT_NONE) {
window_node_balance(view->root, view->auto_balance);
view_update(view);
return view->root;
}
Expand Down
2 changes: 1 addition & 1 deletion src/view.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ struct view
int left_padding;
int right_padding;
int window_gap;
bool auto_balance;
uint32_t auto_balance;
uint64_t flags;
};

Expand Down

0 comments on commit 3547611

Please sign in to comment.