]> git.sur5r.net Git - i3/i3/blob - include/data.h
Use libxkbcommon for translating keysyms, support all XKB groups.
[i3/i3] / include / data.h
1 /*
2  * vim:ts=4:sw=4:expandtab
3  *
4  * i3 - an improved dynamic tiling window manager
5  * © 2009 Michael Stapelberg and contributors (see also: LICENSE)
6  *
7  * include/data.h: This file defines all data structures used by i3
8  *
9  */
10 #pragma once
11
12 #define SN_API_NOT_YET_FROZEN 1
13 #include <libsn/sn-launcher.h>
14
15 #include <xcb/randr.h>
16 #include <stdbool.h>
17 #include <pcre.h>
18 #include <sys/time.h>
19
20 #include "libi3.h"
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  * Helper types
52  *****************************************************************************/
53 typedef enum { D_LEFT,
54                D_RIGHT,
55                D_UP,
56                D_DOWN } direction_t;
57 typedef enum { NO_ORIENTATION = 0,
58                HORIZ,
59                VERT } orientation_t;
60 typedef enum { BS_NORMAL = 0,
61                BS_NONE = 1,
62                BS_PIXEL = 2 } border_style_t;
63
64 /** parameter to specify whether tree_close() and x_window_kill() should kill
65  * only this specific window or the whole X11 client */
66 typedef enum { DONT_KILL_WINDOW = 0,
67                KILL_WINDOW = 1,
68                KILL_CLIENT = 2 } kill_window_t;
69
70 /** describes if the window is adjacent to the output (physical screen) edges. */
71 typedef enum { ADJ_NONE = 0,
72                ADJ_LEFT_SCREEN_EDGE = (1 << 0),
73                ADJ_RIGHT_SCREEN_EDGE = (1 << 1),
74                ADJ_UPPER_SCREEN_EDGE = (1 << 2),
75                ADJ_LOWER_SCREEN_EDGE = (1 << 4) } adjacent_t;
76
77 /**
78  * Container layouts. See Con::layout.
79  */
80 typedef enum {
81     L_DEFAULT = 0,
82     L_STACKED = 1,
83     L_TABBED = 2,
84     L_DOCKAREA = 3,
85     L_OUTPUT = 4,
86     L_SPLITV = 5,
87     L_SPLITH = 6
88 } layout_t;
89
90 /**
91  * Binding input types. See Binding::input_type.
92  */
93 typedef enum {
94     B_KEYBOARD = 0,
95     B_MOUSE = 1
96 } input_type_t;
97
98 /**
99  * Bitmask for matching XCB_XKB_GROUP_1 to XCB_XKB_GROUP_4.
100  */
101 typedef enum {
102     I3_XKB_GROUP_MASK_ANY = 0,
103     I3_XKB_GROUP_MASK_1 = (1 << 0),
104     I3_XKB_GROUP_MASK_2 = (1 << 1),
105     I3_XKB_GROUP_MASK_3 = (1 << 2),
106     I3_XKB_GROUP_MASK_4 = (1 << 3)
107 } i3_xkb_group_mask_t;
108
109 /**
110  * The lower 16 bits contain a xcb_key_but_mask_t, the higher 16 bits contain
111  * an i3_xkb_group_mask_t. This type is necessary for the fallback logic to
112  * work when handling XKB groups (see ticket #1775) and makes the code which
113  * locates keybindings upon KeyPress/KeyRelease events simpler.
114  */
115 typedef uint32_t i3_event_state_mask_t;
116
117 /**
118  * Mouse pointer warping modes.
119  */
120 typedef enum {
121     POINTER_WARPING_OUTPUT = 0,
122     POINTER_WARPING_NONE = 1
123 } warping_t;
124
125 /**
126  * Stores a rectangle, for example the size of a window, the child window etc.
127  * It needs to be packed so that the compiler will not add any padding bytes.
128  * (it is used in src/ewmh.c for example)
129  *
130  * Note that x and y can contain signed values in some cases (for example when
131  * used for the coordinates of a window, which can be set outside of the
132  * visible area, but not when specifying the position of a workspace for the
133  * _NET_WM_WORKAREA hint). Not declaring x/y as int32_t saves us a lot of
134  * typecasts.
135  *
136  */
137 struct Rect {
138     uint32_t x;
139     uint32_t y;
140     uint32_t width;
141     uint32_t height;
142 } __attribute__((packed));
143
144 /**
145  * Stores the reserved pixels on each screen edge read from a
146  * _NET_WM_STRUT_PARTIAL.
147  *
148  */
149 struct reservedpx {
150     uint32_t left;
151     uint32_t right;
152     uint32_t top;
153     uint32_t bottom;
154 };
155
156 /**
157  * Stores a width/height pair, used as part of deco_render_params to check
158  * whether the rects width/height have changed.
159  *
160  */
161 struct width_height {
162     uint32_t w;
163     uint32_t h;
164 };
165
166 /**
167  * Stores the parameters for rendering a window decoration. This structure is
168  * cached in every Con and no re-rendering will be done if the parameters have
169  * not changed (only the pixmaps will be copied).
170  *
171  */
172 struct deco_render_params {
173     struct Colortriple *color;
174     int border_style;
175     struct width_height con_rect;
176     struct width_height con_window_rect;
177     Rect con_deco_rect;
178     uint32_t background;
179     layout_t parent_layout;
180     bool con_is_leaf;
181 };
182
183 /**
184  * Stores which workspace (by name or number) goes to which output.
185  *
186  */
187 struct Workspace_Assignment {
188     char *name;
189     char *output;
190
191     TAILQ_ENTRY(Workspace_Assignment) ws_assignments;
192 };
193
194 struct Ignore_Event {
195     int sequence;
196     int response_type;
197     time_t added;
198
199     SLIST_ENTRY(Ignore_Event) ignore_events;
200 };
201
202 /**
203  * Stores internal information about a startup sequence, like the workspace it
204  * was initiated on.
205  *
206  */
207 struct Startup_Sequence {
208     /** startup ID for this sequence, generated by libstartup-notification */
209     char *id;
210     /** workspace on which this startup was initiated */
211     char *workspace;
212     /** libstartup-notification context for this launch */
213     SnLauncherContext *context;
214     /** time at which this sequence should be deleted (after it was marked as
215      * completed) */
216     time_t delete_at;
217
218     TAILQ_ENTRY(Startup_Sequence) sequences;
219 };
220
221 /**
222  * Regular expression wrapper. It contains the pattern itself as a string (like
223  * ^foo[0-9]$) as well as a pointer to the compiled PCRE expression and the
224  * pcre_extra data returned by pcre_study().
225  *
226  * This makes it easier to have a useful logfile, including the matching or
227  * non-matching pattern.
228  *
229  */
230 struct regex {
231     char *pattern;
232     pcre *regex;
233     pcre_extra *extra;
234 };
235
236 /******************************************************************************
237  * Major types
238  *****************************************************************************/
239
240 /**
241  * Holds a keybinding, consisting of a keycode combined with modifiers and the
242  * command which is executed as soon as the key is pressed (see
243  * src/config_parser.c)
244  *
245  */
246 struct Binding {
247     /* The type of input this binding is for. (Mouse bindings are not yet
248      * implemented. All bindings are currently assumed to be keyboard bindings.) */
249     input_type_t input_type;
250
251     /** If true, the binding should be executed upon a KeyRelease event, not a
252      * KeyPress (the default). */
253     enum {
254         /* This binding will only be executed upon KeyPress events */
255         B_UPON_KEYPRESS = 0,
256         /* This binding will be executed either upon a KeyRelease event, or… */
257         B_UPON_KEYRELEASE = 1,
258         /* …upon a KeyRelease event, even if the modifiers don’t match. This
259          * state is triggered from get_binding() when the corresponding
260          * KeyPress (!) happens, so that users can release the modifier keys
261          * before releasing the actual key. */
262         B_UPON_KEYRELEASE_IGNORE_MODS = 2,
263     } release;
264
265     /** If this is true for a mouse binding, the binding should be executed
266      * when the button is pressed over the window border. */
267     bool border;
268
269     /** If this is true for a mouse binding, the binding should be executed
270      * when the button is pressed over any part of the window, not just the
271      * title bar (default). */
272     bool whole_window;
273
274     uint32_t number_keycodes;
275
276     /** Keycode to bind */
277     uint32_t keycode;
278
279     /** Bitmask which is applied against event->state for KeyPress and
280      * KeyRelease events to determine whether this binding applies to the
281      * current state. */
282     i3_event_state_mask_t event_state_mask;
283
284     /** Symbol the user specified in configfile, if any. This needs to be
285      * stored with the binding to be able to re-convert it into a keycode
286      * if the keyboard mapping changes (using Xmodmap for example) */
287     char *symbol;
288
289     /** Only in use if symbol != NULL. Gets set to the value to which the
290      * symbol got translated when binding. Useful for unbinding and
291      * checking which binding was used when a key press event comes in.
292      *
293      * This is an array of number_keycodes size. */
294     xcb_keycode_t *translated_to;
295
296     /** Command, like in command mode */
297     char *command;
298
299     TAILQ_ENTRY(Binding) bindings;
300 };
301
302 /**
303  * Holds a command specified by either an:
304  * - exec-line
305  * - exec_always-line
306  * in the config (see src/config.c)
307  *
308  */
309 struct Autostart {
310     /** Command, like in command mode */
311     char *command;
312     /** no_startup_id flag for start_application(). Determines whether a
313      * startup notification context/ID should be created. */
314     bool no_startup_id;
315     TAILQ_ENTRY(Autostart) autostarts;
316     TAILQ_ENTRY(Autostart) autostarts_always;
317 };
318
319 /**
320  * An Output is a physical output on your graphics driver. Outputs which
321  * are currently in use have (output->active == true). Each output has a
322  * position and a mode. An output usually corresponds to one connected
323  * screen (except if you are running multiple screens in clone mode).
324  *
325  */
326 struct xoutput {
327     /** Output id, so that we can requery the output directly later */
328     xcb_randr_output_t id;
329
330     /** Whether the output is currently active (has a CRTC attached with a
331      * valid mode) */
332     bool active;
333
334     /** Internal flags, necessary for querying RandR screens (happens in
335      * two stages) */
336     bool changed;
337     bool to_be_disabled;
338     bool primary;
339
340     /** Name of the output */
341     char *name;
342
343     /** Pointer to the Con which represents this output */
344     Con *con;
345
346     /** x, y, width, height */
347     Rect rect;
348
349     TAILQ_ENTRY(xoutput) outputs;
350 };
351
352 /**
353  * A 'Window' is a type which contains an xcb_window_t and all the related
354  * information (hints like _NET_WM_NAME for that window).
355  *
356  */
357 struct Window {
358     xcb_window_t id;
359
360     /** Holds the xcb_window_t (just an ID) for the leader window (logical
361      * parent for toolwindows and similar floating windows) */
362     xcb_window_t leader;
363     xcb_window_t transient_for;
364
365     /** Pointers to the Assignments which were already ran for this Window
366      * (assignments run only once) */
367     uint32_t nr_assignments;
368     Assignment **ran_assignments;
369
370     char *class_class;
371     char *class_instance;
372
373     /** The name of the window. */
374     i3String *name;
375     /** The format with which the window's name should be displayed. */
376     char *title_format;
377
378     /** The WM_WINDOW_ROLE of this window (for example, the pidgin buddy window
379      * sets "buddy list"). Useful to match specific windows in assignments or
380      * for_window. */
381     char *role;
382
383     /** Flag to force re-rendering the decoration upon changes */
384     bool name_x_changed;
385
386     /** Whether the application used _NET_WM_NAME */
387     bool uses_net_wm_name;
388
389     /** Whether the application needs to receive WM_TAKE_FOCUS */
390     bool needs_take_focus;
391
392     /** Whether this window accepts focus. We store this inverted so that the
393      * default will be 'accepts focus'. */
394     bool doesnt_accept_focus;
395
396     /** The _NET_WM_WINDOW_TYPE for this window. */
397     xcb_atom_t window_type;
398
399     /** Whether the window says it is a dock window */
400     enum { W_NODOCK = 0,
401            W_DOCK_TOP = 1,
402            W_DOCK_BOTTOM = 2 } dock;
403
404     /** When this window was marked urgent. 0 means not urgent */
405     struct timeval urgent;
406
407     /** Pixels the window reserves. left/right/top/bottom */
408     struct reservedpx reserved;
409
410     /** Depth of the window */
411     uint16_t depth;
412 };
413
414 /**
415  * A "match" is a data structure which acts like a mask or expression to match
416  * certain windows or not. For example, when using commands, you can specify a
417  * command like this: [title="*Firefox*"] kill. The title member of the match
418  * data structure will then be filled and i3 will check each window using
419  * match_matches_window() to find the windows affected by this command.
420  *
421  */
422 struct Match {
423     struct regex *title;
424     struct regex *application;
425     struct regex *class;
426     struct regex *instance;
427     struct regex *mark;
428     struct regex *window_role;
429     struct regex *workspace;
430     xcb_atom_t window_type;
431     enum {
432         U_DONTCHECK = -1,
433         U_LATEST = 0,
434         U_OLDEST = 1
435     } urgent;
436     enum {
437         M_DONTCHECK = -1,
438         M_NODOCK = 0,
439         M_DOCK_ANY = 1,
440         M_DOCK_TOP = 2,
441         M_DOCK_BOTTOM = 3
442     } dock;
443     xcb_window_t id;
444     enum { M_ANY = 0,
445            M_TILING,
446            M_FLOATING } floating;
447     Con *con_id;
448
449     /* Where the window looking for a match should be inserted:
450      *
451      * M_HERE   = the matched container will be replaced by the window
452      *            (layout saving)
453      * M_ASSIGN_WS = the matched container will be inserted in the target_ws.
454      * M_BELOW  = the window will be inserted as a child of the matched container
455      *            (dockareas)
456      *
457      */
458     enum { M_HERE = 0,
459            M_ASSIGN_WS,
460            M_BELOW } insert_where;
461
462     TAILQ_ENTRY(Match) matches;
463
464     /* Whether this match was generated when restarting i3 inplace.
465      * Leads to not setting focus when managing a new window, because the old
466      * focus stack should be restored. */
467     bool restart_mode;
468 };
469
470 /**
471  * An Assignment makes specific windows go to a specific workspace/output or
472  * run a command for that window. With this mechanism, the user can -- for
473  * example -- assign their browser to workspace "www". Checking if a window is
474  * assigned works by comparing the Match data structure with the window (see
475  * match_matches_window()).
476  *
477  */
478 struct Assignment {
479     /** type of this assignment:
480      *
481      * A_COMMAND = run the specified command for the matching window
482      * A_TO_WORKSPACE = assign the matching window to the specified workspace
483      * A_NO_FOCUS = don't focus matched window when it is managed
484      *
485      * While the type is a bitmask, only one value can be set at a time. It is
486      * a bitmask to allow filtering for multiple types, for example in the
487      * assignment_for() function.
488      *
489      */
490     enum {
491         A_ANY = 0,
492         A_COMMAND = (1 << 0),
493         A_TO_WORKSPACE = (1 << 1),
494         A_NO_FOCUS = (1 << 2)
495     } type;
496
497     /** the criteria to check if a window matches */
498     Match match;
499
500     /** destination workspace/command, depending on the type */
501     union {
502         char *command;
503         char *workspace;
504     } dest;
505
506     TAILQ_ENTRY(Assignment) assignments;
507 };
508
509 /** Fullscreen modes. Used by Con.fullscreen_mode. */
510 typedef enum { CF_NONE = 0,
511                CF_OUTPUT = 1,
512                CF_GLOBAL = 2 } fullscreen_mode_t;
513
514 /**
515  * A 'Con' represents everything from the X11 root window down to a single X11 window.
516  *
517  */
518 struct Con {
519     bool mapped;
520
521     /* Should this container be marked urgent? This gets set when the window
522      * inside this container (if any) sets the urgency hint, for example. */
523     bool urgent;
524
525     /** This counter contains the number of UnmapNotify events for this
526      * container (or, more precisely, for its ->frame) which should be ignored.
527      * UnmapNotify events need to be ignored when they are caused by i3 itself,
528      * for example when reparenting or when unmapping the window on a workspace
529      * change. */
530     uint8_t ignore_unmap;
531
532     /* ids/pixmap/graphics context for the frame window */
533     bool pixmap_recreated;
534     xcb_window_t frame;
535     xcb_pixmap_t pixmap;
536     xcb_gcontext_t pm_gc;
537
538     enum {
539         CT_ROOT = 0,
540         CT_OUTPUT = 1,
541         CT_CON = 2,
542         CT_FLOATING_CON = 3,
543         CT_WORKSPACE = 4,
544         CT_DOCKAREA = 5
545     } type;
546
547     /** the workspace number, if this Con is of type CT_WORKSPACE and the
548      * workspace is not a named workspace (for named workspaces, num == -1) */
549     int num;
550
551     struct Con *parent;
552
553     struct Rect rect;
554     struct Rect window_rect;
555     struct Rect deco_rect;
556     /** the geometry this window requested when getting mapped */
557     struct Rect geometry;
558
559     char *name;
560
561     /* a sticky-group is an identifier which bundles several containers to a
562      * group. The contents are shared between all of them, that is they are
563      * displayed on whichever of the containers is currently visible */
564     char *sticky_group;
565
566     /* user-definable mark to jump to this container later */
567     char *mark;
568     /* cached to decide whether a redraw is needed */
569     bool mark_changed;
570
571     double percent;
572
573     /* aspect ratio from WM_NORMAL_HINTS (MPlayer uses this for example) */
574     double aspect_ratio;
575     /* the wanted size of the window, used in combination with size
576      * increments (see below). */
577     int base_width;
578     int base_height;
579
580     /* the x11 border pixel attribute */
581     int border_width;
582     int current_border_width;
583
584     /* minimum increment size specified for the window (in pixels) */
585     int width_increment;
586     int height_increment;
587
588     struct Window *window;
589
590     /* timer used for disabling urgency */
591     struct ev_timer *urgency_timer;
592
593     /** Cache for the decoration rendering */
594     struct deco_render_params *deco_render_params;
595
596     /* Only workspace-containers can have floating clients */
597     TAILQ_HEAD(floating_head, Con) floating_head;
598
599     TAILQ_HEAD(nodes_head, Con) nodes_head;
600     TAILQ_HEAD(focus_head, Con) focus_head;
601
602     TAILQ_HEAD(swallow_head, Match) swallow_head;
603
604     fullscreen_mode_t fullscreen_mode;
605     /* layout is the layout of this container: one of split[v|h], stacked or
606      * tabbed. Special containers in the tree (above workspaces) have special
607      * layouts like dockarea or output.
608      *
609      * last_split_layout is one of splitv or splith to support the old "layout
610      * default" command which by now should be "layout splitv" or "layout
611      * splith" explicitly.
612      *
613      * workspace_layout is only for type == CT_WORKSPACE cons. When you change
614      * the layout of a workspace without any children, i3 cannot just set the
615      * layout (because workspaces need to be splitv/splith to allow focus
616      * parent and opening new containers). Instead, it stores the requested
617      * layout in workspace_layout and creates a new split container with that
618      * layout whenever a new container is attached to the workspace. */
619     layout_t layout, last_split_layout, workspace_layout;
620     border_style_t border_style;
621     /** floating? (= not in tiling layout) This cannot be simply a bool
622      * because we want to keep track of whether the status was set by the
623      * application (by setting _NET_WM_WINDOW_TYPE appropriately) or by the
624      * user. The user’s choice overwrites automatic mode, of course. The
625      * order of the values is important because we check with >=
626      * FLOATING_AUTO_ON if a client is floating. */
627     enum {
628         FLOATING_AUTO_OFF = 0,
629         FLOATING_USER_OFF = 1,
630         FLOATING_AUTO_ON = 2,
631         FLOATING_USER_ON = 3
632     } floating;
633
634     TAILQ_ENTRY(Con) nodes;
635     TAILQ_ENTRY(Con) focused;
636     TAILQ_ENTRY(Con) all_cons;
637     TAILQ_ENTRY(Con) floating_windows;
638
639     /** callbacks */
640     void (*on_remove_child)(Con *);
641
642     enum {
643         /* Not a scratchpad window. */
644         SCRATCHPAD_NONE = 0,
645
646         /* Just moved to scratchpad, not resized by the user yet.
647          * Window will be auto-centered and sized appropriately. */
648         SCRATCHPAD_FRESH = 1,
649
650         /* The user changed position/size of the scratchpad window. */
651         SCRATCHPAD_CHANGED = 2
652     } scratchpad_state;
653
654     /* The ID of this container before restarting. Necessary to correctly
655      * interpret back-references in the JSON (such as the focus stack). */
656     int old_id;
657
658     /* Depth of the container window */
659     uint16_t depth;
660 };