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