X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=dinput.c;h=283b018c2e93633685c6013da09afaf5acb65f85;hb=4508fd2c4ee3171bdc1bffb7e53ecda8290292ef;hp=f2b504aa4e1fdc52ddcead24bb381065d80cd278;hpb=595e7976601fc77acf12015d3f5f6843e2cdd706;p=dmenu.git diff --git a/dinput.c b/dinput.c index f2b504a..283b018 100644 --- a/dinput.c +++ b/dinput.c @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -38,14 +37,20 @@ static char *prompt = NULL; static char text[4096]; static int promptw = 0; static int ret = 0; +static int screen; static unsigned int cursor = 0; static unsigned int numlockmask = 0; +static unsigned int mw, mh; +static unsigned long normcol[ColLast]; +static unsigned long selcol[ColLast]; static Bool running = True; -static Window win; +static DC dc; +static Display *dpy; +static Window win, parent; void cleanup(void) { - drawcleanup(); + cleanupdraw(&dc); XDestroyWindow(dpy, win); XUngrabKeyboard(dpy, CurrentTime); } @@ -54,9 +59,9 @@ void drawcursor(void) { XRectangle r = { dc.x, dc.y + 2, 1, dc.font.height - 2 }; - r.x += textnw(text, cursor) + dc.font.height / 2; + r.x += textnw(&dc, text, cursor) + dc.font.height / 2; - XSetForeground(dpy, dc.gc, dc.norm[ColFG]); + XSetForeground(dpy, dc.gc, normcol[ColFG]); XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); } @@ -67,15 +72,15 @@ drawinput(void) dc.y = 0; dc.w = mw; dc.h = mh; - drawtext(NULL, dc.norm); + drawtext(&dc, NULL, normcol); /* print prompt? */ if(prompt) { dc.w = promptw; - drawtext(prompt, dc.sel); + drawtext(&dc, prompt, selcol); dc.x += dc.w; } dc.w = mw - dc.x; - drawtext(*text ? text : NULL, dc.norm); + drawtext(&dc, *text ? text : NULL, normcol); drawcursor(); XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, mw, mh, 0, 0); XFlush(dpy); @@ -158,7 +163,7 @@ kpress(XKeyEvent * e) { FILE *fp; char *s; if(!(fp = popen("sselp", "r"))) - eprint("dinput: cannot popen sselp\n"); + eprint("cannot popen sselp\n"); s = fgets(buf, sizeof buf, fp); pclose(fp); if(s == NULL) @@ -263,15 +268,21 @@ setup(Bool topbar) { } XFreeModifiermap(modmap); - initfont(font); + dc.dpy = dpy; + normcol[ColBG] = getcolor(&dc, normbgcolor); + normcol[ColFG] = getcolor(&dc, normfgcolor); + selcol[ColBG] = getcolor(&dc, selbgcolor); + selcol[ColFG] = getcolor(&dc, selfgcolor); + initfont(&dc, font); + fprintf(stderr, "dc.font.xfont: %u\n", (size_t)dc.font.xfont); - /* menu window */ + /* input window */ wa.override_redirect = True; wa.background_pixmap = ParentRelative; wa.event_mask = ExposureMask | ButtonPressMask | KeyPressMask | VisibilityChangeMask; - /* menu window geometry */ - mh = (dc.font.height + 2); + /* input window geometry */ + mh = dc.font.height + 2; #if XINERAMA if(parent == RootWindow(dpy, screen) && XineramaIsActive(dpy) && (info = XineramaQueryScreens(dpy, &n))) { i = 0; @@ -303,9 +314,9 @@ setup(Bool topbar) { DefaultVisual(dpy, screen), CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); - drawsetup(); + setupdraw(&dc, win); if(prompt) - promptw = MIN(textw(prompt), mw / 5); + promptw = MIN(textw(&dc, prompt), mw / 5); cursor = strlen(text); XMapRaised(dpy, win); } @@ -316,6 +327,7 @@ main(int argc, char *argv[]) { Bool topbar = True; /* command line args */ + progname = argv[0]; for(i = 1; i < argc; i++) if(!strcmp(argv[i], "-b")) topbar = False; @@ -350,7 +362,7 @@ main(int argc, char *argv[]) { if(!setlocale(LC_CTYPE, "") || !XSupportsLocale()) fprintf(stderr, "dinput: warning: no locale support\n"); if(!(dpy = XOpenDisplay(NULL))) - eprint("dinput: cannot open display\n"); + eprint("cannot open display\n"); screen = DefaultScreen(dpy); if(!parent) parent = RootWindow(dpy, screen);