if (ppt != 0.0) {
new_current_percent = current->percent + ppt;
} else {
- new_current_percent = px_resize_to_percent(current, px);
- ppt = new_current_percent - current->percent;
+ /* Convert px change to change in percentages */
+ ppt = (double)px / (double)con_rect_size_in_orientation(current->parent);
+ new_current_percent = current->percent + ppt;
}
subtract_percent = ppt / (children - 1);
if (ppt < 0.0 && new_current_percent < percent_for_1px(current)) {
return true;
}
-/*
- * Calculate the given container's new percent given a change in pixels.
- *
- */
-double px_resize_to_percent(Con *con, int px_diff) {
- Con *parent = con->parent;
- const orientation_t o = con_orientation(parent);
- const int total = (o == HORIZ ? parent->rect.width : parent->rect.height);
- /* deco_rect.height is subtracted from each child in render_con_split */
- const int target = px_diff + (o == HORIZ ? con->rect.width : con->rect.height + con->deco_rect.height);
- return ((double)target / (double)total);
-}
-
/*
* Calculate the minimum percent needed for the given container to be at least 1
* pixel.
*
*/
double percent_for_1px(Con *con) {
- Con *parent = con->parent;
- const orientation_t o = con_orientation(parent);
- const int total = (o == HORIZ ? parent->rect.width : parent->rect.height);
- const int target = (o == HORIZ ? 1 : 1 + con->deco_rect.height);
- return ((double)target / (double)total);
+ const int parent_size = con_rect_size_in_orientation(con->parent);
+ /* deco_rect.height is subtracted from each child in render_con_split */
+ const int min_size = (con_orientation(con->parent) == HORIZ ? 1 : 1 + con->deco_rect.height);
+ return ((double)min_size / (double)parent_size);
}
/*
new_first_percent = first->percent + ((double)ppt / 100.0);
new_second_percent = second->percent - ((double)ppt / 100.0);
} else {
- new_first_percent = px_resize_to_percent(first, px);
- new_second_percent = second->percent + first->percent - new_first_percent;
+ /* Convert px change to change in percentages */
+ const double pct = (double)px / (double)con_rect_size_in_orientation(first->parent);
+ new_first_percent = first->percent + pct;
+ new_second_percent = second->percent - pct;
}
/* Ensure that no container will be less than 1 pixel in the resizing
* direction. */
int pixels = (new_position - initial_position);
DLOG("Done, pixels = %d\n", pixels);
+ /* No change; no action needed. */
+ if (pixels == 0) {
+ return;
+ }
+
/* if we got thus far, the containers must have valid percentages. */
assert(first->percent > 0.0);
assert(second->percent > 0.0);