Skip to content

Commit

Permalink
#2200 categorize config auto_balance as a space setting
Browse files Browse the repository at this point in the history
  • Loading branch information
koekeishiya committed Apr 2, 2024
1 parent 23199d3 commit 31e6585
Show file tree
Hide file tree
Showing 10 changed files with 230 additions and 118 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Added
- Added window commands `--raise ['<WINDOW_SEL>']` and `--lower ['<WINDOW_SEL>']` [#2198](https:/koekeishiya/yabai/issues/2198)

### Changed
- Config *global setting* `auto_balance` is now categorized as a *space setting* instead [#2200](https:/koekeishiya/yabai/issues/2200)

## [7.0.4] - 2024-03-30
### Changed
- Consecutive window resize operations would not work correctly because it used a cached value for the window frame [#2182](https:/koekeishiya/yabai/issues/2182)
Expand Down
14 changes: 7 additions & 7 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.20
.\" Date: 2024-03-31
.\" Date: 2024-04-02
.\" Manual: Yabai Manual
.\" Source: Yabai
.\" Language: English
.\"
.TH "YABAI" "1" "2024-03-31" "Yabai" "Yabai Manual"
.TH "YABAI" "1" "2024-04-02" "Yabai" "Yabai Manual"
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.ss \n[.ss] 0
Expand Down Expand Up @@ -316,11 +316,6 @@ Specify how a window should be split.
\fIauto\fP: The axis is determined based on width/height ratio.
.RE
.sp
\fBauto_balance\fP [\fI<BOOL_SEL>\fP]
.RS 4
Balance the window tree upon change, so that all windows occupy the same area.
.RE
.sp
\fBmouse_modifier\fP [\fIcmd|alt|shift|ctrl|fn\fP]
.RS 4
Keyboard modifier used for moving and resizing windows.
Expand Down Expand Up @@ -371,6 +366,11 @@ Padding added at the right side of the selected space.
.RS 4
Size of the gap that separates windows for the selected space.
.RE
.sp
\fBauto_balance\fP [\fI<BOOL_SEL>\fP]
.RS 4
Balance the window tree upon change, so that all windows occupy the same area.
.RE
.SS "Display"
.SS "General Syntax"
.sp
Expand Down
6 changes: 3 additions & 3 deletions doc/yabai.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,6 @@ Global Settings
'horizontal': The window is split along the x-axis. +
'auto': The axis is determined based on width/height ratio.

*auto_balance* ['<BOOL_SEL>']::
Balance the window tree upon change, so that all windows occupy the same area.

*mouse_modifier* ['cmd|alt|shift|ctrl|fn']::
Keyboard modifier used for moving and resizing windows.

Expand Down Expand Up @@ -251,6 +248,9 @@ 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.

Display
~~~~~~~

Expand Down
24 changes: 12 additions & 12 deletions src/event_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ static EVENT_HANDLER(APPLICATION_LAUNCHED)
view_add_window_node_with_insertion_point(view, window, prev_window_id);
window_manager_add_managed_window(&g_window_manager, window, view);

view->is_dirty = true;
view_set_flag(view, VIEW_IS_DIRTY);
view_list[view_count++] = view;

prev_window_id = window->id;
Expand All @@ -197,7 +197,7 @@ static EVENT_HANDLER(APPLICATION_LAUNCHED)
if (!view_is_dirty(view)) continue;

window_node_flush(view->root);
view->is_dirty = false;
view_clear_flag(view, VIEW_IS_DIRTY);
}
}

Expand Down Expand Up @@ -241,7 +241,7 @@ static EVENT_HANDLER(APPLICATION_TERMINATED)
view_remove_window_node(view, window);
window_manager_remove_managed_window(&g_window_manager, window->id);

view->is_dirty = true;
view_set_flag(view, VIEW_IS_DIRTY);
view_list[view_count++] = view;
}

Expand Down Expand Up @@ -274,7 +274,7 @@ static EVENT_HANDLER(APPLICATION_TERMINATED)
if (!view_is_dirty(view)) continue;

