-
Notifications
You must be signed in to change notification settings - Fork 0
/
venowm.h
178 lines (154 loc) · 4.46 KB
/
venowm.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#ifndef VENOWM_H
#define VENOWM_H
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include "backend.h"
#include "khash.h"
#include "logmsg.h"
// the main data types. Some are interdependent.
typedef struct {
be_screen_t *be_screen;
// more data to come at a later time
} screen_t;
typedef struct {
int refs; // how many workspaces is this window in?
be_window_t *be_window;
// windows may close or die while there are still open refs to this struct
bool isvalid;
// pointer to the screen the window is drawn on (or NULL if not drawn)
screen_t *screen;
// pointer to backend
backend_t *be;
} window_t;
// forward declaration of the special workspace hashtable
struct ws_win_info_t;
typedef struct ws_win_info_t ws_win_info_t;
// define our custom hash table type for "workspace window list" data
// name=wswl
// key type = workspace_t*
// value type = ws_win_info_t
// is_map = true (not a set)
// hash and equality functions are architecture-dependent
#if UINTPTR_MAX == 0xffffffffffffffffULL
// 64-bit
#define ptr_hash_func(ptr) kh_int64_hash_func((intptr_t)ptr)
#define ptr_equal_func(a, b) kh_int64_hash_equal(a, b)
#else
// 32-bit
#define ptr_hash_func(ptr) kh_int_hash_func((intptr_t)ptr)
#define ptr_equal_func(a, b) kh_int_hash_equal(a, b)
#endif
KHASH_INIT(wswl, window_t*, ws_win_info_t*, true,
ptr_hash_func, ptr_equal_func);
typedef struct split_t {
bool isleaf;
bool isvertical;
ws_win_info_t *win_info;
float fraction;
struct split_t *parent;
struct split_t *frames[2];
screen_t *screen;
} split_t;
/* workspace_t has a hashtable of workspace-specific information about each
window. workspace_t also has a queue of windows associated with the
workspace but which are hidden. This object is what gets stored in both
the hashmap and the queue, and it represents all of the reverse pointers a
hashmap has towards any window_t. */
struct ws_win_info_t {
window_t *window;
// frame which points to this window (must be NULL if window is in queue)
split_t *frame;
// queue element if window is hidden (must be NULL if window is in a frame)
struct ws_win_info_t *prev;
struct ws_win_info_t *next;
};
typedef struct {
// one root per screen
split_t **roots;
size_t roots_size;
size_t nroots;
// the focused frame, should always be a leaf
split_t *focus;
// hashtable of workspace-specific information about each window
kh_wswl_t *windows;
// a queue of windows associated with the workspace but which are hidden
ws_win_info_t *hidden_first;
ws_win_info_t *hidden_last;
// pointer to backend
backend_t *be;
} workspace_t;
// global variables
// in-focus elements
extern split_t *g_frame;
extern workspace_t *g_workspace;
extern screen_t **g_screens;
extern size_t g_screens_size;
extern size_t g_nscreens;
extern workspace_t **g_workspaces;
extern size_t g_workspaces_size;
extern size_t g_nworkspaces;
// macros for manipulating pointer/size/count triplets
#define INIT_PTR(ptr, size, num, mincount, err) { \
size_t newsize = 2; \
while(newsize < (mincount) * sizeof(*ptr)){ newsize *= 2; } \
ptr = malloc( newsize ); \
err = (ptr == NULL); \
if(!ptr){ \
err = -1; \
size = 0; \
num = 0; \
}else{ \
err = 0; \
size = newsize; \
num = 0; \
} \
}
#define APPEND_PTR(ptr, size, num, val, err){ \
err = 0; \
if(((num) + 1) * sizeof(*ptr) > size ){ \
void *temp = realloc(ptr, size * 2); \
if(!temp){ \
err = -1; \
}else{ \
size *= 2; \
ptr = temp; \
} \
} \
if(!err){ \
ptr[num++] = val; \
} \
}
#define REMOVE_PTR_IDX(ptr, size, num, i){ \
if(i == num - 1){ \
num--; \
}else{ \
memmove(&ptr[i], &ptr[i+1], sizeof(*ptr) * (num - i - 1)); \
num--; \
} \
}
#define REMOVE_PTR(ptr, size, num, val, removed){ \
removed = false; \
for(size_t i = 0; i < num; i++){ \
if(ptr[i] == val){ \
REMOVE_PTR_IDX(ptr, size, num, i); \
removed = true; \
break; \
} \
} \
}
#define PTR_CONTAINS(ptr, size, num, val, ret){ \
ret = false; \
for(size_t i = 0; i < num; i++){ \
if(ptr[i] == val){ \
ret = true; \
break; \
} \
} \
}
#define FREE_PTR(ptr, size, num){ \
free(ptr); \
size = 0; \
num = 0; \
}
#endif // VENOWM_H