]> git.sur5r.net Git - i3/i3/blob - include/data.h
154c0828d6b10b1cc6799516cf787ff01e66af2e
[i3/i3] / include / data.h
1 /*
2  * vim:ts=8:expandtab
3  *
4  * i3 - an improved dynamic tiling window manager
5  *
6  * © 2009-2010 Michael Stapelberg and contributors
7  *
8  * See file LICENSE for license information.
9  *
10  * include/data.h: This file defines all data structures used by i3
11  *
12  */
13 #include <xcb/xcb.h>
14 #include <xcb/randr.h>
15 #include <xcb/xcb_atom.h>
16 #include <stdbool.h>
17
18 #ifndef _DATA_H
19 #define _DATA_H
20 #include "queue.h"
21
22 /*
23  * To get the big concept: There are helper structures like struct Colorpixel
24  * or struct Stack_Window. Everything which is also defined as type (see
25  * forward definitions) is considered to be a major structure, thus important.
26  *
27  * Let’s start from the biggest to the smallest:
28  *
29  * TODO
30  *
31  */
32
33 /* Forward definitions */
34 typedef struct Font i3Font;
35 typedef struct Binding Binding;
36 typedef struct Rect Rect;
37 typedef struct xoutput Output;
38 typedef struct Con Con;
39 typedef struct Match Match;
40 typedef struct Window i3Window;
41
42
43 /******************************************************************************
44  * Helper types
45  *****************************************************************************/
46 typedef enum { D_LEFT, D_RIGHT, D_UP, D_DOWN } direction_t;
47 typedef enum { HORIZ, VERT, NO_ORIENTATION } orientation_t;
48
49 enum {
50         BIND_NONE = 0,
51         BIND_SHIFT = XCB_MOD_MASK_SHIFT,        /* (1 << 0) */
52         BIND_CONTROL = XCB_MOD_MASK_CONTROL,    /* (1 << 2) */
53         BIND_MOD1 = XCB_MOD_MASK_1,             /* (1 << 3) */
54         BIND_MOD2 = XCB_MOD_MASK_2,             /* (1 << 4) */
55         BIND_MOD3 = XCB_MOD_MASK_3,             /* (1 << 5) */
56         BIND_MOD4 = XCB_MOD_MASK_4,             /* (1 << 6) */
57         BIND_MOD5 = XCB_MOD_MASK_5,             /* (1 << 7) */
58         BIND_MODE_SWITCH = (1 << 8)
59 };
60
61 /**
62  * Stores a rectangle, for example the size of a window, the child window etc.
63  * It needs to be packed so that the compiler will not add any padding bytes.
64  * (it is used in src/ewmh.c for example)
65  *
66  * Note that x and y can contain signed values in some cases (for example when
67  * used for the coordinates of a window, which can be set outside of the
68  * visible area, but not when specifying the position of a workspace for the
69  * _NET_WM_WORKAREA hint). Not declaring x/y as int32_t saves us a lot of
70  * typecasts.
71  *
72  */
73 struct Rect {
74         uint32_t x;
75         uint32_t y;
76         uint32_t width;
77         uint32_t height;
78 } __attribute__((packed));
79
80 /**
81  * Used for the cache of colorpixels.
82  *
83  */
84 struct Colorpixel {
85         uint32_t pixel;
86         char *hex;
87         SLIST_ENTRY(Colorpixel) colorpixels;
88 };
89
90 struct Cached_Pixmap {
91         xcb_pixmap_t id;
92
93         /* We’re going to paint on it, so a graphics context will be needed */
94         xcb_gcontext_t gc;
95
96         /* The rect with which the pixmap was created */
97         Rect rect;
98
99         /* The rect of the object to which this pixmap belongs. Necessary to
100          * find out when we need to re-create the pixmap. */
101         Rect *referred_rect;
102
103         xcb_drawable_t referred_drawable;
104 };
105
106 struct Ignore_Event {
107         int sequence;
108         time_t added;
109
110         SLIST_ENTRY(Ignore_Event) ignore_events;
111 };
112
113 /**
114  * Emulates the behaviour of tables of libxcb-wm, which in libxcb 0.3.4
115  * suddenly vanished.
116  *
117  */
118 struct keyvalue_element {
119         uint32_t key;
120         void *value;
121         TAILQ_ENTRY(keyvalue_element) elements;
122 };
123
124 /******************************************************************************
125  * Major types
126  *****************************************************************************/
127
128 /**
129  * Holds a keybinding, consisting of a keycode combined with modifiers and the
130  * command which is executed as soon as the key is pressed (see src/command.c)
131  *
132  */
133 struct Binding {
134         /** Symbol the user specified in configfile, if any. This needs to be
135          * stored with the binding to be able to re-convert it into a keycode
136          * if the keyboard mapping changes (using Xmodmap for example) */
137         char *symbol;
138
139         /** Only in use if symbol != NULL. Gets set to the value to which the
140          * symbol got translated when binding. Useful for unbinding and
141          * checking which binding was used when a key press event comes in.
142          *
143          * This is an array of number_keycodes size. */
144         xcb_keycode_t *translated_to;
145
146         uint32_t number_keycodes;
147
148         /** Keycode to bind */
149         uint32_t keycode;
150
151         /** Bitmask consisting of BIND_MOD_1, BIND_MODE_SWITCH, … */
152         uint32_t mods;
153
154         /** Command, like in command mode */
155         char *command;
156
157         TAILQ_ENTRY(Binding) bindings;
158 };
159
160 /**
161  * Holds a command specified by an exec-line in the config (see src/config.c)
162  *
163  */
164 struct Autostart {
165         /** Command, like in command mode */
166         char *command;
167         TAILQ_ENTRY(Autostart) autostarts;
168 };
169
170 /**
171  * Holds an assignment for a given window class/title to a specific workspace
172  * (see src/config.c)
173  *
174  */
175 struct Assignment {
176         char *windowclass_title;
177         /** floating is true if this was an assignment to the special
178          * workspace "~".  Matching clients will be put into floating mode
179          * automatically. */
180         enum {
181                 ASSIGN_FLOATING_NO,   /* don’t float, but put on a workspace */
182                 ASSIGN_FLOATING_ONLY, /* float, but don’t assign on a workspace */
183                 ASSIGN_FLOATING       /* float and put on a workspace */
184         } floating;
185
186         /** The number of the workspace to assign to. */
187         int workspace;
188         TAILQ_ENTRY(Assignment) assignments;
189 };
190
191 /**
192  * Data structure for cached font information:
193  * - font id in X11 (load it once)
194  * - font height (multiple calls needed to get it)
195  *
196  */
197 struct Font {
198         /** The name of the font, that is what the pattern resolves to */
199         char *name;
200         /** A copy of the pattern to build a cache */
201         char *pattern;
202         /** The height of the font, built from font_ascent + font_descent */
203         int height;
204         /** The xcb-id for the font */
205         xcb_font_t id;
206
207         TAILQ_ENTRY(Font) fonts;
208 };
209
210
211 /**
212  * An Output is a physical output on your graphics driver. Outputs which
213  * are currently in use have (output->active == true). Each output has a
214  * position and a mode. An output usually corresponds to one connected
215  * screen (except if you are running multiple screens in clone mode).
216  *
217  */
218 struct xoutput {
219         /** Output id, so that we can requery the output directly later */
220         xcb_randr_output_t id;
221         /** Name of the output */
222         char *name;
223
224         /** Whether the output is currently active (has a CRTC attached with a
225          * valid mode) */
226         bool active;
227
228         /** Internal flags, necessary for querying RandR screens (happens in
229          * two stages) */
230         bool changed;
231         bool to_be_disabled;
232
233         /** x, y, width, height */
234         Rect rect;
235
236         /** The bar window */
237         xcb_window_t bar;
238         xcb_gcontext_t bargc;
239
240         /** Contains all clients with _NET_WM_WINDOW_TYPE ==
241          * _NET_WM_WINDOW_TYPE_DOCK */
242         SLIST_HEAD(dock_clients_head, Client) dock_clients;
243
244         TAILQ_ENTRY(xoutput) outputs;
245 };
246
247 struct Window {
248     xcb_window_t id;
249
250     const char *class_class;
251     const char *class_instance;
252     const char *name_ucs2;
253     const char *name_utf8;
254     int name_len;
255     bool uses_net_wm_name;
256 };
257
258 struct Match {
259     enum { M_WINDOW, M_CON } what;
260
261     char *title;
262     int title_len;
263     char *application;
264     char *class;
265     char *instance;
266     xcb_window_t id;
267     bool floating;
268
269     enum { M_GLOBAL, M_OUTPUT, M_WORKSPACE } levels;
270
271     enum { M_USER, M_RESTART } source;
272
273     /* wo das fenster eingefügt werden soll. bei here wird es direkt
274      * diesem Con zugewiesen, also layout saving. bei active ist es
275      * ein assignment, welches an der momentan fokussierten stelle einfügt */
276     enum { M_HERE, M_ACTIVE } insert_where;
277
278     TAILQ_ENTRY(Match) matches;
279 };
280
281 struct Con {
282     bool mapped;
283     enum { CT_ROOT = 0, CT_OUTPUT = 1, CT_CON = 2, CT_FLOATING_CON = 3 } type;
284     orientation_t orientation;
285     struct Con *parent;
286     /* parent before setting it to floating */
287     struct Con *old_parent;
288
289     struct Rect rect;
290     struct Rect window_rect;
291     struct Rect deco_rect;
292
293     char *name;
294
295     double percent;
296
297     struct Window *window;
298
299     /* ids/gc for the frame window */
300     xcb_window_t frame;
301     xcb_gcontext_t gc;
302
303     /* Only workspace-containers can have floating clients */
304     TAILQ_HEAD(floating_head, Con) floating_head;
305
306     TAILQ_HEAD(nodes_head, Con) nodes_head;
307     TAILQ_HEAD(focus_head, Con) focus_head;
308
309     TAILQ_HEAD(swallow_head, Match) swallow_head;
310
311     enum { CF_NONE = 0, CF_OUTPUT = 1, CF_GLOBAL = 2 } fullscreen_mode;
312     enum { L_DEFAULT = 0, L_STACKED = 1, L_TABBED = 2 } layout;
313     /** floating? (= not in tiling layout) This cannot be simply a bool
314      * because we want to keep track of whether the status was set by the
315      * application (by setting _NET_WM_WINDOW_TYPE appropriately) or by the
316      * user. The user’s choice overwrites automatic mode, of course. The
317      * order of the values is important because we check with >=
318      * FLOATING_AUTO_ON if a client is floating. */
319     enum {
320         FLOATING_AUTO_OFF = 0,
321         FLOATING_USER_OFF = 1,
322         FLOATING_AUTO_ON = 2,
323         FLOATING_USER_ON = 3
324     } floating;
325
326
327     TAILQ_ENTRY(Con) nodes;
328     TAILQ_ENTRY(Con) focused;
329     TAILQ_ENTRY(Con) all_cons;
330     TAILQ_ENTRY(Con) floating_windows;
331 };
332
333 #endif