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