Skip to content

Commit

Permalink
#184 add command to adjust split the split percentage of a window
Browse files Browse the repository at this point in the history
  • Loading branch information
koekeishiya committed Nov 9, 2019
1 parent b330e99 commit dd4b912
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 24 deletions.
4 changes: 2 additions & 2 deletions doc/yabai.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ COMMAND
*--resize* 'top|left|bottom|right|top_left|top_right|bottom_right|bottom_left|abs:<dx>:<dy>'::
Resize the selected window by moving the given handle 'dx' pixels horizontally and 'dy' pixels vertically. If handle is 'abs' the new size will be 'dx' width and 'dy' height.

*--ratio* 'inc|dec:<dr>'::
Adjust the split ratio for the parent node of the selected window by 'dr' percentage. Action 'inc' with a positive delta will increase the size of the left-child and 'dec' with a positive delta will decrease the size of the left-child.
*--ratio* 'rel|abs:<dr>'::
If type is 'rel' the split ratio of the selected window is changed by 'dr', otherwise 'dr' will become the new split ratio. A positive/negative delta will increase/decrease the size of the left-child.

*--toggle* 'float|sticky|topmost|shadow|split|border|zoom-parent|zoom-fullscreen|native-fullscreen|expose'::
Toggle the given property of the selected window.
Expand Down
17 changes: 3 additions & 14 deletions src/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -875,17 +875,6 @@ static uint8_t parse_value_type(char *type)
}
}

static uint8_t parse_ratio_action(char *action)
{
if (string_equals(action, "inc")) {
return RATIO_INCREASE;
} else if (string_equals(action, "dec")) {
return RATIO_DECREASE;
} else {
return 0;
}
}

static uint8_t parse_resize_handle(char *handle)
{
if (string_equals(handle, "top")) {
Expand Down Expand Up @@ -1464,10 +1453,10 @@ static void handle_domain_window(FILE *rsp, struct token domain, char *message)
}
} else if (token_equals(command, COMMAND_WINDOW_RATIO)) {
float r;
char action[MAXLEN];
char type[MAXLEN];
struct token value = get_token(&message);
if ((sscanf(value.text, ARGUMENT_WINDOW_RATIO, action, &r) == 2)) {
window_manager_adjust_window_ratio(&g_window_manager, acting_window, parse_ratio_action(action), r);
if ((sscanf(value.text, ARGUMENT_WINDOW_RATIO, type, &r) == 2)) {
window_manager_adjust_window_ratio(&g_window_manager, acting_window, parse_value_type(type), r);
} 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
3 changes: 0 additions & 3 deletions src/misc/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,4 @@
#define HANDLE_RIGHT 0x08
#define HANDLE_ABS 0x10

#define RATIO_INCREASE 0x01
#define RATIO_DECREASE 0x02

#endif
10 changes: 5 additions & 5 deletions src/window_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,19 +251,19 @@ void window_manager_add_managed_window(struct window_manager *wm, struct window
window_manager_purify_window(wm, window);
}

void window_manager_adjust_window_ratio(struct window_manager *wm, struct window *window, int action, float ratio)
void window_manager_adjust_window_ratio(struct window_manager *wm, struct window *window, int type, float ratio)
{
struct view *view = window_manager_find_managed_window(wm, window);
if (view) {
struct window_node *node = view_find_window_node(view, window->id);
if (!node || !node->parent) return;

switch (action) {
case RATIO_INCREASE: {
switch (type) {
case TYPE_REL: {
node->parent->ratio = clampf_range(node->parent->ratio + ratio, 0.1f, 0.9f);
} break;
case RATIO_DECREASE: {
node->parent->ratio = clampf_range(node->parent->ratio - ratio, 0.1f, 0.9f);
case TYPE_ABS: {
node->parent->ratio = clampf_range(ratio, 0.1f, 0.9f);
} break;
}

Expand Down

0 comments on commit dd4b912

Please sign in to comment.