-void
-run(void) {
- XEvent ev;
-
- /* main event loop */
- while(running && !XNextEvent(dpy, &ev))
- switch (ev.type) {
- default: /* ignore all crap */
- break;
- case KeyPress:
- kpress(&ev.xkey);
- break;
- case Expose:
- if(ev.xexpose.count == 0)
- drawmenu();
- break;
- }
-}
-
-void
-setup(Bool topbar) {
- int i, j, x, y;
- XModifierKeymap *modmap;
- XSetWindowAttributes wa;
-#if XINERAMA
- XineramaScreenInfo *info = NULL;
-#endif
-
- /* 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(normbgcolor);
- dc.norm[ColFG] = getcolor(normfgcolor);
- dc.sel[ColBG] = getcolor(selbgcolor);
- dc.sel[ColFG] = getcolor(selfgcolor);
- initfont(font);
-
- /* menu window */
- wa.override_redirect = 1;
- wa.background_pixmap = ParentRelative;
- wa.event_mask = ExposureMask | ButtonPressMask | KeyPressMask;
-
- /* menu window geometry */
- mh = dc.font.height + 2;
-#if XINERAMA
- if(XineramaIsActive(dpy)) {
- info = XineramaQueryScreens(dpy, &i);
- x = info[xidx].x_org;
- y = topbar ? info[xidx].y_org : info[xidx].y_org + info[xidx].height - mh;
- mw = info[xidx].width;
- XFree(info);
- }
- else
-#endif
- {
- x = 0;
- y = topbar ? 0 : DisplayHeight(dpy, screen) - mh;
- mw = DisplayWidth(dpy, screen);
- }
-
- win = XCreateWindow(dpy, root, x, y, mw, mh, 0,
- DefaultDepth(dpy, screen), CopyFromParent,
- DefaultVisual(dpy, screen),
- CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
-
- /* pixmap */
- dc.drawable = XCreatePixmap(dpy, root, mw, mh, DefaultDepth(dpy, screen));
- dc.gc = XCreateGC(dpy, root, 0, 0);
- XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
- if(!dc.font.set)
- XSetFont(dpy, dc.gc, dc.font.xfont->fid);
- if(maxname)
- cmdw = textw(maxname);
- if(cmdw > mw / 3)
- cmdw = mw / 3;
- if(prompt)
- promptw = textw(prompt);
- if(promptw > mw / 5)
- promptw = mw / 5;
- text[0] = 0;
- match(text);
- XMapRaised(dpy, win);
-}
-
-int
-textnw(const char *text, uint len) {
- XRectangle r;
-
- if(dc.font.set) {
- XmbTextExtents(dc.font.set, text, len, NULL, &r);
- return r.width;
- }
- return XTextWidth(dc.font.xfont, text, len);
-}
-
-int
-textw(const char *text) {
- return textnw(text, strlen(text)) + dc.font.height;
-}
-