X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=dmenu.c;h=fad4443038f5370e9e6e200c298329da66e0af6e;hb=50145384c821bb05f5497e80a006fee2db9f145b;hp=5e01441912c3cfb13e7e960b9afe6e748f29efef;hpb=7b1493a63162875ba591883e480bd36a063cf222;p=dmenu.git diff --git a/dmenu.c b/dmenu.c index 5e01441..fad4443 100644 --- a/dmenu.c +++ b/dmenu.c @@ -45,14 +45,14 @@ static int inputw, promptw; static size_t cursor = 0; static const char *font = NULL; static const char *prompt = NULL; -static const char *normbgcolor = "#cccccc"; -static const char *normfgcolor = "#000000"; -static const char *selbgcolor = "#0066ff"; -static const char *selfgcolor = "#ffffff"; +static const char *normbgcolor = "#222222"; +static const char *normfgcolor = "#bbbbbb"; +static const char *selbgcolor = "#005577"; +static const char *selfgcolor = "#eeeeee"; static unsigned int lines = 0; static unsigned long normcol[ColLast]; static unsigned long selcol[ColLast]; -static Atom utf8; +static Atom clip, utf8; static Bool topbar = True; static DC *dc; static Item *items = NULL; @@ -72,7 +72,7 @@ main(int argc, char *argv[]) { for(i = 1; i < argc; i++) /* these options take no arguments */ if(!strcmp(argv[i], "-v")) { /* prints version information */ - puts("dmenu-"VERSION", © 2006-2011 dmenu engineers, see LICENSE for details"); + puts("dmenu-"VERSION", © 2006-2012 dmenu engineers, see LICENSE for details"); exit(EXIT_SUCCESS); } else if(!strcmp(argv[i], "-b")) /* appears at the bottom of the screen */ @@ -117,7 +117,7 @@ main(int argc, char *argv[]) { setup(); run(); - return EXIT_FAILURE; /* unreachable */ + return 1; /* unreachable */ } void @@ -243,23 +243,21 @@ keypress(XKeyEvent *ev) { len = XmbLookupString(xic, ev, buf, sizeof buf, &ksym, &status); if(status == XBufferOverflow) return; - if(ev->state & ControlMask) { - KeySym lower, upper; - - XConvertCase(ksym, &lower, &upper); - switch(lower) { + if(ev->state & ControlMask) + switch(ksym) { case XK_a: ksym = XK_Home; break; case XK_b: ksym = XK_Left; break; case XK_c: ksym = XK_Escape; break; case XK_d: ksym = XK_Delete; break; case XK_e: ksym = XK_End; break; case XK_f: ksym = XK_Right; break; + case XK_g: ksym = XK_Escape; break; case XK_h: ksym = XK_BackSpace; break; case XK_i: ksym = XK_Tab; break; case XK_j: ksym = XK_Return; break; case XK_m: ksym = XK_Return; break; - case XK_n: ksym = XK_Up; break; - case XK_p: ksym = XK_Down; break; + case XK_n: ksym = XK_Down; break; + case XK_p: ksym = XK_Up; break; case XK_k: /* delete right */ text[cursor] = '\0'; @@ -275,12 +273,23 @@ keypress(XKeyEvent *ev) { insert(NULL, nextrune(-1) - cursor); break; case XK_y: /* paste selection */ - XConvertSelection(dc->dpy, XA_PRIMARY, utf8, utf8, win, CurrentTime); + XConvertSelection(dc->dpy, (ev->state & ShiftMask) ? clip : XA_PRIMARY, + utf8, utf8, win, CurrentTime); return; default: return; } - } + else if(ev->state & Mod1Mask) + switch(ksym) { + case XK_g: ksym = XK_Home; break; + case XK_G: ksym = XK_End; break; + case XK_h: ksym = XK_Up; break; + case XK_j: ksym = XK_Next; break; + case XK_k: ksym = XK_Prior; break; + case XK_l: ksym = XK_Down; break; + default: + return; + } switch(ksym) { default: if(!iscntrl(*buf)) @@ -327,6 +336,8 @@ keypress(XKeyEvent *ev) { cursor = nextrune(-1); break; } + if(lines > 0) + return; /* fallthrough */ case XK_Up: if(sel && sel->left && (sel = sel->left)->right == curr) { @@ -355,6 +366,8 @@ keypress(XKeyEvent *ev) { cursor = nextrune(+1); break; } + if(lines > 0) + return; /* fallthrough */ case XK_Down: if(sel && sel->right && (sel = sel->right) == next) { @@ -517,6 +530,7 @@ setup(void) { selcol[ColBG] = getcolor(dc, selbgcolor); selcol[ColFG] = getcolor(dc, selfgcolor); + clip = XInternAtom(dc->dpy, "CLIPBOARD", False); utf8 = XInternAtom(dc->dpy, "UTF8_STRING", False); /* calculate menu geometry */ @@ -569,12 +583,12 @@ setup(void) { /* create menu window */ swa.override_redirect = True; - swa.background_pixmap = ParentRelative; + swa.background_pixel = normcol[ColBG]; swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask; win = XCreateWindow(dc->dpy, root, x, y, mw, mh, 0, DefaultDepth(dc->dpy, screen), CopyFromParent, DefaultVisual(dc->dpy, screen), - CWOverrideRedirect | CWBackPixmap | CWEventMask, &swa); + CWOverrideRedirect | CWBackPixel | CWEventMask, &swa); /* open input methods */ xim = XOpenIM(dc->dpy, NULL, NULL, NULL);