+/* query monitor information and cursor position */
+static void
+initmonitor(void)
+{
+ XineramaScreenInfo *info = NULL;
+ Window dw; /* dummy variable */
+ int di; /* dummy variable */
+ unsigned du; /* dummy variable */
+ int cursx, cursy; /* cursor position */
+ int nmons;
+ int i;
+
+ XQueryPointer(dpy, rootwin, &dw, &dw, &cursx, &cursy, &di, &di, &du);
+
+ mon.x = mon.y = 0;
+ mon.w = DisplayWidth(dpy, screen);
+ mon.h = DisplayHeight(dpy, screen);
+
+ if ((info = XineramaQueryScreens(dpy, &nmons)) != NULL) {
+ int selmon = 0;
+
+ if (!mflag || config.monitor < 0 || config.monitor >= nmons) {
+ for (i = 0; i < nmons; i++) {
+ if (BETWEEN(cursx, info[i].x_org, info[i].x_org + info[i].width) &&
+ BETWEEN(cursy, info[i].y_org, info[i].y_org + info[i].height)) {
+ selmon = i;
+ break;
+ }
+ }
+ } else {
+ selmon = config.monitor;
+ }
+
+ mon.x = info[selmon].x_org;
+ mon.y = info[selmon].y_org;
+ mon.w = info[selmon].width;
+ mon.h = info[selmon].height;
+
+ XFree(info);
+ }
+
+ if (!pflag) {
+ config.posx = cursx;
+ config.posy = cursy;
+ } else if (mflag) {
+ config.posx += mon.x;
+ config.posy += mon.y;
+ }
+}
+
+/* read xrdb for configuration options */
+static void
+initresources(void)
+{
+ char *xrm;
+ long n;
+ char *type;
+ XrmDatabase xdb;
+ XrmValue xval;
+
+ XrmInitialize();
+ if ((xrm = XResourceManagerString(dpy)) == NULL)
+ return;
+
+ xdb = XrmGetStringDatabase(xrm);
+
+ if (XrmGetResource(xdb, "xmenu.borderWidth", "*", &type, &xval) == True)
+ if ((n = strtol(xval.addr, NULL, 10)) > 0)
+ config.border_pixels = n;
+ if (XrmGetResource(xdb, "xmenu.separatorWidth", "*", &type, &xval) == True)
+ if ((n = strtol(xval.addr, NULL, 10)) > 0)
+ config.separator_pixels = n;
+ if (XrmGetResource(xdb, "xmenu.height", "*", &type, &xval) == True)
+ if ((n = strtol(xval.addr, NULL, 10)) > 0)
+ config.height_pixels = n;
+ if (XrmGetResource(xdb, "xmenu.width", "*", &type, &xval) == True)
+ if ((n = strtol(xval.addr, NULL, 10)) > 0)
+ config.width_pixels = n;
+ if (XrmGetResource(xdb, "xmenu.gap", "*", &type, &xval) == True)
+ if ((n = strtol(xval.addr, NULL, 10)) > 0)
+ config.gap_pixels = n;
+ if (XrmGetResource(xdb, "xmenu.background", "*", &type, &xval) == True)
+ config.background_color = strdup(xval.addr);
+ if (XrmGetResource(xdb, "xmenu.foreground", "*", &type, &xval) == True)
+ config.foreground_color = strdup(xval.addr);
+ if (XrmGetResource(xdb, "xmenu.selbackground", "*", &type, &xval) == True)
+ config.selbackground_color = strdup(xval.addr);
+ if (XrmGetResource(xdb, "xmenu.selforeground", "*", &type, &xval) == True)
+ config.selforeground_color = strdup(xval.addr);
+ if (XrmGetResource(xdb, "xmenu.separator", "*", &type, &xval) == True)
+ config.separator_color = strdup(xval.addr);
+ if (XrmGetResource(xdb, "xmenu.border", "*", &type, &xval) == True)
+ config.border_color = strdup(xval.addr);
+ if (XrmGetResource(xdb, "xmenu.font", "*", &type, &xval) == True)
+ config.font = strdup(xval.addr);
+
+ XrmDestroyDatabase(xdb);