aewl

diff main.c @ 75:f08271b7cb20

rearranged several stuff
author Anselm R. Garbe <garbeam@wmii.de>
date Sat, 15 Jul 2006 16:30:50 +0200
parents 5370ef170cc9
children 4bd49f404f10
line diff
     1.1 --- a/main.c	Fri Jul 14 22:54:09 2006 +0200
     1.2 +++ b/main.c	Sat Jul 15 16:30:50 2006 +0200
     1.3 @@ -43,16 +43,16 @@
     1.4  Client *clients = NULL;
     1.5  Client *sel = NULL;
     1.6  
     1.7 -static Bool other_wm_running;
     1.8 +static Bool otherwm;
     1.9  static const char version[] =
    1.10  	"dwm-" VERSION ", (C)opyright MMVI Anselm R. Garbe\n";
    1.11 -static int (*x_xerror) (Display *, XErrorEvent *);
    1.12 +static int (*xerrorxlib)(Display *, XErrorEvent *);
    1.13  
    1.14  static void
    1.15 -usage() {	error("usage: dwm [-v]\n"); }
    1.16 +usage() {	eprint("usage: dwm [-v]\n"); }
    1.17  
    1.18  static void
    1.19 -scan_wins()
    1.20 +scan()
    1.21  {
    1.22  	unsigned int i, num;
    1.23  	Window *wins;
    1.24 @@ -73,6 +73,22 @@
    1.25  		XFree(wins);
    1.26  }
    1.27  
    1.28 +static void
    1.29 +cleanup()
    1.30 +{
    1.31 +	while(sel) {
    1.32 +		resize(sel, True);
    1.33 +		unmanage(sel);
    1.34 +	}
    1.35 +	XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
    1.36 +}
    1.37 +
    1.38 +void
    1.39 +quit(Arg *arg)
    1.40 +{
    1.41 +	running = False;
    1.42 +}
    1.43 +
    1.44  static int
    1.45  win_property(Window w, Atom a, Atom t, long l, unsigned char **prop)
    1.46  {
    1.47 @@ -94,7 +110,7 @@
    1.48  }
    1.49  
    1.50  int
    1.51 -proto(Window w)
    1.52 +getproto(Window w)
    1.53  {
    1.54  	unsigned char *protocols;
    1.55  	long res;
    1.56 @@ -129,58 +145,42 @@
    1.57  }
    1.58  
    1.59  /*
    1.60 + * Startup Error handler to check if another window manager
    1.61 + * is already running.
    1.62 + */
    1.63 +static int
    1.64 +xerrorstart(Display *dsply, XErrorEvent *ee)
    1.65 +{
    1.66 +	otherwm = True;
    1.67 +	return -1;
    1.68 +}
    1.69 +
    1.70 +/*
    1.71   * There's no way to check accesses to destroyed windows, thus
    1.72   * those cases are ignored (especially on UnmapNotify's).
    1.73   * Other types of errors call Xlib's default error handler, which
    1.74   * calls exit().
    1.75   */
    1.76  int
    1.77 -xerror(Display *dpy, XErrorEvent *error)
    1.78 +xerror(Display *dpy, XErrorEvent *ee)
    1.79  {
    1.80 -	if(error->error_code == BadWindow
    1.81 -			|| (error->request_code == X_SetInputFocus
    1.82 -				&& error->error_code == BadMatch)
    1.83 -			|| (error->request_code == X_PolyText8
    1.84 -				&& error->error_code == BadDrawable)
    1.85 -			|| (error->request_code == X_PolyFillRectangle
    1.86 -				&& error->error_code == BadDrawable)
    1.87 -			|| (error->request_code == X_PolySegment
    1.88 -				&& error->error_code == BadDrawable)
    1.89 -			|| (error->request_code == X_ConfigureWindow
    1.90 -				&& error->error_code == BadMatch)
    1.91 -			|| (error->request_code == X_GrabKey
    1.92 -				&& error->error_code == BadAccess))
    1.93 +	if(ee->error_code == BadWindow
    1.94 +			|| (ee->request_code == X_SetInputFocus
    1.95 +				&& ee->error_code == BadMatch)
    1.96 +			|| (ee->request_code == X_PolyText8
    1.97 +				&& ee->error_code == BadDrawable)
    1.98 +			|| (ee->request_code == X_PolyFillRectangle
    1.99 +				&& ee->error_code == BadDrawable)
   1.100 +			|| (ee->request_code == X_PolySegment
   1.101 +				&& ee->error_code == BadDrawable)
   1.102 +			|| (ee->request_code == X_ConfigureWindow
   1.103 +				&& ee->error_code == BadMatch)
   1.104 +			|| (ee->request_code == X_GrabKey
   1.105 +				&& ee->error_code == BadAccess))
   1.106  		return 0;
   1.107  	fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n",
   1.108 -			error->request_code, error->error_code);
   1.109 -	return x_xerror(dpy, error); /* may call exit() */
   1.110 -}
   1.111 -
   1.112 -/*
   1.113 - * Startup Error handler to check if another window manager
   1.114 - * is already running.
   1.115 - */
   1.116 -static int
   1.117 -startup_xerror(Display *dpy, XErrorEvent *error)
   1.118 -{
   1.119 -	other_wm_running = True;
   1.120 -	return -1;
   1.121 -}
   1.122 -
   1.123 -static void
   1.124 -cleanup()
   1.125 -{
   1.126 -	while(sel) {
   1.127 -		resize(sel, True);
   1.128 -		unmanage(sel);
   1.129 -	}
   1.130 -	XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
   1.131 -}
   1.132 -
   1.133 -void
   1.134 -quit(Arg *arg)
   1.135 -{
   1.136 -	running = False;
   1.137 +			ee->request_code, ee->error_code);
   1.138 +	return xerrorxlib(dpy, ee); /* may call exit() */
   1.139  }
   1.140  
   1.141  int
   1.142 @@ -208,23 +208,23 @@
   1.143  
   1.144  	dpy = XOpenDisplay(0);
   1.145  	if(!dpy)
   1.146 -		error("dwm: cannot connect X server\n");
   1.147 +		eprint("dwm: cannot connect X server\n");
   1.148  
   1.149  	screen = DefaultScreen(dpy);
   1.150  	root = RootWindow(dpy, screen);
   1.151  
   1.152  	/* check if another WM is already running */
   1.153 -	other_wm_running = False;
   1.154 -	XSetErrorHandler(startup_xerror);
   1.155 +	otherwm = False;
   1.156 +	XSetErrorHandler(xerrorstart);
   1.157  	/* this causes an error if some other WM is running */
   1.158  	XSelectInput(dpy, root, SubstructureRedirectMask);
   1.159  	XFlush(dpy);
   1.160  
   1.161 -	if(other_wm_running)
   1.162 -		error("dwm: another window manager is already running\n");
   1.163 +	if(otherwm)
   1.164 +		eprint("dwm: another window manager is already running\n");
   1.165  
   1.166  	XSetErrorHandler(0);
   1.167 -	x_xerror = XSetErrorHandler(xerror);
   1.168 +	xerrorxlib = XSetErrorHandler(xerror);
   1.169  
   1.170  	/* init atoms */
   1.171  	wm_atom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
   1.172 @@ -278,7 +278,7 @@
   1.173  	XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
   1.174  
   1.175  	strcpy(stext, "dwm-"VERSION);
   1.176 -	scan_wins();
   1.177 +	scan();
   1.178  
   1.179  	/* main event loop, reads status text from stdin as well */
   1.180  Mainloop:
   1.181 @@ -292,7 +292,7 @@
   1.182  		if(i == -1 && errno == EINTR)
   1.183  			continue;
   1.184  		if(i < 0)
   1.185 -			error("select failed\n");
   1.186 +			eprint("select failed\n");
   1.187  		else if(i > 0) {
   1.188  			if(FD_ISSET(ConnectionNumber(dpy), &rd)) {
   1.189  				while(XPending(dpy)) {