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;
17 struct modes_head modes;
18 struct barconfig_head barconfigs = TAILQ_HEAD_INITIALIZER(barconfigs);
21 * Ungrabs all keys, to be called before re-grabbing the keys because of a
22 * mapping_notify event or a configuration file reload
25 void ungrab_all_keys(xcb_connection_t *conn) {
26 DLOG("Ungrabbing all keys\n");
27 xcb_ungrab_key(conn, XCB_GRAB_ANY, root, XCB_BUTTON_MASK_ANY);
31 * Sends the current bar configuration as an event to all barconfig_update listeners.
34 void update_barconfig() {
36 TAILQ_FOREACH(current, &barconfigs, configs) {
37 ipc_send_barconfig_update_event(current);
42 * Finds the configuration file to use (either the one specified by
43 * override_configpath), the user’s one or the system default) and calls
47 bool parse_configuration(const char *override_configpath, bool use_nagbar) {
48 char *path = get_config_path(override_configpath, true);
50 die("Unable to find the configuration file (looked at "
51 "~/.i3/config, $XDG_CONFIG_HOME/i3/config, " SYSCONFDIR "/i3/config and $XDG_CONFIG_DIRS/i3/config)");
54 LOG("Parsing configfile %s\n", path);
55 FREE(current_configpath);
56 current_configpath = path;
58 /* initialize default bindings if we're just validating the config file */
59 if (!use_nagbar && bindings == NULL) {
60 bindings = scalloc(1, sizeof(struct bindings_head));
64 return parse_file(path, use_nagbar);
68 * (Re-)loads the configuration file (sets useful defaults before).
71 void load_configuration(xcb_connection_t *conn, const char *override_configpath, bool reload) {
73 /* If we are currently in a binding mode, we first revert to the
74 * default since we have no guarantee that the current mode will even
75 * still exist after parsing the config again. See #2228. */
76 switch_mode("default");
78 /* First ungrab the keys */
79 ungrab_all_keys(conn);
82 while (!SLIST_EMPTY(&modes)) {
83 mode = SLIST_FIRST(&modes);
86 /* Clear the old binding list */
87 while (!TAILQ_EMPTY(mode->bindings)) {
88 Binding *bind = TAILQ_FIRST(mode->bindings);
89 TAILQ_REMOVE(mode->bindings, bind, bindings);
94 SLIST_REMOVE(&modes, mode, Mode, modes);
98 struct Assignment *assign;
99 while (!TAILQ_EMPTY(&assignments)) {
100 assign = TAILQ_FIRST(&assignments);
101 if (assign->type == A_TO_WORKSPACE)
102 FREE(assign->dest.workspace);
103 else if (assign->type == A_COMMAND)
104 FREE(assign->dest.command);
105 match_free(&(assign->match));
106 TAILQ_REMOVE(&assignments, assign, assignments);
110 /* Clear bar configs */
111 Barconfig *barconfig;
112 while (!TAILQ_EMPTY(&barconfigs)) {
113 barconfig = TAILQ_FIRST(&barconfigs);
115 for (int c = 0; c < barconfig->num_outputs; c++)
116 free(barconfig->outputs[c]);
118 while (!TAILQ_EMPTY(&(barconfig->bar_bindings))) {
119 struct Barbinding *binding = TAILQ_FIRST(&(barconfig->bar_bindings));
120 FREE(binding->command);
121 TAILQ_REMOVE(&(barconfig->bar_bindings), binding, bindings);
125 while (!TAILQ_EMPTY(&(barconfig->tray_outputs))) {
126 struct tray_output_t *tray_output = TAILQ_FIRST(&(barconfig->tray_outputs));
127 FREE(tray_output->output);
128 TAILQ_REMOVE(&(barconfig->tray_outputs), tray_output, tray_outputs);
132 FREE(barconfig->outputs);
133 FREE(barconfig->socket_path);
134 FREE(barconfig->status_command);
135 FREE(barconfig->i3bar_command);
136 FREE(barconfig->font);
137 FREE(barconfig->colors.background);
138 FREE(barconfig->colors.statusline);
139 FREE(barconfig->colors.separator);
140 FREE(barconfig->colors.focused_background);
141 FREE(barconfig->colors.focused_statusline);
142 FREE(barconfig->colors.focused_separator);
143 FREE(barconfig->colors.focused_workspace_border);
144 FREE(barconfig->colors.focused_workspace_bg);
145 FREE(barconfig->colors.focused_workspace_text);
146 FREE(barconfig->colors.active_workspace_border);
147 FREE(barconfig->colors.active_workspace_bg);
148 FREE(barconfig->colors.active_workspace_text);
149 FREE(barconfig->colors.inactive_workspace_border);
150 FREE(barconfig->colors.inactive_workspace_bg);
151 FREE(barconfig->colors.inactive_workspace_text);
152 FREE(barconfig->colors.urgent_workspace_border);
153 FREE(barconfig->colors.urgent_workspace_bg);
154 FREE(barconfig->colors.urgent_workspace_text);
155 FREE(barconfig->colors.binding_mode_border);
156 FREE(barconfig->colors.binding_mode_bg);
157 FREE(barconfig->colors.binding_mode_text);
158 TAILQ_REMOVE(&barconfigs, barconfig, configs);
162 /* Invalidate pixmap caches in case font or colors changed */
164 TAILQ_FOREACH(con, &all_cons, all_cons)
165 FREE(con->deco_render_params);
167 /* Get rid of the current font */
170 free(config.ipc_socket_path);
171 free(config.restart_state_path);
172 free(config.fake_outputs);
177 struct Mode *default_mode = scalloc(1, sizeof(struct Mode));
178 default_mode->name = sstrdup("default");
179 default_mode->bindings = scalloc(1, sizeof(struct bindings_head));
180 TAILQ_INIT(default_mode->bindings);
181 SLIST_INSERT_HEAD(&modes, default_mode, modes);
183 bindings = default_mode->bindings;
185 #define REQUIRED_OPTION(name) \
186 if (config.name == NULL) \
187 die("You did not specify required configuration option " #name "\n");
189 /* Clear the old config or initialize the data structure */
190 memset(&config, 0, sizeof(config));
192 /* Initialize default colors */
193 #define INIT_COLOR(x, cborder, cbackground, ctext, cindicator) \
195 x.border = draw_util_hex_to_color(cborder); \
196 x.background = draw_util_hex_to_color(cbackground); \
197 x.text = draw_util_hex_to_color(ctext); \
198 x.indicator = draw_util_hex_to_color(cindicator); \
199 x.child_border = draw_util_hex_to_color(cbackground); \
202 config.client.background = draw_util_hex_to_color("#000000");
203 INIT_COLOR(config.client.focused, "#4c7899", "#285577", "#ffffff", "#2e9ef4");
204 INIT_COLOR(config.client.focused_inactive, "#333333", "#5f676a", "#ffffff", "#484e50");
205 INIT_COLOR(config.client.unfocused, "#333333", "#222222", "#888888", "#292d2e");
206 INIT_COLOR(config.client.urgent, "#2f343a", "#900000", "#ffffff", "#900000");
208 /* border and indicator color are ignored for placeholder contents */
209 INIT_COLOR(config.client.placeholder, "#000000", "#0c0c0c", "#ffffff", "#000000");
211 /* the last argument (indicator color) is ignored for bar colors */
212 INIT_COLOR(config.bar.focused, "#4c7899", "#285577", "#ffffff", "#000000");
213 INIT_COLOR(config.bar.unfocused, "#333333", "#222222", "#888888", "#000000");
214 INIT_COLOR(config.bar.urgent, "#2f343a", "#900000", "#ffffff", "#000000");
216 config.show_marks = true;
218 config.default_border = BS_NORMAL;
219 config.default_floating_border = BS_NORMAL;
220 config.default_border_width = logical_px(2);
221 config.default_floating_border_width = logical_px(2);
222 /* Set default_orientation to NO_ORIENTATION for auto orientation. */
223 config.default_orientation = NO_ORIENTATION;
225 /* Set default urgency reset delay to 500ms */
226 if (config.workspace_urgency_timer == 0)
227 config.workspace_urgency_timer = 0.5;
229 parse_configuration(override_configpath, true);
234 regrab_all_buttons(conn);
237 if (config.font.type == FONT_TYPE_NONE) {
238 ELOG("You did not specify required configuration option \"font\"\n");
239 config.font = load_font("fixed", true);
240 set_font(&config.font);
243 /* Redraw the currently visible decorations on reload, so that
244 * the possibly new drawing parameters changed. */
246 x_deco_recurse(croot);