/** Execute a system command * \param cmd Command * \return child pid */ pid_t spawn(const char *format, ...) { char *sh = NULL; char cmd[512]; va_list ap; pid_t pid; size_t len; va_start(ap, format); len = vsnprintf(cmd, sizeof(cmd), format, ap); va_end(ap); if (len >= sizeof(cmd)) { warnxl("command too long (> 512 bytes)"); return -1; } if(!(sh = getenv("SHELL")) || sh[0] != '/') sh = "/bin/sh"; if(!(pid = fork())) { setsid(); if (execl(sh, sh, "-c", cmd, (char*)NULL) == -1) warnl("execl(sh -c %s)", cmd); exit(EXIT_FAILURE); } else if (pid == -1) warnl("fork"); return pid; }
void wmfs_init_font(char *font, struct theme *t) { XFontStruct **xfs = NULL; char **misschar, **names, *defstring; int d; if(!(t->font.fontset = XCreateFontSet(W->dpy, font, &misschar, &d, &defstring))) { warnxl("Can't load font '%s'", font); t->font.fontset = XCreateFontSet(W->dpy, "fixed", &misschar, &d, &defstring); } XExtentsOfFontSet(t->font.fontset); XFontsOfFontSet(t->font.fontset, &xfs, &names); t->font.as = xfs[0]->max_bounds.ascent; t->font.de = xfs[0]->max_bounds.descent; t->font.width = xfs[0]->max_bounds.width; t->font.height = t->font.as + t->font.de; if(misschar) XFreeStringList(misschar); }
int wmfs_error_handler(Display *d, XErrorEvent *event) { char mess[256]; /* Check if there is another WM running */ if(event->error_code == BadAccess && W->root == event->resourceid) errl(EXIT_FAILURE, "Another Window Manager is already running."); /* Ignore focus change error for unmapped client * 42 = X_SetInputFocus * 28 = X_GrabButton */ if(client_gb_win(event->resourceid)) if(event->error_code == BadWindow || event->request_code == 42 || event->request_code == 28) return 0; if(XGetErrorText(d, event->error_code, mess, 128)) warnxl("%s(%d) opcodes %d/%d\n resource #%lx\n", mess, event->error_code, event->request_code, event->minor_code, event->resourceid); return 1; }
void config_init(void) { if(get_conf(W->confpath) == -1) { warnl("parsing configuration file (%s) failed.", W->confpath); sprintf(W->confpath, "%s/"CONFIG_DEFAULT_PATH, getenv("HOME")); if(get_conf(W->confpath) == -1) { warnxl("parsing default configuration file (%s) failed.", W->confpath); sprintf(W->confpath, "%s/wmfs/wmfsrc", XDG_CONFIG_DIR); if(get_conf(W->confpath) == -1) errxl(1, "parsing system configuration file (%s) failed.", W->confpath); } } config_theme(); config_keybind(); config_tag(); config_client(); config_bars(); config_rule(); config_launcher(); free_conf(); }
/** strdup with error support * \param str char pointer * \retun non null void pointer */ char * xstrdup(const char *str) { char *ret = NULL; if(str == NULL || (ret = strdup(str)) == NULL) warnxl("strdup(%s)", str); return ret; }
static void config_keybind(void) { int i, n; size_t j; struct conf_sec *sec, **ks; struct opt_type *opt; char *cmd; struct keybind *k; /* [keys] */ sec = fetch_section_first(NULL, "keys"); ks = fetch_section(sec, "key"); n = fetch_section_count(ks); SLIST_INIT(&W->h.keybind); /* [key] */ for(i = 0; i < n; ++i) { k = (struct keybind*)xcalloc(1, sizeof(struct keybind)); /* mod = {} */ opt = fetch_opt(ks[i], "", "mod"); for(j = k->mod = 0; j < fetch_opt_count(opt); ++j) k->mod |= modkey_keysym(opt[j].str); free(opt); /* key = */ k->keysym = XStringToKeysym(fetch_opt_first(ks[i], "None", "key").str); /* func = */ if(!(k->func = uicb_name_func(fetch_opt_first(ks[i], "", "func").str))) { warnxl("configuration: Unknown Function \"%s\".", fetch_opt_first(ks[i], "", "func").str); k->func = uicb_spawn; } /* cmd = */ if((cmd = fetch_opt_first(ks[i], "", "cmd").str)) k->cmd = xstrdup(cmd); SLIST_INSERT_HEAD(&W->h.keybind, k, next); } wmfs_grab_keys(); free(ks); }