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