]> git.sur5r.net Git - i3/i3/blob - include/data.h
Merge branch 'master' into next
[i3/i3] / include / data.h
1 /*
2  * vim:ts=4:sw=4:expandtab
3  *
4  * i3 - an improved dynamic tiling window manager
5  * © 2009-2012 Michael Stapelberg and contributors (see also: LICENSE)
6  *
7  * include/data.h: This file defines all data structures used by i3
8  *
9  */
10 #ifndef _DATA_H
11 #define _DATA_H
12
13 #define SN_API_NOT_YET_FROZEN 1
14 #include <libsn/sn-launcher.h>
15
16 #include <xcb/randr.h>
17 #include <xcb/xcb_atom.h>
18 #include <stdbool.h>
19 #include <pcre.h>
20
21 #include "queue.h"
22
23 /*
24  * To get the big concept: There are helper structures like struct
25  * Workspace_Assignment. Every struct which is also defined as type (see
26  * forward definitions) is considered to be a major structure, thus important.
27  *
28  * The following things are all stored in a 'Con', from very high level (the
29  * biggest Cons) to very small (a single window):
30  *
31  * 1) X11 root window (as big as all your outputs combined)
32  * 2) output (like LVDS1)
33  * 3) content container, dockarea containers
34  * 4) workspaces
35  * 5) split containers
36  * ... (you can arbitrarily nest split containers)
37  * 6) X11 window containers
38  *
39  */
40
41 /* Forward definitions */
42 typedef struct Binding Binding;
43 typedef struct Rect Rect;
44 typedef struct xoutput Output;
45 typedef struct Con Con;
46 typedef struct Match Match;
47 typedef struct Assignment Assignment;
48 typedef struct Window i3Window;
49
50
51 /******************************************************************************
52  * Helper types
53  *****************************************************************************/
54 typedef enum { D_LEFT, D_RIGHT, D_UP, D_DOWN } direction_t;
55 typedef enum { NO_ORIENTATION = 0, HORIZ, VERT } orientation_t;
56 typedef enum { BS_NORMAL = 0, BS_NONE = 1, BS_1PIXEL = 2 } border_style_t;
57
58 /** parameter to specify whether tree_close() and x_window_kill() should kill
59  * only this specific window or the whole X11 client */
60 typedef enum { DONT_KILL_WINDOW = 0, KILL_WINDOW = 1, KILL_CLIENT = 2 } kill_window_t;
61
62 enum {
63     BIND_NONE = 0,
64     BIND_SHIFT = XCB_MOD_MASK_SHIFT,        /* (1 << 0) */
65     BIND_CONTROL = XCB_MOD_MASK_CONTROL,    /* (1 << 2) */
66     BIND_MOD1 = XCB_MOD_MASK_1,             /* (1 << 3) */
67     BIND_MOD2 = XCB_MOD_MASK_2,             /* (1 << 4) */
68     BIND_MOD3 = XCB_MOD_MASK_3,             /* (1 << 5) */
69     BIND_MOD4 = XCB_MOD_MASK_4,             /* (1 << 6) */
70     BIND_MOD5 = XCB_MOD_MASK_5,             /* (1 << 7) */
71     BIND_MODE_SWITCH = (1 << 8)
72 };
73
74 /**
75  * Stores a rectangle, for example the size of a window, the child window etc.
76  * It needs to be packed so that the compiler will not add any padding bytes.
77  * (it is used in src/ewmh.c for example)
78  *
79  * Note that x and y can contain signed values in some cases (for example when
80  * used for the coordinates of a window, which can be set outside of the
81  * visible area, but not when specifying the position of a workspace for the
82  * _NET_WM_WORKAREA hint). Not declaring x/y as int32_t saves us a lot of
83  * typecasts.
84  *
85  */
86 struct Rect {
87     uint32_t x;
88     uint32_t y;
89     uint32_t width;
90     uint32_t height;
91 } __attribute__((packed));
92
93 /**
94  * Stores the reserved pixels on each screen edge read from a
95  * _NET_WM_STRUT_PARTIAL.
96  *
97  */
98 struct reservedpx {
99     uint32_t left;
100     uint32_t right;
101     uint32_t top;
102     uint32_t bottom;
103 };
104
105 /**
106  * Stores a width/height pair, used as part of deco_render_params to check
107  * whether the rects width/height have changed.
108  *
109  */
110 struct width_height {
111     uint32_t w;
112     uint32_t h;
113 };
114
115 /**
116  * Stores the parameters for rendering a window decoration. This structure is
117  * cached in every Con and no re-rendering will be done if the parameters have
118  * not changed (only the pixmaps will be copied).
119  *
120  */
121 struct deco_render_params {
122     struct Colortriple *color;
123     int border_style;
124     struct width_height con_rect;
125     struct width_height con_window_rect;
126     Rect con_deco_rect;
127     uint32_t background;
128     bool con_is_leaf;
129 };
130
131 /**
132  * Stores which workspace (by name) goes to which output.
133  *
134  */
135 struct Workspace_Assignment {
136     char *name;
137     char *output;
138
139     TAILQ_ENTRY(Workspace_Assignment) ws_assignments;
140 };
141
142 struct Ignore_Event {
143     int sequence;
144     int response_type;
145     time_t added;
146
147     SLIST_ENTRY(Ignore_Event) ignore_events;
148 };
149
150 /**
151  * Stores internal information about a startup sequence, like the workspace it
152  * was initiated on.
153  *
154  */
155 struct Startup_Sequence {
156     /** startup ID for this sequence, generated by libstartup-notification */
157     char *id;
158     /** workspace on which this startup was initiated */
159     char *workspace;
160     /** libstartup-notification context for this launch */
161     SnLauncherContext *context;
162
163     TAILQ_ENTRY(Startup_Sequence) sequences;
164 };
165
166 /**
167  * Regular expression wrapper. It contains the pattern itself as a string (like
168  * ^foo[0-9]$) as well as a pointer to the compiled PCRE expression and the
169  * pcre_extra data returned by pcre_study().
170  *
171  * This makes it easier to have a useful logfile, including the matching or
172  * non-matching pattern.
173  *
174  */
175 struct regex {
176     char *pattern;
177     pcre *regex;
178     pcre_extra *extra;
179 };
180
181 /******************************************************************************
182  * Major types
183  *****************************************************************************/
184
185 /**
186  * Holds a keybinding, consisting of a keycode combined with modifiers and the
187  * command which is executed as soon as the key is pressed (see src/cfgparse.y)
188  *
189  */
190 struct Binding {
191     /** Symbol the user specified in configfile, if any. This needs to be
192      * stored with the binding to be able to re-convert it into a keycode
193      * if the keyboard mapping changes (using Xmodmap for example) */
194     char *symbol;
195
196     /** Only in use if symbol != NULL. Gets set to the value to which the
197      * symbol got translated when binding. Useful for unbinding and
198      * checking which binding was used when a key press event comes in.
199      *
200      * This is an array of number_keycodes size. */
201     xcb_keycode_t *translated_to;
202
203     uint32_t number_keycodes;
204
205     /** Keycode to bind */
206     uint32_t keycode;
207
208     /** Bitmask consisting of BIND_MOD_1, BIND_MODE_SWITCH, … */
209     uint32_t mods;
210
211     /** Command, like in command mode */
212     char *command;
213
214     TAILQ_ENTRY(Binding) bindings;
215 };
216
217 /**
218  * Holds a command specified by either an:
219  * - exec-line
220  * - exec_always-line
221  * in the config (see src/config.c)
222  *
223  */
224 struct Autostart {
225     /** Command, like in command mode */
226     char *command;
227     /** no_startup_id flag for start_application(). Determines whether a
228      * startup notification context/ID should be created. */
229     bool no_startup_id;
230     TAILQ_ENTRY(Autostart) autostarts;
231     TAILQ_ENTRY(Autostart) autostarts_always;
232 };
233
234 /**
235  * An Output is a physical output on your graphics driver. Outputs which
236  * are currently in use have (output->active == true). Each output has a
237  * position and a mode. An output usually corresponds to one connected
238  * screen (except if you are running multiple screens in clone mode).
239  *
240  */
241 struct xoutput {
242     /** Output id, so that we can requery the output directly later */
243     xcb_randr_output_t id;
244     /** Name of the output */
245     char *name;
246
247     /** Pointer to the Con which represents this output */
248     Con *con;
249
250     /** Whether the output is currently active (has a CRTC attached with a
251      * valid mode) */
252     bool active;
253
254     /** Internal flags, necessary for querying RandR screens (happens in
255      * two stages) */
256     bool changed;
257     bool to_be_disabled;
258     bool primary;
259
260     /** x, y, width, height */
261     Rect rect;
262
263     TAILQ_ENTRY(xoutput) outputs;
264 };
265
266 /**
267  * A 'Window' is a type which contains an xcb_window_t and all the related
268  * information (hints like _NET_WM_NAME for that window).
269  *
270  */
271 struct Window {
272     xcb_window_t id;
273
274     /** Holds the xcb_window_t (just an ID) for the leader window (logical
275      * parent for toolwindows and similar floating windows) */
276     xcb_window_t leader;
277     xcb_window_t transient_for;
278
279     char *class_class;
280     char *class_instance;
281
282     /** The name of the window as it will be passed to X11 (in UCS2 if the
283      * application supports _NET_WM_NAME, in COMPOUND_TEXT otherwise). */
284     char *name_x;
285
286     /** The WM_WINDOW_ROLE of this window (for example, the pidgin buddy window
287      * sets "buddy list"). Useful to match specific windows in assignments or
288      * for_window. */
289     char *role;
290
291     /** Flag to force re-rendering the decoration upon changes */
292     bool name_x_changed;
293
294     /** The name of the window as used in JSON (in UTF-8 if the application
295      * supports _NET_WM_NAME, in COMPOUND_TEXT otherwise) */
296     char *name_json;
297
298     /** The length of the name in glyphs (not bytes) */
299     size_t name_len;
300
301     /** Whether the application used _NET_WM_NAME */
302     bool uses_net_wm_name;
303
304     /** Whether the application needs to receive WM_TAKE_FOCUS */
305     bool needs_take_focus;
306
307     /** Whether this window accepts focus. We store this inverted so that the
308      * default will be 'accepts focus'. */
309     bool doesnt_accept_focus;
310
311     /** Whether the window says it is a dock window */
312     enum { W_NODOCK = 0, W_DOCK_TOP = 1, W_DOCK_BOTTOM = 2 } dock;
313
314     /** Pixels the window reserves. left/right/top/bottom */
315     struct reservedpx reserved;
316
317     /** Pointers to the Assignments which were already ran for this Window
318      * (assignments run only once) */
319     uint32_t nr_assignments;
320     Assignment **ran_assignments;
321 };
322
323 /**
324  * A "match" is a data structure which acts like a mask or expression to match
325  * certain windows or not. For example, when using commands, you can specify a
326  * command like this: [title="*Firefox*"] kill. The title member of the match
327  * data structure will then be filled and i3 will check each window using
328  * match_matches_window() to find the windows affected by this command.
329  *
330  */
331 struct Match {
332     struct regex *title;
333     struct regex *application;
334     struct regex *class;
335     struct regex *instance;
336     struct regex *mark;
337     struct regex *role;
338     enum {
339         M_DONTCHECK = -1,
340         M_NODOCK = 0,
341         M_DOCK_ANY = 1,
342         M_DOCK_TOP = 2,
343         M_DOCK_BOTTOM = 3
344     } dock;
345     xcb_window_t id;
346     Con *con_id;
347     enum { M_ANY = 0, M_TILING, M_FLOATING } floating;
348
349     /* Where the window looking for a match should be inserted:
350      *
351      * M_HERE   = the matched container will be replaced by the window
352      *            (layout saving)
353      * M_ASSIGN_WS = the matched container will be inserted in the target_ws.
354      * M_BELOW  = the window will be inserted as a child of the matched container
355      *            (dockareas)
356      *
357      */
358     enum { M_HERE = 0, M_ASSIGN_WS, M_BELOW } insert_where;
359
360     TAILQ_ENTRY(Match) matches;
361 };
362
363 /**
364  * An Assignment makes specific windows go to a specific workspace/output or
365  * run a command for that window. With this mechanism, the user can -- for
366  * example -- assign his browser to workspace "www". Checking if a window is
367  * assigned works by comparing the Match data structure with the window (see
368  * match_matches_window()).
369  *
370  */
371 struct Assignment {
372     /** type of this assignment:
373      *
374      * A_COMMAND = run the specified command for the matching window
375      * A_TO_WORKSPACE = assign the matching window to the specified workspace
376      * A_TO_OUTPUT = assign the matching window to the specified output
377      *
378      * While the type is a bitmask, only one value can be set at a time. It is
379      * a bitmask to allow filtering for multiple types, for example in the
380      * assignment_for() function.
381      *
382      */
383     enum {
384         A_ANY          = 0,
385         A_COMMAND      = (1 << 0),
386         A_TO_WORKSPACE = (1 << 1),
387         A_TO_OUTPUT    = (1 << 2)
388     } type;
389
390     /** the criteria to check if a window matches */
391     Match match;
392
393     /** destination workspace/output/command, depending on the type */
394     union {
395         char *command;
396         char *workspace;
397         char *output;
398     } dest;
399
400     TAILQ_ENTRY(Assignment) assignments;
401 };
402
403 /**
404  * A 'Con' represents everything from the X11 root window down to a single X11 window.
405  *
406  */
407 struct Con {
408     bool mapped;
409     enum {
410         CT_ROOT = 0,
411         CT_OUTPUT = 1,
412         CT_CON = 2,
413         CT_FLOATING_CON = 3,
414         CT_WORKSPACE = 4,
415         CT_DOCKAREA = 5
416     } type;
417     orientation_t orientation;
418     struct Con *parent;
419
420     struct Rect rect;
421     struct Rect window_rect;
422     struct Rect deco_rect;
423     /** the geometry this window requested when getting mapped */
424     struct Rect geometry;
425
426     char *name;
427
428     /** the workspace number, if this Con is of type CT_WORKSPACE and the
429      * workspace is not a named workspace (for named workspaces, num == -1) */
430     int num;
431
432     /* a sticky-group is an identifier which bundles several containers to a
433      * group. The contents are shared between all of them, that is they are
434      * displayed on whichever of the containers is currently visible */
435     char *sticky_group;
436
437     /* user-definable mark to jump to this container later */
438     char *mark;
439
440     double percent;
441
442     /* proportional width/height, calculated from WM_NORMAL_HINTS, used to
443      * apply an aspect ratio to windows (think of MPlayer) */
444     int proportional_width;
445     int proportional_height;
446     /* the wanted size of the window, used in combination with size
447      * increments (see below). */
448     int base_width;
449     int base_height;
450
451     /* the x11 border pixel attribute */
452     int border_width;
453
454     /* minimum increment size specified for the window (in pixels) */
455     int width_increment;
456     int height_increment;
457
458     struct Window *window;
459
460     /* Should this container be marked urgent? This gets set when the window
461      * inside this container (if any) sets the urgency hint, for example. */
462     bool urgent;
463
464     /* ids/pixmap/graphics context for the frame window */
465     xcb_window_t frame;
466     xcb_pixmap_t pixmap;
467     xcb_gcontext_t pm_gc;
468     bool pixmap_recreated;
469
470     /** Cache for the decoration rendering */
471     struct deco_render_params *deco_render_params;
472
473     /* Only workspace-containers can have floating clients */
474     TAILQ_HEAD(floating_head, Con) floating_head;
475
476     TAILQ_HEAD(nodes_head, Con) nodes_head;
477     TAILQ_HEAD(focus_head, Con) focus_head;
478
479     TAILQ_HEAD(swallow_head, Match) swallow_head;
480
481     enum { CF_NONE = 0, CF_OUTPUT = 1, CF_GLOBAL = 2 } fullscreen_mode;
482     enum { L_DEFAULT = 0, L_STACKED = 1, L_TABBED = 2, L_DOCKAREA = 3, L_OUTPUT = 4 } layout;
483     border_style_t border_style;
484     /** floating? (= not in tiling layout) This cannot be simply a bool
485      * because we want to keep track of whether the status was set by the
486      * application (by setting _NET_WM_WINDOW_TYPE appropriately) or by the
487      * user. The user’s choice overwrites automatic mode, of course. The
488      * order of the values is important because we check with >=
489      * FLOATING_AUTO_ON if a client is floating. */
490     enum {
491         FLOATING_AUTO_OFF = 0,
492         FLOATING_USER_OFF = 1,
493         FLOATING_AUTO_ON = 2,
494         FLOATING_USER_ON = 3
495     } floating;
496
497     /** This counter contains the number of UnmapNotify events for this
498      * container (or, more precisely, for its ->frame) which should be ignored.
499      * UnmapNotify events need to be ignored when they are caused by i3 itself,
500      * for example when reparenting or when unmapping the window on a workspace
501      * change. */
502     uint8_t ignore_unmap;
503
504     TAILQ_ENTRY(Con) nodes;
505     TAILQ_ENTRY(Con) focused;
506     TAILQ_ENTRY(Con) all_cons;
507     TAILQ_ENTRY(Con) floating_windows;
508
509     /** callbacks */
510     void(*on_remove_child)(Con *);
511
512     enum {
513         SCRATCHPAD_NONE = 0,
514         SCRATCHPAD_FRESH = 1,
515         SCRATCHPAD_CHANGED = 2
516     } scratchpad_state;
517 };
518
519 #endif