2 * vim:ts=4:sw=4:expandtab
4 * i3 - an improved dynamic tiling window manager
5 * © 2009 Michael Stapelberg and contributors (see also: LICENSE)
7 * config.c: Configuration file (calling the parser (src/config_parser.c) with
8 * the correct path, switching key bindings mode).
13 #include <xkbcommon/xkbcommon.h>
15 char *current_configpath = NULL;
16 char *current_config = 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(1, 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 /* If we are currently in a binding mode, we first revert to the
75 * default since we have no guarantee that the current mode will even
76 * still exist after parsing the config again. See #2228. */
77 switch_mode("default");
79 /* First ungrab the keys */
80 ungrab_all_keys(conn);
83 while (!SLIST_EMPTY(&modes)) {
84 mode = SLIST_FIRST(&modes);
87 /* Clear the old binding list */
88 while (!TAILQ_EMPTY(mode->bindings)) {
89 Binding *bind = TAILQ_FIRST(mode->bindings);
90 TAILQ_REMOVE(mode->bindings, bind, bindings);
95 SLIST_REMOVE(&modes, mode, Mode, modes);
99 struct Assignment *assign;
100 while (!TAILQ_EMPTY(&assignments)) {
101 assign = TAILQ_FIRST(&assignments);
102 if (assign->type == A_TO_WORKSPACE)
103 FREE(assign->dest.workspace);
104 else if (assign->type == A_COMMAND)
105 FREE(assign->dest.command);
106 match_free(&(assign->match));
107 TAILQ_REMOVE(&assignments, assign, assignments);
111 /* Clear bar configs */
112 Barconfig *barconfig;
113 while (!TAILQ_EMPTY(&barconfigs)) {
114 barconfig = TAILQ_FIRST(&barconfigs);
116 for (int c = 0; c < barconfig->num_outputs; c++)
117 free(barconfig->outputs[c]);
119 while (!TAILQ_EMPTY(&(barconfig->bar_bindings))) {
120 struct Barbinding *binding = TAILQ_FIRST(&(barconfig->bar_bindings));
121 FREE(binding->command);
122 TAILQ_REMOVE(&(barconfig->bar_bindings), binding, bindings);
126 while (!TAILQ_EMPTY(&(barconfig->tray_outputs))) {
127 struct tray_output_t *tray_output = TAILQ_FIRST(&(barconfig->tray_outputs));
128 FREE(tray_output->output);
129 TAILQ_REMOVE(&(barconfig->tray_outputs), tray_output, tray_outputs);
133 FREE(barconfig->outputs);
134 FREE(barconfig->socket_path);
135 FREE(barconfig->status_command);
136 FREE(barconfig->i3bar_command);
137 FREE(barconfig->font);
138 FREE(barconfig->colors.background);
139 FREE(barconfig->colors.statusline);
140 FREE(barconfig->colors.separator);
141 FREE(barconfig->colors.focused_background);
142 FREE(barconfig->colors.focused_statusline);
143 FREE(barconfig->colors.focused_separator);
144 FREE(barconfig->colors.focused_workspace_border);
145 FREE(barconfig->colors.focused_workspace_bg);
146 FREE(barconfig->colors.focused_workspace_text);
147 FREE(barconfig->colors.active_workspace_border);
148 FREE(barconfig->colors.active_workspace_bg);
149 FREE(barconfig->colors.active_workspace_text);
150 FREE(barconfig->colors.inactive_workspace_border);
151 FREE(barconfig->colors.inactive_workspace_bg);
152 FREE(barconfig->colors.inactive_workspace_text);
153 FREE(barconfig->colors.urgent_workspace_border);
154 FREE(barconfig->colors.urgent_workspace_bg);
155 FREE(barconfig->colors.urgent_workspace_text);
156 FREE(barconfig->colors.binding_mode_border);
157 FREE(barconfig->colors.binding_mode_bg);
158 FREE(barconfig->colors.binding_mode_text);
159 TAILQ_REMOVE(&barconfigs, barconfig, configs);
163 /* Invalidate pixmap caches in case font or colors changed */
165 TAILQ_FOREACH(con, &all_cons, all_cons)
166 FREE(con->deco_render_params);
168 /* Get rid of the current font */
171 free(config.ipc_socket_path);
172 free(config.restart_state_path);
173 free(config.fake_outputs);
178 struct Mode *default_mode = scalloc(1, sizeof(struct Mode));
179 default_mode->name = sstrdup("default");
180 default_mode->bindings = scalloc(1, sizeof(struct bindings_head));
181 TAILQ_INIT(default_mode->bindings);
182 SLIST_INSERT_HEAD(&modes, default_mode, modes);
184 bindings = default_mode->bindings;
186 #define REQUIRED_OPTION(name) \
187 if (config.name == NULL) \
188 die("You did not specify required configuration option " #name "\n");
190 /* Clear the old config or initialize the data structure */
191 memset(&config, 0, sizeof(config));
193 /* Initialize default colors */
194 #define INIT_COLOR(x, cborder, cbackground, ctext, cindicator) \
196 x.border = draw_util_hex_to_color(cborder); \
197 x.background = draw_util_hex_to_color(cbackground); \
198 x.text = draw_util_hex_to_color(ctext); \
199 x.indicator = draw_util_hex_to_color(cindicator); \
200 x.child_border = draw_util_hex_to_color(cbackground); \
203 config.client.background = draw_util_hex_to_color("#000000");
204 INIT_COLOR(config.client.focused, "#4c7899", "#285577", "#ffffff", "#2e9ef4");
205 INIT_COLOR(config.client.focused_inactive, "#333333", "#5f676a", "#ffffff", "#484e50");
206 INIT_COLOR(config.client.unfocused, "#333333", "#222222", "#888888", "#292d2e");
207 INIT_COLOR(config.client.urgent, "#2f343a", "#900000", "#ffffff", "#900000");
209 /* border and indicator color are ignored for placeholder contents */
210 INIT_COLOR(config.client.placeholder, "#000000", "#0c0c0c", "#ffffff", "#000000");
212 /* the last argument (indicator color) is ignored for bar colors */
213 INIT_COLOR(config.bar.focused, "#4c7899", "#285577", "#ffffff", "#000000");
214 INIT_COLOR(config.bar.unfocused, "#333333", "#222222", "#888888", "#000000");
215 INIT_COLOR(config.bar.urgent, "#2f343a", "#900000", "#ffffff", "#000000");
217 config.show_marks = true;
219 config.default_border = BS_NORMAL;
220 config.default_floating_border = BS_NORMAL;
221 config.default_border_width = logical_px(2);
222 config.default_floating_border_width = logical_px(2);
223 /* Set default_orientation to NO_ORIENTATION for auto orientation. */
224 config.default_orientation = NO_ORIENTATION;
226 /* Set default urgency reset delay to 500ms */
227 if (config.workspace_urgency_timer == 0)
228 config.workspace_urgency_timer = 0.5;
230 parse_configuration(override_configpath, true);
235 regrab_all_buttons(conn);
238 if (config.font.type == FONT_TYPE_NONE) {
239 ELOG("You did not specify required configuration option \"font\"\n");
240 config.font = load_font("fixed", true);
241 set_font(&config.font);
244 /* Redraw the currently visible decorations on reload, so that
245 * the possibly new drawing parameters changed. */
247 x_deco_recurse(croot);