]> git.sur5r.net Git - i3/i3/blob - include/data.h
5354217bcac24fda2b4cf3483359842c06b1d559
[i3/i3] / include / data.h
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  * include/data.h: This file defines all data structures used by i3
11  *
12  */
13 #include <xcb/xcb.h>
14 #include <xcb/xcb_atom.h>
15 #include <stdbool.h>
16
17 #ifndef _DATA_H
18 #define _DATA_H
19 #include "queue.h"
20
21 /*
22  * To get the big concept: There are helper structures like struct Colorpixel or
23  * struct Stack_Window. Everything which is also defined as type (see forward definitions)
24  * is considered to be a major structure, thus important.
25  *
26  * Let’s start from the biggest to the smallest:
27  * - An i3Screen is a virtual screen (Xinerama). This can be a single one, though two monitors
28  *   might be connected, if you’re running clone mode. There can also be multiple of them.
29  *
30  * - Each i3Screen contains Workspaces. The concept is known from various other window managers.
31  *   Basically, a workspace is a specific set of windows, usually grouped thematically (irc,
32  *   www, work, …). You can switch between these.
33  *
34  * - Each Workspace has a table, which is our layout abstraction. You manage your windows
35  *   by moving them around in your table. It grows as necessary.
36  *
37  * - Each cell of the table has a container, which can be in default or stacking mode. In default
38  *   mode, each client is given equally much space in the container. In stacking mode, only one
39  *   client is shown at a time, but all the titlebars are rendered at the top.
40  *
41  * - Inside the container are clients, which is X11-speak for a window.
42  *
43  */
44
45 /* Forward definitions */
46 typedef struct Cell Cell;
47 typedef struct Font i3Font;
48 typedef struct Container Container;
49 typedef struct Client Client;
50 typedef struct Binding Binding;
51 typedef struct Workspace Workspace;
52 typedef struct Rect Rect;
53 typedef struct Screen i3Screen;
54
55 /******************************************************************************
56  * Helper types
57  *****************************************************************************/
58 typedef enum { D_LEFT, D_RIGHT, D_UP, D_DOWN } direction_t;
59
60 enum {
61         BIND_NONE = 0,
62         BIND_SHIFT = XCB_MOD_MASK_SHIFT,        /* (1 << 0) */
63         BIND_CONTROL = XCB_MOD_MASK_CONTROL,    /* (1 << 2) */
64         BIND_MOD1 = XCB_MOD_MASK_1,             /* (1 << 3) */
65         BIND_MOD2 = XCB_MOD_MASK_2,             /* (1 << 4) */
66         BIND_MOD3 = XCB_MOD_MASK_3,             /* (1 << 5) */
67         BIND_MOD4 = XCB_MOD_MASK_4,             /* (1 << 6) */
68         BIND_MOD5 = XCB_MOD_MASK_5,             /* (1 << 7) */
69         BIND_MODE_SWITCH = (1 << 8)
70 };
71
72 struct Rect {
73         uint32_t x, y;
74         uint32_t width, height;
75 };
76
77 /*
78  * Defines a position in the table
79  *
80  */
81 struct Cell {
82         int row;
83         int column;
84 };
85
86 /*
87  * Used for the cache of colorpixels.
88  *
89  */
90 struct Colorpixel {
91         uint32_t pixel;
92
93         char *hex;
94
95         SLIST_ENTRY(Colorpixel) colorpixels;
96 };
97
98 /*
99  * Contains data for the windows needed to draw the titlebars on in stacking mode
100  *
101  */
102 struct Stack_Window {
103         xcb_window_t window;
104         xcb_gcontext_t gc;
105         Rect rect;
106
107         /* Backpointer to the container this stack window is in */
108         Container *container;
109
110         SLIST_ENTRY(Stack_Window) stack_windows;
111 };
112
113 struct Ignore_Event {
114         int sequence;
115         time_t added;
116
117         SLIST_ENTRY(Ignore_Event) ignore_events;
118 };
119
120 /*
121  * Emulates the behaviour of tables of libxcb-wm, which in libxcb 0.3.4 suddenly vanished.
122  *
123  */
124 struct keyvalue_element {
125         uint32_t key;
126         void *value;
127
128         TAILQ_ENTRY(keyvalue_element) elements;
129 };
130
131 typedef struct {
132         enum xcb_atom_fast_tag_t tag;
133         union {
134                 xcb_get_window_attributes_cookie_t cookie;
135                 uint8_t override_redirect;
136         } u;
137 } window_attributes_t;
138
139 /******************************************************************************
140  * Major types
141  *****************************************************************************/
142
143 /*
144  * The concept of Workspaces is known from various other window managers. Basically,
145  * a workspace is a specific set of windows, usually grouped thematically (irc,
146  * www, work, …). You can switch between these.
147  *
148  */
149 struct Workspace {
150         /* Number of this workspace, starting from 0 */
151         int num;
152
153         /* x, y, width, height */
154         Rect rect;
155
156         /* table dimensions */
157         int cols;
158         int rows;
159
160         /* These are stored here only while this workspace is _not_ shown (see show_workspace()) */
161         int current_row;
162         int current_col;
163
164         Client *fullscreen_client;
165
166         /* The focus stack contains the clients in the correct order of focus so that
167            the focus can be reverted correctly when a client is closed */
168         SLIST_HEAD(focus_stack_head, Client) focus_stack;
169
170         /* Backpointer to the screen this workspace is on */
171         i3Screen *screen;
172
173         /* This is a two-dimensional dynamic array of Container-pointers. I’ve always wanted
174          * to be a three-star programmer :) */
175         Container ***table;
176
177         /* width_factor and height_factor contain the amount of space (percentage) a column/row
178            has of all the space which is available for resized windows. This ensures that
179            non-resized windows (newly opened, for example) have the same size as always */
180         float *width_factor;
181         float *height_factor;
182 };
183
184 /*
185  * Holds a keybinding, consisting of a keycode combined with modifiers and the command
186  * which is executed as soon as the key is pressed (see src/command.c)
187  *
188  */
189 struct Binding {
190         /* Keycode to bind */
191         uint32_t keycode;
192         /* Bitmask consisting of BIND_MOD_1, BIND_MODE_SWITCH, … */
193         uint32_t mods;
194         /* Command, like in command mode */
195         char *command;
196
197         TAILQ_ENTRY(Binding) bindings;
198 };
199
200 /*
201  * Holds a command specified by an exec-line in the config (see src/config.c)
202  *
203  */
204 struct Autostart {
205         /* Command, like in command mode */
206         char *command;
207         TAILQ_ENTRY(Autostart) autostarts;
208 };
209
210 /*
211  * Holds an assignment for a given window class/title to a specific workspace
212  * (see src/config.c)
213  *
214  */
215 struct Assignment {
216         char *windowclass_title;
217         int workspace;
218         TAILQ_ENTRY(Assignment) assignments;
219 };
220
221 /*
222  * Data structure for cached font information:
223  * - font id in X11 (load it once)
224  * - font height (multiple calls needed to get it)
225  *
226  */
227 struct Font {
228         /* The name of the font, that is what the pattern resolves to */
229         char *name;
230         /* A copy of the pattern to build a cache */
231         char *pattern;
232         /* The height of the font, built from font_ascent + font_descent */
233         int height;
234         /* The xcb-id for the font */
235         xcb_font_t id;
236
237         TAILQ_ENTRY(Font) fonts;
238 };
239
240 /*
241  * A client is X11-speak for a window.
242  *
243  */
244 struct Client {
245         /* initialized will be set to true if the client was fully initialized by
246          * manage_window() and all functions can be used normally */
247         bool initialized;
248
249         /* if you set a client to floating and set it back to managed, it does remember its old
250            position and *tries* to get back there */
251         Cell old_position;
252
253         /* Backpointer. A client is inside a container */
254         Container *container;
255         /* Because dock clients don’t have a container, we have this workspace-backpointer */
256         Workspace *workspace;
257
258         /* x, y, width, height of the frame */
259         Rect rect;
260         /* Position in floating mode and in tiling mode are saved separately */
261         Rect floating_rect;
262         /* x, y, width, height of the child (relative to its frame) */
263         Rect child_rect;
264
265         /* contains the size calculated from the hints set by the window or 0 if the client
266            did not send any hints */
267         int proportional_height;
268         int proportional_width;
269
270         /* Height which was determined by reading the _NET_WM_STRUT_PARTIAL top/bottom of the screen
271            reservation */
272         int desired_height;
273
274         /* Name (= window title) */
275         char *name;
276         /* name_len stores the real string length (glyphs) of the window title if the client uses
277            _NET_WM_NAME. Otherwise, it is set to -1 to indicate that name should be just passed
278            to X as 8-bit string and therefore will not be rendered correctly. This behaviour is
279            to support legacy applications which do not set _NET_WM_NAME */
280         int name_len;
281         /* This will be set to true as soon as the first _NET_WM_NAME comes in. If set to true,
282            legacy window names are ignored. */
283         bool uses_net_wm_name;
284
285         /* Holds the WM_CLASS, useful for matching the client in commands */
286         char *window_class;
287
288         /* fullscreen is pretty obvious */
289         bool fullscreen;
290
291         /* floating? (= not in tiling layout) This cannot be simply a bool because we want to keep track
292          * of whether the status was set by the application (by setting WM_CLASS to tools for example) or
293          * by the user. The user’s choice overwrites automatic mode, of course. The order of the values
294          * is important because we check with >= FLOATING_AUTO_ON if a client is floating. */
295         enum { FLOATING_AUTO_OFF = 0, FLOATING_USER_OFF = 1, FLOATING_AUTO_ON = 2, FLOATING_USER_ON = 3 } floating;
296
297         /* Ensure TITLEBAR_TOP maps to 0 because we use calloc for initialization later */
298         enum { TITLEBAR_TOP = 0, TITLEBAR_LEFT, TITLEBAR_RIGHT, TITLEBAR_BOTTOM, TITLEBAR_OFF } titlebar_position;
299
300         /* If a client is set as a dock, it is placed at the very bottom of the screen and its
301            requested size is used */
302         bool dock;
303
304         /* After leaving fullscreen mode, a client needs to be reconfigured (configuration =
305            setting X, Y, width and height). By setting the force_reconfigure flag, render_layout()
306            will reconfigure the client. */
307         bool force_reconfigure;
308
309         /* When reparenting a window, an unmap-notify is sent. As we delete windows when they’re
310            unmapped, we need to ignore that one. Therefore, this flag is set when reparenting. */
311         bool awaiting_useless_unmap;
312
313         /* XCB contexts */
314         xcb_window_t frame;             /* Our window: The frame around the client */
315         xcb_gcontext_t titlegc;         /* The titlebar’s graphic context inside the frame */
316         xcb_window_t child;             /* The client’s window */
317
318         /* The following entry provides the necessary list pointers to use Client with LIST_* macros */
319         CIRCLEQ_ENTRY(Client) clients;
320         SLIST_ENTRY(Client) dock_clients;
321         SLIST_ENTRY(Client) focus_clients;
322 };
323
324 /*
325  * A container is either in default or stacking mode. It sits inside each cell of the table.
326  *
327  */
328 struct Container {
329         /* Those are speaking for themselves: */
330         Client *currently_focused;
331         int colspan;
332         int rowspan;
333
334         /* Position of the container inside our table */
335         int row;
336         int col;
337         /* Xinerama: X/Y of the container */
338         int x;
339         int y;
340         /* Width/Height of the container. Changeable by the user */
341         int width;
342         int height;
343
344         /* When in stacking mode, we draw the titlebars of each client onto a separate window */
345         struct Stack_Window stack_win;
346
347         /* Backpointer to the workspace this container is in */
348         Workspace *workspace;
349
350         /* Ensure MODE_DEFAULT maps to 0 because we use calloc for initialization later */
351         enum { MODE_DEFAULT = 0, MODE_STACK } mode;
352         CIRCLEQ_HEAD(client_head, Client) clients;
353 };
354
355 /*
356  * This is a virtual screen (Xinerama). This can be a single one, though two monitors
357  * might be connected, if you’re running clone mode. There can also be multiple of them.
358  *
359  */
360 struct Screen {
361         /* Virtual screen number */
362         int num;
363
364         /* Current workspace selected on this virtual screen */
365         int current_workspace;
366
367         /* x, y, width, height */
368         Rect rect;
369
370         /* The bar window */
371         xcb_window_t bar;
372         xcb_gcontext_t bargc;
373
374         /* Contains all clients with _NET_WM_WINDOW_TYPE == _NET_WM_WINDOW_TYPE_DOCK */
375         SLIST_HEAD(dock_clients_head, Client) dock_clients;
376
377         TAILQ_ENTRY(Screen) screens;
378 };
379
380 #endif