Implement horizontal resize

This commit is contained in:
Michael Stapelberg
2009-09-06 16:50:45 +02:00
parent a81108c527
commit e893902585
3 changed files with 94 additions and 25 deletions

View File

@ -47,13 +47,6 @@ int resize_graphical_handler(xcb_connection_t *conn, Workspace *ws, int first, i
LOG("Screen dimensions: (%d, %d) %d x %d\n", screen->rect.x, screen->rect.y, screen->rect.width, screen->rect.height);
/* FIXME: horizontal resizing causes empty spaces to exist */
if (orientation == O_HORIZONTAL) {
LOG("Sorry, horizontal resizing is not yet activated due to creating layout bugs."
"If you are brave, enable the code for yourself and try fixing it.\n");
return 1;
}
uint32_t mask = 0;
uint32_t values[2];
@ -123,6 +116,7 @@ int resize_graphical_handler(xcb_connection_t *conn, Workspace *ws, int first, i
xcb_destroy_window(conn, grabwin);
xcb_flush(conn);
/* TODO: refactor this, both blocks are very identical */
if (orientation == O_VERTICAL) {
LOG("Resize was from X = %d to X = %d\n", event->root_x, new_position);
if (event->root_x == new_position) {
@ -188,22 +182,69 @@ int resize_graphical_handler(xcb_connection_t *conn, Workspace *ws, int first, i
LOG("\n\n\n");
} else {
#if 0
LOG("Resize was from Y = %d to Y = %d\n", event->root_y, new_position);
LOG("Resize was from X = %d to X = %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;
int default_height = ws->rect.height / ws->rows;
int old_unoccupied_y = get_unoccupied_y(ws);
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
/* 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->rect.height;
if (ws->height_factor[first] == 0)
new_unoccupied_y += default_height;
if (ws->height_factor[second] == 0)
new_unoccupied_y += default_height;
LOG("\n\n\n");
LOG("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;
LOG("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;
LOG("to %f\n", ws->height_factor[row]);
}
LOG("old_unoccupied_y = %d\n", old_unoccupied_y);
LOG("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->rect.height / ws->rows) / new_unoccupied_y;
LOG("middle = %f\n", ws->height_factor[first]);
int old_height = ws->height_factor[first] * old_unoccupied_y;
LOG("first->width = %d, new_position = %d, event->root_x = %d\n", old_height, new_position, event->root_y);
ws->height_factor[first] *= (float)(old_height + (new_position - event->root_y)) / old_height;
LOG("-> %f\n", ws->height_factor[first]);
LOG("Updating second (before = %f)\n", ws->height_factor[second]);
if (ws->height_factor[second] == 0)
ws->height_factor[second] = ((float)ws->rect.height / ws->rows) / new_unoccupied_y;
LOG("middle = %f\n", ws->height_factor[second]);
old_height = ws->height_factor[second] * old_unoccupied_y;
LOG("second->width = %d, new_position = %d, event->root_x = %d\n", old_height, new_position, event->root_y);
ws->height_factor[second] *= (float)(old_height - (new_position - event->root_y)) / old_height;
LOG("-> %f\n", ws->height_factor[second]);
LOG("new unoccupied_y = %d\n", get_unoccupied_y(ws));
LOG("\n\n\n");
}
render_layout(conn);