]> git.sur5r.net Git - i3/i3/blob - include/data.h
21ea722eaba89f471711666059983713f6fb27b8
[i3/i3] / include / data.h
1 /*
2  * vim:ts=8:expandtab
3  *
4  * i3 - an improved dynamic tiling window manager
5  *
6  * (c) 2009 Michael Stapelberg and contributors
7  *
8  * See file LICENSE for license information.
9  *
10  * include/data.h: This file defines all data structures used by i3
11  *
12  */
13 #include <xcb/xcb.h>
14 #include <stdbool.h>
15
16 #ifndef _DATA_H
17 #define _DATA_H
18 #include "queue.h"
19
20 /*
21  * To get the big concept: There are helper structures like struct Colorpixel or
22  * struct Stack_Window. Everything which is also defined as type (see forward definitions)
23  * is considered to be a major structure, thus important.
24  *
25  * Let’s start from the biggest to the smallest:
26  * - An i3Screen is a virtual screen (Xinerama). This can be a single one, though two monitors
27  *   might be connected, if you’re running clone mode. There can also be multiple of them.
28  *
29  * - Each i3Screen contains Workspaces. The concept is known from various other window managers.
30  *   Basically, a workspace is a specific set of windows, usually grouped thematically (irc,
31  *   www, work, …). You can switch between these.
32  *
33  * - Each Workspace has a table, which is our layout abstraction. You manage your windows
34  *   by moving them around in your table. It grows as necessary.
35  *
36  * - Each cell of the table has a container, which can be in default or stacking mode. In default
37  *   mode, each client is given equally much space in the container. In stacking mode, only one
38  *   client is shown at a time, but all the titlebars are rendered at the top.
39  *
40  * - Inside the container are clients, which is X11-speak for a window.
41  *
42  */
43
44 /* Forward definitions */
45 typedef struct Cell Cell;
46 typedef struct Font i3Font;
47 typedef struct Container Container;
48 typedef struct Client Client;
49 typedef struct Binding Binding;
50 typedef struct Workspace Workspace;
51 typedef struct Rect Rect;
52 typedef struct Screen i3Screen;
53
54 /******************************************************************************
55  * Helper types
56  *****************************************************************************/
57 typedef enum { D_LEFT, D_RIGHT, D_UP, D_DOWN } direction_t;
58
59 enum {
60         BIND_NONE = 0,
61         BIND_SHIFT = XCB_MOD_MASK_SHIFT,        /* (1 << 0) */
62         BIND_CONTROL = XCB_MOD_MASK_CONTROL,    /* (1 << 2) */
63         BIND_MOD1 = XCB_MOD_MASK_1,             /* (1 << 3) */
64         BIND_MOD2 = XCB_MOD_MASK_2,             /* (1 << 4) */
65         BIND_MOD3 = XCB_MOD_MASK_3,             /* (1 << 5) */
66         BIND_MOD4 = XCB_MOD_MASK_4,             /* (1 << 6) */
67         BIND_MOD5 = XCB_MOD_MASK_5,             /* (1 << 7) */
68         BIND_MODE_SWITCH = (1 << 8)
69 };
70
71 struct Rect {
72         uint32_t x, y;
73         uint32_t width, height;
74 };
75
76 /*
77  * Defines a position in the table
78  *
79  */
80 struct Cell {
81         int row;
82         int column;
83 };
84
85 /*
86  * Used for the cache of colorpixels.
87  *
88  */
89 struct Colorpixel {
90         uint32_t pixel;
91
92         char *hex;
93
94         SLIST_ENTRY(Colorpixel) colorpixels;
95 };
96
97 /*
98  * Contains data for the windows needed to draw the titlebars on in stacking mode
99  *
100  */
101 struct Stack_Window {
102         xcb_window_t window;
103         xcb_gcontext_t gc;
104         Rect rect;
105
106         /* Backpointer to the container this stack window is in */
107         Container *container;
108
109         SLIST_ENTRY(Stack_Window) stack_windows;
110 };
111
112 struct Ignore_Event {
113         int sequence;
114         time_t added;
115
116         SLIST_ENTRY(Ignore_Event) ignore_events;
117 };
118
119 /******************************************************************************
120  * Major types
121  *****************************************************************************/
122
123 /*
124  * The concept of Workspaces is known from various other window managers. Basically,
125  * a workspace is a specific set of windows, usually grouped thematically (irc,
126  * www, work, …). You can switch between these.
127  *
128  */
129 struct Workspace {
130         /* Number of this workspace, starting from 0 */
131         int num;
132
133         /* x, y, width, height */
134         Rect rect;
135
136         /* table dimensions */
137         int cols;
138         int rows;
139
140         /* These are stored here only while this workspace is _not_ shown (see show_workspace()) */
141         int current_row;
142         int current_col;
143
144         Client *fullscreen_client;
145
146         /* Contains all clients with _NET_WM_WINDOW_TYPE == _NET_WM_WINDOW_TYPE_DOCK */
147         SLIST_HEAD(dock_clients_head, Client) dock_clients;
148
149         /* The focus stack contains the clients in the correct order of focus so that
150            the focus can be reverted correctly when a client is closed */
151         SLIST_HEAD(focus_stack_head, Client) focus_stack;
152
153         /* Backpointer to the screen this workspace is on */
154         i3Screen *screen;
155
156         /* This is a two-dimensional dynamic array of Container-pointers. I’ve always wanted
157          * to be a three-star programmer :) */
158         Container ***table;
159 };
160
161 /*
162  * Holds a keybinding, consisting of a keycode combined with modifiers and the command
163  * which is executed as soon as the key is pressed (see src/command.c)
164  *
165  */
166 struct Binding {
167         /* Keycode to bind */
168         uint32_t keycode;
169         /* Bitmask consisting of BIND_MOD_1, BIND_MODE_SWITCH, … */
170         uint32_t mods;
171         /* Command, like in command mode */
172         char *command;
173
174         TAILQ_ENTRY(Binding) bindings;
175 };
176
177 /*
178  * Data structure for cached font information:
179  * - font id in X11 (load it once)
180  * - font height (multiple calls needed to get it)
181  *
182  */
183 struct Font {
184         /* The name of the font, that is what the pattern resolves to */
185         char *name;
186         /* A copy of the pattern to build a cache */
187         char *pattern;
188         /* The height of the font, built from font_ascent + font_descent */
189         int height;
190         /* The xcb-id for the font */
191         xcb_font_t id;
192
193         TAILQ_ENTRY(Font) fonts;
194 };
195
196 /*
197  * A client is X11-speak for a window.
198  *
199  */
200 struct Client {
201         /* if you set a client to floating and set it back to managed, it does remember its old
202            position and *tries* to get back there */
203         Cell old_position;
204
205         /* Backpointer. A client is inside a container */
206         Container *container;
207         /* Because dock clients don’t have a container, we have this workspace-backpointer */
208         Workspace *workspace;
209
210         /* x, y, width, height of the frame */
211         Rect rect;
212         /* x, y, width, height of the child (relative to its frame) */
213         Rect child_rect;
214
215         /* contains the size calculated from the hints set by the window or 0 if the client
216            did not send any hints */
217         int proportional_height;
218         int proportional_width;
219
220         /* Height which was determined by reading the _NET_WM_STRUT_PARTIAL top/bottom of the screen
221            reservation */
222         int desired_height;
223
224         /* Name (= window title) */
225         char *name;
226         /* name_len stores the real string length (glyphs) of the window title if the client uses
227            _NET_WM_NAME. Otherwise, it is set to -1 to indicate that name should be just passed
228            to X as 8-bit string and therefore will not be rendered correctly. This behaviour is
229            to support legacy applications which do not set _NET_WM_NAME */
230         int name_len;
231         /* This will be set to true as soon as the first _NET_WM_NAME comes in. If set to true,
232            legacy window names are ignored. */
233         bool uses_net_wm_name;
234
235         /* fullscreen is pretty obvious */
236         bool fullscreen;
237
238         /* Ensure TITLEBAR_TOP maps to 0 because we use calloc for initialization later */
239         enum { TITLEBAR_TOP = 0, TITLEBAR_LEFT, TITLEBAR_RIGHT, TITLEBAR_BOTTOM, TITLEBAR_OFF } titlebar_position;
240
241         /* If a client is set as a dock, it is placed at the very bottom of the screen and its
242            requested size is used */
243         bool dock;
244
245         /* After leaving fullscreen mode, a client needs to be reconfigured (configuration =
246            setting X, Y, width and height). By setting the force_reconfigure flag, render_layout()
247            will reconfigure the client. */
248         bool force_reconfigure;
249
250         /* When reparenting a window, an unmap-notify is sent. As we delete windows when they’re
251            unmapped, we need to ignore that one. Therefore, this flag is set when reparenting. */
252         bool awaiting_useless_unmap;
253
254         /* XCB contexts */
255         xcb_window_t frame;             /* Our window: The frame around the client */
256         xcb_gcontext_t titlegc;         /* The titlebar’s graphic context inside the frame */
257         xcb_window_t child;             /* The client’s window */
258
259         /* The following entry provides the necessary list pointers to use Client with LIST_* macros */
260         CIRCLEQ_ENTRY(Client) clients;
261         SLIST_ENTRY(Client) dock_clients;
262         SLIST_ENTRY(Client) focus_clients;
263 };
264
265 /*
266  * A container is either in default or stacking mode. It sits inside each cell of the table.
267  *
268  */
269 struct Container {
270         /* Those are speaking for themselves: */
271         Client *currently_focused;
272         int colspan;
273         int rowspan;
274
275         /* Position of the container inside our table */
276         int row;
277         int col;
278         /* Xinerama: X/Y of the container */
279         int x;
280         int y;
281         /* Width/Height of the container. Changeable by the user */
282         int width;
283         int height;
284         /* width_factor and height_factor contain the amount of space (percentage) a window
285            has of all the space which is available for resized windows. This ensures that
286            non-resized windows (newly opened, for example) have the same size as always */
287         float width_factor;
288         float height_factor;
289
290         /* When in stacking mode, we draw the titlebars of each client onto a separate window */
291         struct Stack_Window stack_win;
292
293         /* Backpointer to the workspace this container is in */
294         Workspace *workspace;
295
296         /* Ensure MODE_DEFAULT maps to 0 because we use calloc for initialization later */
297         enum { MODE_DEFAULT = 0, MODE_STACK } mode;
298         CIRCLEQ_HEAD(client_head, Client) clients;
299 };
300
301 /*
302  * This is a virtual screen (Xinerama). This can be a single one, though two monitors
303  * might be connected, if you’re running clone mode. There can also be multiple of them.
304  *
305  */
306 struct Screen {
307         /* Virtual screen number */
308         int num;
309
310         /* Current workspace selected on this virtual screen */
311         int current_workspace;
312
313         /* x, y, width, height */
314         Rect rect;
315
316         /* The bar window */
317         xcb_window_t bar;
318         xcb_gcontext_t bargc;
319
320         TAILQ_ENTRY(Screen) screens;
321 };
322
323 #endif