summary refs log tree commit diff
path: root/calmwm.c
diff options
context:
space:
mode:
authorokan <okan>2012-12-19 15:21:34 +0000
committerokan <okan>2012-12-19 15:21:34 +0000
commitf77166194f4586cb19abcb7951ca05e356ac74e1 (patch)
tree304227f75a0b05af3f544be74a6ce47b3fae676e /calmwm.c
parent878eb6bf050c6b55104e12c17b9644c2625bace0 (diff)
parentdc1e3a88438dc732349154bca610dbe813d2fc04 (diff)
downloadcwm-f77166194f4586cb19abcb7951ca05e356ac74e1.tar.gz
cwm-f77166194f4586cb19abcb7951ca05e356ac74e1.tar.xz
cwm-f77166194f4586cb19abcb7951ca05e356ac74e1.zip
cvsimport
Diffstat (limited to 'calmwm.c')
-rw-r--r--calmwm.c97
1 files changed, 30 insertions, 67 deletions
diff --git a/calmwm.c b/calmwm.c
index 08d0b53..58cb768 100644
--- a/calmwm.c
+++ b/calmwm.c
@@ -26,6 +26,7 @@
 #include <errno.h>
 #include <getopt.h>
 #include <locale.h>
+#include <pwd.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -48,21 +49,22 @@ struct client_ctx_q		 Clientq = TAILQ_HEAD_INITIALIZER(Clientq);
 
 int				 HasRandr, Randr_ev;
 struct conf			 Conf;
+char				*homedir;
 
 static void	sigchld_cb(int);
 static void	dpy_init(const char *);
 static int	x_errorhandler(Display *, XErrorEvent *);
 static int	x_wmerrorhandler(Display *, XErrorEvent *);
 static void	x_setup(void);
-static void	x_setupscreen(struct screen_ctx *, u_int);
 static void	x_teardown(void);
 
 int
 main(int argc, char **argv)
 {
 	const char	*conf_file = NULL;
-	char		*display_name = NULL;
+	char		*conf_path, *display_name = NULL;
 	int		 ch;
+	struct passwd	*pw;
 
 	if (!setlocale(LC_CTYPE, "") || !XSupportsLocale())
 		warnx("no locale support");
@@ -87,15 +89,36 @@ main(int argc, char **argv)
 	if (signal(SIGCHLD, sigchld_cb) == SIG_ERR)
 		err(1, "signal");
 
+	if ((homedir = getenv("HOME")) == NULL || *homedir == '\0') {
+		pw = getpwuid(getuid());
+		if (pw != NULL && pw->pw_dir != NULL && *pw->pw_dir != '\0')
+			homedir = pw->pw_dir;
+		else
+			homedir = "/";
+	}
+
+	if (conf_file == NULL)
+		xasprintf(&conf_path, "%s/%s", homedir, CONFFILE);
+	else
+		conf_path = xstrdup(conf_file);
+
+	if (access(conf_path, R_OK) != 0) {
+		if (conf_file != NULL)
+			warn("%s", conf_file);
+		free(conf_path);
+		conf_path = NULL;
+	}
+
 	dpy_init(display_name);
 
-	bzero(&Conf, sizeof(Conf));
-	conf_setup(&Conf, conf_file);
+	conf_init(&Conf);
+	if (conf_path && (parse_config(conf_path, &Conf) == -1))
+		warnx("config file %s has errors, not loading", conf_path);
+	free(conf_path);
+
 	xu_getatoms();
 	x_setup();
-
 	xev_loop();
-
 	x_teardown();
 
 	return (0);
@@ -135,7 +158,7 @@ x_setup(void)
 
 	for (i = 0; i < ScreenCount(X_Dpy); i++) {
 		sc = xcalloc(1, sizeof(*sc));
-		x_setupscreen(sc, i);
+		screen_init(sc, i);
 		TAILQ_INSERT_TAIL(&Screenq, sc, entry);
 	}
 
@@ -150,69 +173,9 @@ x_setup(void)
 static void
 x_teardown(void)
 {
-	struct screen_ctx	*sc;
-
-	TAILQ_FOREACH(sc, &Screenq, entry)
-		XFreeGC(X_Dpy, sc->gc);
-
 	XCloseDisplay(X_Dpy);
 }
 
-static void
-x_setupscreen(struct screen_ctx *sc, u_int which)
-{
-	Window			*wins, w0, w1;
-	XWindowAttributes	 winattr;
-	XSetWindowAttributes	 rootattr;
-	u_int			 nwins, i;
-
-	sc->which = which;
-	sc->rootwin = RootWindow(X_Dpy, sc->which);
-
-	xu_ewmh_net_supported(sc);
-	xu_ewmh_net_supported_wm_check(sc);
-
-	conf_gap(&Conf, sc);
-
-	screen_update_geometry(sc);
-
-	conf_color(&Conf, sc);
-
-	group_init(sc);
-	conf_font(&Conf, sc);
-
-	TAILQ_INIT(&sc->mruq);
-
-	/* Initialize menu window. */
-	menu_init(sc);
-
-	rootattr.cursor = Cursor_normal;
-	rootattr.event_mask = CHILDMASK|PropertyChangeMask|EnterWindowMask|
-	    LeaveWindowMask|ColormapChangeMask|BUTTONMASK;
-
-	XChangeWindowAttributes(X_Dpy, sc->rootwin,
-	    CWEventMask|CWCursor, &rootattr);
-
-	/* Deal with existing clients. */
-	XQueryTree(X_Dpy, sc->rootwin, &w0, &w1, &wins, &nwins);
-
-	for (i = 0; i < nwins; i++) {
-		XGetWindowAttributes(X_Dpy, wins[i], &winattr);
-		if (winattr.override_redirect ||
-		    winattr.map_state != IsViewable)
-			continue;
-		(void)client_new(wins[i], sc, winattr.map_state != IsUnmapped);
-	}
-	XFree(wins);
-
-	screen_updatestackingorder(sc);
-
-	if (HasRandr)
-		XRRSelectInput(X_Dpy, sc->rootwin, RRScreenChangeNotifyMask);
-
-	XSync(X_Dpy, False);
-}
-
 static int
 x_wmerrorhandler(Display *dpy, XErrorEvent *e)
 {