X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=main.c;h=743967adbdd1379a6976c09fef4e948759144a79;hb=796c4fb9e542d3e14c9a2a62a4a673d210c9ad12;hp=7b4365e59ff09b7ed349070b2c8b54a34a0848de;hpb=5fd7af18c6b24bffd4701156feffcbc0db3b1d69;p=dmenu.git diff --git a/main.c b/main.c index 7b4365e..743967a 100644 --- a/main.c +++ b/main.c @@ -2,17 +2,16 @@ * (C)opyright MMVI Sander van Dijk * See LICENSE file for license details. */ - #include "dmenu.h" #include +#include #include #include #include #include #include #include -#include #include #include @@ -146,7 +145,7 @@ kpress(XKeyEvent * e) { len = strlen(text); buf[0] = 0; - num = XLookupString(e, buf, sizeof(buf), &ksym, 0); + num = XLookupString(e, buf, sizeof buf, &ksym, 0); if(IsFunctionKey(ksym) || IsKeypadKey(ksym) || IsMiscFunctionKey(ksym) || IsPFKey(ksym) || IsPrivateKeypadKey(ksym)) @@ -183,7 +182,7 @@ kpress(XKeyEvent * e) { case XK_Tab: if(!sel) return; - strncpy(text, sel->text, sizeof(text)); + strncpy(text, sel->text, sizeof text); match(text); break; case XK_Right: @@ -223,9 +222,9 @@ kpress(XKeyEvent * e) { if(num && !iscntrl((int) buf[0])) { buf[num] = 0; if(len > 0) - strncat(text, buf, sizeof(text)); + strncat(text, buf, sizeof text); else - strncpy(text, buf, sizeof(text)); + strncpy(text, buf, sizeof text); match(text); } } @@ -240,7 +239,7 @@ readstdin(void) { Item *i, *new; i = 0; - while(fgets(buf, sizeof(buf), stdin)) { + while(fgets(buf, sizeof buf, stdin)) { len = strlen(buf); if (buf[len - 1] == '\n') buf[len - 1] = 0; @@ -287,24 +286,31 @@ main(int argc, char *argv[]) { timeout.tv_sec = 3; /* command line args */ for(i = 1; i < argc; i++) - if(!strncmp(argv[i], "-font", 6)) - font = argv[++i]; - else if(!strncmp(argv[i], "-normbg", 8)) - normbg = argv[++i]; - else if(!strncmp(argv[i], "-normfg", 8)) - normfg = argv[++i]; - else if(!strncmp(argv[i], "-selbg", 7)) - selbg = argv[++i]; - else if(!strncmp(argv[i], "-selfg", 7)) - selfg = argv[++i]; - else if(!strncmp(argv[i], "-t", 3)) - timeout.tv_sec = atoi(argv[++i]); + if(!strncmp(argv[i], "-font", 6)) { + if(++i < argc) font = argv[i]; + } + else if(!strncmp(argv[i], "-normbg", 8)) { + if(++i < argc) normbg = argv[i]; + } + else if(!strncmp(argv[i], "-normfg", 8)) { + if(++i < argc) normfg = argv[i]; + } + else if(!strncmp(argv[i], "-selbg", 7)) { + if(++i < argc) selbg = argv[i]; + } + else if(!strncmp(argv[i], "-selfg", 7)) { + if(++i < argc) selfg = argv[i]; + } + else if(!strncmp(argv[i], "-t", 3)) { + if(++i < argc) timeout.tv_sec = atoi(argv[i]); + } else if(!strncmp(argv[i], "-v", 3)) { fputs("dmenu-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout); exit(EXIT_SUCCESS); } else eprint("usage: dmenu [-font ] [-{norm,sel}{bg,fg} ] [-t ] [-v]\n", stdout); + setlocale(LC_CTYPE, ""); dpy = XOpenDisplay(0); if(!dpy) eprint("dmenu: cannot open display\n"); @@ -341,7 +347,6 @@ main(int argc, char *argv[]) { DefaultDepth(dpy, screen), CopyFromParent, DefaultVisual(dpy, screen), CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); - XDefineCursor(dpy, win, XCreateFontCursor(dpy, XC_xterm)); /* pixmap */ dc.drawable = XCreatePixmap(dpy, root, mw, mh, DefaultDepth(dpy, screen)); dc.gc = XCreateGC(dpy, root, 0, 0); @@ -357,7 +362,7 @@ main(int argc, char *argv[]) { XSync(dpy, False); /* main event loop */ - while(running && !XNextEvent(dpy, &ev)) { + while(running && !XNextEvent(dpy, &ev)) switch (ev.type) { default: /* ignore all crap */ break; @@ -369,7 +374,6 @@ main(int argc, char *argv[]) { drawmenu(); break; } - } /* cleanup */ while(allitems) {