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
95 } __attribute__((packed));
98 * Defines a position in the table
107 * Used for the cache of colorpixels.
113 SLIST_ENTRY(Colorpixel) colorpixels;
116 struct Cached_Pixmap {
119 /* We’re going to paint on it, so a graphics context will be needed */
122 /* The rect with which the pixmap was created */
125 /* The rect of the object to which this pixmap belongs. Necessary to
126 * find out when we need to re-create the pixmap. */
129 xcb_drawable_t referred_drawable;
133 * Contains data for the windows needed to draw the titlebars on in stacking
137 struct Stack_Window {
139 struct Cached_Pixmap pixmap;
142 /** Backpointer to the container this stack window is in */
143 Container *container;
145 SLIST_ENTRY(Stack_Window) stack_windows;
148 struct Ignore_Event {
152 SLIST_ENTRY(Ignore_Event) ignore_events;
156 * Emulates the behaviour of tables of libxcb-wm, which in libxcb 0.3.4
160 struct keyvalue_element {
163 TAILQ_ENTRY(keyvalue_element) elements;
166 /******************************************************************************
168 *****************************************************************************/
171 * The concept of Workspaces is known from various other window
172 * managers. Basically, a workspace is a specific set of windows, usually
173 * grouped thematically (irc, www, work, …). You can switch between these.
177 /** Number of this workspace, starting from 0 */
180 /** Name of the workspace (in UCS-2) */
183 /** Length of the workspace’s name (in glyphs) */
186 /** Width of the workspace’s name (in pixels) rendered in config.font */
189 /** x, y, width, height */
192 /** table dimensions */
194 /** table dimensions */
197 /** These are stored here only while this workspace is _not_ shown
198 * (see show_workspace()) */
200 /** These are stored here only while this workspace is _not_ shown
201 * (see show_workspace()) */
204 /** Should clients on this workspace be automatically floating? */
206 /** Are the floating clients on this workspace currently hidden? */
207 bool floating_hidden;
209 /** The name of the RandR output this screen should be on */
210 char *preferred_output;
212 /** Temporary flag needed for re-querying xinerama screens */
215 /** True if any client on this workspace has its urgent flag set */
218 /** the client who is started in fullscreen mode on this workspace,
219 * NULL if there is none */
220 Client *fullscreen_client;
222 /** The focus stack contains the clients in the correct order of focus
223 so that the focus can be reverted correctly when a client is
225 SLIST_HEAD(focus_stack_head, Client) focus_stack;
227 /** This tail queue contains the floating clients in order of when
228 * they were first set to floating (new floating clients are just
230 TAILQ_HEAD(floating_clients_head, Client) floating_clients;
232 /** Backpointer to the output this workspace is on */
235 /** This is a two-dimensional dynamic array of
236 * Container-pointers. I’ve always wanted to be a three-star
240 /** width_factor and height_factor contain the amount of space
241 * (percentage) a column/row has of all the space which is available
242 * for resized windows. This ensures that non-resized windows (newly
243 * opened, for example) have the same size as always */
245 float *height_factor;
247 TAILQ_ENTRY(Workspace) workspaces;
251 * Holds a keybinding, consisting of a keycode combined with modifiers and the
252 * command which is executed as soon as the key is pressed (see src/command.c)
256 /** Symbol the user specified in configfile, if any. This needs to be
257 * stored with the binding to be able to re-convert it into a keycode
258 * if the keyboard mapping changes (using Xmodmap for example) */
261 /** Only in use if symbol != NULL. Gets set to the value to which the
262 * symbol got translated when binding. Useful for unbinding and
263 * checking which binding was used when a key press event comes in.
265 * This is an array of number_keycodes size. */
266 xcb_keycode_t *translated_to;
268 uint32_t number_keycodes;
270 /** Keycode to bind */
273 /** Bitmask consisting of BIND_MOD_1, BIND_MODE_SWITCH, … */
276 /** Command, like in command mode */
279 TAILQ_ENTRY(Binding) bindings;
283 * Holds a command specified by an exec-line in the config (see src/config.c)
287 /** Command, like in command mode */
289 TAILQ_ENTRY(Autostart) autostarts;
293 * Holds an assignment for a given window class/title to a specific workspace
298 char *windowclass_title;
299 /** floating is true if this was an assignment to the special
300 * workspace "~". Matching clients will be put into floating mode
303 ASSIGN_FLOATING_NO, /* don’t float, but put on a workspace */
304 ASSIGN_FLOATING_ONLY, /* float, but don’t assign on a workspace */
305 ASSIGN_FLOATING /* float and put on a workspace */
308 /** The number of the workspace to assign to. */
310 TAILQ_ENTRY(Assignment) assignments;
314 * Data structure for cached font information:
315 * - font id in X11 (load it once)
316 * - font height (multiple calls needed to get it)
320 /** The name of the font, that is what the pattern resolves to */
322 /** A copy of the pattern to build a cache */
324 /** The height of the font, built from font_ascent + font_descent */
326 /** The xcb-id for the font */
329 TAILQ_ENTRY(Font) fonts;
333 * A client is X11-speak for a window.
337 /** initialized will be set to true if the client was fully
338 * initialized by manage_window() and all functions can be used
342 /** if you set a client to floating and set it back to managed, it
343 * does remember its old position and *tries* to get back there */
346 /** Backpointer. A client is inside a container */
347 Container *container;
348 /** Because dock clients don’t have a container, we have this
349 * workspace-backpointer */
350 Workspace *workspace;
352 /** x, y, width, height of the frame */
354 /** Position in floating mode and in tiling mode are saved
357 /** x, y, width, height of the child (relative to its frame) */
360 /** contains the size calculated from the hints set by the window or 0
361 * if the client did not send any hints */
362 int proportional_height;
363 int proportional_width;
368 /** The amount of pixels which X will draw around the client. */
371 /** contains the minimum increment size as specified for the window
374 int height_increment;
376 /** Height which was determined by reading the _NET_WM_STRUT_PARTIAL
377 * top/bottom of the screen reservation */
380 /** Name (= window title) */
382 /** name_len stores the real string length (glyphs) of the window
383 * title if the client uses _NET_WM_NAME. Otherwise, it is set to -1
384 * to indicate that name should be just passed to X as 8-bit string
385 * and therefore will not be rendered correctly. This behaviour is to
386 * support legacy applications which do not set _NET_WM_NAME */
388 /** This will be set to true as soon as the first _NET_WM_NAME comes
389 * in. If set to true, legacy window names are ignored. */
390 bool uses_net_wm_name;
392 /** Holds the WM_CLASS (which consists of two strings, the instance
393 * and the class), useful for matching the client in commands */
394 char *window_class_instance;
395 char *window_class_class;
397 /** Holds the client’s mark, for vim-like jumping */
400 /** Holds the xcb_window_t (just an ID) for the leader window (logical
401 * parent for toolwindows and similar floating windows) */
404 /** fullscreen is pretty obvious */
407 /** floating? (= not in tiling layout) This cannot be simply a bool
408 * because we want to keep track of whether the status was set by the
409 * application (by setting WM_CLASS to tools for example) or by the
410 * user. The user’s choice overwrites automatic mode, of course. The
411 * order of the values is important because we check with >=
412 * FLOATING_AUTO_ON if a client is floating. */
413 enum { FLOATING_AUTO_OFF = 0, FLOATING_USER_OFF = 1, FLOATING_AUTO_ON = 2, FLOATING_USER_ON = 3 } floating;
415 /** Ensure TITLEBAR_TOP maps to 0 because we use calloc for
416 * initialization later */
417 enum { TITLEBAR_TOP = 0, TITLEBAR_LEFT, TITLEBAR_RIGHT, TITLEBAR_BOTTOM, TITLEBAR_OFF } titlebar_position;
419 /** Contains a bool specifying whether this window should not be drawn
420 * with the usual decorations */
423 /** If a client is set as a dock, it is placed at the very bottom of
424 * the screen and its requested size is used */
427 /** True if the client set the urgency flag in its WM_HINTS property */
430 /* After leaving fullscreen mode, a client needs to be reconfigured
431 * (configuration = setting X, Y, width and height). By setting the
432 * force_reconfigure flag, render_layout() will reconfigure the
434 bool force_reconfigure;
436 /* When reparenting a window, an unmap-notify is sent. As we delete
437 * windows when they’re unmapped, we need to ignore that
438 * one. Therefore, this flag is set when reparenting. */
439 bool awaiting_useless_unmap;
442 xcb_window_t frame; /**< Our window: The frame around the
444 xcb_gcontext_t titlegc; /**< The titlebar’s graphic context
445 * inside the frame */
446 xcb_window_t child; /**< The client’s window */
448 /** The following entry provides the necessary list pointers to use
449 * Client with LIST_* macros */
450 CIRCLEQ_ENTRY(Client) clients;
451 SLIST_ENTRY(Client) dock_clients;
452 SLIST_ENTRY(Client) focus_clients;
453 TAILQ_ENTRY(Client) floating_clients;
457 * A container is either in default, stacking or tabbed mode. There is one for
458 * each cell of the table.
462 /* Those are speaking for themselves: */
463 Client *currently_focused;
467 /* Position of the container inside our table */
470 /* Xinerama: X/Y of the container */
473 /* Width/Height of the container. Changeable by the user */
477 /* When in stacking mode, we draw the titlebars of each client onto a
479 struct Stack_Window stack_win;
481 /* Backpointer to the workspace this container is in */
482 Workspace *workspace;
484 /* Ensure MODE_DEFAULT maps to 0 because we use calloc for
485 * initialization later */
486 enum { MODE_DEFAULT = 0, MODE_STACK, MODE_TABBED } mode;
488 /* When in stacking, one can either have unlimited windows inside the
489 * container or set a limit for the rows or columns the stack window
490 * should display to use the screen more efficiently. */
491 enum { STACK_LIMIT_NONE = 0, STACK_LIMIT_COLS, STACK_LIMIT_ROWS } stack_limit;
493 /* The number of columns or rows to limit to, see stack_limit */
494 int stack_limit_value;
496 CIRCLEQ_HEAD(client_head, Client) clients;
500 * An Output is a physical output on your graphics driver. Outputs which
501 * are currently in use have (output->active == true). Each output has a
502 * position and a mode. An output usually corresponds to one connected
503 * screen (except if you are running multiple screens in clone mode).
507 /** Output id, so that we can requery the output directly later */
508 xcb_randr_output_t id;
509 /** Name of the output */
512 /** Whether the output is currently (has a CRTC attached with a valid
516 /** Internal flags, necessary for querying RandR screens (happens in
521 /** Current workspace selected on this virtual screen */
522 Workspace *current_workspace;
524 /** x, y, width, height */
527 /** The bar window */
529 xcb_gcontext_t bargc;
531 /** Contains all clients with _NET_WM_WINDOW_TYPE ==
532 * _NET_WM_WINDOW_TYPE_DOCK */
533 SLIST_HEAD(dock_clients_head, Client) dock_clients;
535 TAILQ_ENTRY(xoutput) outputs;