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 f6912fc commit b330e99
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Config option *window_border_placement* to specify placement of window borders (exterior, interior, inset) [#216](https://github.com/koekeishiya/yabai/issues/216)
- Config option *active_window_border_topmost* to specify if the active border should always stay on top of other windows (off, on) [#216](https://github.com/koekeishiya/yabai/issues/216)
- Ability to label spaces, making the given label an alias that can be passed to any command taking a `<SPACE_SEL>` parameter [#119](https://github.com/koekeishiya/yabai/issues/119)
- New command to adjust the split percentage of a window [#184](https://github.com/koekeishiya/yabai/issues/184)

### Changed
- Don't draw borders for minimized or hidden windows when a display is (dis)connected [#250](https://github.com/koekeishiya/yabai/issues/250)
Expand Down
3 changes: 3 additions & 0 deletions doc/yabai.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,9 @@ 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.

*--toggle* 'float|sticky|topmost|shadow|split|border|zoom-parent|zoom-fullscreen|native-fullscreen|expose'::
Toggle the given property of the selected window.

Expand Down
22 changes: 22 additions & 0 deletions src/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ extern struct bar g_bar;
#define COMMAND_WINDOW_GRID "--grid"
#define COMMAND_WINDOW_MOVE "--move"
#define COMMAND_WINDOW_RESIZE "--resize"
#define COMMAND_WINDOW_RATIO "--ratio"
#define COMMAND_WINDOW_CLOSE "--close"
#define COMMAND_WINDOW_TOGGLE "--toggle"
#define COMMAND_WINDOW_DISPLAY "--display"
Expand All @@ -133,6 +134,7 @@ extern struct bar g_bar;
#define ARGUMENT_WINDOW_GRID "%d:%d:%d:%d:%d:%d"
#define ARGUMENT_WINDOW_MOVE "%255[^:]:%f:%f"
#define ARGUMENT_WINDOW_RESIZE "%255[^:]:%f:%f"
#define ARGUMENT_WINDOW_RATIO "%255[^:]:%f"
#define ARGUMENT_WINDOW_TOGGLE_ON_TOP "topmost"
#define ARGUMENT_WINDOW_TOGGLE_FLOAT "float"
#define ARGUMENT_WINDOW_TOGGLE_STICKY "sticky"
Expand Down Expand Up @@ -873,6 +875,17 @@ 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 @@ -1449,6 +1462,15 @@ static void handle_domain_window(FILE *rsp, struct token domain, char *message)
} 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_WINDOW_RATIO)) {
float r;
char action[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);
} 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_WINDOW_CLOSE)) {
if (!window_manager_close_window(acting_window)) {
daemon_fail(rsp, "could not close window with id '%d'\n", acting_window->id);
Expand Down
7 changes: 7 additions & 0 deletions src/misc/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,11 @@ static int regex_match(bool valid, regex_t *regex, const char *match)
return result == 0 ? REGEX_MATCH_YES : REGEX_MATCH_NO;
}

static inline float clampf_range(float value, float min, float max)
{
if (value < min) return min;
if (value > max) return max;
return value;
}

#endif
3 changes: 3 additions & 0 deletions src/misc/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@
#define HANDLE_RIGHT 0x08
#define HANDLE_ABS 0x10

#define RATIO_INCREASE 0x01
#define RATIO_DECREASE 0x02

#endif
2 changes: 1 addition & 1 deletion src/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ static void window_node_split(struct view *view, struct window_node *node, struc
area_make_pair(view, node);
}

static void window_node_update(struct view *view, struct window_node *node)
void window_node_update(struct view *view, struct window_node *node)
{
if (window_node_is_intermediate(node)) {
area_make_pair(view, node->parent);
Expand Down
1 change: 1 addition & 0 deletions src/view.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ struct view

float window_node_border_window_offset(struct window *window);
void window_node_flush(struct window_node *node);
void window_node_update(struct view *view, struct window_node *node);
struct window_node *window_node_find_first_leaf(struct window_node *root);
struct window_node *window_node_find_last_leaf(struct window_node *root);
struct window_node *window_node_find_prev_leaf(struct window_node *node);
Expand Down
21 changes: 21 additions & 0 deletions src/window_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,27 @@ 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)
{
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: {
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);
} break;
}

window_node_update(view, node->parent);
window_node_flush(node->parent);
}
}

void window_manager_move_window_relative(struct window_manager *wm, struct window *window, int type, float dx, float dy)
{
struct view *view = window_manager_find_managed_window(wm, window);
Expand Down
1 change: 1 addition & 0 deletions src/window_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ bool window_manager_should_manage_window(struct window *window);
void window_manager_tile_window(struct window_manager *wm, struct window *window);
void window_manager_move_window(struct window *window, float x, float y);
void window_manager_resize_window(struct window *window, float width, float height);
void window_manager_adjust_window_ratio(struct window_manager *wm, struct window *window, int action, float ratio);
void window_manager_set_window_frame(struct window *window, float x, float y, float width, float height);
struct window *window_manager_find_window_at_point_filtering_window(struct window_manager *wm, CGPoint point, uint32_t filter_wid);
struct window *window_manager_find_window_at_point(struct window_manager *wm, CGPoint point);
Expand Down

0 comments on commit b330e99

Please sign in to comment.