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]'.
*
continue;
}
- if (cwidth > 0 && mode_width && strcmp(mode_width, "ppt") == 0) {
- /* get the appropriate current container (skip stacked/tabbed cons) */
- Con *target = current->con;
- 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 (cwidth > 0 && mode_width) {
+ success &= resize_set_tiling(current_match, cmd_output, current->con,
+ HORIZ, strcmp(mode_width, "ppt") == 0, cwidth);
}
-
- if (cheight > 0 && mode_height && strcmp(mode_height, "ppt") == 0) {
- /* get the appropriate current container (skip stacked/tabbed cons) */
- 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;
- }
+ if (cheight > 0 && mode_height) {
+ success &= resize_set_tiling(current_match, cmd_output, current->con,
+ VERT, strcmp(mode_height, "ppt") == 0, cheight);
}
}
}
cmp_float($nodes->[0]->{percent}, 0.20, 'left window got 20%');
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
############################################################
cmp_float($nodes->[0]->{percent}, 0.20, 'top window got 20%');
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
############################################################
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%');
+# 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
cmp_float($nodes->[0]->{percent}, 0.25, 'left container got 25%');
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
cmp_float($nodes->[0]->{percent}, 0.25, 'left container got 25%');
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;