4 * i3 - an improved dynamic tiling window manager
6 * © 2009 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/xcb_atom.h>
22 * To get the big concept: There are helper structures like struct Colorpixel
23 * or struct Stack_Window. Everything which is also defined as type (see
24 * forward definitions) is considered to be a major structure, thus important.
26 * Let’s start from the biggest to the smallest:
28 * - An i3Screen is a virtual screen (Xinerama). This can be a single one,
29 * though two monitors might be connected, if you’re running clone
30 * mode. There can also be multiple of them.
32 * - Each i3Screen contains Workspaces. The concept is known from various
33 * other window managers. Basically, a workspace is a specific set of
34 * windows, usually grouped thematically (irc, www, work, …). You can switch
37 * - Each Workspace has a table, which is our layout abstraction. You manage
38 * your windows by moving them around in your table. It grows as necessary.
40 * - Each cell of the table has a container, which can be in default or
41 * stacking mode. In default mode, each client is given equally much space
42 * in the container. In stacking mode, only one client is shown at a time,
43 * but all the titlebars are rendered at the top.
45 * - Inside the container are clients, which is X11-speak for a window.
49 /* Forward definitions */
50 typedef struct Cell Cell;
51 typedef struct Font i3Font;
52 typedef struct Container Container;
53 typedef struct Client Client;
54 typedef struct Binding Binding;
55 typedef struct Workspace Workspace;
56 typedef struct Rect Rect;
57 typedef struct Screen i3Screen;
59 /******************************************************************************
61 *****************************************************************************/
62 typedef enum { D_LEFT, D_RIGHT, D_UP, D_DOWN } direction_t;
66 BIND_SHIFT = XCB_MOD_MASK_SHIFT, /* (1 << 0) */
67 BIND_CONTROL = XCB_MOD_MASK_CONTROL, /* (1 << 2) */
68 BIND_MOD1 = XCB_MOD_MASK_1, /* (1 << 3) */
69 BIND_MOD2 = XCB_MOD_MASK_2, /* (1 << 4) */
70 BIND_MOD3 = XCB_MOD_MASK_3, /* (1 << 5) */
71 BIND_MOD4 = XCB_MOD_MASK_4, /* (1 << 6) */
72 BIND_MOD5 = XCB_MOD_MASK_5, /* (1 << 7) */
73 BIND_MODE_SWITCH = (1 << 8)
77 * Stores a rectangle, for example the size of a window, the child window etc.
82 uint32_t width, height;
86 * Defines a position in the table
95 * Used for the cache of colorpixels.
101 SLIST_ENTRY(Colorpixel) colorpixels;
104 struct Cached_Pixmap {
107 /* We’re going to paint on it, so a graphics context will be needed */
110 /* The rect with which the pixmap was created */
113 /* The rect of the object to which this pixmap belongs. Necessary to
114 * find out when we need to re-create the pixmap. */
117 xcb_drawable_t referred_drawable;
121 * Contains data for the windows needed to draw the titlebars on in stacking
125 struct Stack_Window {
127 struct Cached_Pixmap pixmap;
130 /** Backpointer to the container this stack window is in */
131 Container *container;
133 SLIST_ENTRY(Stack_Window) stack_windows;
136 struct Ignore_Event {
140 SLIST_ENTRY(Ignore_Event) ignore_events;
144 * Emulates the behaviour of tables of libxcb-wm, which in libxcb 0.3.4
148 struct keyvalue_element {
151 TAILQ_ENTRY(keyvalue_element) elements;
154 /******************************************************************************
156 *****************************************************************************/
159 * The concept of Workspaces is known from various other window
160 * managers. Basically, a workspace is a specific set of windows, usually
161 * grouped thematically (irc, www, work, …). You can switch between these.
165 /** Number of this workspace, starting from 0 */
168 /** Name of the workspave */
171 /** x, y, width, height */
174 /** table dimensions */
176 /** table dimensions */
179 /** These are stored here only while this workspace is _not_ shown
180 * (see show_workspace()) */
182 /** These are stored here only while this workspace is _not_ shown
183 * (see show_workspace()) */
186 /** Should clients on this workspace be automatically floating? */
188 /** Are the floating clients on this workspace currently hidden? */
189 bool floating_hidden;
191 /** the client who is started in fullscreen mode on this workspace,
192 * NULL if there is none */
193 Client *fullscreen_client;
195 /** The focus stack contains the clients in the correct order of focus
196 so that the focus can be reverted correctly when a client is
198 SLIST_HEAD(focus_stack_head, Client) focus_stack;
200 /** This tail queue contains the floating clients in order of when
201 * they were first set to floating (new floating clients are just
203 TAILQ_HEAD(floating_clients_head, Client) floating_clients;
205 /** Backpointer to the screen this workspace is on */
208 /** This is a two-dimensional dynamic array of
209 * Container-pointers. I’ve always wanted to be a three-star
213 /** width_factor and height_factor contain the amount of space
214 * (percentage) a column/row has of all the space which is available
215 * for resized windows. This ensures that non-resized windows (newly
216 * opened, for example) have the same size as always */
218 float *height_factor;
222 * Holds a keybinding, consisting of a keycode combined with modifiers and the
223 * command which is executed as soon as the key is pressed (see src/command.c)
227 /** Keycode to bind */
229 /** Bitmask consisting of BIND_MOD_1, BIND_MODE_SWITCH, … */
231 /** Command, like in command mode */
233 TAILQ_ENTRY(Binding) bindings;
237 * Holds a command specified by an exec-line in the config (see src/config.c)
241 /** Command, like in command mode */
243 TAILQ_ENTRY(Autostart) autostarts;
247 * Holds an assignment for a given window class/title to a specific workspace
252 char *windowclass_title;
253 /** floating is true if this was an assignment to the special
254 * workspace "~". Matching clients will be put into floating mode
257 ASSIGN_FLOATING_NO, /* don’t float, but put on a workspace */
258 ASSIGN_FLOATING_ONLY, /* float, but don’t assign on a workspace */
259 ASSIGN_FLOATING /* float and put on a workspace */
262 /** The number of the workspace to assign to. */
264 TAILQ_ENTRY(Assignment) assignments;
268 * Data structure for cached font information:
269 * - font id in X11 (load it once)
270 * - font height (multiple calls needed to get it)
274 /** The name of the font, that is what the pattern resolves to */
276 /** A copy of the pattern to build a cache */
278 /** The height of the font, built from font_ascent + font_descent */
280 /** The xcb-id for the font */
283 TAILQ_ENTRY(Font) fonts;
287 * A client is X11-speak for a window.
291 /** initialized will be set to true if the client was fully
292 * initialized by manage_window() and all functions can be used
296 /** if you set a client to floating and set it back to managed, it
297 * does remember its old position and *tries* to get back there */
300 /** Backpointer. A client is inside a container */
301 Container *container;
302 /** Because dock clients don’t have a container, we have this
303 * workspace-backpointer */
304 Workspace *workspace;
306 /** x, y, width, height of the frame */
308 /** Position in floating mode and in tiling mode are saved
311 /** x, y, width, height of the child (relative to its frame) */
314 /** contains the size calculated from the hints set by the window or 0
315 * if the client did not send any hints */
316 int proportional_height;
317 int proportional_width;
319 /** Height which was determined by reading the _NET_WM_STRUT_PARTIAL
320 * top/bottom of the screen reservation */
323 /** Name (= window title) */
325 /** name_len stores the real string length (glyphs) of the window
326 * title if the client uses _NET_WM_NAME. Otherwise, it is set to -1
327 * to indicate that name should be just passed to X as 8-bit string
328 * and therefore will not be rendered correctly. This behaviour is to
329 * support legacy applications which do not set _NET_WM_NAME */
331 /** This will be set to true as soon as the first _NET_WM_NAME comes
332 * in. If set to true, legacy window names are ignored. */
333 bool uses_net_wm_name;
335 /** Holds the WM_CLASS, useful for matching the client in commands */
338 /** fullscreen is pretty obvious */
341 /** floating? (= not in tiling layout) This cannot be simply a bool
342 * because we want to keep track of whether the status was set by the
343 * application (by setting WM_CLASS to tools for example) or by the
344 * user. The user’s choice overwrites automatic mode, of course. The
345 * order of the values is important because we check with >=
346 * FLOATING_AUTO_ON if a client is floating. */
347 enum { FLOATING_AUTO_OFF = 0, FLOATING_USER_OFF = 1, FLOATING_AUTO_ON = 2, FLOATING_USER_ON = 3 } floating;
349 /** Ensure TITLEBAR_TOP maps to 0 because we use calloc for
350 * initialization later */
351 enum { TITLEBAR_TOP = 0, TITLEBAR_LEFT, TITLEBAR_RIGHT, TITLEBAR_BOTTOM, TITLEBAR_OFF } titlebar_position;
353 /** If a client is set as a dock, it is placed at the very bottom of
354 * the screen and its requested size is used */
357 /* After leaving fullscreen mode, a client needs to be reconfigured
358 * (configuration = setting X, Y, width and height). By setting the
359 * force_reconfigure flag, render_layout() will reconfigure the
361 bool force_reconfigure;
363 /* When reparenting a window, an unmap-notify is sent. As we delete
364 * windows when they’re unmapped, we need to ignore that
365 * one. Therefore, this flag is set when reparenting. */
366 bool awaiting_useless_unmap;
369 xcb_window_t frame; /**< Our window: The frame around the
371 xcb_gcontext_t titlegc; /**< The titlebar’s graphic context
372 * inside the frame */
373 xcb_window_t child; /**< The client’s window */
375 /** The following entry provides the necessary list pointers to use
376 * Client with LIST_* macros */
377 CIRCLEQ_ENTRY(Client) clients;
378 SLIST_ENTRY(Client) dock_clients;
379 SLIST_ENTRY(Client) focus_clients;
380 TAILQ_ENTRY(Client) floating_clients;
384 * A container is either in default or stacking mode. It sits inside each cell
389 /* Those are speaking for themselves: */
390 Client *currently_focused;
394 /* Position of the container inside our table */
397 /* Xinerama: X/Y of the container */
400 /* Width/Height of the container. Changeable by the user */
404 /* When in stacking mode, we draw the titlebars of each client onto a
406 struct Stack_Window stack_win;
408 /* Backpointer to the workspace this container is in */
409 Workspace *workspace;
411 /* Ensure MODE_DEFAULT maps to 0 because we use calloc for
412 * initialization later */
413 enum { MODE_DEFAULT = 0, MODE_STACK } mode;
414 CIRCLEQ_HEAD(client_head, Client) clients;
418 * This is a virtual screen (Xinerama). This can be a single one, though two
419 * monitors might be connected, if you’re running clone mode. There can also
420 * be multiple of them.
424 /** Virtual screen number */
427 /** Current workspace selected on this virtual screen */
428 int current_workspace;
430 /** x, y, width, height */
433 /** The bar window */
435 xcb_gcontext_t bargc;
437 /** Contains all clients with _NET_WM_WINDOW_TYPE ==
438 * _NET_WM_WINDOW_TYPE_DOCK */
439 SLIST_HEAD(dock_clients_head, Client) dock_clients;
441 TAILQ_ENTRY(Screen) screens;