]> git.sur5r.net Git - i3/i3/commitdiff
Bugfix: Containers could lose their snap state (Thanks Atsutane)
authorMichael Stapelberg <michael@stapelberg.de>
Fri, 1 Jan 2010 21:40:50 +0000 (22:40 +0100)
committerMichael Stapelberg <michael@stapelberg.de>
Fri, 1 Jan 2010 21:43:02 +0000 (22:43 +0100)
When being on a different workspace than the one where the snapped
container is, the function to cleanup cols/rows would clean up too
much.

include/table.h
src/click.c
src/commands.c
src/table.c

index 18561474bb14d394e65ddaa0fdb57df57f271749..6236bef56e1283c0ae85dd65583ae8476bd29908 100644 (file)
@@ -48,7 +48,7 @@ void expand_table_cols_at_head(Workspace *workspace);
  * Performs simple bounds checking for the given column/row
  *
  */
-bool cell_exists(int col, int row);
+bool cell_exists(Workspace *ws, int col, int row);
 
 /**
  * Shrinks the table by "compacting" it, that is, removing completely empty
index efb26ad3cb3572abcd4ae4eb1051cb0e48671a01..dbbc43380cd5f21b45524513e6423eae4a1e3a56 100644 (file)
@@ -211,7 +211,7 @@ static bool floating_mod_on_tiled_client(xcb_connection_t *conn, Client *client,
                 first = con->col + (con->colspan - 1);
                 LOG("column %d\n", first);
 
-                if (!cell_exists(first, con->row) ||
+                if (!cell_exists(ws, first, con->row) ||
                     (first == (ws->cols-1)))
                         return false;
 
@@ -239,7 +239,7 @@ static bool floating_mod_on_tiled_client(xcb_connection_t *conn, Client *client,
                    to_bottom < to_top) {
                 /* …bottom border */
                 first = con->row + (con->rowspan - 1);
