]> git.sur5r.net Git - i3/i3/commitdiff
Bugfix: Fix display/resizing of colspanned containers
authorMichael Stapelberg <michael+x200@stapelberg.de>
Sat, 9 May 2009 16:43:02 +0000 (18:43 +0200)
committerMichael Stapelberg <michael+x200@stapelberg.de>
Sat, 9 May 2009 16:43:02 +0000 (18:43 +0200)
include/resize.h
src/handlers.c
src/layout.c
src/resize.c

index aefbb0059e1a5e5323762afd787defd67f39bb23..520d4398431c5624286a5ff6ded67bb23b5a5f17 100644 (file)
@@ -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
index 57d2509c1184a1652a7230c73907ebf795e41356..c1a55893c2051907dadc69e0d19ae4c1d086863a 100644 (file)
@@ -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);
 }
 
 /*
index 1c736c318ffa18e7e8a167e1996759aeb8914015..83cc9ff3a0726e99c1454e6402baa9a0ff859c5d 100644 (file)
@@ -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);
index c54965d971cf0e8027e7d065c8d7c541b4942a53..9c6cbab40a60361cdf0ac7628d2e76772a291d90 100644 (file)
@@ -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));