-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;
+ XSetWindowAttributes swa;
+ XIM xim;
+#ifdef XINERAMA
+ XineramaScreenInfo *info;
+ Window w, pw, dw, *dws;
+ XWindowAttributes wa;
+ int a, j, di, n, i = 0, area = 0;
+ unsigned int du;
+#endif
+
+ /* init appearance */
+ scheme[SchemeNorm] = drw_scm_create(drw, colors[SchemeNorm], 2);
+ scheme[SchemeSel] = drw_scm_create(drw, colors[SchemeSel], 2);
+ scheme[SchemeOut] = drw_scm_create(drw, colors[SchemeOut], 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
+ if ((info = XineramaQueryScreens(dpy, &n))) {
+ XGetInputFocus(dpy, &w, &di);
+ if (mon != -1 && 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 == -1 && !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]))
+ 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
+ {
+ x = 0;
+ y = topbar ? 0 : sh - mh;
+ mw = sw;