]> git.lizzy.rs Git - bspwm.git/blob - types.h
Prevent potential memory leak
[bspwm.git] / types.h
1 /* Copyright (c) 2012, Bastien Dejean
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice, this
8  *    list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright notice,
10  *    this list of conditions and the following disclaimer in the documentation
11  *    and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  */
24
25 #ifndef BSPWM_TYPES_H
26 #define BSPWM_TYPES_H
27 #include <stdbool.h>
28 #include <xcb/xcb.h>
29 #include <xcb/randr.h>
30 #include <xcb/xcb_event.h>
31 #include "helpers.h"
32
33 #define MISSING_VALUE        "N/A"
34 #define MAX_STATE            4
35
36 typedef enum {
37         TYPE_HORIZONTAL,
38         TYPE_VERTICAL
39 } split_type_t;
40
41 typedef enum {
42         MODE_AUTOMATIC,
43         MODE_MANUAL
44 } split_mode_t;
45
46 typedef enum {
47         STATE_TILED,
48         STATE_PSEUDO_TILED,
49         STATE_FLOATING,
50         STATE_FULLSCREEN
51 } client_state_t;
52
53 typedef enum {
54         LAYER_BELOW,
55         LAYER_NORMAL,
56         LAYER_ABOVE
57 } stack_layer_t;
58
59 typedef enum {
60         OPTION_NONE,
61         OPTION_TRUE,
62         OPTION_FALSE
63 } option_bool_t;
64
65 typedef enum {
66         ALTER_TOGGLE,
67         ALTER_SET
68 } alter_state_t;
69
70 typedef enum {
71         CYCLE_NEXT,
72         CYCLE_PREV
73 } cycle_dir_t;
74
75 typedef enum {
76         CIRCULATE_FORWARD,
77         CIRCULATE_BACKWARD
78 } circulate_dir_t;
79
80 typedef enum {
81         HISTORY_OLDER,
82         HISTORY_NEWER
83 } history_dir_t;
84
85 typedef enum {
86         DIR_RIGHT,
87         DIR_DOWN,
88         DIR_LEFT,
89         DIR_UP
90 } direction_t;
91
92 typedef enum {
93         CORNER_TOP_LEFT,
94         CORNER_TOP_RIGHT,
95         CORNER_BOTTOM_RIGHT,
96         CORNER_BOTTOM_LEFT
97 } corner_t;
98
99 typedef enum {
100         SIDE_LEFT,
101         SIDE_TOP,
102         SIDE_RIGHT,
103         SIDE_BOTTOM
104 } side_t;
105
106 typedef enum {
107         ACTION_NONE,
108         ACTION_FOCUS,
109         ACTION_MOVE,
110         ACTION_RESIZE_SIDE,
111         ACTION_RESIZE_CORNER
112 } pointer_action_t;
113
114 typedef enum {
115         LAYOUT_TILED,
116         LAYOUT_MONOCLE
117 } layout_t;
118
119 typedef enum {
120         FLIP_HORIZONTAL,
121         FLIP_VERTICAL
122 } flip_t;
123
124 typedef enum {
125         FIRST_CHILD,
126         SECOND_CHILD
127 } child_polarity_t;
128
129 typedef struct {
130         option_bool_t tiled;
131         option_bool_t pseudo_tiled;
132         option_bool_t floating;
133         option_bool_t fullscreen;
134         option_bool_t locked;
135         option_bool_t sticky;
136         option_bool_t private;
137         option_bool_t urgent;
138         option_bool_t same_class;
139         option_bool_t automatic;
140         option_bool_t local;
141         option_bool_t focused;
142         stack_layer_t *layer;
143 } client_select_t;
144
145 typedef struct {
146         option_bool_t occupied;
147         option_bool_t urgent;
148         option_bool_t local;
149 } desktop_select_t;
150
151 typedef struct {
152         xcb_window_t window;
153         char class_name[3 * SMALEN / 2];
154         char instance_name[3 * SMALEN / 2];
155         unsigned int border_width;
156         bool locked;                            /* protects window from being closed */
157         bool sticky;
158         bool urgent;
159         bool private;
160         bool icccm_focus;
161         bool icccm_input;
162         client_state_t state;
163         client_state_t last_state;
164         stack_layer_t layer;
165         stack_layer_t last_layer;
166         xcb_rectangle_t floating_rectangle;
167         xcb_rectangle_t tiled_rectangle;
168         uint16_t min_width;
169         uint16_t max_width;
170         uint16_t min_height;
171         uint16_t max_height;
172         xcb_atom_t wm_state[MAX_STATE];
173         int num_states;
174 } client_t;
175
176 typedef struct node_t node_t;
177 struct node_t {
178         split_type_t split_type;
179         double split_ratio;
180         split_mode_t split_mode;
181         direction_t split_dir;
182         int birth_rotation;
183         xcb_rectangle_t rectangle;
184         bool vacant;                            /* vacant nodes only hold floating clients */
185         int privacy_level;
186         node_t *first_child;
187         node_t *second_child;
188         node_t *parent;
189         client_t *client;                       /* NULL except for leaves */
190 };
191
192 typedef struct desktop_t desktop_t;
193 struct desktop_t {
194         char name[SMALEN];
195         layout_t layout;
196         node_t *root;
197         node_t *focus;
198         desktop_t *prev;
199         desktop_t *next;
200         int top_padding;
201         int right_padding;
202         int bottom_padding;
203         int left_padding;
204         int window_gap;
205         unsigned int border_width;
206 };
207
208 typedef struct monitor_t monitor_t;
209 struct monitor_t {
210         char name[SMALEN];
211         xcb_randr_output_t id;
212         xcb_rectangle_t rectangle;
213         xcb_window_t root;
214         bool wired;
215         int top_padding;
216         int right_padding;
217         int bottom_padding;
218         int left_padding;
219         desktop_t *desk;
220         desktop_t *desk_head;
221         desktop_t *desk_tail;
222         monitor_t *prev;
223         monitor_t *next;
224         int num_sticky;
225 };
226
227 typedef struct {
228         monitor_t *monitor;
229         desktop_t *desktop;
230         node_t *node;
231 } coordinates_t;
232
233 typedef struct history_t history_t;
234 struct history_t {
235         coordinates_t loc;
236         bool latest;
237         history_t *prev;
238         history_t *next;
239 };
240
241 typedef struct stacking_list_t stacking_list_t;
242 struct stacking_list_t {
243         node_t *node;
244         stacking_list_t *prev;
245         stacking_list_t *next;
246 };
247
248 typedef struct subscriber_list_t subscriber_list_t;
249 struct subscriber_list_t {
250         int fd;
251         FILE *stream;
252         int field;
253         subscriber_list_t *prev;
254         subscriber_list_t *next;
255 };
256
257 typedef struct rule_t rule_t;
258 struct rule_t {
259         char cause[MAXLEN];
260         char effect[MAXLEN];
261         bool one_shot;
262         rule_t *prev;
263         rule_t *next;
264 };
265
266 typedef struct {
267         char class_name[3 * SMALEN / 2];
268         char instance_name[3 * SMALEN / 2];
269         char monitor_desc[MAXLEN];
270         char desktop_desc[MAXLEN];
271         char node_desc[MAXLEN];
272         char split_dir[SMALEN];
273         stack_layer_t *layer;
274         client_state_t *state;
275         double split_ratio;
276         uint16_t min_width;
277         uint16_t max_width;
278         uint16_t min_height;
279         uint16_t max_height;
280         bool locked;
281         bool sticky;
282         bool private;
283         bool center;
284         bool follow;
285         bool manage;
286         bool focus;
287         bool border;
288 } rule_consequence_t;
289
290 typedef struct pending_rule_t pending_rule_t;
291 struct pending_rule_t {
292         int fd;
293         xcb_window_t win;
294         rule_consequence_t *csq;
295         pending_rule_t *prev;
296         pending_rule_t *next;
297 };
298
299 typedef struct {
300         xcb_point_t position;
301         pointer_action_t action;
302         xcb_rectangle_t rectangle;
303         node_t *vertical_fence;
304         node_t *horizontal_fence;
305         monitor_t *monitor;
306         desktop_t *desktop;
307         node_t *node;
308         client_t *client;
309         xcb_window_t window;
310         bool is_tiled;
311         double vertical_ratio;
312         double horizontal_ratio;
313         corner_t corner;
314         side_t side;
315 } pointer_state_t;
316
317 typedef struct {
318         node_t *fence;
319         unsigned int distance;
320 } fence_distance_t;
321
322 #endif