]> git.sur5r.net Git - i3/i3/blob - include/data.h
Implement the configuration option floating_modifier and document it
[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 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         /* Should clients on this workspace be automatically floating? */
165         bool auto_float;
166         /* Are the floating clients on this workspace currently hidden? */
167         bool floating_hidden;
168
169         Client *fullscreen_client;
170
171         /* The focus stack contains the clients in the correct order of focus so that
172            the focus can be reverted correctly when a client is closed */
173         SLIST_HEAD(focus_stack_head, Client) focus_stack;
174
175         /* This tail queue contains the floating clients in order of when they were first
176          * set to floating (new floating clients are just appended) */
177         TAILQ_HEAD(floating_clients_head, Client) floating_clients;
178
179         /* Backpointer to the screen this workspace is on */
180         i3Screen *screen;
181
182         /* This is a two-dimensional dynamic array of Container-pointers. I’ve always wanted
183          * to be a three-star programmer :) */
184         Container ***table;
185
186         /* width_factor and height_factor contain the amount of space (percentage) a column/row
187            has of all the space which is available for resized windows. This ensures that
188            non-resized windows (newly opened, for example) have the same size as always */
189         float *width_factor;
190         float *height_factor;
191 };
192
193 /*
194  * Holds a keybinding, consisting of a keycode combined with modifiers and the command
195  * which is executed as soon as the key is pressed (see src/command.c)
196  *
197  */
198 struct Binding {
199         /* Keycode to bind */
200         uint32_t keycode;
201         /* Bitmask consisting of BIND_MOD_1, BIND_MODE_SWITCH, … */
202         uint32_t mods;
203         /* Command, like in command mode */
204         char *command;
205
206         TAILQ_ENTRY(Binding) bindings;
207 };
208
209 /*
210  * Holds a command specified by an exec-line in the config (see src/config.c)
211  *
212  */
213 struct Autostart {
214         /* Command, like in command mode */
215         char *command;
216         TAILQ_ENTRY(Autostart) autostarts;
217 };
218
219 /*
220  * Holds an assignment for a given window class/title to a specific workspace
221  * (see src/config.c)
222  *
223  */
224 struct Assignment {
225         char *windowclass_title;
226         /* floating is true if this was an assignment to the special workspace "~".
227          * Matching clients will be put into floating mode automatically. */
228         bool floating;
229         int workspace;
230         TAILQ_ENTRY(Assignment) assignments;
231 };
232
233 /*
234  * Data structure for cached font information:
235  * - font id in X11 (load it once)
236  * - font height (multiple calls needed to get it)
237  *
238  */
239 struct Font {
240         /* The name of the font, that is what the pattern resolves to */
241         char *name;
242         /* A copy of the pattern to build a cache */
243         char *pattern;
244         /* The height of the font, built from font_ascent + font_descent */
245         int height;
246         /* The xcb-id for the font */
247         xcb_font_t id;
248
249         TAILQ_ENTRY(Font) fonts;
250 };
251
252 /*
253  * A client is X11-speak for a window.
254  *
255  */
256 struct Client {
257         /* initialized will be set to true if the client was fully initialized by
258          * manage_window() and all functions can be used normally */
259         bool initialized;
260
261         /* if you set a client to floating and set it back to managed, it does remember its old
262            position and *tries* to get back there */
263         Cell old_position;
264
265         /* Backpointer. A client is inside a container */
266         Container *container;
267         /* Because dock clients don’t have a container, we have this workspace-backpointer */
268         Workspace *workspace;
269
270         /* x, y, width, height of the frame */
271         Rect rect;
272         /* Position in floating mode and in tiling mode are saved separately */
273         Rect floating_rect;
274         /* x, y, width, height of the child (relative to its frame) */
275         Rect child_rect;
276
277         /* contains the size calculated from the hints set by the window or 0 if the client
278            did not send any hints */
279         int proportional_height;
280         int proportional_width;
281
282         /* Height which was determined by reading the _NET_WM_STRUT_PARTIAL top/bottom of the screen
283            reservation */
284         int desired_height;
285
286         /* Name (= window title) */
287         char *name;
288         /* name_len stores the real string length (glyphs) of the window title if the client uses
289            _NET_WM_NAME. Otherwise, it is set to -1 to indicate that name should be just passed
290            to X as 8-bit string and therefore will not be rendered correctly. This behaviour is
291            to support legacy applications which do not set _NET_WM_NAME */
292         int name_len;
293         /* This will be set to true as soon as the first _NET_WM_NAME comes in. If set to true,
294            legacy window names are ignored. */
295         bool uses_net_wm_name;
296
297         /* Holds the WM_CLASS, useful for matching the client in commands */
298         char *window_class;
299
300         /* fullscreen is pretty obvious */
301         bool fullscreen;
302
303         /* floating? (= not in tiling layout) This cannot be simply a bool because we want to keep track
304          * of whether the status was set by the application (by setting WM_CLASS to tools for example) or
305          * by the user. The user’s choice overwrites automatic mode, of course. The order of the values
306          * is important because we check with >= FLOATING_AUTO_ON if a client is floating. */
307         enum { FLOATING_AUTO_OFF = 0, FLOATING_USER_OFF = 1, FLOATING_AUTO_ON = 2, FLOATING_USER_ON = 3 } floating;
308
309         /* Ensure TITLEBAR_TOP maps to 0 because we use calloc for initialization later */
310         enum { TITLEBAR_TOP = 0, TITLEBAR_LEFT, TITLEBAR_RIGHT, TITLEBAR_BOTTOM, TITLEBAR_OFF } titlebar_position;
311
312         /* If a client is set as a dock, it is placed at the very bottom of the screen and its
313            requested size is used */
314         bool dock;
315
316         /* After leaving fullscreen mode, a client needs to be reconfigured (configuration =
317            setting X, Y, width and height). By setting the force_reconfigure flag, render_layout()
318            will reconfigure the client. */
319         bool force_reconfigure;
320
321         /* When reparenting a window, an unmap-notify is sent. As we delete windows when they’re
322            unmapped, we need to ignore that one. Therefore, this flag is set when reparenting. */
323         bool awaiting_useless_unmap;
324
325         /* XCB contexts */
326         xcb_window_t frame;             /* Our window: The frame around the client */
327         xcb_gcontext_t titlegc;         /* The titlebar’s graphic context inside the frame */
328         xcb_window_t child;             /* The client’s window */
329
330         /* The following entry provides the necessary list pointers to use Client with LIST_* macros */
331         CIRCLEQ_ENTRY(Client) clients;
332         SLIST_ENTRY(Client) dock_clients;
333         SLIST_ENTRY(Client) focus_clients;
334         TAILQ_ENTRY(Client) floating_clients;
335 };
336
337 /*
338  * A container is either in default or stacking mode. It sits inside each cell of the table.
339  *
340  */
341 struct Container {
342         /* Those are speaking for themselves: */
343         Client *currently_focused;
344         int colspan;
345         int rowspan;
346
347         /* Position of the container inside our table */
348         int row;
349         int col;
350         /* Xinerama: X/Y of the container */
351         int x;
352         int y;
353         /* Width/Height of the container. Changeable by the user */
354         int width;
355         int height;
356
357         /* When in stacking mode, we draw the titlebars of each client onto a separate window */
358         struct Stack_Window stack_win;
359
360         /* Backpointer to the workspace this container is in */
361         Workspace *workspace;
362
363         /* Ensure MODE_DEFAULT maps to 0 because we use calloc for initialization later */
364         enum { MODE_DEFAULT = 0, MODE_STACK } mode;
365         CIRCLEQ_HEAD(client_head, Client) clients;
366 };
367
368 /*
369  * This is a virtual screen (Xinerama). This can be a single one, though two monitors
370  * might be connected, if you’re running clone mode. There can also be multiple of them.
371  *
372  */
373 struct Screen {
374         /* Virtual screen number */
375         int num;
376
377         /* Current workspace selected on this virtual screen */
378         int current_workspace;
379
380         /* x, y, width, height */
381         Rect rect;
382
383         /* The bar window */
384         xcb_window_t bar;
385         xcb_gcontext_t bargc;
386
387         /* Contains all clients with _NET_WM_WINDOW_TYPE == _NET_WM_WINDOW_TYPE_DOCK */
388         SLIST_HEAD(dock_clients_head, Client) dock_clients;
389
390         TAILQ_ENTRY(Screen) screens;
391 };
392
393 #endif