From: Michael Stapelberg Date: Sat, 9 May 2009 16:43:02 +0000 (+0200) Subject: Bugfix: Fix display/resizing of colspanned containers X-Git-Tag: 3.b~114 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=1256730b4bd5735b14223fd82b3b6d4d882842a7;p=i3%2Fi3 Bugfix: Fix display/resizing of colspanned containers --- diff --git a/include/resize.h b/include/resize.h index aefbb005..520d4398 100644 --- a/include/resize.h +++ b/include/resize.h @@ -21,7 +21,7 @@ typedef enum { O_HORIZONTAL, O_VERTICAL } resize_orientation_t; * the table column/row. * */ -int resize_graphical_handler(xcb_connection_t *conn, Container *first, Container *second, +int resize_graphical_handler(xcb_connection_t *conn, Workspace *ws, int first, int second, resize_orientation_t orientation, xcb_button_press_event_t *event); #endif diff --git a/src/handlers.c b/src/handlers.c index 0ce1724c..7652f07b 100644 --- a/src/handlers.c +++ b/src/handlers.c @@ -304,9 +304,8 @@ int handle_button_press(void *ignored, xcb_connection_t *conn, xcb_button_press_ /* Let’s see if this was on the borders (= resize). If not, we’re done */ LOG("press button on x=%d, y=%d\n", event->event_x, event->event_y); resize_orientation_t orientation = O_VERTICAL; - Container *con = client->container, - *first = NULL, - *second = NULL; + Container *con = client->container; + int first, second; if (con == NULL) { LOG("dock. done.\n"); @@ -335,31 +334,38 @@ int handle_button_press(void *ignored, xcb_connection_t *conn, xcb_button_press_ /* This was a press on the top border */ if (con->row == 0) return 1; - first = con->workspace->table[con->col][con->row-1]; - second = con; + first = con->row - 1; + second = con->row; orientation = O_HORIZONTAL; } else if (event->event_y >= (client->rect.height - 2)) { /* …bottom border */ - if (con->row == (con->workspace->rows-1)) + first = con->row + (con->rowspan - 1); + if (!cell_exists(con->col, first) || + (first == (con->workspace->rows-1))) return 1; - first = con; - second = con->workspace->table[con->col][con->row+1]; + + second = first + 1; orientation = O_HORIZONTAL; } else if (event->event_x <= 2) { /* …left border */ if (con->col == 0) return 1; - first = con->workspace->table[con->col-1][con->row]; - second = con; + + first = con->col - 1; + second = con->col; } else if (event->event_x > 2) { /* …right border */ - if (con->col == (con->workspace->cols-1)) + first = con->col + (con->colspan - 1); + LOG("column %d\n", first); + + if (!cell_exists(first, con->row) || + (first == (con->workspace->cols-1))) return 1; - first = con; - second = con->workspace->table[con->col+1][con->row]; + + second = first + 1; } - return resize_graphical_handler(conn, first, second, orientation, event); + return resize_graphical_handler(conn, con->workspace, first, second, orientation, event); } /* diff --git a/src/layout.c b/src/layout.c index 1c736c31..83cc9ff3 100644 --- a/src/layout.c +++ b/src/layout.c @@ -520,12 +520,14 @@ void render_workspace(xcb_connection_t *conn, i3Screen *screen, Workspace *r_ws) container->col = cols; container->x = xoffset[rows]; container->y = yoffset[cols]; + container->width = 0; - if (r_ws->width_factor[cols] == 0) - container->width = (width / r_ws->cols); - else container->width = get_unoccupied_x(r_ws) * r_ws->width_factor[cols]; + for (int c = 0; c < container->colspan; c++) { + if (r_ws->width_factor[cols+c] == 0) + container->width += (width / r_ws->cols); + else container->width += get_unoccupied_x(r_ws) * r_ws->width_factor[cols+c]; + } single_width = container->width; - container->width *= container->colspan; //if (container->height_factor == 0) container->height = (height / r_ws->rows); diff --git a/src/resize.c b/src/resize.c index c54965d9..9c6cbab4 100644 --- a/src/resize.c +++ b/src/resize.c @@ -30,7 +30,7 @@ * the table column/row. * */ -int resize_graphical_handler(xcb_connection_t *conn, Container *first, Container *second, +int resize_graphical_handler(xcb_connection_t *conn, Workspace *ws, int first, int second, resize_orientation_t orientation, xcb_button_press_event_t *event) { int new_position; xcb_window_t root = xcb_setup_roots_iterator(xcb_get_setup(conn)).data->root; @@ -132,7 +132,6 @@ int resize_graphical_handler(xcb_connection_t *conn, Container *first, Container xcb_destroy_window(conn, grabwin); xcb_flush(conn); - Workspace *ws = first->workspace; 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) { @@ -150,10 +149,10 @@ int resize_graphical_handler(xcb_connection_t *conn, Container *first, Container if (old_unoccupied_x == 0) old_unoccupied_x = ws->rect.width; - if (ws->width_factor[first->col] == 0) + if (ws->width_factor[first] == 0) new_unoccupied_x += default_width; - if (ws->width_factor[second->col] == 0) + if (ws->width_factor[second] == 0) new_unoccupied_x += default_width; LOG("\n\n\n"); @@ -173,24 +172,26 @@ int resize_graphical_handler(xcb_connection_t *conn, Container *first, Container LOG("old_unoccupied_x = %d\n", old_unoccupied_x); - LOG("Updating first (before = %f)\n", ws->width_factor[first->col]); + LOG("Updating first (before = %f)\n", ws->width_factor[first]); /* Convert 0 (for default width_factor) to actual numbers */ - if (ws->width_factor[first->col] == 0) - ws->width_factor[first->col] = ((float)ws->rect.width / ws->cols) / new_unoccupied_x; - - LOG("middle = %f\n", ws->width_factor[first->col]); - LOG("first->width = %d, new_position = %d, event->root_x = %d\n", first->width, new_position, event->root_x); - ws->width_factor[first->col] *= (float)(first->width + (new_position - event->root_x)) / first->width; - LOG("-> %f\n", ws->width_factor[first->col]); - - - LOG("Updating second (before = %f)\n", ws->width_factor[second->col]); - if (ws->width_factor[second->col] == 0) - ws->width_factor[second->col] = ((float)ws->rect.width / ws->cols) / new_unoccupied_x; - LOG("middle = %f\n", ws->width_factor[second->col]); - LOG("second->width = %d, new_position = %d, event->root_x = %d\n", second->width, new_position, event->root_x); - ws->width_factor[second->col] *= (float)(second->width - (new_position - event->root_x)) / second->width; - LOG("-> %f\n", ws->width_factor[second->col]); + if (ws->width_factor[first] == 0) + ws->width_factor[first] = ((float)ws->rect.width / ws->cols) / new_unoccupied_x; + + LOG("middle = %f\n", ws->width_factor[first]); + int old_width = ws->width_factor[first] * old_unoccupied_x; + LOG("first->width = %d, new_position = %d, event->root_x = %d\n", old_width, new_position, event->root_x); + ws->width_factor[first] *= (float)(old_width + (new_position - event->root_x)) / old_width; + LOG("-> %f\n", ws->width_factor[first]); + + + LOG("Updating second (before = %f)\n", ws->width_factor[second]); + if (ws->width_factor[second] == 0) + ws->width_factor[second] = ((float)ws->rect.width / ws->cols) / new_unoccupied_x; + LOG("middle = %f\n", ws->width_factor[second]); + old_width = ws->width_factor[second] * old_unoccupied_x; + LOG("second->width = %d, new_position = %d, event->root_x = %d\n", old_width, new_position, event->root_x); + ws->width_factor[second] *= (float)(old_width - (new_position - event->root_x)) / old_width; + LOG("-> %f\n", ws->width_factor[second]); LOG("new unoccupied_x = %d\n", get_unoccupied_x(ws));