]> git.sur5r.net Git - i3/i3/blob - include/data.h
3f35c595c08e57f28bea9db17ecb999c316fd344
[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         /** Name of the workspace (in UCS-2) */
169         char *name;
170
171         /** Length of the workspace’s name (in glyphs) */
172         int name_len;
173
174         /** Width of the workspace’s name (in pixels) rendered in config.font */
175         int text_width;
176
177         /** x, y, width, height */
178         Rect rect;
179
180         /** table dimensions */
181         int cols;
182         /** table dimensions */
183         int rows;
184
185         /** These are stored here only while this workspace is _not_ shown
186          * (see show_workspace()) */
187         int current_row;
188         /** These are stored here only while this workspace is _not_ shown
189          * (see show_workspace()) */
190         int current_col;
191
192         /** Should clients on this workspace be automatically floating? */
193         bool auto_float;
194         /** Are the floating clients on this workspace currently hidden? */
195         bool floating_hidden;
196
197         /** A <screen> specifier on which this workspace would like to be (if
198          * the screen is available). screen := <number> | <position> */
199         char *preferred_screen;
200
201         /** Temporary flag needed for re-querying xinerama screens */
202         bool reassigned;
203
204         /** True if any client on this workspace has its urgent flag set */
205         bool urgent;
206
207         /** the client who is started in fullscreen mode on this workspace,
208          * NULL if there is none */
209         Client *fullscreen_client;
210
211         /** The focus stack contains the clients in the correct order of focus
212            so that the focus can be reverted correctly when a client is
213            closed */
214         SLIST_HEAD(focus_stack_head, Client) focus_stack;
215
216         /** This tail queue contains the floating clients in order of when
217          * they were first set to floating (new floating clients are just
218          * appended) */
219         TAILQ_HEAD(floating_clients_head, Client) floating_clients;
220
221         /** Backpointer to the screen this workspace is on */
222         i3Screen *screen;
223
224         /** This is a two-dimensional dynamic array of
225          * Container-pointers. I’ve always wanted to be a three-star
226          * programmer :) */
227         Container ***table;
228
229         /** width_factor and height_factor contain the amount of space
230          * (percentage) a column/row has of all the space which is available
231          * for resized windows. This ensures that non-resized windows (newly
232          * opened, for example) have the same size as always */
233         float *width_factor;
234         float *height_factor;
235 };
236
237 /**
238  * Holds a keybinding, consisting of a keycode combined with modifiers and the
239  * command which is executed as soon as the key is pressed (see src/command.c)
240  *
241  */
242 struct Binding {
243         /** Symbol the user specified in configfile, if any. This needs to be
244          * stored with the binding to be able to re-convert it into a keycode
245          * if the keyboard mapping changes (using Xmodmap for example) */
246         char *symbol;
247
248         /** Only in use if symbol != NULL. Gets set to the value to which the
249          * symbol got translated when binding. Useful for unbinding and
250          * checking which binding was used when a key press event comes in.
251          *
252          * This is an array of number_keycodes size. */
253         xcb_keycode_t *translated_to;
254
255         uint32_t number_keycodes;
256
257         /** Keycode to bind */
258         uint32_t keycode;
259
260         /** Bitmask consisting of BIND_MOD_1, BIND_MODE_SWITCH, … */
261         uint32_t mods;
262
263         /** Command, like in command mode */
264         char *command;
265
266         TAILQ_ENTRY(Binding) bindings;
267 };
268
269 /**
270  * Holds a command specified by an exec-line in the config (see src/config.c)
271  *
272  */
273 struct Autostart {
274         /** Command, like in command mode */
275         char *command;
276         TAILQ_ENTRY(Autostart) autostarts;
277 };
278
279 /**
280  * Holds an assignment for a given window class/title to a specific workspace
281  * (see src/config.c)
282  *
283  */
284 struct Assignment {
285         char *windowclass_title;
286         /** floating is true if this was an assignment to the special
287          * workspace "~".  Matching clients will be put into floating mode
288          * automatically. */
289         enum {
290                 ASSIGN_FLOATING_NO,   /* don’t float, but put on a workspace */
291                 ASSIGN_FLOATING_ONLY, /* float, but don’t assign on a workspace */
292                 ASSIGN_FLOATING       /* float and put on a workspace */
293         } floating;
294
295         /** The number of the workspace to assign to. */
296         int workspace;
297         TAILQ_ENTRY(Assignment) assignments;
298 };
299
300 /**
301  * Data structure for cached font information:
302  * - font id in X11 (load it once)
303  * - font height (multiple calls needed to get it)
304  *
305  */
306 struct Font {
307         /** The name of the font, that is what the pattern resolves to */
308         char *name;
309         /** A copy of the pattern to build a cache */
310         char *pattern;
311         /** The height of the font, built from font_ascent + font_descent */
312         int height;
313         /** The xcb-id for the font */
314         xcb_font_t id;
315
316         TAILQ_ENTRY(Font) fonts;
317 };
318
319 /**
320  * A client is X11-speak for a window.
321  *
322  */
323 struct Client {
324         /** initialized will be set to true if the client was fully
325          * initialized by manage_window() and all functions can be used
326          * normally */
327         bool initialized;
328
329         /** if you set a client to floating and set it back to managed, it
330          * does remember its old position and *tries* to get back there */
331         Cell old_position;
332
333         /** Backpointer. A client is inside a container */
334         Container *container;
335         /** Because dock clients don’t have a container, we have this
336          * workspace-backpointer */
337         Workspace *workspace;
338
339         /** x, y, width, height of the frame */
340         Rect rect;
341         /** Position in floating mode and in tiling mode are saved
342          * separately */
343         Rect floating_rect;
344         /** x, y, width, height of the child (relative to its frame) */
345         Rect child_rect;
346
347         /** contains the size calculated from the hints set by the window or 0
348          * if the client did not send any hints */
349         int proportional_height;
350         int proportional_width;
351
352         int base_height;
353         int base_width;
354
355         /** contains the minimum increment size as specified for the window
356          * (in pixels). */
357         int width_increment;
358         int height_increment;
359
360         /** Height which was determined by reading the _NET_WM_STRUT_PARTIAL
361          * top/bottom of the screen reservation */
362         int desired_height;
363
364         /** Name (= window title) */
365         char *name;
366         /** name_len stores the real string length (glyphs) of the window
367          * title if the client uses _NET_WM_NAME. Otherwise, it is set to -1
368          * to indicate that name should be just passed to X as 8-bit string
369          * and therefore will not be rendered correctly. This behaviour is to
370          * support legacy applications which do not set _NET_WM_NAME */
371         int name_len;
372         /** This will be set to true as soon as the first _NET_WM_NAME comes
373          * in. If set to true, legacy window names are ignored. */
374         bool uses_net_wm_name;
375
376         /** Holds the WM_CLASS, useful for matching the client in commands */
377         char *window_class;
378
379         /** Holds the client’s mark, for vim-like jumping */
380         char *mark;
381
382         /** Holds the xcb_window_t (just an ID) for the leader window (logical
383          * parent for toolwindows and similar floating windows) */
384         xcb_window_t leader;
385
386         /** fullscreen is pretty obvious */
387         bool fullscreen;
388
389         /** floating? (= not in tiling layout) This cannot be simply a bool
390          * because we want to keep track of whether the status was set by the
391          * application (by setting WM_CLASS to tools for example) or by the
392          * user. The user’s choice overwrites automatic mode, of course. The
393          * order of the values is important because we check with >=
394          * FLOATING_AUTO_ON if a client is floating. */
395         enum { FLOATING_AUTO_OFF = 0, FLOATING_USER_OFF = 1, FLOATING_AUTO_ON = 2, FLOATING_USER_ON = 3 } floating;
396
397         /** Ensure TITLEBAR_TOP maps to 0 because we use calloc for
398          * initialization later */
399         enum { TITLEBAR_TOP = 0, TITLEBAR_LEFT, TITLEBAR_RIGHT, TITLEBAR_BOTTOM, TITLEBAR_OFF } titlebar_position;
400
401         /** Contains a bool specifying whether this window should not be drawn
402          * with the usual decorations */
403         bool borderless;
404
405         /** If a client is set as a dock, it is placed at the very bottom of
406          * the screen and its requested size is used */
407         bool dock;
408
409         /** True if the client set the urgency flag in its WM_HINTS property */
410         bool urgent;
411
412         /* After leaving fullscreen mode, a client needs to be reconfigured
413          * (configuration = setting X, Y, width and height). By setting the
414          * force_reconfigure flag, render_layout() will reconfigure the
415          * client. */
416         bool force_reconfigure;
417
418         /* When reparenting a window, an unmap-notify is sent. As we delete
419          * windows when they’re unmapped, we need to ignore that
420          * one. Therefore, this flag is set when reparenting. */
421         bool awaiting_useless_unmap;
422
423         /* XCB contexts */
424         xcb_window_t frame;             /**< Our window: The frame around the
425                                          * client */
426         xcb_gcontext_t titlegc;         /**< The titlebar’s graphic context
427                                          * inside the frame */
428         xcb_window_t child;             /**< The client’s window */
429
430         /** The following entry provides the necessary list pointers to use
431          * Client with LIST_* macros */
432         CIRCLEQ_ENTRY(Client) clients;
433         SLIST_ENTRY(Client) dock_clients;
434         SLIST_ENTRY(Client) focus_clients;
435         TAILQ_ENTRY(Client) floating_clients;
436 };
437
438 /**
439  * A container is either in default, stacking or tabbed mode. There is one for
440  * each cell of the table.
441  *
442  */
443 struct Container {
444         /* Those are speaking for themselves: */
445         Client *currently_focused;
446         int colspan;
447         int rowspan;
448
449         /* Position of the container inside our table */
450         int row;
451         int col;
452         /* Xinerama: X/Y of the container */
453         int x;
454         int y;
455         /* Width/Height of the container. Changeable by the user */
456         int width;
457         int height;
458
459         /* When in stacking mode, we draw the titlebars of each client onto a
460          * separate window */
461         struct Stack_Window stack_win;
462
463         /* Backpointer to the workspace this container is in */
464         Workspace *workspace;
465
466         /* Ensure MODE_DEFAULT maps to 0 because we use calloc for
467          * initialization later */
468         enum { MODE_DEFAULT = 0, MODE_STACK, MODE_TABBED } mode;
469
470         /* When in stacking, one can either have unlimited windows inside the
471          * container or set a limit for the rows or columns the stack window
472          * should display to use the screen more efficiently. */
473         enum { STACK_LIMIT_NONE = 0, STACK_LIMIT_COLS, STACK_LIMIT_ROWS } stack_limit;
474
475         /* The number of columns or rows to limit to, see stack_limit */
476         int stack_limit_value;
477
478         CIRCLEQ_HEAD(client_head, Client) clients;
479 };
480
481 /**
482  * This is a virtual screen (Xinerama). This can be a single one, though two
483  * monitors might be connected, if you’re running clone mode. There can also
484  * be multiple of them.
485  *
486  */
487 struct Screen {
488         /** Virtual screen number */
489         int num;
490
491         /** Current workspace selected on this virtual screen */
492         int current_workspace;
493
494         /** x, y, width, height */
495         Rect rect;
496
497         /** The bar window */
498         xcb_window_t bar;
499         xcb_gcontext_t bargc;
500
501         /** Contains all clients with _NET_WM_WINDOW_TYPE ==
502          * _NET_WM_WINDOW_TYPE_DOCK */
503         SLIST_HEAD(dock_clients_head, Client) dock_clients;
504
505         TAILQ_ENTRY(Screen) screens;
506 };
507
508 #endif