wmfs: Check if another window manager is already running

This commit is contained in:
Martin Duquesnoy 2008-10-16 21:34:53 +02:00
parent e35434ecb9
commit 187029fc90
2 changed files with 51 additions and 16 deletions

View File

@ -54,6 +54,38 @@ errorhandlerdummy(Display *d, XErrorEvent *event)
return 0; return 0;
} }
/* Only for check if another WM is already running */
int
errorhandlerstart(Display *d, XErrorEvent *event)
{
owm = True;
return -1;
}
void
quit(void)
{
int i;
/* Exiting WMFS :'( */
XftFontClose(dpy, xftfont);
XFreeCursor(dpy, cursor[CurNormal]);
XFreeCursor(dpy, cursor[CurMove]);
XFreeCursor(dpy, cursor[CurResize]);
bar_delete(bar);
bar_delete(layoutsym);
if(conf.nbutton)
for(i = 0; i < conf.nbutton; ++i)
bar_delete(conf.barbutton[i].bw);
free(conf.barbutton);
free(keys);
free(clients);
XSync(dpy, False);
return;
}
void void
init(void) init(void)
{ {
@ -81,7 +113,7 @@ init(void)
xftfont = XftFontOpenName(dpy, screen, "sans-10"); xftfont = XftFontOpenName(dpy, screen, "sans-10");
} }
fonth = (xftfont->ascent + xftfont->descent); fonth = (xftfont->ascent + xftfont->descent);
barheight = fonth + 4; barheight = fonth + 3;
/* INIT CURSOR */ /* INIT CURSOR */
@ -123,7 +155,6 @@ init(void)
updatebar(); updatebar();
/* INIT STUFF */ /* INIT STUFF */
XSetErrorHandler(errorhandler);
grabkeys(); grabkeys();
return; return;
@ -269,25 +300,26 @@ main(int argc, char **argv)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
/* Check if an other WM is already running */
owm = False;
XSetErrorHandler(errorhandlerstart);
XSelectInput(dpy, DefaultRootWindow(dpy), SubstructureRedirectMask);
XSync(dpy, False);
if(owm)
{
fprintf(stderr, "WMFS Error: Another Window Manager is already running.\n");
exit(EXIT_FAILURE);
}
XSetErrorHandler(errorhandler);
XSync(dpy, False);
/* Let's Go ! */ /* Let's Go ! */
init_conf(); init_conf();
init(); init();
scan(); scan();
mainloop(); mainloop();
quit();
/* Exiting WMFS :'( */
XftFontClose(dpy, xftfont);
XFreeCursor(dpy, cursor[CurNormal]);
XFreeCursor(dpy, cursor[CurMove]);
XFreeCursor(dpy, cursor[CurResize]);
bar_delete(bar);
if(conf.nbutton)
for(i = 0; i < conf.nbutton; ++i)
bar_delete(conf.barbutton[i].bw);
free(conf.barbutton);
free(keys);
XSync(dpy, False);
XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
XCloseDisplay(dpy); XCloseDisplay(dpy);

View File

@ -159,6 +159,8 @@ void uicb_set_nmaster(uicb_t);
/* wmfs.c */ /* wmfs.c */
int errorhandler(Display *d, XErrorEvent *event); int errorhandler(Display *d, XErrorEvent *event);
int errorhandlerdummy(Display *d, XErrorEvent *event); int errorhandlerdummy(Display *d, XErrorEvent *event);
int errorhandlerstart(Display *d, XErrorEvent *event);
void quit(void);
void init(void); void init(void);
void mainloop(void); void mainloop(void);
void scan(void); void scan(void);
@ -176,6 +178,7 @@ int mw, mh;
Conf conf; Conf conf;
Key *keys; Key *keys;
Bool exiting; Bool exiting;
Bool owm;
/* Atoms / Cursors */ /* Atoms / Cursors */
Atom wm_atom[WMLast]; Atom wm_atom[WMLast];