]> git.sur5r.net Git - i3/i3/blob - include/config.h
d5465c3f06858cff50459dca962e369aefc76caf
[i3/i3] / include / config.h
1 /*
2  * vim:ts=4:sw=4:expandtab
3  *
4  * i3 - an improved dynamic tiling window manager
5  * © 2009 Michael Stapelberg and contributors (see also: LICENSE)
6  *
7  * include/config.h: Contains all structs/variables for the configurable
8  * part of i3 as well as functions handling the configuration file (calling
9  * the parser (src/config_parse.c) with the correct path, switching key
10  * bindings mode).
11  *
12  */
13 #pragma once
14
15 #include <stdbool.h>
16 #include "queue.h"
17 #include "i3.h"
18 #include "libi3.h"
19
20 typedef struct Config Config;
21 typedef struct Barconfig Barconfig;
22 extern char *current_configpath;
23 extern Config config;
24 extern SLIST_HEAD(modes_head, Mode) modes;
25 extern TAILQ_HEAD(barconfig_head, Barconfig) barconfigs;
26
27 /**
28  * Used during the config file lexing/parsing to keep the state of the lexer
29  * in order to provide useful error messages in yyerror().
30  *
31  */
32 struct context {
33     bool has_errors;
34     bool has_warnings;
35
36     int line_number;
37     char *line_copy;
38     const char *filename;
39
40     char *compact_error;
41
42     /* These are the same as in YYLTYPE */
43     int first_column;
44     int last_column;
45 };
46
47 /**
48  * Part of the struct Config. It makes sense to group colors for background,
49  * border and text as every element in i3 has them (window decorations, bar).
50  *
51  */
52 struct Colortriple {
53     color_t border;
54     color_t background;
55     color_t text;
56     color_t indicator;
57     color_t decoration_border;
58 };
59
60 /**
61  * Holds a user-assigned variable for parsing the configuration file. The key
62  * is replaced by value in every following line of the file.
63  *
64  */
65 struct Variable {
66     char *key;
67     char *value;
68     char *next_match;
69
70     SLIST_ENTRY(Variable) variables;
71 };
72
73 /**
74  * The configuration file can contain multiple sets of bindings. Apart from the
75  * default set (name == "default"), you can specify other sets and change the
76  * currently active set of bindings by using the "mode <name>" command.
77  *
78  */
79 struct Mode {
80     char *name;
81     bool pango_markup;
82     struct bindings_head *bindings;
83
84     SLIST_ENTRY(Mode) modes;
85 };
86
87 /**
88  * Holds part of the configuration (the part which is not already in dedicated
89  * structures in include/data.h).
90  *
91  */
92 struct Config {
93     const char *terminal;
94     i3Font font;
95
96     char *ipc_socket_path;
97     char *restart_state_path;
98
99     layout_t default_layout;
100     int container_stack_limit;
101     int container_stack_limit_value;
102     int default_border_width;
103     int default_floating_border_width;
104
105     /** Default orientation for new containers */
106     int default_orientation;
107
108     /** By default, focus follows mouse. If the user explicitly wants to
109      * turn this off (and instead rely only on the keyboard for changing
110      * focus), we allow them to do this with this relatively special option.
111      * It is not planned to add any different focus models. */
112     bool disable_focus_follows_mouse;
113
114     /** By default, when switching focus to a window on a different output
115      * (e.g. focusing a window on workspace 3 on output VGA-1, coming from
116      * workspace 2 on LVDS-1), the mouse cursor is warped to the center of
117      * that window.
118      *
119      * With the mouse_warping option, you can control when the mouse cursor
120      * should be warped. "none" disables warping entirely, whereas "output"
121      * is the default behavior described above. */
122     warping_t mouse_warping;
123
124     /** Remove borders if they are adjacent to the screen edge.
125      * This is useful if you are reaching scrollbar on the edge of the
126      * screen or do not want to waste a single pixel of displayspace.
127      * By default, this is disabled. */
128     adjacent_t hide_edge_borders;
129
130     /** By default, a workspace bar is drawn at the bottom of the screen.
131      * If you want to have a more fancy bar, it is recommended to replace
132      * the whole bar by dzen2, for example using the i3-wsbar script which
133      * comes with i3. Thus, you can turn it off entirely. */
134     bool disable_workspace_bar;
135
136     /** Think of the following layout: Horizontal workspace with a tabbed
137      * con on the left of the screen and a terminal on the right of the
138      * screen. You are in the second container in the tabbed container and
139      * focus to the right. By default, i3 will set focus to the terminal on
140      * the right. If you are in the first container in the tabbed container
141      * however, focusing to the left will wrap. This option forces i3 to
142      * always wrap, which will result in you having to use "focus parent"
143      * more often. */
144     bool force_focus_wrapping;
145
146     /** By default, use the RandR API for multi-monitor setups.
147      * Unfortunately, the nVidia binary graphics driver doesn't support
148      * this API. Instead, it only support the less powerful Xinerama API,
149      * which can be enabled by this option.
150      *
151      * Note: this option takes only effect on the initial startup (eg.
152      * reconfiguration is not possible). On startup, the list of screens
153      * is fetched once and never updated. */
154     bool force_xinerama;
155
156     /** Overwrites output detection (for testing), see src/fake_outputs.c */
157     char *fake_outputs;
158
159     /** Automatic workspace back and forth switching. If this is set, a
160      * switch to the currently active workspace will switch to the
161      * previously focused one instead, making it possible to fast toggle
162      * between two workspaces. */
163     bool workspace_auto_back_and_forth;
164
165     /** By default, urgency is cleared immediately when switching to another
166      * workspace leads to focusing the con with the urgency hint. When having
167      * multiple windows on that workspace, the user needs to guess which
168      * application raised the event. To prevent this, the reset of the urgency
169      * flag can be delayed using an urgency timer. */
170     float workspace_urgency_timer;
171
172     /** Behavior when a window sends a NET_ACTIVE_WINDOW message. */
173     enum {
174         /* Focus if the target workspace is visible, set urgency hint otherwise. */
175         FOWA_SMART,
176         /* Always set the urgency hint. */
177         FOWA_URGENT,
178         /* Always focus the window. */
179         FOWA_FOCUS,
180         /* Ignore the request (no focus, no urgency hint). */
181         FOWA_NONE
182     } focus_on_window_activation;
183
184     /** Specifies whether or not marks should be displayed in the window
185      * decoration. Marks starting with a "_" will be ignored either way. */
186     bool show_marks;
187
188     /** The default border style for new windows. */
189     border_style_t default_border;
190
191     /** The default border style for new floating windows. */
192     border_style_t default_floating_border;
193
194     /** The modifier which needs to be pressed in combination with your mouse
195      * buttons to do things with floating windows (move, resize) */
196     uint32_t floating_modifier;
197
198     /** Maximum and minimum dimensions of a floating window */
199     int32_t floating_maximum_width;
200     int32_t floating_maximum_height;
201     int32_t floating_minimum_width;
202     int32_t floating_minimum_height;
203
204     /* Color codes are stored here */
205     struct config_client {
206         color_t background;
207         struct Colortriple focused;
208         struct Colortriple focused_inactive;
209         struct Colortriple unfocused;
210         struct Colortriple urgent;
211         struct Colortriple placeholder;
212     } client;
213     struct config_bar {
214         struct Colortriple focused;
215         struct Colortriple unfocused;
216         struct Colortriple urgent;
217     } bar;
218
219     /** What should happen when a new popup is opened during fullscreen mode */
220     enum {
221         /* display (and focus) the popup when it belongs to the fullscreen
222          * window only. */
223         PDF_SMART = 0,
224
225         /* leave fullscreen mode unconditionally */
226         PDF_LEAVE_FULLSCREEN = 1,
227
228         /* just ignore the popup, that is, don’t map it */
229         PDF_IGNORE = 2,
230     } popup_during_fullscreen;
231
232     /* The number of currently parsed barconfigs */
233     int number_barconfigs;
234 };
235
236 /**
237  * Holds the status bar configuration (i3bar). One of these structures is
238  * created for each 'bar' block in the config.
239  *
240  */
241 struct Barconfig {
242     /** Automatically generated ID for this bar config. Used by the bar process
243      * to request a specific configuration. */
244     char *id;
245
246     /** Number of outputs in the outputs array */
247     int num_outputs;
248     /** Outputs on which this bar should show up on. We use an array for
249      * simplicity (since we store just strings). */
250     char **outputs;
251
252     /* List of outputs on which the tray is allowed to be shown, in order.
253      * The special value "none" disables it (per default, it will be shown) and
254      * the special value "primary" enabled it on the primary output. */
255     TAILQ_HEAD(tray_outputs_head, tray_output_t) tray_outputs;
256
257     /* Padding around the tray icons. */
258     int tray_padding;
259
260     /** Path to the i3 IPC socket. This option is discouraged since programs
261      * can find out the path by looking for the I3_SOCKET_PATH property on the
262      * root window! */
263     char *socket_path;
264
265     /** Bar display mode (hide unless modifier is pressed or show in dock mode or always hide in invisible mode) */
266     enum { M_DOCK = 0,
267            M_HIDE = 1,
268            M_INVISIBLE = 2 } mode;
269
270     /* The current hidden_state of the bar, which indicates whether it is hidden or shown */
271     enum { S_HIDE = 0,
272            S_SHOW = 1 } hidden_state;
273
274     /** Bar modifier (to show bar when in hide mode). */
275     enum {
276         M_NONE = 0,
277         M_CONTROL = 1,
278         M_SHIFT = 2,
279         M_MOD1 = 3,
280         M_MOD2 = 4,
281         M_MOD3 = 5,
282         M_MOD4 = 6,
283         M_MOD5 = 7
284     } modifier;
285
286     TAILQ_HEAD(bar_bindings_head, Barbinding) bar_bindings;
287
288     /** Bar position (bottom by default). */
289     enum { P_BOTTOM = 0,
290            P_TOP = 1 } position;
291
292     /** Command that should be run to execute i3bar, give a full path if i3bar is not
293      * in your $PATH.
294      * By default just 'i3bar' is executed. */
295     char *i3bar_command;
296
297     /** Command that should be run to get a statusline, for example 'i3status'.
298      * Will be passed to the shell. */
299     char *status_command;
300
301     /** Font specification for all text rendered on the bar. */
302     char *font;
303
304     /** A custom separator to use instead of a vertical line. */
305     char *separator_symbol;
306
307     /** Hide workspace buttons? Configuration option is 'workspace_buttons no'
308      * but we invert the bool to get the correct default when initializing with
309      * zero. */
310     bool hide_workspace_buttons;
311
312     /** Strip workspace numbers? Configuration option is
313      * 'strip_workspace_numbers yes'. */
314     bool strip_workspace_numbers;
315
316     /** Hide mode button? Configuration option is 'binding_mode_indicator no'
317      * but we invert the bool for the same reason as hide_workspace_buttons.*/
318     bool hide_binding_mode_indicator;
319
320     /** Enable verbose mode? Useful for debugging purposes. */
321     bool verbose;
322
323     struct bar_colors {
324         char *background;
325         char *statusline;
326         char *separator;
327
328         char *focused_background;
329         char *focused_statusline;
330         char *focused_separator;
331
332         char *focused_workspace_border;
333         char *focused_workspace_bg;
334         char *focused_workspace_text;
335
336         char *active_workspace_border;
337         char *active_workspace_bg;
338         char *active_workspace_text;
339
340         char *inactive_workspace_border;
341         char *inactive_workspace_bg;
342         char *inactive_workspace_text;
343
344         char *urgent_workspace_border;
345         char *urgent_workspace_bg;
346         char *urgent_workspace_text;
347
348         char *binding_mode_border;
349         char *binding_mode_bg;
350         char *binding_mode_text;
351     } colors;
352
353     TAILQ_ENTRY(Barconfig) configs;
354 };
355
356 /**
357  * Defines a mouse command to be executed instead of the default behavior when
358  * clicking on the non-statusline part of i3bar.
359  *
360  */
361 struct Barbinding {
362     /** The button to be used (e.g., 1 for "button1"). */
363     int input_code;
364
365     /** The command which is to be executed for this button. */
366     char *command;
367
368     TAILQ_ENTRY(Barbinding) bindings;
369 };
370
371 struct tray_output_t {
372     char *output;
373
374     TAILQ_ENTRY(tray_output_t) tray_outputs;
375 };
376
377 /**
378  * Finds the configuration file to use (either the one specified by
379  * override_configpath), the user’s one or the system default) and calls
380  * parse_file().
381  *
382  * If you specify override_configpath, only this path is used to look for a
383  * configuration file.
384  *
385  * If use_nagbar is false, don't try to start i3-nagbar but log the errors to
386  * stdout/stderr instead.
387  *
388  */
389 bool parse_configuration(const char *override_configpath, bool use_nagbar);
390
391 /**
392  * Reads the configuration from ~/.i3/config or /etc/i3/config if not found.
393  *
394  * If you specify override_configpath, only this path is used to look for a
395  * configuration file.
396  *
397  */
398 void load_configuration(xcb_connection_t *conn, const char *override_configfile, bool reload);
399
400 /**
401  * Ungrabs all keys, to be called before re-grabbing the keys because of a
402  * mapping_notify event or a configuration file reload
403  *
404  */
405 void ungrab_all_keys(xcb_connection_t *conn);
406
407 /**
408  * Sends the current bar configuration as an event to all barconfig_update listeners.
409  *
410  */
411 void update_barconfig();
412
413 /**
414  * Kills the configerror i3-nagbar process, if any.
415  *
416  * Called when reloading/restarting.
417  *
418  * If wait_for_it is set (restarting), this function will waitpid(), otherwise,
419  * ev is assumed to handle it (reloading).
420  *
421  */
422 void kill_configerror_nagbar(bool wait_for_it);