-#if 0
- LOG("Resize was from Y = %d to Y = %d\n", event->root_y, new_position);
- if (event->root_y == new_position) {
- LOG("Nothing changed, not updating anything\n");
- return 1;
- }
-
- /* Convert 0 (for default height_factor) to actual numbers */
- if (first->height_factor == 0)
- first->height_factor = ((float)ws->rect.height / ws->rows) / ws->rect.height;
- if (second->height_factor == 0)
- second->height_factor = ((float)ws->rect.height / ws->rows) / ws->rect.height;
-
- first->height_factor *= (float)(first->height + (new_position - event->root_y)) / first->height;
- second->height_factor *= (float)(second->height - (new_position - event->root_y)) / second->height;
-#endif
+ int ws_height = workspace_height(ws);
+ int default_height = ws_height / ws->rows;
+ int old_unoccupied_y = get_unoccupied_y(ws);
+
+ /* We pre-calculate the unoccupied space to see if we need to adapt sizes before
+ * doing the resize */
+ int new_unoccupied_y = old_unoccupied_y;
+
+ if (old_unoccupied_y == 0)
+ old_unoccupied_y = ws_height;
+
+ if (ws->height_factor[first] == 0)
+ new_unoccupied_y += default_height;
+
+ if (ws->height_factor[second] == 0)
+ new_unoccupied_y += default_height;
+
+ int cols_without_hf = 0;
+ int old_height, old_second_height;
+ for (int row = 0; row < ws->rows; row++)
+ if (ws->height_factor[row] == 0)
+ cols_without_hf++;
+
+ DLOG("old_unoccupied_y = %d\n", old_unoccupied_y);
+
+ DLOG("Updating first (before = %f)\n", ws->height_factor[first]);
+ /* Convert 0 (for default width_factor) to actual numbers */
+ if (ws->height_factor[first] == 0)
+ old_height = (old_unoccupied_y / max(cols_without_hf, 1));
+ else old_height = ws->height_factor[first] * old_unoccupied_y;
+
+ DLOG("second (before = %f)\n", ws->height_factor[second]);
+ if (ws->height_factor[second] == 0)
+ old_second_height = (old_unoccupied_y / max(cols_without_hf, 1));
+ else old_second_height = ws->height_factor[second] * old_unoccupied_y;
+
+ DLOG("middle = %f\n", ws->height_factor[first]);
+
+
+ DLOG("\n\n\n");
+ DLOG("old = %d, new = %d\n", old_unoccupied_y, new_unoccupied_y);
+
+ /* If the space used for customly resized columns has changed we need to adapt the
+ * other customly resized columns, if any */
+ if (new_unoccupied_y != old_unoccupied_y)
+ for (int row = 0; row < ws->rows; row++) {
+ if (ws->height_factor[row] == 0)
+ continue;
+
+ DLOG("Updating other column (%d) (current width_factor = %f)\n", row, ws->height_factor[row]);
+ ws->height_factor[row] = (ws->height_factor[row] * old_unoccupied_y) / new_unoccupied_y;
+ DLOG("to %f\n", ws->height_factor[row]);
+ }
+
+
+ DLOG("Updating first (before = %f)\n", ws->height_factor[first]);
+ /* Convert 0 (for default width_factor) to actual numbers */
+ if (ws->height_factor[first] == 0)
+ ws->height_factor[first] = ((float)ws_height / ws->rows) / new_unoccupied_y;
+
+ DLOG("first->width = %d, pixels = %d\n", old_height, pixels);
+ ws->height_factor[first] *= (float)(old_height + pixels) / old_height;
+ DLOG("-> %f\n", ws->height_factor[first]);
+
+
+ DLOG("Updating second (before = %f)\n", ws->height_factor[second]);
+ if (ws->height_factor[second] == 0)
+ ws->height_factor[second] = ((float)ws_height / ws->rows) / new_unoccupied_y;
+ DLOG("middle = %f\n", ws->height_factor[second]);
+ DLOG("second->width = %d, pixels = %d\n", old_second_height, pixels);
+ ws->height_factor[second] *= (float)(old_second_height - pixels) / old_second_height;
+ DLOG("-> %f\n", ws->height_factor[second]);
+
+ DLOG("new unoccupied_y = %d\n", get_unoccupied_y(ws));
+
+ DLOG("\n\n\n");