2 #define I3__FILE__ "config_directives.c"
18 #define y(x, ...) yajl_gen_ ## x (cmd_output->json_gen, ##__VA_ARGS__)
19 #define ystr(str) yajl_gen_string(cmd_output->json_gen, (unsigned char*)str, strlen(str))
20 #define ysuccess(success) do { \
41 DLOG(
"Initializing criteria, current_match = %p, state = %d\n",
current_match, _state);
54 CFGFUN(criteria_add,
const char *ctype,
const char *cvalue) {
55 DLOG(
"ctype=*%s*, cvalue=*%s*\n", ctype, cvalue);
57 if (strcmp(ctype,
"class") == 0) {
62 if (strcmp(ctype,
"instance") == 0) {
67 if (strcmp(ctype,
"window_role") == 0) {
72 if (strcmp(ctype,
"con_id") == 0) {
74 long parsed = strtol(cvalue, &end, 10);
75 if (parsed == LONG_MIN ||
78 (end && *end !=
'\0')) {
79 ELOG(
"Could not parse con id \"%s\"\n", cvalue);
87 if (strcmp(ctype,
"id") == 0) {
89 long parsed = strtol(cvalue, &end, 10);
90 if (parsed == LONG_MIN ||
93 (end && *end !=
'\0')) {
94 ELOG(
"Could not parse window id \"%s\"\n", cvalue);
102 if (strcmp(ctype,
"con_mark") == 0) {
107 if (strcmp(ctype,
"title") == 0) {
112 if (strcmp(ctype,
"urgent") == 0) {
113 if (strcasecmp(cvalue,
"latest") == 0 ||
114 strcasecmp(cvalue,
"newest") == 0 ||
115 strcasecmp(cvalue,
"recent") == 0 ||
116 strcasecmp(cvalue,
"last") == 0) {
118 }
else if (strcasecmp(cvalue,
"oldest") == 0 ||
119 strcasecmp(cvalue,
"first") == 0) {
125 ELOG(
"Unknown criterion: %s\n", ctype);
135 return (strcasecmp(str,
"1") == 0 ||
136 strcasecmp(str,
"yes") == 0 ||
137 strcasecmp(str,
"true") == 0 ||
138 strcasecmp(str,
"on") == 0 ||
139 strcasecmp(str,
"enable") == 0 ||
140 strcasecmp(str,
"active") == 0);
149 if (strstr(str,
"Mod1") != NULL)
151 if (strstr(str,
"Mod2") != NULL)
153 if (strstr(str,
"Mod3") != NULL)
155 if (strstr(str,
"Mod4") != NULL)
157 if (strstr(str,
"Mod5") != NULL)
159 if (strstr(str,
"Control") != NULL ||
160 strstr(str,
"Ctrl") != NULL)
162 if (strstr(str,
"Shift") != NULL)
164 if (strstr(str,
"Mode_switch") != NULL)
181 CFGFUN(binding,
const char *bindtype,
const char *modifiers,
const char *key,
const char *release,
const char *command) {
183 DLOG(
"bindtype %s, modifiers %s, key %s, release %s\n", bindtype, modifiers, key, release);
184 new_binding->
release = (release != NULL ? B_UPON_KEYRELEASE : B_UPON_KEYPRESS);
185 if (strcmp(bindtype,
"bindsym") == 0) {
189 new_binding->
keycode = atoi(key);
190 if (new_binding->
keycode == 0) {
191 ELOG(
"Could not parse \"%s\" as a keycode, ignoring this binding.\n", key);
207 CFGFUN(mode_binding,
const char *bindtype,
const char *modifiers,
const char *key,
const char *release,
const char *command) {
209 DLOG(
"bindtype %s, modifiers %s, key %s, release %s\n", bindtype, modifiers, key, release);
210 new_binding->
release = (release != NULL ? B_UPON_KEYRELEASE : B_UPON_KEYPRESS);
211 if (strcmp(bindtype,
"bindsym") == 0) {
215 new_binding->
keycode = atoi(key);
216 if (new_binding->
keycode == 0) {
217 ELOG(
"Could not parse \"%s\" as a keycode, ignoring this binding.\n", key);
226 CFGFUN(enter_mode,
const char *modename) {
227 if (strcasecmp(modename,
"default") == 0) {
228 ELOG(
"You cannot use the name \"default\" for your mode\n");
231 DLOG(
"\t now in mode %s\n", modename);
240 CFGFUN(exec,
const char *exectype,
const char *no_startup_id,
const char *command) {
242 new->command =
sstrdup(command);
243 new->no_startup_id = (no_startup_id != NULL);
244 if (strcmp(exectype,
"exec") == 0) {
253 ELOG(
"Match is empty, ignoring this for_window statement\n");
256 DLOG(
"\t should execute command %s for the criteria mentioned above\n", command);
258 assignment->
type = A_COMMAND;
274 CFGFUN(floating_modifier,
const char *modifiers) {
278 CFGFUN(default_orientation,
const char *orientation) {
279 if (strcmp(orientation,
"horizontal") == 0)
281 else if (strcmp(orientation,
"vertical") == 0)
286 CFGFUN(workspace_layout,
const char *layout) {
287 if (strcmp(layout,
"default") == 0)
289 else if (strcmp(layout,
"stacking") == 0 ||
290 strcmp(layout,
"stacked") == 0)
295 CFGFUN(new_window,
const char *windowtype,
const char *border,
const long width) {
302 if (strcmp(border,
"1pixel") == 0) {
305 }
else if (strcmp(border,
"none") == 0) {
308 }
else if (strcmp(border,
"pixel") == 0) {
310 border_width =
width;
313 border_width =
width;
316 if (strcmp(windowtype,
"new_window") == 0) {
325 CFGFUN(hide_edge_borders,
const char *borders) {
326 if (strcmp(borders,
"vertical") == 0)
328 else if (strcmp(borders,
"horizontal") == 0)
330 else if (strcmp(borders,
"both") == 0)
332 else if (strcmp(borders,
"none") == 0)
339 CFGFUN(focus_follows_mouse,
const char *value) {
343 CFGFUN(force_xinerama,
const char *value) {
347 CFGFUN(force_focus_wrapping,
const char *value) {
359 CFGFUN(force_display_urgency_hint,
const long duration_ms) {
363 CFGFUN(workspace,
const char *workspace,
const char *output) {
364 DLOG(
"Assigning workspace \"%s\" to output \"%s\"\n", workspace, output);
369 bool duplicate =
false;
371 if (strcasecmp(assignment->
name, workspace) == 0) {
372 ELOG(
"You have a duplicate workspace assignment for workspace \"%s\"\n",
390 CFGFUN(restart_state,
const char *path) {
394 CFGFUN(popup_during_fullscreen,
const char *value) {
396 (strcmp(value,
"ignore") == 0 ? PDF_IGNORE : PDF_LEAVE_FULLSCREEN);
399 CFGFUN(color_single,
const char *colorclass,
const char *color) {
404 CFGFUN(color,
const char *colorclass,
const char *border,
const char *background,
const char *text,
const char *indicator) {
405 #define APPLY_COLORS(classname) \
407 if (strcmp(colorclass, "client." #classname) == 0) { \
408 config.client.classname.border = get_colorpixel(border); \
409 config.client.classname.background = get_colorpixel(background); \
410 config.client.classname.text = get_colorpixel(text); \
411 if (indicator != NULL) { \
412 config.client. classname .indicator = get_colorpixel(indicator); \
427 ELOG(
"Match is empty, ignoring this assignment\n");
430 DLOG(
"new assignment, using above criteria, to workspace %s\n", workspace);
433 assignment->
type = A_TO_WORKSPACE;
450 current_bar.
mode = (strcmp(mode,
"hide") == 0 ? M_HIDE : M_DOCK);
464 CFGFUN(bar_modifier,
const char *modifier) {
465 if (strcmp(modifier,
"Mod1") == 0)
467 else if (strcmp(modifier,
"Mod2") == 0)
469 else if (strcmp(modifier,
"Mod3") == 0)
471 else if (strcmp(modifier,
"Mod4") == 0)
473 else if (strcmp(modifier,
"Mod5") == 0)
475 else if (strcmp(modifier,
"Control") == 0 ||
476 strcmp(modifier,
"Ctrl") == 0)
478 else if (strcmp(modifier,
"Shift") == 0)
482 CFGFUN(bar_position,
const char *position) {
483 current_bar.
position = (strcmp(position,
"top") == 0 ? P_TOP : P_BOTTOM);
486 CFGFUN(bar_i3bar_command,
const char *i3bar_command) {
491 CFGFUN(bar_color,
const char *colorclass,
const char *border,
const char *background,
const char *text) {
492 #define APPLY_COLORS(classname) \
494 if (strcmp(colorclass, #classname) == 0) { \
495 if (text != NULL) { \
497 current_bar.colors. classname ## _border = sstrdup(border); \
498 current_bar.colors. classname ## _bg = sstrdup(background); \
499 current_bar.colors. classname ## _text = sstrdup(text); \
502 current_bar.colors. classname ## _bg = sstrdup(background); \
503 current_bar.colors. classname ## _text = sstrdup(border); \
516 CFGFUN(bar_socket_path,
const char *socket_path) {
526 CFGFUN(bar_color_single,
const char *colorclass,
const char *color) {
527 if (strcmp(colorclass,
"background") == 0)
532 CFGFUN(bar_status_command,
const char *command) {
537 CFGFUN(bar_workspace_buttons,
const char *value) {
542 DLOG(
"\t new bar configuration finished, saving.\n");
548 char *
x = current_bar.
id + strlen(
"bar-");
550 *(x++) = (rand() % 26) +
'a';
560 memcpy(bar_config, ¤t_bar,
sizeof(
Barconfig));
563 memset(¤t_bar,
'\0',
sizeof(
Barconfig));