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 or
23 * struct Stack_Window. Everything which is also defined as type (see forward definitions)
24 * is considered to be a major structure, thus important.
26 * Let’s start from the biggest to the smallest:
27 * - An i3Screen is a virtual screen (Xinerama). This can be a single one, though two monitors
28 * might be connected, if you’re running clone mode. There can also be multiple of them.
30 * - Each i3Screen contains Workspaces. The concept is known from various other window managers.
31 * Basically, a workspace is a specific set of windows, usually grouped thematically (irc,
32 * www, work, …). You can switch between these.
34 * - Each Workspace has a table, which is our layout abstraction. You manage your windows
35 * by moving them around in your table. It grows as necessary.
37 * - Each cell of the table has a container, which can be in default or stacking mode. In default
38 * mode, each client is given equally much space in the container. In stacking mode, only one
39 * client is shown at a time, but all the titlebars are rendered at the top.
41 * - Inside the container are clients, which is X11-speak for a window.
45 /* Forward definitions */
46 typedef struct Cell Cell;
47 typedef struct Font i3Font;
48 typedef struct Container Container;
49 typedef struct Client Client;
50 typedef struct Binding Binding;
51 typedef struct Workspace Workspace;
52 typedef struct Rect Rect;
53 typedef struct Screen i3Screen;
55 /******************************************************************************
57 *****************************************************************************/
58 typedef enum { D_LEFT, D_RIGHT, D_UP, D_DOWN } direction_t;
62 BIND_SHIFT = XCB_MOD_MASK_SHIFT, /* (1 << 0) */
63 BIND_CONTROL = XCB_MOD_MASK_CONTROL, /* (1 << 2) */
64 BIND_MOD1 = XCB_MOD_MASK_1, /* (1 << 3) */
65 BIND_MOD2 = XCB_MOD_MASK_2, /* (1 << 4) */
66 BIND_MOD3 = XCB_MOD_MASK_3, /* (1 << 5) */
67 BIND_MOD4 = XCB_MOD_MASK_4, /* (1 << 6) */
68 BIND_MOD5 = XCB_MOD_MASK_5, /* (1 << 7) */
69 BIND_MODE_SWITCH = (1 << 8)
74 uint32_t width, height;
78 * Defines a position in the table
87 * Used for the cache of colorpixels.
95 SLIST_ENTRY(Colorpixel) colorpixels;
99 * Contains data for the windows needed to draw the titlebars on in stacking mode
102 struct Stack_Window {
107 /* Backpointer to the container this stack window is in */
108 Container *container;
110 SLIST_ENTRY(Stack_Window) stack_windows;
113 struct Ignore_Event {
117 SLIST_ENTRY(Ignore_Event) ignore_events;
121 * Emulates the behaviour of tables of libxcb-wm, which in libxcb 0.3.4 suddenly vanished.
124 struct keyvalue_element {
128 TAILQ_ENTRY(keyvalue_element) elements;
132 enum xcb_atom_fast_tag_t tag;
134 xcb_get_window_attributes_cookie_t cookie;
135 uint8_t override_redirect;
137 } window_attributes_t;
139 /******************************************************************************
141 *****************************************************************************/
144 * The concept of Workspaces is known from various other window managers. Basically,
145 * a workspace is a specific set of windows, usually grouped thematically (irc,
146 * www, work, …). You can switch between these.
150 /* Number of this workspace, starting from 0 */
153 /* x, y, width, height */
156 /* table dimensions */
160 /* These are stored here only while this workspace is _not_ shown (see show_workspace()) */
164 /* Should clients on this workspace be automatically floating? */
166 /* Are the floating clients on this workspace currently hidden? */
167 bool floating_hidden;
169 Client *fullscreen_client;
171 /* The focus stack contains the clients in the correct order of focus so that
172 the focus can be reverted correctly when a client is closed */
173 SLIST_HEAD(focus_stack_head, Client) focus_stack;
175 /* This tail queue contains the floating clients in order of when they were first
176 * set to floating (new floating clients are just appended) */
177 TAILQ_HEAD(floating_clients_head, Client) floating_clients;
179 /* Backpointer to the screen this workspace is on */
182 /* This is a two-dimensional dynamic array of Container-pointers. I’ve always wanted
183 * to be a three-star programmer :) */
186 /* width_factor and height_factor contain the amount of space (percentage) a column/row
187 has of all the space which is available for resized windows. This ensures that
188 non-resized windows (newly opened, for example) have the same size as always */
190 float *height_factor;
194 * Holds a keybinding, consisting of a keycode combined with modifiers and the command
195 * which is executed as soon as the key is pressed (see src/command.c)
199 /* Keycode to bind */
201 /* Bitmask consisting of BIND_MOD_1, BIND_MODE_SWITCH, … */
203 /* Command, like in command mode */
206 TAILQ_ENTRY(Binding) bindings;
210 * Holds a command specified by an exec-line in the config (see src/config.c)
214 /* Command, like in command mode */
216 TAILQ_ENTRY(Autostart) autostarts;
220 * Holds an assignment for a given window class/title to a specific workspace
225 char *windowclass_title;
226 /* floating is true if this was an assignment to the special workspace "~".
227 * Matching clients will be put into floating mode automatically. */
230 TAILQ_ENTRY(Assignment) assignments;
234 * Data structure for cached font information:
235 * - font id in X11 (load it once)
236 * - font height (multiple calls needed to get it)
240 /* The name of the font, that is what the pattern resolves to */
242 /* A copy of the pattern to build a cache */
244 /* The height of the font, built from font_ascent + font_descent */
246 /* The xcb-id for the font */
249 TAILQ_ENTRY(Font) fonts;
253 * A client is X11-speak for a window.
257 /* initialized will be set to true if the client was fully initialized by
258 * manage_window() and all functions can be used normally */
261 /* if you set a client to floating and set it back to managed, it does remember its old
262 position and *tries* to get back there */
265 /* Backpointer. A client is inside a container */
266 Container *container;
267 /* Because dock clients don’t have a container, we have this workspace-backpointer */
268 Workspace *workspace;
270 /* x, y, width, height of the frame */
272 /* Position in floating mode and in tiling mode are saved separately */
274 /* x, y, width, height of the child (relative to its frame) */
277 /* contains the size calculated from the hints set by the window or 0 if the client
278 did not send any hints */
279 int proportional_height;
280 int proportional_width;
282 /* Height which was determined by reading the _NET_WM_STRUT_PARTIAL top/bottom of the screen
286 /* Name (= window title) */
288 /* name_len stores the real string length (glyphs) of the window title if the client uses
289 _NET_WM_NAME. Otherwise, it is set to -1 to indicate that name should be just passed
290 to X as 8-bit string and therefore will not be rendered correctly. This behaviour is
291 to support legacy applications which do not set _NET_WM_NAME */
293 /* This will be set to true as soon as the first _NET_WM_NAME comes in. If set to true,
294 legacy window names are ignored. */
295 bool uses_net_wm_name;
297 /* Holds the WM_CLASS, useful for matching the client in commands */
300 /* fullscreen is pretty obvious */
303 /* floating? (= not in tiling layout) This cannot be simply a bool because we want to keep track
304 * of whether the status was set by the application (by setting WM_CLASS to tools for example) or
305 * by the user. The user’s choice overwrites automatic mode, of course. The order of the values
306 * is important because we check with >= FLOATING_AUTO_ON if a client is floating. */
307 enum { FLOATING_AUTO_OFF = 0, FLOATING_USER_OFF = 1, FLOATING_AUTO_ON = 2, FLOATING_USER_ON = 3 } floating;
309 /* Ensure TITLEBAR_TOP maps to 0 because we use calloc for initialization later */
310 enum { TITLEBAR_TOP = 0, TITLEBAR_LEFT, TITLEBAR_RIGHT, TITLEBAR_BOTTOM, TITLEBAR_OFF } titlebar_position;
312 /* If a client is set as a dock, it is placed at the very bottom of the screen and its
313 requested size is used */
316 /* After leaving fullscreen mode, a client needs to be reconfigured (configuration =
317 setting X, Y, width and height). By setting the force_reconfigure flag, render_layout()
318 will reconfigure the client. */
319 bool force_reconfigure;
321 /* When reparenting a window, an unmap-notify is sent. As we delete windows when they’re
322 unmapped, we need to ignore that one. Therefore, this flag is set when reparenting. */
323 bool awaiting_useless_unmap;
326 xcb_window_t frame; /* Our window: The frame around the client */
327 xcb_gcontext_t titlegc; /* The titlebar’s graphic context inside the frame */
328 xcb_window_t child; /* The client’s window */
330 /* The following entry provides the necessary list pointers to use Client with LIST_* macros */
331 CIRCLEQ_ENTRY(Client) clients;
332 SLIST_ENTRY(Client) dock_clients;
333 SLIST_ENTRY(Client) focus_clients;
334 TAILQ_ENTRY(Client) floating_clients;
338 * A container is either in default or stacking mode. It sits inside each cell of the table.
342 /* Those are speaking for themselves: */
343 Client *currently_focused;
347 /* Position of the container inside our table */
350 /* Xinerama: X/Y of the container */
353 /* Width/Height of the container. Changeable by the user */
357 /* When in stacking mode, we draw the titlebars of each client onto a separate window */
358 struct Stack_Window stack_win;
360 /* Backpointer to the workspace this container is in */
361 Workspace *workspace;
363 /* Ensure MODE_DEFAULT maps to 0 because we use calloc for initialization later */
364 enum { MODE_DEFAULT = 0, MODE_STACK } mode;
365 CIRCLEQ_HEAD(client_head, Client) clients;
369 * This is a virtual screen (Xinerama). This can be a single one, though two monitors
370 * might be connected, if you’re running clone mode. There can also be multiple of them.
374 /* Virtual screen number */
377 /* Current workspace selected on this virtual screen */
378 int current_workspace;
380 /* x, y, width, height */
385 xcb_gcontext_t bargc;
387 /* Contains all clients with _NET_WM_WINDOW_TYPE == _NET_WM_WINDOW_TYPE_DOCK */
388 SLIST_HEAD(dock_clients_head, Client) dock_clients;
390 TAILQ_ENTRY(Screen) screens;