]> git.sur5r.net Git - i3/i3/blob - include/data.h
Change workspace assignments to use the RandR output name instead of <screen>
[i3/i3] / include / data.h
1 /*
2  * vim:ts=8:expandtab
3  *
4  * i3 - an improved dynamic tiling window manager
5  *
6  * © 2009-2010 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/randr.h>
15 #include <xcb/xcb_atom.h>
16 #include <stdbool.h>
17
18 #ifndef _DATA_H
19 #define _DATA_H
20 #include "queue.h"
21
22 /*
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.
26  *
27  * Let’s start from the biggest to the smallest:
28  *
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).
33  *
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
37  *   between these.
38  *
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.
41  *
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.
46  *
47  * - Inside the container are clients, which is X11-speak for a window.
48  *
49  */
50
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;
60
61 /******************************************************************************
62  * Helper types
63  *****************************************************************************/
64 typedef enum { D_LEFT, D_RIGHT, D_UP, D_DOWN } direction_t;
65
66 enum {
67         BIND_NONE = 0,
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)
76 };
77
78 /**
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)
82  *
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
87  * typecasts.
88  *
89  */
90 struct Rect {
91         uint32_t x;
92         uint32_t y;
93         uint32_t width;
94         uint32_t height;
95 } __attribute__((packed));
96
97 /**
98  * Defines a position in the table
99  *
100  */
101 struct Cell {
102         int row;
103         int column;
104 };
105
106 /**
107  * Used for the cache of colorpixels.
108  *
109  */
110 struct Colorpixel {
111         uint32_t pixel;
112         char *hex;
113         SLIST_ENTRY(Colorpixel) colorpixels;
114 };
115
116 struct Cached_Pixmap {
117         xcb_pixmap_t id;
118
119         /* We’re going to paint on it, so a graphics context will be needed */
120         xcb_gcontext_t gc;
121
122         /* The rect with which the pixmap was created */
123         Rect rect;
124
125         /* The rect of the object to which this pixmap belongs. Necessary to
126          * find out when we need to re-create the pixmap. */
127         Rect *referred_rect;
128
129         xcb_drawable_t referred_drawable;
130 };
131
132 /**
133  * Contains data for the windows needed to draw the titlebars on in stacking
134  * mode
135  *
136  */
137 struct Stack_Window {
138         xcb_window_t window;
139         struct Cached_Pixmap pixmap;
140         Rect rect;
141
142         /** Backpointer to the container this stack window is in */
143         Container *container;
144
145         SLIST_ENTRY(Stack_Window) stack_windows;
146 };
147
148 struct Ignore_Event {
149         int sequence;
150         time_t added;
151
152         SLIST_ENTRY(Ignore_Event) ignore_events;
153 };
154
155 /**
156  * Emulates the behaviour of tables of libxcb-wm, which in libxcb 0.3.4
157  * suddenly vanished.
158  *
159  */
160 struct keyvalue_element {
161         uint32_t key;
162         void *value;
163         TAILQ_ENTRY(keyvalue_element) elements;
164 };
165
166 /******************************************************************************
167  * Major types
168  *****************************************************************************/
169
170 /**
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.
174  *
175  */
176 struct Workspace {
177         /** Number of this workspace, starting from 0 */
178         int num;
179
180         /** Name of the workspace (in UCS-2) */
181         char *name;
182
183         /** Length of the workspace’s name (in glyphs) */
184         int name_len;
185
186         /** Width of the workspace’s name (in pixels) rendered in config.font */
187         int text_width;
188
189         /** x, y, width, height */
190         Rect rect;
191
192         /** table dimensions */
193         int cols;
194         /** table dimensions */
195         int rows;
196
197         /** These are stored here only while this workspace is _not_ shown
198          * (see show_workspace()) */
199         int current_row;
200         /** These are stored here only while this workspace is _not_ shown
201          * (see show_workspace()) */
202         int current_col;
203
204         /** Should clients on this workspace be automatically floating? */
205         bool auto_float;
206         /** Are the floating clients on this workspace currently hidden? */
207         bool floating_hidden;
208
209         /** The name of the RandR output this screen should be on */
210         char *preferred_output;
211
212         /** Temporary flag needed for re-querying xinerama screens */
213         bool reassigned;
214
215         /** True if any client on this workspace has its urgent flag set */
216         bool urgent;
217
218         /** the client who is started in fullscreen mode on this workspace,
219          * NULL if there is none */
220         Client *fullscreen_client;
221
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
224            closed */
225         SLIST_HEAD(focus_stack_head, Client) focus_stack;
226
227         /** This tail queue contains the floating clients in order of when
228          * they were first set to floating (new floating clients are just
229          * appended) */
230         TAILQ_HEAD(floating_clients_head, Client) floating_clients;
231
232         /** Backpointer to the output this workspace is on */
233         Output *output;
234
235         /** This is a two-dimensional dynamic array of
236          * Container-pointers. I’ve always wanted to be a three-star
237          * programmer :) */
238         Container ***table;
239
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 */
244         float *width_factor;
245         float *height_factor;
246
247         TAILQ_ENTRY(Workspace) workspaces;
248 };
249
250 /**
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)
253  *
254  */
255 struct Binding {
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) */
259         char *symbol;
260
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.
264          *
265          * This is an array of number_keycodes size. */
266         xcb_keycode_t *translated_to;
267
268         uint32_t number_keycodes;
269
270         /** Keycode to bind */
271         uint32_t keycode;
272
273         /** Bitmask consisting of BIND_MOD_1, BIND_MODE_SWITCH, … */
274         uint32_t mods;
275
276         /** Command, like in command mode */
277         char *command;
278
279         TAILQ_ENTRY(Binding) bindings;
280 };
281
282 /**
283  * Holds a command specified by an exec-line in the config (see src/config.c)
284  *
285  */
286 struct Autostart {
287         /** Command, like in command mode */
288         char *command;
289         TAILQ_ENTRY(Autostart) autostarts;
290 };
291
292 /**
293  * Holds an assignment for a given window class/title to a specific workspace
294  * (see src/config.c)
295  *
296  */
297 struct Assignment {
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
301          * automatically. */
302         enum {
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 */
306         } floating;
307
308         /** The number of the workspace to assign to. */
309         int workspace;
310         TAILQ_ENTRY(Assignment) assignments;
311 };
312
313 /**
314  * Data structure for cached font information:
315  * - font id in X11 (load it once)
316  * - font height (multiple calls needed to get it)
317  *
318  */
319 struct Font {
320         /** The name of the font, that is what the pattern resolves to */
321         char *name;
322         /** A copy of the pattern to build a cache */
323         char *pattern;
324         /** The height of the font, built from font_ascent + font_descent */
325         int height;
326         /** The xcb-id for the font */
327         xcb_font_t id;
328
329         TAILQ_ENTRY(Font) fonts;
330 };
331
332 /**
333  * A client is X11-speak for a window.
334  *
335  */
336 struct Client {
337         /** initialized will be set to true if the client was fully
338          * initialized by manage_window() and all functions can be used
339          * normally */
340         bool initialized;
341
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 */
344         Cell old_position;
345
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;
351
352         /** x, y, width, height of the frame */
353         Rect rect;
354         /** Position in floating mode and in tiling mode are saved
355          * separately */
356         Rect floating_rect;
357         /** x, y, width, height of the child (relative to its frame) */
358         Rect child_rect;
359
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;
364
365         int base_height;
366         int base_width;
367
368         /** The amount of pixels which X will draw around the client. */
369         int border_width;
370
371         /** contains the minimum increment size as specified for the window
372          * (in pixels). */
373         int width_increment;
374         int height_increment;
375
376         /** Height which was determined by reading the _NET_WM_STRUT_PARTIAL
377          * top/bottom of the screen reservation */
378         int desired_height;
379
380         /** Name (= window title) */
381         char *name;
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 */
387         int name_len;
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;
391
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;
396
397         /** Holds the client’s mark, for vim-like jumping */
398         char *mark;
399
400         /** Holds the xcb_window_t (just an ID) for the leader window (logical
401          * parent for toolwindows and similar floating windows) */
402         xcb_window_t leader;
403
404         /** fullscreen is pretty obvious */
405         bool fullscreen;
406
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;
414
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;
418
419         /** Contains a bool specifying whether this window should not be drawn
420          * with the usual decorations */
421         bool borderless;
422
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 */
425         bool dock;
426
427         /** True if the client set the urgency flag in its WM_HINTS property */
428         bool urgent;
429
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
433          * client. */
434         bool force_reconfigure;
435
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;
440
441         /* XCB contexts */
442         xcb_window_t frame;             /**< Our window: The frame around the
443                                          * client */
444         xcb_gcontext_t titlegc;         /**< The titlebar’s graphic context
445                                          * inside the frame */
446         xcb_window_t child;             /**< The client’s window */
447
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;
454 };
455
456 /**
457  * A container is either in default, stacking or tabbed mode. There is one for
458  * each cell of the table.
459  *
460  */
461 struct Container {
462         /* Those are speaking for themselves: */
463         Client *currently_focused;
464         int colspan;
465         int rowspan;
466
467         /* Position of the container inside our table */
468         int row;
469         int col;
470         /* Xinerama: X/Y of the container */
471         int x;
472         int y;
473         /* Width/Height of the container. Changeable by the user */
474         int width;
475         int height;
476
477         /* When in stacking mode, we draw the titlebars of each client onto a
478          * separate window */
479         struct Stack_Window stack_win;
480
481         /* Backpointer to the workspace this container is in */
482         Workspace *workspace;
483
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;
487
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;
492
493         /* The number of columns or rows to limit to, see stack_limit */
494         int stack_limit_value;
495
496         CIRCLEQ_HEAD(client_head, Client) clients;
497 };
498
499 /**
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).
504  *
505  */
506 struct xoutput {
507         /** Output id, so that we can requery the output directly later */
508         xcb_randr_output_t id;
509         /** Name of the output */
510         char *name;
511
512         /** Whether the output is currently (has a CRTC attached with a valid
513          * mode) */
514         bool active;
515
516         /** Current workspace selected on this virtual screen */
517         Workspace *current_workspace;
518
519         /** x, y, width, height */
520         Rect rect;
521
522         /** The bar window */
523         xcb_window_t bar;
524         xcb_gcontext_t bargc;
525
526         /** Contains all clients with _NET_WM_WINDOW_TYPE ==
527          * _NET_WM_WINDOW_TYPE_DOCK */
528         SLIST_HEAD(dock_clients_head, Client) dock_clients;
529
530         TAILQ_ENTRY(xoutput) outputs;
531 };
532
533 #endif