4 * i3 - an improved dynamic tiling window manager
6 * © 2009-2010 Michael Stapelberg and contributors
8 * See file LICENSE for license information.
10 * include/data.h: This file defines all data structures used by i3
14 #include <xcb/randr.h>
15 #include <xcb/xcb_atom.h>
23 * To get the big concept: There are helper structures like struct Colorpixel
24 * or struct Stack_Window. Everything which is also defined as type (see
25 * forward definitions) is considered to be a major structure, thus important.
27 * Let’s start from the biggest to the smallest:
29 * - An Output is a physical output on your graphics driver. Outputs which
30 * are currently in use have (output->active == true). Each output has a
31 * position and a mode. An output usually corresponds to one connected
32 * screen (except if you are running multiple screens in clone mode).
34 * - Each Output contains Workspaces. The concept is known from various
35 * other window managers. Basically, a workspace is a specific set of
36 * windows, usually grouped thematically (irc, www, work, …). You can switch
39 * - Each Workspace has a table, which is our layout abstraction. You manage
40 * your windows by moving them around in your table. It grows as necessary.
42 * - Each cell of the table has a container, which can be in default or
43 * stacking mode. In default mode, each client is given equally much space
44 * in the container. In stacking mode, only one client is shown at a time,
45 * but all the titlebars are rendered at the top.
47 * - Inside the container are clients, which is X11-speak for a window.
51 /* Forward definitions */
52 typedef struct Cell Cell;
53 typedef struct Font i3Font;
54 typedef struct Container Container;
55 typedef struct Client Client;
56 typedef struct Binding Binding;
57 typedef struct Workspace Workspace;
58 typedef struct Rect Rect;
59 typedef struct xoutput Output;
61 /******************************************************************************
63 *****************************************************************************/
64 typedef enum { D_LEFT, D_RIGHT, D_UP, D_DOWN } direction_t;
68 BIND_SHIFT = XCB_MOD_MASK_SHIFT, /* (1 << 0) */
69 BIND_CONTROL = XCB_MOD_MASK_CONTROL, /* (1 << 2) */
70 BIND_MOD1 = XCB_MOD_MASK_1, /* (1 << 3) */
71 BIND_MOD2 = XCB_MOD_MASK_2, /* (1 << 4) */
72 BIND_MOD3 = XCB_MOD_MASK_3, /* (1 << 5) */
73 BIND_MOD4 = XCB_MOD_MASK_4, /* (1 << 6) */
74 BIND_MOD5 = XCB_MOD_MASK_5, /* (1 << 7) */
75 BIND_MODE_SWITCH = (1 << 8)
79 * Stores a rectangle, for example the size of a window, the child window etc.
80 * It needs to be packed so that the compiler will not add any padding bytes.
81 * (it is used in src/ewmh.c for example)
83 * Note that x and y can contain signed values in some cases (for example when
84 * used for the coordinates of a window, which can be set outside of the
85 * visible area, but not when specifying the position of a workspace for the
86 * _NET_WM_WORKAREA hint). Not declaring x/y as int32_t saves us a lot of
89 * Note that x and y can contain signed values in some cases (for example when
90 * used for the coordinates of a window, which can be set outside of the
91 * visible area, but not when specifying the position of a workspace for the
92 * _NET_WM_WORKAREA hint). Not declaring x/y as int32_t saves us a lot of
101 } __attribute__((packed));
104 * Defines a position in the table
113 * Used for the cache of colorpixels.
119 SLIST_ENTRY(Colorpixel) colorpixels;
122 struct Cached_Pixmap {
125 /* We’re going to paint on it, so a graphics context will be needed */
128 /* The rect with which the pixmap was created */
131 /* The rect of the object to which this pixmap belongs. Necessary to
132 * find out when we need to re-create the pixmap. */
135 xcb_drawable_t referred_drawable;
139 * Contains data for the windows needed to draw the titlebars on in stacking
143 struct Stack_Window {
145 struct Cached_Pixmap pixmap;
148 /** Backpointer to the container this stack window is in */
149 Container *container;
151 SLIST_ENTRY(Stack_Window) stack_windows;
154 struct Ignore_Event {
158 SLIST_ENTRY(Ignore_Event) ignore_events;
162 * Emulates the behaviour of tables of libxcb-wm, which in libxcb 0.3.4
166 struct keyvalue_element {
169 TAILQ_ENTRY(keyvalue_element) elements;
172 /******************************************************************************
174 *****************************************************************************/
177 * The concept of Workspaces is known from various other window
178 * managers. Basically, a workspace is a specific set of windows, usually
179 * grouped thematically (irc, www, work, …). You can switch between these.
183 /** Number of this workspace, starting from 0 */
186 /** Name of the workspace (in UTF-8) */
189 /** Name of the workspace (in UCS-2) */
192 /** Length of the workspace’s name (in glyphs) */
195 /** Width of the workspace’s name (in pixels) rendered in config.font */
198 /** x, y, width, height */
201 /** table dimensions */
203 /** table dimensions */
206 /** These are stored here only while this workspace is _not_ shown
207 * (see show_workspace()) */
209 /** These are stored here only while this workspace is _not_ shown
210 * (see show_workspace()) */
213 /** Should clients on this workspace be automatically floating? */
215 /** Are the floating clients on this workspace currently hidden? */
216 bool floating_hidden;
218 /** The name of the RandR output this screen should be on */
219 char *preferred_output;
221 /** True if any client on this workspace has its urgent flag set */
224 /** the client who is started in fullscreen mode on this workspace,
225 * NULL if there is none */
226 Client *fullscreen_client;
228 /** The focus stack contains the clients in the correct order of focus
229 so that the focus can be reverted correctly when a client is
231 SLIST_HEAD(focus_stack_head, Client) focus_stack;
233 /** This tail queue contains the floating clients in order of when
234 * they were first set to floating (new floating clients are just
236 TAILQ_HEAD(floating_clients_head, Client) floating_clients;
238 /** Backpointer to the output this workspace is on */
241 /** This is a two-dimensional dynamic array of
242 * Container-pointers. I’ve always wanted to be a three-star
246 /** width_factor and height_factor contain the amount of space
247 * (percentage) a column/row has of all the space which is available
248 * for resized windows. This ensures that non-resized windows (newly
249 * opened, for example) have the same size as always */
251 float *height_factor;
253 TAILQ_ENTRY(Workspace) workspaces;
257 * Holds a keybinding, consisting of a keycode combined with modifiers and the
258 * command which is executed as soon as the key is pressed (see src/command.c)
262 /** Symbol the user specified in configfile, if any. This needs to be
263 * stored with the binding to be able to re-convert it into a keycode
264 * if the keyboard mapping changes (using Xmodmap for example) */
267 /** Only in use if symbol != NULL. Gets set to the value to which the
268 * symbol got translated when binding. Useful for unbinding and
269 * checking which binding was used when a key press event comes in.
271 * This is an array of number_keycodes size. */
272 xcb_keycode_t *translated_to;
274 uint32_t number_keycodes;
276 /** Keycode to bind */
279 /** Bitmask consisting of BIND_MOD_1, BIND_MODE_SWITCH, … */
282 /** Command, like in command mode */
285 TAILQ_ENTRY(Binding) bindings;
289 * Holds a command specified by an exec-line in the config (see src/config.c)
293 /** Command, like in command mode */
295 TAILQ_ENTRY(Autostart) autostarts;
299 * Holds an assignment for a given window class/title to a specific workspace
304 char *windowclass_title;
305 /** floating is true if this was an assignment to the special
306 * workspace "~". Matching clients will be put into floating mode
309 ASSIGN_FLOATING_NO, /* don’t float, but put on a workspace */
310 ASSIGN_FLOATING_ONLY, /* float, but don’t assign on a workspace */
311 ASSIGN_FLOATING /* float and put on a workspace */
314 /** The number of the workspace to assign to. */
316 TAILQ_ENTRY(Assignment) assignments;
320 * Data structure for cached font information:
321 * - font id in X11 (load it once)
322 * - font height (multiple calls needed to get it)
326 /** The name of the font, that is what the pattern resolves to */
328 /** A copy of the pattern to build a cache */
330 /** The height of the font, built from font_ascent + font_descent */
332 /** The xcb-id for the font */
335 TAILQ_ENTRY(Font) fonts;
339 * A client is X11-speak for a window.
343 /** initialized will be set to true if the client was fully
344 * initialized by manage_window() and all functions can be used
348 /** if you set a client to floating and set it back to managed, it
349 * does remember its old position and *tries* to get back there */
352 /** Backpointer. A client is inside a container */
353 Container *container;
354 /** Because dock clients don’t have a container, we have this
355 * workspace-backpointer */
356 Workspace *workspace;
358 /** x, y, width, height of the frame */
360 /** Position in floating mode and in tiling mode are saved
363 /** x, y, width, height of the child (relative to its frame) */
366 /** contains the size calculated from the hints set by the window or 0
367 * if the client did not send any hints */
368 int proportional_height;
369 int proportional_width;
374 /** The amount of pixels which X will draw around the client. */
377 /** contains the minimum increment size as specified for the window
380 int height_increment;
382 /** Height which was determined by reading the _NET_WM_STRUT_PARTIAL
383 * top/bottom of the screen reservation */
386 /** Name (= window title) */
388 /** name_len stores the real string length (glyphs) of the window
389 * title if the client uses _NET_WM_NAME. Otherwise, it is set to -1
390 * to indicate that name should be just passed to X as 8-bit string
391 * and therefore will not be rendered correctly. This behaviour is to
392 * support legacy applications which do not set _NET_WM_NAME */
394 /** This will be set to true as soon as the first _NET_WM_NAME comes
395 * in. If set to true, legacy window names are ignored. */
396 bool uses_net_wm_name;
398 /** Holds the WM_CLASS (which consists of two strings, the instance
399 * and the class), useful for matching the client in commands */
400 char *window_class_instance;
401 char *window_class_class;
403 /** Holds the client’s mark, for vim-like jumping */
406 /** Holds the xcb_window_t (just an ID) for the leader window (logical
407 * parent for toolwindows and similar floating windows) */
410 /** fullscreen is pretty obvious */
413 /** floating? (= not in tiling layout) This cannot be simply a bool
414 * because we want to keep track of whether the status was set by the
415 * application (by setting WM_CLASS to tools for example) or by the
416 * user. The user’s choice overwrites automatic mode, of course. The
417 * order of the values is important because we check with >=
418 * FLOATING_AUTO_ON if a client is floating. */
419 enum { FLOATING_AUTO_OFF = 0, FLOATING_USER_OFF = 1, FLOATING_AUTO_ON = 2, FLOATING_USER_ON = 3 } floating;
421 /** Ensure TITLEBAR_TOP maps to 0 because we use calloc for
422 * initialization later */
423 enum { TITLEBAR_TOP = 0, TITLEBAR_LEFT, TITLEBAR_RIGHT, TITLEBAR_BOTTOM, TITLEBAR_OFF } titlebar_position;
425 /** Contains a bool specifying whether this window should not be drawn
426 * with the usual decorations */
429 /** If a client is set as a dock, it is placed at the very bottom of
430 * the screen and its requested size is used */
433 /** True if the client set the urgency flag in its WM_HINTS property */
436 /* After leaving fullscreen mode, a client needs to be reconfigured
437 * (configuration = setting X, Y, width and height). By setting the
438 * force_reconfigure flag, render_layout() will reconfigure the
440 bool force_reconfigure;
442 /* When reparenting a window, an unmap-notify is sent. As we delete
443 * windows when they’re unmapped, we need to ignore that
444 * one. Therefore, this flag is set when reparenting. */
445 bool awaiting_useless_unmap;
448 xcb_window_t frame; /**< Our window: The frame around the
450 xcb_gcontext_t titlegc; /**< The titlebar’s graphic context
451 * inside the frame */
452 xcb_window_t child; /**< The client’s window */
454 /** The following entry provides the necessary list pointers to use
455 * Client with LIST_* macros */
456 CIRCLEQ_ENTRY(Client) clients;
457 SLIST_ENTRY(Client) dock_clients;
458 SLIST_ENTRY(Client) focus_clients;
459 TAILQ_ENTRY(Client) floating_clients;
463 * A container is either in default, stacking or tabbed mode. There is one for
464 * each cell of the table.
468 /* Those are speaking for themselves: */
469 Client *currently_focused;
473 /* Position of the container inside our table */
476 /* Xinerama: X/Y of the container */
479 /* Width/Height of the container. Changeable by the user */
483 /* When in stacking mode, we draw the titlebars of each client onto a
485 struct Stack_Window stack_win;
487 /* Backpointer to the workspace this container is in */
488 Workspace *workspace;
490 /* Ensure MODE_DEFAULT maps to 0 because we use calloc for
491 * initialization later */
492 enum { MODE_DEFAULT = 0, MODE_STACK, MODE_TABBED } mode;
494 /* When in stacking, one can either have unlimited windows inside the
495 * container or set a limit for the rows or columns the stack window
496 * should display to use the screen more efficiently. */
497 enum { STACK_LIMIT_NONE = 0, STACK_LIMIT_COLS, STACK_LIMIT_ROWS } stack_limit;
499 /* The number of columns or rows to limit to, see stack_limit */
500 int stack_limit_value;
502 CIRCLEQ_HEAD(client_head, Client) clients;
506 * An Output is a physical output on your graphics driver. Outputs which
507 * are currently in use have (output->active == true). Each output has a
508 * position and a mode. An output usually corresponds to one connected
509 * screen (except if you are running multiple screens in clone mode).
513 /** Output id, so that we can requery the output directly later */
514 xcb_randr_output_t id;
515 /** Name of the output */
518 /** Whether the output is currently active (has a CRTC attached with a
522 /** Internal flags, necessary for querying RandR screens (happens in
527 /** Current workspace selected on this virtual screen */
528 Workspace *current_workspace;
530 /** x, y, width, height */
533 /** The bar window */
535 xcb_gcontext_t bargc;
537 /** Contains all clients with _NET_WM_WINDOW_TYPE ==
538 * _NET_WM_WINDOW_TYPE_DOCK */
539 SLIST_HEAD(dock_clients_head, Client) dock_clients;
541 TAILQ_ENTRY(xoutput) outputs;