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