aboutsummaryrefslogtreecommitdiffstats
path: root/conf.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--conf.c293
1 files changed, 39 insertions, 254 deletions
diff --git a/conf.c b/conf.c
index f31abc4..d446f29 100644
--- a/conf.c
+++ b/conf.c
@@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
- * $Id: conf.c,v 1.22 2008/03/22 15:09:45 oga Exp $
+ * $Id: conf.c,v 1.23 2008/03/23 15:09:21 simon Exp $
*/
#include "headers.h"
@@ -28,58 +28,7 @@
((tsp)->tv_sec cmp (usp)->tv_sec))
#endif
-#define CONF_MAX_WINTITLE 256
-#define CONF_IGNORECASE 0x01
-
-
-/*
- * Match a window.
- */
-struct winmatch {
- TAILQ_ENTRY(winmatch) entry;
-
- char title[CONF_MAX_WINTITLE];
- int opts;
-};
-
-TAILQ_HEAD(winmatch_q, winmatch);
-struct winmatch_q ignoreq;
-
-/* XXX - until we get a real configuration parser. */
-#define WINMATCH_ADD(queue, str) do { \
- struct winmatch *wm; \
- XCALLOC(wm, struct winmatch); \
- strlcpy(wm->title, str, sizeof(wm->title)); \
- wm->opts |= CONF_IGNORECASE; \
- TAILQ_INSERT_TAIL(queue, wm, entry); \
-} while (0)
-
-/* Initializes the command menu */
-
-void
-conf_cmd_init(struct conf *c)
-{
- TAILQ_INIT(&c->cmdq);
-}
-
-/* Removes all static entries */
-
-void
-conf_cmd_clear(struct conf *c)
-{
- struct cmd *cmd, *next;
-
- for (cmd = TAILQ_FIRST(&c->cmdq); cmd != NULL; cmd = next) {
- next = TAILQ_NEXT(cmd, entry);
-
- /* Do not remove static entries */
- if (cmd->flags & CMD_STATIC)
- continue;
-
- TAILQ_REMOVE(&c->cmdq, cmd, entry);
- free(cmd);
- }
-}
+extern struct screen_ctx *Curscreen;
/* Add an command menu entry to the end of the menu */
void
@@ -102,94 +51,45 @@ conf_cmd_add(struct conf *c, char *image, char *label, int flags)
}
int
-conf_cmd_changed(char *path)
+conf_changed(char *path)
{
-#ifdef __OpenBSD__
static struct timespec old_ts;
-#else
- static time_t old_time;
-#endif
struct stat sb;
int changed;
- /* If the directory does not exist we pretend that nothing changed */
- if (stat(path, &sb) == -1 || !(sb.st_mode & S_IFDIR))
+ /* If the file does not exist we pretend that nothing changed */
+ if (stat(path, &sb) == -1 || !(sb.st_mode & S_IFREG))
return (0);
-#ifdef __OpenBSD__
changed = !timespeccmp(&sb.st_mtimespec, &old_ts, ==);
old_ts = sb.st_mtimespec;
-#else
- changed = old_time != sb.st_mtime;
- old_time = sb.st_mtime;
-#endif
return (changed);
}
void
-conf_cmd_populate(struct conf *c, char *path)
+conf_reload(struct conf *c)
{
- DIR *dir;
- struct dirent *file;
- char fullname[PATH_MAX];
- int off;
-
- if (strlen(path) >= sizeof (fullname) - 2)
- errx(1, "directory name too long");
-
- dir = opendir(path);
- if (dir == NULL)
- err(1, "opendir");
-
- strlcpy(fullname, path, sizeof (fullname));
- off = strlen(fullname);
- if (fullname[off - 1] != '/') {
- strlcat(fullname, "/", sizeof(fullname));
- off++;
- }
-
- while ((file = readdir(dir)) != NULL) {
- char *filename = file->d_name;
- if (filename[0] == '.')
- continue;
-
- strlcpy(fullname + off, filename, sizeof(fullname) - off);
-
- /* Add a dynamic entry to the command menu */
- conf_cmd_add(c, fullname, filename, 0);
- }
-
- closedir(dir);
-
-}
+ if (!conf_changed(c->conf_path))
+ return;
-void
-conf_cmd_refresh(struct conf *c)
-{
- if (!conf_cmd_changed(c->menu_path))
+ if (parse_config(c->conf_path, c) == -1) {
+ warnx("config file %s has errors, not reloading", c->conf_path);
return;
+ }
- conf_cmd_clear(c);
- conf_cmd_populate(c, c->menu_path);
+ DefaultFont = font_getx(Curscreen, c->DefaultFontName);
}
void
-conf_setup(struct conf *c)
+conf_init(struct conf *c)
{
- char dir_keydefs[MAXPATHLEN];
- char dir_settings[MAXPATHLEN];
- char dir_ignored[MAXPATHLEN];
- char dir_autogroup[MAXPATHLEN];
- char *home = getenv("HOME");
-
- if (home == NULL)
- errx(1, "No HOME directory.");
- snprintf(c->menu_path, sizeof(c->menu_path), "%s/.calmwm", home);
-
- conf_cmd_init(c);
+ c->flags = 0;
+ TAILQ_INIT(&c->ignoreq);
+ TAILQ_INIT(&c->cmdq);
TAILQ_INIT(&c->keybindingq);
+ TAILQ_INIT(&c->autogroupq);
conf_bindname(c, "CM-Return", "terminal");
conf_bindname(c, "CM-Delete", "lock");
@@ -247,39 +147,31 @@ conf_setup(struct conf *c)
conf_bindname(c, "CS-Up", "bigptrmoveup");
conf_bindname(c, "CS-Right", "bigptrmoveright");
- snprintf(dir_keydefs, sizeof(dir_keydefs), "%s/.calmwm/.keys", home);
- if (dirent_isdir(dir_keydefs))
- conf_parsekeys(c, dir_keydefs);
-
- snprintf(dir_settings, sizeof(dir_settings),
- "%s/.calmwm/.settings", home);
- if (dirent_isdir(dir_settings))
- conf_parsesettings(c, dir_settings);
-
- TAILQ_INIT(&ignoreq);
-
- snprintf(dir_ignored, sizeof(dir_ignored), "%s/.calmwm/.ignore", home);
- if (dirent_isdir(dir_ignored))
- conf_parseignores(c, dir_ignored);
- else {
- WINMATCH_ADD(&ignoreq, "XMMS");
- WINMATCH_ADD(&ignoreq, "xwi");
- WINMATCH_ADD(&ignoreq, "xapm");
- WINMATCH_ADD(&ignoreq, "xclock");
- }
+ /* Default term/lock */
+ strlcpy(c->termpath, "xterm", sizeof(c->termpath));
+ strlcpy(c->lockpath, "xlock", sizeof(c->lockpath));
- TAILQ_INIT(&c->autogroupq);
+ c->DefaultFontName = DEFAULTFONTNAME;
+}
+
+void
+conf_setup(struct conf *c, const char *conffile)
+{
+ if (conffile == NULL) {
+ char *home = getenv("HOME");
- snprintf(dir_autogroup, sizeof(dir_autogroup),
- "%s/.calmwm/.autogroup", home);
- if (dirent_isdir(dir_autogroup))
- conf_parseautogroups(c, dir_autogroup);
+ if (home == NULL)
+ errx(1, "No HOME directory.");
- c->flags = 0;
+ snprintf(c->conf_path, sizeof(c->conf_path), "%s/%s", home,
+ CONFFILE);
+ }
+ else
+ snprintf(c->conf_path, sizeof(c->conf_path), "%s", conffile);
- /* Default term/lock */
- strlcpy(Conf.termpath, "xterm", sizeof(Conf.termpath));
- strlcpy(Conf.lockpath, "xlock", sizeof(Conf.lockpath));
+ conf_init(c);
+
+ (void)parse_config(c->conf_path, c);
}
int
@@ -294,7 +186,7 @@ conf_get_int(struct client_ctx *cc, enum conftype ctype)
/* Can wname be NULL? */
if (wname != NULL) {
- TAILQ_FOREACH(wm, &ignoreq, entry) {
+ TAILQ_FOREACH(wm, &Conf.ignoreq, entry) {
int (*cmpfun)(const char *, const char *, size_t) =
wm->opts & CONF_IGNORECASE ? strncasecmp : strncmp;
if ((*cmpfun)(wm->title, wname, strlen(wm->title)) == 0) {
@@ -393,37 +285,6 @@ struct {
};
void
-conf_parsekeys(struct conf *c, char *filename)
-{
- DIR *dir;
- struct dirent *ent;
- char buffer[MAXPATHLEN];
- char current_file[MAXPATHLEN];
-
- dir = opendir(filename);
- while ((ent = readdir(dir)) != NULL) {
- if (ent->d_name[0] == '.')
- continue;
-
- snprintf(current_file, sizeof(current_file),
- "%s/%s", filename, ent->d_name);
- if (strchr(ent->d_name, '-') == NULL && ent->d_name[0] != '[')
- continue;
- if (!dirent_islink(current_file))
- continue;
-
-
- memset(buffer, 0, MAXPATHLEN);
- if (readlink(current_file, buffer, MAXPATHLEN) < 0)
- continue;
-
- conf_bindname(c, ent->d_name, buffer);
- }
-
- closedir(dir);
-}
-
-void
conf_bindname(struct conf *c, char *name, char *binding)
{
int iter;
@@ -518,79 +379,3 @@ void conf_unbind(struct conf *c, struct keybinding *unbind)
TAILQ_REMOVE(&c->keybindingq, key, entry);
}
}
-
-void
-conf_parsesettings(struct conf *c, char *filename)
-{
- DIR *dir;
- struct dirent *ent;
-
- dir = opendir(filename);
- while ((ent = readdir(dir)) != NULL) {
- if (ent->d_name[0] == '.')
- continue;
- if (strncmp(ent->d_name, "sticky", 7)==0)
- Conf.flags |= CONF_STICKY_GROUPS;
- }
- closedir(dir);
-}
-
-void
-conf_parseignores(struct conf *c, char *filename)
-{
- DIR *dir;
- struct dirent *ent;
-
- dir = opendir(filename);
- while ((ent = readdir(dir)) != NULL) {
- if (ent->d_name[0] == '.')
- continue;
- WINMATCH_ADD(&ignoreq, ent->d_name);
- }
-
- closedir(dir);
-}
-
-void
-conf_parseautogroups(struct conf *c, char *filename)
-{
- DIR *dir;
- struct dirent *ent;
- struct autogroupwin *aw;
- char current_file[MAXPATHLEN], *p;
- char group[CALMWM_MAXNAMELEN];
- int len;
-
- dir = opendir(filename);
- while ((ent = readdir(dir)) != NULL) {
- if (ent->d_name[0] == '.')
- continue;
-
- snprintf(current_file, sizeof(current_file),
- "%s/%s", filename, ent->d_name);
- if (!dirent_islink(current_file))
- continue;
-
- if ((len = readlink(current_file,
- group, sizeof(group) - 1)) < 0)
- continue;
- group[len] = '\0';
-
- XCALLOC(aw, struct autogroupwin);
-
- if ((p = strchr(ent->d_name, ',')) == NULL) {
- aw->name = NULL;
- aw->class = xstrdup(ent->d_name);
- } else {
- *(p++) = '\0';
- aw->name = xstrdup(ent->d_name);
- aw->class = xstrdup(p);
- }
- aw->group = xstrdup(group);
-
- TAILQ_INSERT_TAIL(&c->autogroupq, aw, entry);
- }
-
- closedir(dir);
-
-}