summary refs log tree commit diff
path: root/calmwm.c
diff options
context:
space:
mode:
authorokan <okan>2014-01-22 21:48:27 +0000
committerokan <okan>2014-01-22 21:48:27 +0000
commit77aa5ac45b06b4afa392e21d55e3318913b0347b (patch)
tree958f412e4eb2d3682b95e9c62eb40085e43d3e41 /calmwm.c
parentac3162439ad826026b499363b445e8c533313ff2 (diff)
downloadcwm-77aa5ac45b06b4afa392e21d55e3318913b0347b.tar.gz
cwm-77aa5ac45b06b4afa392e21d55e3318913b0347b.tar.xz
cwm-77aa5ac45b06b4afa392e21d55e3318913b0347b.zip
Somewhat streamline event loop/restart/quit handling; most notable
change allows a restart to trigger proper teardown first, even though
teardown is not (yet) complete.

After some discussion with oga@nicotinebsd.org regarding a more
complicated version/idea.
Diffstat (limited to 'calmwm.c')
-rw-r--r--calmwm.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/calmwm.c b/calmwm.c
index 75bb675..9e76d34 100644
--- a/calmwm.c
+++ b/calmwm.c
@@ -47,10 +47,12 @@ struct client_ctx_q		 Clientq = TAILQ_HEAD_INITIALIZER(Clientq);
 int				 HasRandr, Randr_ev;
 struct conf			 Conf;
 const char			*homedir;
+volatile sig_atomic_t		 cwm_status;
 
 static void	sigchld_cb(int);
 static int	x_errorhandler(Display *, XErrorEvent *);
 static void	x_init(const char *);
+static void	x_restart(void);
 static void	x_teardown(void);
 static int	x_wmerrorhandler(Display *, XErrorEvent *);
 
@@ -111,8 +113,12 @@ main(int argc, char **argv)
 	free(conf_path);
 
 	x_init(display_name);
-	xev_loop();
+	cwm_status = CWM_RUNNING;
+	while (cwm_status == CWM_RUNNING)
+		xev_process();
 	x_teardown();
+	if (cwm_status == CWM_RESTART)
+		x_restart();
 
 	return (0);
 }
@@ -141,6 +147,13 @@ x_init(const char *dpyname)
 }
 
 static void
+x_restart(void)
+{
+	(void)setsid();
+	(void)execvp(cwm_argv[0], cwm_argv);
+}
+
+static void
 x_teardown(void)
 {
 	XCloseDisplay(X_Dpy);