]> git.sur5r.net Git - i3/i3/blob - src/table.c
Fix some movement/rendering bugs
[i3/i3] / src / table.c
1 /*
2  * vim:ts=8:expandtab
3  *
4  * i3 - an improved dynamic tiling window manager
5  *
6  * © 2009 Michael Stapelberg and contributors
7  *
8  * See file LICENSE for license information.
9  *
10  * table.c: Functions/macros for easy modifying/accessing of _the_ table (defining our
11  *          layout).
12  *
13  */
14 #include <stdio.h>
15 #include <assert.h>
16 #include <stdlib.h>
17 #include <string.h>
18 #include <sys/types.h>
19 #include <unistd.h>
20 #include <stdbool.h>
21 #include <assert.h>
22
23 #include "data.h"
24 #include "table.h"
25
26 int current_workspace = 0;
27 Workspace workspaces[10];
28 /* Convenience pointer to the current workspace */
29 Workspace *c_ws = &workspaces[0];
30 int current_col = 0;
31 int current_row = 0;
32
33 /*
34  * Initialize table
35  *
36  */
37 void init_table() {
38         memset(workspaces, 0, sizeof(workspaces));
39
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]));
45         }
46 }
47
48 static void new_container(Workspace *workspace, Container **container) {
49         Container *new;
50         new = *container = calloc(sizeof(Container), 1);
51         CIRCLEQ_INIT(&(new->clients));
52         new->colspan = 1;
53         new->rowspan = 1;
54         new->workspace = workspace;
55 }
56
57 /*
58  * Add one row to the table
59  *
60  */
61 void expand_table_rows(Workspace *workspace) {
62         workspace->rows++;
63
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]));
67         }
68 }
69
70 /*
71  * Add one column to the table
72  *
73  */
74 void expand_table_cols(Workspace *workspace) {
75         workspace->cols++;
76
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]));
81 }
82
83 /*
84  * Performs simple bounds checking for the given column/row
85  *
86  */
87 bool cell_exists(int col, int row) {
88         return (col >= 0 && col < c_ws->cols) &&
89                 (row >= 0 && row < c_ws->rows);
90 }