-                if (!cell_exists(con->col, first) ||
+                if (!cell_exists(ws, con->col, first) ||
                     (first == (ws->rows-1)))
                         return false;
 
@@ -376,7 +376,7 @@ int handle_button_press(void *ignored, xcb_connection_t *conn, xcb_button_press_
         } else if (event->event_y >= (client->rect.height - 2)) {
                 /* …bottom border */
                 first = con->row + (con->rowspan - 1);
-                if (!cell_exists(con->col, first) ||
+                if (!cell_exists(ws, con->col, first) ||
                     (first == (ws->rows-1)))
                         return 1;
 
@@ -394,7 +394,7 @@ int handle_button_press(void *ignored, xcb_connection_t *conn, xcb_button_press_
                 first = con->col + (con->colspan - 1);
                 LOG("column %d\n", first);
 
-                if (!cell_exists(first, con->row) ||
+                if (!cell_exists(ws, first, con->row) ||
                     (first == (ws->cols-1)))
                         return 1;
 
index 4ef03d9cd37de96fddc59b49c5ff98b25ff20ef2..d60de2c1d43e8475cc2435fda9f601959571449b 100644 (file)
@@ -143,9 +143,9 @@ static void focus_thing(xcb_connection_t *conn, direction_t direction, thing_t t
                         if (focus_window_in_container(conn, container, direction))
                                 return;
 
-                if (direction == D_DOWN && cell_exists(current_col, current_row+1))
+                if (direction == D_DOWN && cell_exists(t_ws, current_col, current_row+1))
                         new_row = current_row + t_ws->table[current_col][current_row]->rowspan;
-                else if (direction == D_UP && cell_exists(current_col, current_row-1)) {
+                else if (direction == D_UP && cell_exists(c_ws, current_col, current_row-1)) {
                         /* Set new_row as a sane default, but it may get overwritten in a second */
                         new_row--;
 
@@ -186,9 +186,9 @@ static void focus_thing(xcb_connection_t *conn, direction_t direction, thing_t t
                         LOG("Fixed it to new col %d\n", new_col);
                 }
         } else if (direction == D_LEFT || direction == D_RIGHT) {
-                if (direction == D_RIGHT && cell_exists(current_col+1, current_row))
+                if (direction == D_RIGHT && cell_exists(t_ws, current_col+1, current_row))
                         new_col = current_col + t_ws->table[current_col][current_row]->colspan;
-                else if (direction == D_LEFT && cell_exists(current_col-1, current_row)) {
+                else if (direction == D_LEFT && cell_exists(t_ws, current_col-1, current_row)) {
                         /* Set new_col as a sane default, but it may get overwritten in a second */
                         new_col--;
 
@@ -451,7 +451,7 @@ static void snap_current_container(xcb_connection_t *conn, direction_t direction
         switch (direction) {
                 case D_LEFT:
                         /* Snap to the left is actually a move to the left and then a snap right */
-                        if (!cell_exists(container->col - 1, container->row) ||
+                        if (!cell_exists(container->workspace, container->col - 1, container->row) ||
                             CUR_TABLE[container->col-1][container->row]->currently_focused != NULL) {
                                 LOG("cannot snap to left - the cell is already used\n");
                                 return;
@@ -464,7 +464,7 @@ static void snap_current_container(xcb_connection_t *conn, direction_t direction
                         /* Check if the cell is used */
                         int new_col = container->col + container->colspan;
                         for (int i = 0; i < container->rowspan; i++)
-                                if (!cell_exists(new_col, container->row + i) ||
+                                if (!cell_exists(container->workspace, new_col, container->row + i) ||
                                     CUR_TABLE[new_col][container->row + i]->currently_focused != NULL) {
                                         LOG("cannot snap to right - the cell is already used\n");
                                         return;
@@ -484,7 +484,7 @@ static void snap_current_container(xcb_connection_t *conn, direction_t direction
                         break;
                 }
                 case D_UP:
-                        if (!cell_exists(container->col, container->row - 1) ||
+                        if (!cell_exists(container->workspace, container->col, container->row - 1) ||
                             CUR_TABLE[container->col][container->row-1]->currently_focused != NULL) {
                                 LOG("cannot snap to top - the cell is already used\n");
                                 return;
@@ -497,7 +497,7 @@ static void snap_current_container(xcb_connection_t *conn, direction_t direction
                         LOG("snapping down\n");
                         int new_row = container->row + container->rowspan;
                         for (int i = 0; i < container->colspan; i++)
-                                if (!cell_exists(container->col + i, new_row) ||
+                                if (!cell_exists(container->workspace, container->col + i, new_row) ||
                                     CUR_TABLE[container->col + i][new_row]->currently_focused != NULL) {
                                         LOG("cannot snap down - the cell is already used\n");
                                         return;
@@ -823,7 +823,7 @@ static void parse_resize_command(xcb_connection_t *conn, Client *last_focused, c
                 first = con->col + (con->colspan - 1);
                 LOG("column %d\n", first);
 
-                if (!cell_exists(first, con->row) ||
+                if (!cell_exists(ws, first, con->row) ||
                     (first == (ws->cols-1)))
                         return;
 
@@ -838,7 +838,7 @@ static void parse_resize_command(xcb_connection_t *conn, Client *last_focused, c
                 command += strlen("top");
         } else if (STARTS_WITH(command, "bottom")) {
                 first = con->row + (con->rowspan - 1);
-                if (!cell_exists(con->col, first) ||
+                if (!cell_exists(ws, con->col, first) ||
                     (first == (ws->rows-1)))
                         return;
 
index eebe8de03bb2f2f193033f2ca6fead0b13c018a6..4330ca11e615f9fe86783cacafa367a867d71f47 100644 (file)
@@ -241,9 +241,9 @@ static void shrink_table_rows(Workspace *workspace) {
  * Performs simple bounds checking for the given column/row
  *
  */
-bool cell_exists(int col, int row) {
-        return (col >= 0 && col < c_ws->cols) &&
-               (row >= 0 && row < c_ws->rows);
+bool cell_exists(Workspace *ws, int col, int row) {
+        return (col >= 0 && col < ws->cols) &&
+               (row >= 0 && row < ws->rows);
 }
 
 static void free_container(xcb_connection_t *conn, Workspace *workspace, int col, int row) {
@@ -388,7 +388,7 @@ void fix_colrowspan(xcb_connection_t *conn, Workspace *workspace) {
                 if (con->colspan > 1) {
                         LOG("gots one with colspan %d (at %d c, %d r)\n", con->colspan, cols, rows);
                         while (con->colspan > 1 &&
-                               (!cell_exists(cols + (con->colspan-1), rows) ||
+                               (!cell_exists(workspace, cols + (con->colspan-1), rows) &&
                                 workspace->table[cols + (con->colspan - 1)][rows]->currently_focused != NULL))
                                 con->colspan--;
                         LOG("fixed it to %d\n", con->colspan);
@@ -396,7 +396,7 @@ void fix_colrowspan(xcb_connection_t *conn, Workspace *workspace) {
                 if (con->rowspan > 1) {
                         LOG("gots one with rowspan %d (at %d c, %d r)\n", con->rowspan, cols, rows);
                         while (con->rowspan > 1 &&
-                               (!cell_exists(cols, rows + (con->rowspan - 1)) ||
+                               (!cell_exists(workspace, cols, rows + (con->rowspan - 1)) &&
                                 workspace->table[cols][rows + (con->rowspan - 1)]->currently_focused != NULL))
                                 con->rowspan--;
                         LOG("fixed it to %d\n", con->rowspan);