commit 29b78688308dfb0cd4edeac00d8f57f8a287405f
parent 4888eeacaf0de69e2f66a4b01e026f69355ee9b5
Author: wael <wael@wael.cc>
Date: Fri, 6 Jan 2023 10:41:20 +0300
check for wm before running
Diffstat:
M | shod.c | | | 22 | ++++++++++++++++++++++ |
1 file changed, 22 insertions(+), 0 deletions(-)
diff --git a/shod.c b/shod.c
@@ -90,6 +90,16 @@ xerror(Display *dpy, XErrorEvent *e)
exit(1); /* unreached */
}
+
+/* Startup Error handler to check if another window manager
+ * is already running. */
+static int
+xerrorstart(Display *dpy, XErrorEvent *ee)
+{
+ fprintf(stderr, "shod: another window manager is already running\n");
+ exit(1);
+}
+
/* stop running */
static void
siginthandler(int signo)
@@ -268,6 +278,17 @@ autostart(char *filename)
waitpid(pid, NULL, 0);
}
+static void
+checkotherwm(void)
+{
+ xerrorxlib = XSetErrorHandler(xerrorstart);
+ /* this causes an error if some other window manager is running */
+ XSelectInput(dpy, DefaultRootWindow(dpy), SubstructureRedirectMask);
+ XSync(dpy, False);
+ XSetErrorHandler(xerror);
+ XSync(dpy, False);
+}
+
/* destroy dummy windows */
static void
cleandummywindows(void)
@@ -327,6 +348,7 @@ main(int argc, char *argv[])
if (!setlocale(LC_ALL, "") || !XSupportsLocale())
warnx("warning: no locale support");
xinit();
+ checkotherwm();
xinitvisual();
xiniterrfunc(xerror, &xerrorxlib);
XrmInitialize();