Improve resize_find_tiling_participants() and simplify cmd_resize_tiling_width_height() (#3111)

This commit is contained in:
livanh 2018-01-06 17:59:27 +01:00 committed by Michael Stapelberg
parent 2f29fce801
commit c0378f737b
4 changed files with 18 additions and 34 deletions

View File

@ -11,6 +11,6 @@
#include <config.h>
bool resize_find_tiling_participants(Con **current, Con **other, direction_t direction);
bool resize_find_tiling_participants(Con **current, Con **other, direction_t direction, bool both_sides);
int resize_graphical_handler(Con *first, Con *second, orientation_t orientation, const xcb_button_press_event_t *event);

View File

@ -49,7 +49,7 @@ static bool tiling_resize_for_border(Con *con, border_t border, xcb_button_press
break;
}
bool res = resize_find_tiling_participants(&first, &second, search_direction);
bool res = resize_find_tiling_participants(&first, &second, search_direction, false);
if (!res) {
LOG("No second container in this direction found.\n");
return false;

View File

@ -511,7 +511,7 @@ static bool cmd_resize_tiling_direction(I3_CMD, Con *current, const char *way, c
else
search_direction = D_DOWN;
bool res = resize_find_tiling_participants(&first, &second, search_direction);
bool res = resize_find_tiling_participants(&first, &second, search_direction, false);
if (!res) {
LOG("No second container in this direction found.\n");
ysuccess(false);
@ -552,19 +552,15 @@ static bool cmd_resize_tiling_direction(I3_CMD, Con *current, const char *way, c
static bool cmd_resize_tiling_width_height(I3_CMD, Con *current, const char *way, const char *direction, int ppt) {
LOG("width/height resize\n");
/* get the appropriate current container (skip stacked/tabbed cons) */
while (current->parent->layout == L_STACKED ||
current->parent->layout == L_TABBED)
current = current->parent;
/* Then further go up until we find one with the matching orientation. */
orientation_t search_orientation =
(strcmp(direction, "width") == 0 ? HORIZ : VERT);
while (current->type != CT_WORKSPACE &&
current->type != CT_FLOATING_CON &&
(con_orientation(current->parent) != search_orientation || con_num_children(current->parent) == 1))
current = current->parent;
Con *dummy = NULL;
direction_t search_direction = (strcmp(direction, "width") == 0 ? D_LEFT : D_DOWN);
bool search_result = resize_find_tiling_participants(&current, &dummy, search_direction, true);
if (search_result == false) {
ysuccess(false);
return false;
}
/* get the default percentage */
int children = con_num_children(current->parent);
@ -572,24 +568,6 @@ static bool cmd_resize_tiling_width_height(I3_CMD, Con *current, const char *way
double percentage = 1.0 / children;
LOG("default percentage = %f\n", percentage);
orientation_t orientation = con_orientation(current->parent);
if ((orientation == HORIZ &&
strcmp(direction, "height") == 0) ||
(orientation == VERT &&
strcmp(direction, "width") == 0)) {
LOG("You cannot resize in that direction. Your focus is in a %s split container currently.\n",
(orientation == HORIZ ? "horizontal" : "vertical"));
ysuccess(false);
return false;
}
if (children == 1) {
LOG("This is the only container, cannot resize.\n");
ysuccess(false);
return false;
}
/* Ensure all the other children have a percentage set. */
Con *child;
TAILQ_FOREACH(child, &(current->parent->nodes_head), nodes) {

View File

@ -47,7 +47,7 @@ DRAGGING_CB(resize_callback) {
xcb_flush(conn);
}
bool resize_find_tiling_participants(Con **current, Con **other, direction_t direction) {
bool resize_find_tiling_participants(Con **current, Con **other, direction_t direction, bool both_sides) {
DLOG("Find two participants for resizing container=%p in direction=%i\n", other, direction);
Con *first = *current;
Con *second = NULL;
@ -74,8 +74,14 @@ bool resize_find_tiling_participants(Con **current, Con **other, direction_t dir
/* get the counterpart for this resizement */
if (dir_backwards) {
second = TAILQ_PREV(first, nodes_head, nodes);
if (second == NULL && both_sides == true) {
second = TAILQ_NEXT(first, nodes);
}
} else {
second = TAILQ_NEXT(first, nodes);
if (second == NULL && both_sides == true) {
second = TAILQ_PREV(first, nodes_head, nodes);
}
}
if (second == NULL) {