From ba2dd3a3ebef790b0f342027476238ef8bfc9d8e Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Fri, 1 Jan 2010 22:40:50 +0100 Subject: [PATCH] Bugfix: Containers could lose their snap state (Thanks Atsutane) 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 | 2 +- src/click.c | 8 ++++---- src/commands.c | 20 ++++++++++---------- src/table.c | 10 +++++----- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/include/table.h b/include/table.h index 18561474..6236bef5 100644 --- a/include/table.h +++ b/include/table.h @@ -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 diff --git a/src/click.c b/src/click.c index dccd5b4f..2ec071c4 100644 --- a/src/click.c +++ b/src/click.c @@ -212,7 +212,7 @@ static bool floating_mod_on_tiled_client(xcb_connection_t *conn, Client *client, first = con->col + (con->colspan - 1); DLOG("column %d\n", first); - if (!cell_exists(first, con->row) || + if (!cell_exists(ws, first, con->row) || (first == (ws->cols-1))) return false; @@ -240,7 +240,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; @@ -377,7 +377,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; @@ -395,7 +395,7 @@ int handle_button_press(void *ignored, xcb_connection_t *conn, xcb_button_press_ first = con->col + (con->colspan - 1); DLOG("column %d\n", first); - if (!cell_exists(first, con->row) || + if (!cell_exists(ws, first, con->row) || (first == (ws->cols-1))) return 1; diff --git a/src/commands.c b/src/commands.c index 32b7a398..31564bb9 100644 --- a/src/commands.c +++ b/src/commands.c @@ -144,9 +144,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--; @@ -187,9 +187,9 @@ static void focus_thing(xcb_connection_t *conn, direction_t direction, thing_t t DLOG("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--; @@ -452,7 +452,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) { ELOG("cannot snap to left - the cell is already used\n"); return; @@ -465,7 +465,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) { ELOG("cannot snap to right - the cell is already used\n"); return; @@ -485,7 +485,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) { ELOG("cannot snap to top - the cell is already used\n"); return; @@ -498,7 +498,7 @@ static void snap_current_container(xcb_connection_t *conn, direction_t direction DLOG("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) { ELOG("cannot snap down - the cell is already used\n"); return; @@ -824,7 +824,7 @@ static void parse_resize_command(xcb_connection_t *conn, Client *last_focused, c first = con->col + (con->colspan - 1); DLOG("column %d\n", first); - if (!cell_exists(first, con->row) || + if (!cell_exists(ws, first, con->row) || (first == (ws->cols-1))) return; @@ -839,7 +839,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; diff --git a/src/table.c b/src/table.c index 8aa02fba..1660d308 100644 --- a/src/table.c +++ b/src/table.c @@ -242,9 +242,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) { @@ -389,7 +389,7 @@ void fix_colrowspan(xcb_connection_t *conn, Workspace *workspace) { if (con->colspan > 1) { DLOG("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--; DLOG("fixed it to %d\n", con->colspan); @@ -397,7 +397,7 @@ void fix_colrowspan(xcb_connection_t *conn, Workspace *workspace) { if (con->rowspan > 1) { DLOG("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--; DLOG("fixed it to %d\n", con->rowspan); -- 2.39.5