Make resize set px work with tiling containers
This commit is contained in:
parent
f28c50b631
commit
51d230ad4c
|
@ -2337,9 +2337,8 @@ optional ppt argument means "percentage points", and if specified it indicates
|
||||||
that a *tiling container* should be grown or shrunk by that many points, instead
|
that a *tiling container* should be grown or shrunk by that many points, instead
|
||||||
of by the +px+ value.
|
of by the +px+ value.
|
||||||
|
|
||||||
Notes about +resize set+: a value of 0 for <width> or <height> means "do
|
Note about +resize set+: a value of 0 for <width> or <height> means "do not
|
||||||
not resize in this direction", and resizing a tiling container by +px+ is not
|
resize in this direction".
|
||||||
implemented.
|
|
||||||
|
|
||||||
It is recommended to define bindings for resizing in a dedicated binding mode.
|
It is recommended to define bindings for resizing in a dedicated binding mode.
|
||||||
See <<binding_modes>> and the example in the i3
|
See <<binding_modes>> and the example in the i3
|
||||||
|
|
|
@ -629,6 +629,35 @@ void cmd_resize(I3_CMD, const char *way, const char *direction, long resize_px,
|
||||||
ysuccess(true);
|
ysuccess(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool resize_set_tiling(I3_CMD, Con *target, orientation_t resize_orientation, bool is_ppt, long target_size) {
|
||||||
|
direction_t search_direction;
|
||||||
|
char *mode;
|
||||||
|
if (resize_orientation == HORIZ) {
|
||||||
|
search_direction = D_LEFT;
|
||||||
|
mode = "width";
|
||||||
|
} else {
|
||||||
|
search_direction = D_DOWN;
|
||||||
|
mode = "height";
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get the appropriate current container (skip stacked/tabbed cons) */
|
||||||
|
Con *dummy;
|
||||||
|
resize_find_tiling_participants(&target, &dummy, search_direction, true);
|
||||||
|
|
||||||
|
/* Calculate new size for the target container */
|
||||||
|
int ppt = 0;
|
||||||
|
int px = 0;
|
||||||
|
if (is_ppt) {
|
||||||
|
ppt = target_size - target->percent * 100;
|
||||||
|
} else {
|
||||||
|
px = target_size - (resize_orientation == HORIZ ? target->rect.width : target->rect.height);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Perform resizing and report failure if not possible */
|
||||||
|
return cmd_resize_tiling_width_height(current_match, cmd_output,
|
||||||
|
target, mode, px, ppt);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Implementation of 'resize set <width> [px | ppt] <height> [px | ppt]'.
|
* Implementation of 'resize set <width> [px | ppt] <height> [px | ppt]'.
|
||||||
*
|
*
|
||||||
|
@ -665,50 +694,13 @@ void cmd_resize_set(I3_CMD, long cwidth, const char *mode_width, long cheight, c
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cwidth > 0 && mode_width && strcmp(mode_width, "ppt") == 0) {
|
if (cwidth > 0 && mode_width) {
|
||||||
/* get the appropriate current container (skip stacked/tabbed cons) */
|
success &= resize_set_tiling(current_match, cmd_output, current->con,
|
||||||
Con *target = current->con;
|
HORIZ, strcmp(mode_width, "ppt") == 0, cwidth);
|
||||||
Con *dummy;
|
|
||||||
resize_find_tiling_participants(&target, &dummy, D_LEFT, true);
|
|
||||||
|
|
||||||
/* Calculate new size for the target container */
|
|
||||||
double current_percent = target->percent;
|
|
||||||
long adjustment;
|
|
||||||
|
|
||||||
if (current_percent > cwidth) {
|
|
||||||
adjustment = (int)(current_percent * 100) - cwidth;
|
|
||||||
} else {
|
|
||||||
adjustment = cwidth - (int)(current_percent * 100);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* perform resizing and report failure if not possible */
|
|
||||||
if (!cmd_resize_tiling_width_height(current_match, cmd_output,
|
|
||||||
target, "width", 0, adjustment)) {
|
|
||||||
success = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (cheight > 0 && mode_height) {
|
||||||
if (cheight > 0 && mode_height && strcmp(mode_height, "ppt") == 0) {
|
success &= resize_set_tiling(current_match, cmd_output, current->con,
|
||||||
/* get the appropriate current container (skip stacked/tabbed cons) */
|
VERT, strcmp(mode_height, "ppt") == 0, cheight);
|
||||||
Con *target = current->con;
|
|
||||||
Con *dummy;
|
|
||||||
resize_find_tiling_participants(&target, &dummy, D_DOWN, true);
|
|
||||||
|
|
||||||
/* Calculate new size for the target container */
|
|
||||||
double current_percent = target->percent;
|
|
||||||
long adjustment;
|
|
||||||
|
|
||||||
if (current_percent > cheight) {
|
|
||||||
adjustment = (int)(current_percent * 100) - cheight;
|
|
||||||
} else {
|
|
||||||
adjustment = cheight - (int)(current_percent * 100);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* perform resizing and report failure if not possible */
|
|
||||||
if (!cmd_resize_tiling_width_height(current_match, cmd_output,
|
|
||||||
target, "height", 0, adjustment)) {
|
|
||||||
success = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,13 @@ cmd 'resize set width 80 ppt';
|
||||||
cmp_float($nodes->[0]->{percent}, 0.20, 'left window got 20%');
|
cmp_float($nodes->[0]->{percent}, 0.20, 'left window got 20%');
|
||||||
cmp_float($nodes->[1]->{percent}, 0.80, 'right window got 80%');
|
cmp_float($nodes->[1]->{percent}, 0.80, 'right window got 80%');
|
||||||
|
|
||||||
|
# Same but with px.
|
||||||
|
cmd 'resize set width 200 px';
|
||||||
|
|
||||||
|
($nodes, $focus) = get_ws_content($tmp);
|
||||||
|
|
||||||
|
cmp_float($nodes->[1]->{rect}->{width}, 200, 'right window got 200 px');
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
# resize vertically
|
# resize vertically
|
||||||
############################################################
|
############################################################
|
||||||
|
@ -77,6 +84,13 @@ cmd 'resize set height 80 ppt';
|
||||||
cmp_float($nodes->[0]->{percent}, 0.20, 'top window got 20%');
|
cmp_float($nodes->[0]->{percent}, 0.20, 'top window got 20%');
|
||||||
cmp_float($nodes->[1]->{percent}, 0.80, 'bottom window got 80%');
|
cmp_float($nodes->[1]->{percent}, 0.80, 'bottom window got 80%');
|
||||||
|
|
||||||
|
# Same but with px.
|
||||||
|
cmd 'resize set height 200 px';
|
||||||
|
|
||||||
|
($nodes, $focus) = get_ws_content($tmp);
|
||||||
|
|
||||||
|
cmp_float($nodes->[1]->{rect}->{height}, 200, 'bottom window got 200 px');
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
# resize horizontally and vertically
|
# resize horizontally and vertically
|
||||||
############################################################
|
############################################################
|
||||||
|
@ -102,6 +116,13 @@ cmp_float($nodes->[1]->{percent}, 0.75, 'right container got 75%');
|
||||||
cmp_float($nodes->[1]->{nodes}->[0]->{percent}, 0.25, 'top-right window got 25%');
|
cmp_float($nodes->[1]->{nodes}->[0]->{percent}, 0.25, 'top-right window got 25%');
|
||||||
cmp_float($nodes->[1]->{nodes}->[1]->{percent}, 0.75, 'bottom-right window got 75%');
|
cmp_float($nodes->[1]->{nodes}->[1]->{percent}, 0.75, 'bottom-right window got 75%');
|
||||||
|
|
||||||
|
# Same but with px.
|
||||||
|
cmd 'resize set 155 px 135 px';
|
||||||
|
|
||||||
|
($nodes, $focus) = get_ws_content($tmp);
|
||||||
|
|
||||||
|
cmp_float($nodes->[1]->{nodes}->[1]->{rect}->{width}, 155, 'bottom-right window got 155 px width');
|
||||||
|
cmp_float($nodes->[1]->{nodes}->[1]->{rect}->{height}, 135, 'bottom-right window got 135 px height');
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
# resize from inside a tabbed container
|
# resize from inside a tabbed container
|
||||||
|
@ -130,6 +151,12 @@ cmd 'resize set 75 ppt 0 ppt';
|
||||||
cmp_float($nodes->[0]->{percent}, 0.25, 'left container got 25%');
|
cmp_float($nodes->[0]->{percent}, 0.25, 'left container got 25%');
|
||||||
cmp_float($nodes->[1]->{percent}, 0.75, 'right container got 75%');
|
cmp_float($nodes->[1]->{percent}, 0.75, 'right container got 75%');
|
||||||
|
|
||||||
|
# Same but with px.
|
||||||
|
cmd 'resize set 155 px';
|
||||||
|
|
||||||
|
($nodes, $focus) = get_ws_content($tmp);
|
||||||
|
|
||||||
|
cmp_float($nodes->[1]->{rect}->{width}, 155, 'right container got 155 px');
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
# resize from inside a stacked container
|
# resize from inside a stacked container
|
||||||
|
@ -158,5 +185,11 @@ cmd 'resize set 75 ppt 0 ppt';
|
||||||
cmp_float($nodes->[0]->{percent}, 0.25, 'left container got 25%');
|
cmp_float($nodes->[0]->{percent}, 0.25, 'left container got 25%');
|
||||||
cmp_float($nodes->[1]->{percent}, 0.75, 'right container got 75%');
|
cmp_float($nodes->[1]->{percent}, 0.75, 'right container got 75%');
|
||||||
|
|
||||||
|
# Same but with px.
|
||||||
|
cmd 'resize set 130 px';
|
||||||
|
|
||||||
|
($nodes, $focus) = get_ws_content($tmp);
|
||||||
|
|
||||||
|
cmp_float($nodes->[1]->{rect}->{width}, 130, 'right container got 130 px');
|
||||||
|
|
||||||
done_testing;
|
done_testing;
|
||||||
|
|
Loading…
Reference in New Issue