2 #define I3__FILE__ "config.c"
4 * vim:ts=4:sw=4:expandtab
6 * i3 - an improved dynamic tiling window manager
7 * © 2009 Michael Stapelberg and contributors (see also: LICENSE)
9 * config.c: Configuration file (calling the parser (src/config_parser.c) with
10 * the correct path, switching key bindings mode).
14 #include <xkbcommon/xkbcommon.h>
16 char *current_configpath = NULL;
18 struct modes_head modes;
19 struct barconfig_head barconfigs = TAILQ_HEAD_INITIALIZER(barconfigs);
22 * Ungrabs all keys, to be called before re-grabbing the keys because of a
23 * mapping_notify event or a configuration file reload
26 void ungrab_all_keys(xcb_connection_t *conn) {
27 DLOG("Ungrabbing all keys\n");
28 xcb_ungrab_key(conn, XCB_GRAB_ANY, root, XCB_BUTTON_MASK_ANY);
32 * Sends the current bar configuration as an event to all barconfig_update listeners.
35 void update_barconfig() {
37 TAILQ_FOREACH(current, &barconfigs, configs) {
38 ipc_send_barconfig_update_event(current);
43 * Finds the configuration file to use (either the one specified by
44 * override_configpath), the user’s one or the system default) and calls
48 bool parse_configuration(const char *override_configpath, bool use_nagbar) {
49 char *path = get_config_path(override_configpath, true);
51 die("Unable to find the configuration file (looked at "
52 "~/.i3/config, $XDG_CONFIG_HOME/i3/config, " SYSCONFDIR "/i3/config and $XDG_CONFIG_DIRS/i3/config)");
55 LOG("Parsing configfile %s\n", path);
56 FREE(current_configpath);
57 current_configpath = path;
59 /* initialize default bindings if we're just validating the config file */
60 if (!use_nagbar && bindings == NULL) {
61 bindings = scalloc(sizeof(struct bindings_head));
65 return parse_file(path, use_nagbar);
69 * (Re-)loads the configuration file (sets useful defaults before).
72 void load_configuration(xcb_connection_t *conn, const char *override_configpath, bool reload) {
74 /* First ungrab the keys */
75 ungrab_all_keys(conn);
79 while (!SLIST_EMPTY(&modes)) {
80 mode = SLIST_FIRST(&modes);
83 /* Clear the old binding list */
84 bindings = mode->bindings;
85 while (!TAILQ_EMPTY(bindings)) {
86 bind = TAILQ_FIRST(bindings);
87 TAILQ_REMOVE(bindings, bind, bindings);
91 SLIST_REMOVE(&modes, mode, Mode, modes);
94 struct Assignment *assign;
95 while (!TAILQ_EMPTY(&assignments)) {
96 assign = TAILQ_FIRST(&assignments);
97 if (assign->type == A_TO_WORKSPACE)
98 FREE(assign->dest.workspace);
99 else if (assign->type == A_COMMAND)
100 FREE(assign->dest.command);
101 match_free(&(assign->match));
102 TAILQ_REMOVE(&assignments, assign, assignments);
106 /* Clear bar configs */
107 Barconfig *barconfig;
108 while (!TAILQ_EMPTY(&barconfigs)) {
109 barconfig = TAILQ_FIRST(&barconfigs);
111 for (int c = 0; c < barconfig->num_outputs; c++)
112 free(barconfig->outputs[c]);
113 FREE(barconfig->outputs);
114 FREE(barconfig->tray_output);
115 FREE(barconfig->socket_path);
116 FREE(barconfig->status_command);
117 FREE(barconfig->i3bar_command);
118 FREE(barconfig->font);
119 FREE(barconfig->colors.background);
120 FREE(barconfig->colors.statusline);
121 FREE(barconfig->colors.focused_workspace_border);
122 FREE(barconfig->colors.focused_workspace_bg);
123 FREE(barconfig->colors.focused_workspace_text);
124 FREE(barconfig->colors.active_workspace_border);
125 FREE(barconfig->colors.active_workspace_bg);
126 FREE(barconfig->colors.active_workspace_text);
127 FREE(barconfig->colors.inactive_workspace_border);
128 FREE(barconfig->colors.inactive_workspace_bg);
129 FREE(barconfig->colors.inactive_workspace_text);
130 FREE(barconfig->colors.urgent_workspace_border);
131 FREE(barconfig->colors.urgent_workspace_bg);
132 FREE(barconfig->colors.urgent_workspace_text);
133 FREE(barconfig->colors.binding_mode_border);
134 FREE(barconfig->colors.binding_mode_bg);
135 FREE(barconfig->colors.binding_mode_text);
136 TAILQ_REMOVE(&barconfigs, barconfig, configs);
140 /* Clear workspace names */
143 TAILQ_FOREACH(ws, workspaces, workspaces)
144 workspace_set_name(ws, NULL);
147 /* Invalidate pixmap caches in case font or colors changed */
149 TAILQ_FOREACH(con, &all_cons, all_cons)
150 FREE(con->deco_render_params);
152 /* Get rid of the current font */
158 struct Mode *default_mode = scalloc(sizeof(struct Mode));
159 default_mode->name = sstrdup("default");
160 default_mode->bindings = scalloc(sizeof(struct bindings_head));
161 TAILQ_INIT(default_mode->bindings);
162 SLIST_INSERT_HEAD(&modes, default_mode, modes);
164 bindings = default_mode->bindings;
166 #define REQUIRED_OPTION(name) \
167 if (config.name == NULL) \
168 die("You did not specify required configuration option " #name "\n");
170 /* Clear the old config or initialize the data structure */
171 memset(&config, 0, sizeof(config));
173 /* Initialize default colors */
174 #define INIT_COLOR(x, cborder, cbackground, ctext, cindicator) \
176 x.border = get_colorpixel(cborder); \
177 x.background = get_colorpixel(cbackground); \
178 x.text = get_colorpixel(ctext); \
179 x.indicator = get_colorpixel(cindicator); \
182 config.client.background = get_colorpixel("#000000");
183 INIT_COLOR(config.client.focused, "#4c7899", "#285577", "#ffffff", "#2e9ef4");
184 INIT_COLOR(config.client.focused_inactive, "#333333", "#5f676a", "#ffffff", "#484e50");
185 INIT_COLOR(config.client.unfocused, "#333333", "#222222", "#888888", "#292d2e");
186 INIT_COLOR(config.client.urgent, "#2f343a", "#900000", "#ffffff", "#900000");
188 /* border and indicator color are ignored for placeholder contents */
189 INIT_COLOR(config.client.placeholder, "#000000", "#0c0c0c", "#ffffff", "#000000");
191 /* the last argument (indicator color) is ignored for bar colors */
192 INIT_COLOR(config.bar.focused, "#4c7899", "#285577", "#ffffff", "#000000");
193 INIT_COLOR(config.bar.unfocused, "#333333", "#222222", "#888888", "#000000");
194 INIT_COLOR(config.bar.urgent, "#2f343a", "#900000", "#ffffff", "#000000");
196 config.show_marks = true;
198 config.default_border = BS_NORMAL;
199 config.default_floating_border = BS_NORMAL;
200 config.default_border_width = logical_px(2);
201 config.default_floating_border_width = logical_px(2);
202 /* Set default_orientation to NO_ORIENTATION for auto orientation. */
203 config.default_orientation = NO_ORIENTATION;
205 /* Set default urgency reset delay to 500ms */
206 if (config.workspace_urgency_timer == 0)
207 config.workspace_urgency_timer = 0.5;
209 /* Set default zero displays exit delay to 500ms */
210 if (config.zero_disp_exit_timer_ms == 0)
211 config.zero_disp_exit_timer_ms = 500;
213 parse_configuration(override_configpath, true);
217 grab_all_keys(conn, false);
220 if (config.font.type == FONT_TYPE_NONE) {
221 ELOG("You did not specify required configuration option \"font\"\n");
222 config.font = load_font("fixed", true);
223 set_font(&config.font);
226 /* Redraw the currently visible decorations on reload, so that
227 * the possibly new drawing parameters changed. */
229 x_deco_recurse(croot);
234 /* Set an empty name for every workspace which got no name */
236 TAILQ_FOREACH(ws, workspaces, workspaces) {
237 if (ws->name != NULL) {
238 /* If the font was not specified when the workspace name
239 * was loaded, we need to predict the text width now */
240 if (ws->text_width == 0)
241 ws->text_width = predict_text_width(global_conn,
242 config.font, ws->name, ws->name_len);
246 workspace_set_name(ws, NULL);