window_node_flush(view->root);
view->is_dirty = false;
view_clear_flag(view, VIEW_IS_DIRTY);
}

out:
Expand Down Expand Up @@ -369,7 +369,7 @@ static EVENT_HANDLER(APPLICATION_VISIBLE)
view_add_window_node_with_insertion_point(view, window, prev_window_id);
window_manager_add_managed_window(&g_window_manager, window, view);

view->is_dirty = true;
view_set_flag(view, VIEW_IS_DIRTY);
view_list[view_count++] = view;

prev_window_id = window->id;
Expand All @@ -391,7 +391,7 @@ static EVENT_HANDLER(APPLICATION_VISIBLE)
if (!view_is_dirty(view)) continue;

window_node_flush(view->root);
view->is_dirty = false;
view_clear_flag(view, VIEW_IS_DIRTY);
}

event_signal_push(SIGNAL_APPLICATION_VISIBLE, application);
Expand Down Expand Up @@ -432,7 +432,7 @@ static EVENT_HANDLER(APPLICATION_HIDDEN)
window_manager_remove_managed_window(&g_window_manager, window->id);
window_manager_purify_window(&g_window_manager, window);

view->is_dirty = true;
view_set_flag(view, VIEW_IS_DIRTY);
view_list[view_count++] = view;
}
}
Expand All @@ -452,7 +452,7 @@ static EVENT_HANDLER(APPLICATION_HIDDEN)
if (!view_is_dirty(view)) continue;

window_node_flush(view->root);
view->is_dirty = false;
view_clear_flag(view, VIEW_IS_DIRTY);
}

event_signal_push(SIGNAL_APPLICATION_HIDDEN, application);
Expand Down Expand Up @@ -599,7 +599,7 @@ static EVENT_HANDLER(WINDOW_MOVED)
if (space_is_visible(view->sid)) {
window_node_flush(node);
} else {
view->is_dirty = true;
view_set_flag(view, VIEW_IS_DIRTY);
}
}
}
Expand Down Expand Up @@ -677,7 +677,7 @@ static EVENT_HANDLER(WINDOW_RESIZED)
if (space_is_visible(view->sid)) {
window_node_flush(node);
} else {
view->is_dirty = true;
view_set_flag(view, VIEW_IS_DIRTY);
}
}
}
Expand Down Expand Up @@ -812,7 +812,7 @@ static EVENT_HANDLER(SPACE_CHANGED)

if (view_is_dirty(view)) {
window_node_flush(view->root);
view->is_dirty = false;
view_clear_flag(view, VIEW_IS_DIRTY);
}
}

Expand Down Expand Up @@ -864,7 +864,7 @@ static EVENT_HANDLER(DISPLAY_CHANGED)

if (view_is_dirty(view)) {
window_node_flush(view->root);
view->is_dirty = false;
view_clear_flag(view, VIEW_IS_DIRTY);
}
}

