]> git.sur5r.net Git - i3/i3/blob - table.c
Implement more moving
[i3/i3] / table.c
1 /*
2  * This file provides functions for easier accessing of _the_ table
3  *
4  */
5 #include <stdio.h>
6 #include <assert.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <sys/types.h>
10 #include <unistd.h>
11 #include <stdbool.h>
12 #include <assert.h>
13
14 #include "data.h"
15 #include "table.h"
16
17 /* This is a two-dimensional dynamic array of Container-pointers. I’ve always wanted
18  * to be a three-star programmer :) */
19 Container ***table = NULL;
20
21 struct table_dimensions_t table_dims = {0, 0};
22
23 /*
24  * Initialize table
25  *
26  */
27 void init_table() {
28         expand_table_cols();
29         expand_table_rows();
30 }
31
32 /*
33  * Add one row to the table
34  *
35  */
36 void expand_table_rows() {
37         int c;
38         Container *new;
39
40         table_dims.y++;
41
42         for (c = 0; c < table_dims.x; c++) {
43                 table[c] = realloc(table[c], sizeof(Container*) * table_dims.y);
44                 new = table[c][table_dims.y-1] = calloc(sizeof(Container), 1);
45                 CIRCLEQ_INIT(&(new->clients));
46         }
47 }
48
49 /*
50  * Add one column to the table
51  *
52  */
53 void expand_table_cols() {
54         int c;
55         Container *new;
56
57         table_dims.x++;
58         table = realloc(table, sizeof(Container**) * table_dims.x);
59         table[table_dims.x-1] = calloc(sizeof(Container*) * table_dims.y, 1);
60         for (c = 0; c < table_dims.y; c++) {
61                 new = table[table_dims.x-1][c] = calloc(sizeof(Container), 1);
62                 CIRCLEQ_INIT(&(new->clients));
63         }
64 }
65
66 /*
67  * Performs simple bounds checking for the given column/row
68  *
69  */
70 bool cell_exists(int col, int row) {
71         return (col >= 0 && col < table_dims.x) &&
72                 (row >= 0 && row < table_dims.y);
73 }