dwm-meillo

diff main.c @ 291:8e6e0aa5e2ae

removed NUMLOCKMASK, added dynamically calculated numlockmask instead
author Anselm R.Garbe <arg@10ksloc.org>
date Mon, 14 Aug 2006 19:18:02 +0200
parents 0d0444d32c59
children 4aa632b6ba66
line diff
     1.1 --- a/main.c	Mon Aug 14 18:47:13 2006 +0200
     1.2 +++ b/main.c	Mon Aug 14 19:18:02 2006 +0200
     1.3 @@ -11,6 +11,7 @@
     1.4  #include <unistd.h>
     1.5  #include <sys/select.h>
     1.6  #include <X11/cursorfont.h>
     1.7 +#include <X11/keysym.h>
     1.8  #include <X11/Xatom.h>
     1.9  #include <X11/Xproto.h>
    1.10  
    1.11 @@ -85,7 +86,7 @@
    1.12  char stext[1024];
    1.13  Bool *seltag;
    1.14  int screen, sx, sy, sw, sh, bx, by, bw, bh, mw;
    1.15 -unsigned int ntags;
    1.16 +unsigned int ntags, numlockmask;
    1.17  Atom wmatom[WMLast], netatom[NetLast];
    1.18  Bool running = True;
    1.19  Bool issel = True;
    1.20 @@ -162,12 +163,13 @@
    1.21  int
    1.22  main(int argc, char *argv[])
    1.23  {
    1.24 -	int i, xfd;
    1.25 +	int i, j, xfd;
    1.26  	unsigned int mask;
    1.27  	fd_set rd;
    1.28  	Bool readin = True;
    1.29  	Window w;
    1.30  	XEvent ev;
    1.31 +	XModifierKeymap *modmap;
    1.32  	XSetWindowAttributes wa;
    1.33  
    1.34  	if(argc == 2 && !strncmp("-v", argv[1], 3)) {
    1.35 @@ -211,7 +213,16 @@
    1.36  	cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
    1.37  	cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
    1.38  
    1.39 -	wa.event_mask = SubstructureRedirectMask | EnterWindowMask | LeaveWindowMask;
    1.40 +	modmap = XGetModifierMapping(dpy);
    1.41 +	for (i = 0; i < 8; i++) {
    1.42 +		for (j = 0; j < modmap->max_keypermod; j++) {
    1.43 +			if(modmap->modifiermap[i * modmap->max_keypermod + j] == XKeysymToKeycode(dpy, XK_Num_Lock))
    1.44 +				numlockmask = (1 << i);
    1.45 +		}
    1.46 +	}
    1.47 +	XFree(modmap);
    1.48 +
    1.49 +	wa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask | EnterWindowMask | LeaveWindowMask;
    1.50  	wa.cursor = cursor[CurNormal];
    1.51  	XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
    1.52  
    1.53 @@ -233,13 +244,12 @@
    1.54  	sh = DisplayHeight(dpy, screen);
    1.55  	mw = (sw * MASTERW) / 100;
    1.56  
    1.57 +	bx = by = 0;
    1.58 +	bw = sw;
    1.59 +	dc.h = bh = dc.font.height + 4;
    1.60  	wa.override_redirect = 1;
    1.61  	wa.background_pixmap = ParentRelative;
    1.62  	wa.event_mask = ButtonPressMask | ExposureMask;
    1.63 -
    1.64 -	bx = by = 0;
    1.65 -	bw = sw;
    1.66 -	dc.h = bh = dc.font.height + 4;
    1.67  	barwin = XCreateWindow(dpy, root, bx, by, bw, bh, 0, DefaultDepth(dpy, screen),
    1.68  			CopyFromParent, DefaultVisual(dpy, screen),
    1.69  			CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
    1.70 @@ -258,6 +268,7 @@
    1.71  
    1.72  	/* main event loop, also reads status text from stdin */
    1.73  	XSync(dpy, False);
    1.74 +	goto XLoop;
    1.75  	while(running) {
    1.76  		FD_ZERO(&rd);
    1.77  		if(readin)
    1.78 @@ -278,6 +289,7 @@
    1.79  				drawstatus();
    1.80  			}
    1.81  			if(FD_ISSET(xfd, &rd)) {
    1.82 +XLoop:
    1.83  				while(XPending(dpy)) {
    1.84  					XNextEvent(dpy, &ev);
    1.85  					if(handler[ev.type])