-void
-readstdin(void) {
- char *p, buf[sizeof text];
- unsigned int len = 0, max = 0;
- Item *i, *new;
-
- i = NULL;
- while(fgets(buf, sizeof buf, stdin)) {
- len = strlen(buf);
- if(buf[len-1] == '\n')
- buf[--len] = '\0';
- if(!(p = strdup(buf)))
- eprint("cannot strdup %u bytes\n", len);
- if((max = MAX(max, len)) == len)
- maxname = p;
- if(!(new = malloc(sizeof *new)))
- eprint("cannot malloc %u bytes\n", sizeof *new);
- new->next = new->left = new->right = NULL;
- new->text = p;
- if(!i)
- allitems = new;
- else
- i->next = new;
- i = new;
+static void
+setup(void)
+{
+ int x, y, i, j;
+ unsigned int du, tmp;
+ XSetWindowAttributes swa;
+ XIM xim;
+ Window w, dw, *dws;
+ XWindowAttributes wa;
+ XClassHint ch = {"dmenu", "dmenu"};
+ struct item *item;
+#ifdef XINERAMA
+ XineramaScreenInfo *info;
+ Window pw;
+ int a, di, n, area = 0;
+#endif
+ /* init appearance */
+ for (j = 0; j < SchemeLast; j++)
+ scheme[j] = drw_scm_create(drw, colors[j], 2);
+
+ clip = XInternAtom(dpy, "CLIPBOARD", False);
+ utf8 = XInternAtom(dpy, "UTF8_STRING", False);
+
+ /* calculate menu geometry */
+ bh = drw->fonts->h + 2;
+ lines = MAX(lines, 0);
+ mh = (lines + 1) * bh;
+#ifdef XINERAMA
+ i = 0;
+ if (parentwin == root && (info = XineramaQueryScreens(dpy, &n))) {
+ XGetInputFocus(dpy, &w, &di);
+ if (mon >= 0 && mon < n)
+ i = mon;
+ else if (w != root && w != PointerRoot && w != None) {
+ /* find top-level window containing current input focus */
+ do {
+ if (XQueryTree(dpy, (pw = w), &dw, &w, &dws, &du) && dws)
+ XFree(dws);
+ } while (w != root && w != pw);
+ /* find xinerama screen with which the window intersects most */
+ if (XGetWindowAttributes(dpy, pw, &wa))
+ for (j = 0; j < n; j++)
+ if ((a = INTERSECT(wa.x, wa.y, wa.width, wa.height, info[j])) > area) {
+ area = a;
+ i = j;
+ }
+ }
+ /* no focused window is on screen, so use pointer location instead */
+ if (mon < 0 && !area && XQueryPointer(dpy, root, &dw, &dw, &x, &y, &di, &di, &du))
+ for (i = 0; i < n; i++)
+ if (INTERSECT(x, y, 1, 1, info[i]) != 0)
+ break;
+
+ x = info[i].x_org;
+ y = info[i].y_org + (topbar ? 0 : info[i].height - mh);
+ mw = info[i].width;
+ XFree(info);
+ } else
+#endif
+ {
+ if (!XGetWindowAttributes(dpy, parentwin, &wa))
+ die("could not get embedding window attributes: 0x%lx",
+ parentwin);
+ x = 0;
+ y = topbar ? 0 : wa.height - mh;
+ mw = wa.width;