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