X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=main.c;h=f1f71fd199c0043b043416b32027e7884ce851c2;hb=3ba8b71abafdd52adaf8c2d4bfa56dc9023c865e;hp=46e0b443bdfe9ac0ae61fbf5e861780d8b5e1d6e;hpb=c0fcfb782793ec6cc10531a1f76d4a25d1cbe48a;p=dmenu.git diff --git a/main.c b/main.c index 46e0b44..f1f71fd 100644 --- a/main.c +++ b/main.c @@ -15,6 +15,8 @@ #include #include +#define CLEANMASK(mask) (mask & ~(numlockmask | LockMask)) + typedef struct Item Item; struct Item { Item *next; /* traverses all items */ @@ -26,11 +28,12 @@ struct Item { static char text[4096]; static char *prompt = NULL; -static int mx, my, mw, mh; +static int mw, mh; static int ret = 0; static int nitem = 0; static unsigned int cmdw = 0; static unsigned int promptw = 0; +static unsigned int numlockmask = 0; static Bool running = True; static Item *allitems = NULL; /* first of all items */ static Item *item = NULL; /* first of pattern matching items */ @@ -187,7 +190,7 @@ kpress(XKeyEvent * e) { return; } } - if(e->state & Mod1Mask) { + if(CLEANMASK(e->state) & Mod1Mask) { switch(ksym) { default: return; case XK_h: @@ -347,10 +350,11 @@ main(int argc, char *argv[]) { char *selbg = SELBGCOLOR; char *selfg = SELFGCOLOR; fd_set rd; - int i; + int i, j; struct timeval timeout; Item *itm; XEvent ev; + XModifierKeymap *modmap; XSetWindowAttributes wa; timeout.tv_usec = 0; @@ -408,6 +412,15 @@ main(int argc, char *argv[]) { if(select(ConnectionNumber(dpy) + 1, &rd, NULL, NULL, &timeout) < 1) goto UninitializedEnd; maxname = readstdin(); + /* init modifier map */ + modmap = XGetModifierMapping(dpy); + for (i = 0; i < 8; i++) { + for (j = 0; j < modmap->max_keypermod; j++) { + if(modmap->modifiermap[i * modmap->max_keypermod + j] == XKeysymToKeycode(dpy, XK_Num_Lock)) + numlockmask = (1 << i); + } + } + XFreeModifiermap(modmap); /* style */ dc.norm[ColBG] = getcolor(normbg); dc.norm[ColFG] = getcolor(normfg); @@ -418,12 +431,10 @@ main(int argc, char *argv[]) { wa.override_redirect = 1; wa.background_pixmap = ParentRelative; wa.event_mask = ExposureMask | ButtonPressMask | KeyPressMask; - mx = my = 0; mw = DisplayWidth(dpy, screen); mh = dc.font.height + 2; - if(bottom) - my += DisplayHeight(dpy, screen) - mh; - win = XCreateWindow(dpy, root, mx, my, mw, mh, 0, + win = XCreateWindow(dpy, root, 0, + bottom ? DisplayHeight(dpy, screen) - mh : 0, mw, mh, 0, DefaultDepth(dpy, screen), CopyFromParent, DefaultVisual(dpy, screen), CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);