Expand Down
45 changes: 30 additions & 15 deletions src/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -1332,7 +1332,7 @@ static void handle_domain_config(FILE *rsp, struct token domain, char *message)
if (value.type == TOKEN_TYPE_INVALID) {
fprintf(rsp, "%d\n", view->top_padding);
} else if (value.type == TOKEN_TYPE_INT) {
view->custom_top_padding = true;
view_set_flag(view, VIEW_TOP_PADDING);
view->top_padding = value.int_value;
view_update(view);
view_flush(view);
Expand All @@ -1355,7 +1355,7 @@ static void handle_domain_config(FILE *rsp, struct token domain, char *message)
if (value.type == TOKEN_TYPE_INVALID) {
fprintf(rsp, "%d\n", view->bottom_padding);
} else if (value.type == TOKEN_TYPE_INT) {
view->custom_bottom_padding = true;
view_set_flag(view, VIEW_BOTTOM_PADDING);
view->bottom_padding = value.int_value;
view_update(view);
view_flush(view);
Expand All @@ -1378,7 +1378,7 @@ static void handle_domain_config(FILE *rsp, struct token domain, char *message)
if (value.type == TOKEN_TYPE_INVALID) {
fprintf(rsp, "%d\n", view->left_padding);
} else if (value.type == TOKEN_TYPE_INT) {
view->custom_left_padding = true;
view_set_flag(view, VIEW_LEFT_PADDING);
view->left_padding = value.int_value;
view_update(view);
view_flush(view);
Expand All @@ -1401,7 +1401,7 @@ static void handle_domain_config(FILE *rsp, struct token domain, char *message)
if (value.type == TOKEN_TYPE_INVALID) {
fprintf(rsp, "%d\n", view->right_padding);
} else if (value.type == TOKEN_TYPE_INT) {
view->custom_right_padding = true;
view_set_flag(view, VIEW_RIGHT_PADDING);
view->right_padding = value.int_value;
view_update(view);
view_flush(view);
Expand All @@ -1424,7 +1424,7 @@ static void handle_domain_config(FILE *rsp, struct token domain, char *message)
if (value.type == TOKEN_TYPE_INVALID) {
fprintf(rsp, "%d\n", view->window_gap);
} else if (value.type == TOKEN_TYPE_INT) {
view->custom_window_gap = true;
view_set_flag(view, VIEW_WINDOW_GAP);
view->window_gap = value.int_value;
view_update(view);
view_flush(view);
Expand All @@ -1448,26 +1448,26 @@ static void handle_domain_config(FILE *rsp, struct token domain, char *message)
fprintf(rsp, "%s\n", view_type_str[view->layout]);
} else if (token_equals(value, ARGUMENT_CONFIG_LAYOUT_BSP)) {
if (space_is_user(sel_sid)) {
view_set_flag(view, VIEW_LAYOUT);
view->layout = VIEW_BSP;
view->custom_layout = true;
view_clear(view);
window_manager_validate_and_check_for_windows_on_space(&g_space_manager, &g_window_manager, sel_sid);
} else {
daemon_fail(rsp, "cannot set layout for a macOS fullscreen space!\n");
}
} else if (token_equals(value, ARGUMENT_CONFIG_LAYOUT_STACK)) {
if (space_is_user(sel_sid)) {
view_set_flag(view, VIEW_LAYOUT);
view->layout = VIEW_STACK;
view->custom_layout = true;
view_clear(view);
window_manager_validate_and_check_for_windows_on_space(&g_space_manager, &g_window_manager, sel_sid);
} else {
daemon_fail(rsp, "cannot set layout for a macOS fullscreen space!\n");
}
} else if (token_equals(value, ARGUMENT_CONFIG_LAYOUT_FLOAT)) {
if (space_is_user(sel_sid)) {
view_set_flag(view, VIEW_LAYOUT);
view->layout = VIEW_FLOAT;
view->custom_layout = true;
view_clear(view);
} else {
daemon_fail(rsp, "cannot set layout for a macOS fullscreen space!\n");
Expand Down Expand Up @@ -1512,14 +1512,29 @@ static void handle_domain_config(FILE *rsp, struct token domain, char *message)
}
} else if (token_equals(command, COMMAND_CONFIG_AUTO_BALANCE)) {
struct token value = get_token(&message);
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)) {
g_space_manager.auto_balance = false;
} else if (token_equals(value, ARGUMENT_COMMON_VAL_ON)) {
g_space_manager.auto_balance = true;
if (sel_sid) {
struct view *view = space_manager_find_view(&g_space_manager, sel_sid);
if (!token_is_valid(value)) {
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;
} else if (token_equals(value, ARGUMENT_COMMON_VAL_ON)) {
view_set_flag(view, VIEW_AUTO_BALANCE);
view->auto_balance = true;
} 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 {
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);
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);
} else if (token_equals(value, ARGUMENT_COMMON_VAL_ON)) {
space_manager_set_auto_balance_for_all_spaces(&g_space_manager, true);
} 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_equals(command, COMMAND_CONFIG_MOUSE_MOD)) {
struct token value = get_token(&message);
Expand Down
Loading

0 comments on commit 31e6585

Please sign in to comment.