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