4 * i3 - an improved dynamic tiling window manager
6 * © 2009 Michael Stapelberg and contributors
8 * See file LICENSE for license information.
10 * table.c: Functions/macros for easy modifying/accessing of _the_ table (defining our
18 #include <sys/types.h>
26 int current_workspace = 0;
27 Workspace workspaces[10];
28 /* Convenience pointer to the current workspace */
29 Workspace *c_ws = &workspaces[0];
38 memset(workspaces, 0, sizeof(workspaces));
40 for (int i = 0; i < 10; i++) {
41 workspaces[i].screen = NULL;
42 SLIST_INIT(&(workspaces[i].dock_clients));
43 expand_table_cols(&(workspaces[i]));
44 expand_table_rows(&(workspaces[i]));
48 static void new_container(Workspace *workspace, Container **container) {
50 new = *container = calloc(sizeof(Container), 1);
51 CIRCLEQ_INIT(&(new->clients));
54 new->workspace = workspace;
58 * Add one row to the table
61 void expand_table_rows(Workspace *workspace) {
64 for (int c = 0; c < workspace->cols; c++) {
65 workspace->table[c] = realloc(workspace->table[c], sizeof(Container*) * workspace->rows);
66 new_container(workspace, &(workspace->table[c][workspace->rows-1]));
71 * Add one column to the table
74 void expand_table_cols(Workspace *workspace) {
77 workspace->table = realloc(workspace->table, sizeof(Container**) * workspace->cols);
78 workspace->table[workspace->cols-1] = calloc(sizeof(Container*) * workspace->rows, 1);
79 for (int c = 0; c < workspace->rows; c++)
80 new_container(workspace, &(workspace->table[workspace->cols-1][c]));
84 * Performs simple bounds checking for the given column/row
87 bool cell_exists(int col, int row) {
88 return (col >= 0 && col < c_ws->cols) &&
89 (row >= 0 && row < c_ws->rows);