]> git.sur5r.net Git - i3/i3/blob - src/table.c
Add vim hints, copyright notice to each file, add LICENSE, retab! everything
[i3/i3] / src / table.c
1 /*
2  * vim:ts=8:expandtab
3  *
4  * i3 - an improved dynamic tiling window manager
5  *
6  * (c) 2009 Michael Stapelberg and contributors
7  *
8  * See file LICENSE for license information.
9  *
10  */
11 /*
12  * This file provides functions for easier accessing of _the_ table
13  *
14  */
15 #include <stdio.h>
16 #include <assert.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include <sys/types.h>
20 #include <unistd.h>
21 #include <stdbool.h>
22 #include <assert.h>
23
24 #include "data.h"
25 #include "table.h"
26
27 int current_workspace = 0;
28 Workspace workspaces[10];
29 /* Convenience pointer to the current workspace */
30 Workspace *c_ws = &workspaces[0];
31 int current_col = 0;
32 int current_row = 0;
33
34 /*
35  * Initialize table
36  *
37  */
38 void init_table() {
39         int i;
40         memset(workspaces, 0, sizeof(workspaces));
41
42         for (i = 0; i < 10; i++) {
43                 expand_table_cols(&(workspaces[i]));
44                 expand_table_rows(&(workspaces[i]));
45         }
46 }
47
48 static void new_container(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 }
55
56 /*
57  * Add one row to the table
58  *
59  */
60 void expand_table_rows(Workspace *workspace) {
61         int c;
62
63         workspace->rows++;
64
65         for (c = 0; c < workspace->cols; c++) {
66                 workspace->table[c] = realloc(workspace->table[c], sizeof(Container*) * workspace->rows);
67                 new_container(&(workspace->table[c][workspace->rows-1]));
68         }
69 }
70
71 /*
72  * Add one column to the table
73  *
74  */
75 void expand_table_cols(Workspace *workspace) {
76         int c;
77
78         workspace->cols++;
79
80         workspace->table = realloc(workspace->table, sizeof(Container**) * workspace->cols);
81         workspace->table[workspace->cols-1] = calloc(sizeof(Container*) * workspace->rows, 1);
82         for (c = 0; c < workspace->rows; c++)
83                 new_container(&(workspace->table[workspace->cols-1][c]));
84 }
85
86 /*
87  * Performs simple bounds checking for the given column/row
88  *
89  */
90 bool cell_exists(int col, int row) {
91         return (col >= 0 && col < c_ws->rows) &&
92                 (row >= 0 && row < c_ws->cols);
93 }