Move DWM global var "xerrorxlib" to "src/xbase.c"
This commit is contained in:
parent
a973317c39
commit
cfd27170e7
5 changed files with 34 additions and 34 deletions
20
src/dwm.c
20
src/dwm.c
|
@ -152,7 +152,6 @@ static void attach(Client *c);
|
|||
static void attachstack(Client *c);
|
||||
static void configborder(const Arg *arg);
|
||||
static void configgap(const Arg *arg);
|
||||
static void checkotherwm();
|
||||
static void cleanup();
|
||||
static void configure(Client *c);
|
||||
static void detach(Client *c);
|
||||
|
@ -230,7 +229,6 @@ static Xbase xbase = NULL;
|
|||
static Unit global_unit = NULL;
|
||||
|
||||
static const char broken[] = "broken";
|
||||
static int (*xerrorxlib)(Display *, XErrorEvent *);
|
||||
static unsigned int numlockmask = 0;
|
||||
static Atoms atoms = NULL;
|
||||
static int running = 1;
|
||||
|
@ -274,9 +272,7 @@ static void (*handler[LASTEvent])(XEvent*) = {
|
|||
|
||||
int dwm_main(const char *const new_program_title)
|
||||
{
|
||||
xbase = xbase_new(new_program_title);
|
||||
|
||||
checkotherwm();
|
||||
xbase = xbase_new(new_program_title, xerror);
|
||||
|
||||
if (!(atoms = atoms_create(xbase->x_display))) {
|
||||
fatal("cannot create atoms");
|
||||
|
@ -511,20 +507,6 @@ void configgap(const Arg *const arg)
|
|||
arrange(selmon);
|
||||
}
|
||||
|
||||
void checkotherwm()
|
||||
{
|
||||
xerrorxlib = XSetErrorHandler(xerrorstart);
|
||||
/* this causes an error if some other window manager is running */
|
||||
XSelectInput(
|
||||
xbase->x_display,
|
||||
DefaultRootWindow(xbase->x_display),
|
||||
SubstructureRedirectMask
|
||||
);
|
||||
XSync(xbase->x_display, False);
|
||||
XSetErrorHandler(xerror);
|
||||
XSync(xbase->x_display, False);
|
||||
}
|
||||
|
||||
void cleanup()
|
||||
{
|
||||
Layout foo = { NULL, NULL };
|
||||
|
|
|
@ -25,7 +25,7 @@ int xerror(Display *const dpy, XErrorEvent *const ee)
|
|||
ee->error_code
|
||||
);
|
||||
|
||||
return xerrorxlib(dpy, ee); /* may call exit */
|
||||
return xbase->x_error(dpy, ee); /* may call exit */
|
||||
}
|
||||
|
||||
int xerrordummy(
|
||||
|
@ -35,14 +35,4 @@ int xerrordummy(
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* Startup Error handler to check if another window manager
|
||||
* is already running. */
|
||||
int xerrorstart(
|
||||
__attribute__((unused)) Display *const dpy,
|
||||
__attribute__((unused)) XErrorEvent *const ee
|
||||
) {
|
||||
fatal("another window manager is already running");
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif // _DWM_XERROR_C
|
||||
|
|
|
@ -3,6 +3,5 @@
|
|||
|
||||
static int xerror(Display *dpy, XErrorEvent *ee);
|
||||
static int xerrordummy(Display *dpy, XErrorEvent *ee);
|
||||
static int xerrorstart(Display *dpy, XErrorEvent *ee);
|
||||
|
||||
#endif // _DWM_XERROR_H
|
||||
|
|
31
src/xbase.c
31
src/xbase.c
|
@ -5,8 +5,14 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
Xbase xbase_new(const char *const program_title)
|
||||
{
|
||||
/* Startup Error handler to check if another
|
||||
* window manager is already running. */
|
||||
static int x_error_wm_check(Display*, XErrorEvent*);
|
||||
|
||||
Xbase xbase_new(
|
||||
const char *const program_title,
|
||||
const XErrorHandler x_error_handler
|
||||
) {
|
||||
if (!XSupportsLocale()) warning("no locale support in X");
|
||||
|
||||
Xbase xbase = malloc(sizeof(struct Xbase));
|
||||
|
@ -27,6 +33,20 @@ Xbase xbase_new(const char *const program_title)
|
|||
DisplayHeight(xbase->x_display, xbase->x_screen)
|
||||
);
|
||||
|
||||
if (!(xbase->x_error = XSetErrorHandler(x_error_wm_check))) {
|
||||
fatal("no X error handler is given");
|
||||
}
|
||||
|
||||
// This causes an error if some other window manager is running
|
||||
XSelectInput(
|
||||
xbase->x_display,
|
||||
DefaultRootWindow(xbase->x_display),
|
||||
SubstructureRedirectMask
|
||||
);
|
||||
XSync(xbase->x_display, False);
|
||||
XSetErrorHandler(x_error_handler);
|
||||
XSync(xbase->x_display, False);
|
||||
|
||||
return xbase;
|
||||
}
|
||||
|
||||
|
@ -38,3 +58,10 @@ void xbase_delete(const Xbase xbase)
|
|||
XCloseDisplay(xbase->x_display);
|
||||
free(xbase);
|
||||
}
|
||||
|
||||
int x_error_wm_check(
|
||||
__attribute__((unused)) Display *const x_display,
|
||||
__attribute__((unused)) XErrorEvent *const x_error_event
|
||||
) {
|
||||
fatal("another window manager is already running");
|
||||
}
|
||||
|
|
|
@ -19,9 +19,11 @@ typedef struct Xbase {
|
|||
int x_root;
|
||||
|
||||
struct Sizes screen_sizes;
|
||||
|
||||
int (*x_error)(Display*, XErrorEvent*);
|
||||
} *Xbase;
|
||||
|
||||
Xbase xbase_new(const char *program_title);
|
||||
Xbase xbase_new(const char *program_title, XErrorHandler x_error_handler);
|
||||
void xbase_delete(Xbase xbase);
|
||||
|
||||
#endif // _XBASE_H
|
||||
|
|
Loading…
Reference in a new issue