diff --git a/include/table.h b/include/table.h index 9d1d19f9..0e4cdfe9 100644 --- a/include/table.h +++ b/include/table.h @@ -28,10 +28,10 @@ extern int current_row; void init_table(); void expand_table_rows(Workspace *workspace); void expand_table_cols(Workspace *workspace); +void expand_table_cols_at_head(Workspace *workspace); bool cell_exists(int col, int row); void cleanup_table(xcb_connection_t *conn, Workspace *workspace); void fix_colrowspan(xcb_connection_t *conn, Workspace *workspace); void dump_table(xcb_connection_t *conn, Workspace *workspace); - #endif diff --git a/src/commands.c b/src/commands.c index e47855f6..22d067a4 100644 --- a/src/commands.c +++ b/src/commands.c @@ -181,11 +181,13 @@ static void move_current_window(xcb_connection_t *conn, direction_t direction) { switch (direction) { case D_LEFT: - /* TODO: If we’re at the left-most position, move the rest of the table right */ - if (current_col == 0) - return; + /* If we’re at the left-most position, move the rest of the table right */ + if (current_col == 0) { + expand_table_cols_at_head(c_ws); + new = CUR_TABLE[current_col][current_row]; + } else + new = CUR_TABLE[--current_col][current_row]; - new = CUR_TABLE[--current_col][current_row]; break; case D_RIGHT: if (current_col == (c_ws->cols-1)) diff --git a/src/table.c b/src/table.c index 4c13be83..91763972 100644 --- a/src/table.c +++ b/src/table.c @@ -85,6 +85,28 @@ void expand_table_cols(Workspace *workspace) { new_container(workspace, &(workspace->table[workspace->cols-1][c]), workspace->cols-1, c); } +/* + * Inserts one column at the table’s head + * + */ +void expand_table_cols_at_head(Workspace *workspace) { + workspace->cols++; + + workspace->table = realloc(workspace->table, sizeof(Container**) * workspace->cols); + workspace->table[workspace->cols-1] = calloc(sizeof(Container*) * workspace->rows, 1); + + /* Move the other columns */ + for (int rows = 0; rows < workspace->rows; rows++) + for (int cols = workspace->cols - 1; cols > 0; cols--) { + LOG("Moving col %d to %d\n", cols-1, cols); + workspace->table[cols][rows] = workspace->table[cols-1][rows]; + workspace->table[cols][rows]->col = cols; + } + + for (int rows = 0; rows < workspace->rows; rows++) + new_container(workspace, &(workspace->table[0][rows]), 0, rows); +} + /* * Shrinks the table by one column. *