static Atom netatom[NetLast];
/* flags */
-static int fflag = 0; /* whether glyphs should align based on the first font */
static int iflag = 0; /* whether to disable icons */
static int mflag = 0; /* whether the user specified a monitor with -p */
static int pflag = 0; /* whether the user specified a position with -p */
XClassHint classh;
int ch;
- while ((ch = getopt(argc, argv, "fip:w")) != -1) {
+ while ((ch = getopt(argc, argv, "ip:w")) != -1) {
switch (ch) {
- case 'f':
- fflag = 1;
- break;
case 'i':
iflag = 1;
break;
/* open connection to server and set X variables */
if ((dpy = XOpenDisplay(NULL)) == NULL)
- errx(1, "cannot open display");
+ errx(1, "could not open display");
screen = DefaultScreen(dpy);
visual = DefaultVisual(dpy, screen);
rootwin = RootWindow(dpy, screen);
i = 0;
while (isspace(*p))
p++;
- while (i < sizeof buf && *p != '\0' && *p != ',') {
+ while (i < sizeof buf && *p != '\0' && *p != ',')
buf[i++] = *p++;
- }
if (i >= sizeof buf)
errx(1, "font name too long");
if (*p == ',')
if ((dc.pattern = FcNameParse((FcChar8 *)buf)) == NULL)
errx(1, "the first font in the cache must be loaded from a font string");
if ((dc.fonts[nfont++] = XftFontOpenName(dpy, screen, buf)) == NULL)
- errx(1, "cannot load font");
+ errx(1, "could not load font");
}
}
ealloccolor(const char *s, XftColor *color)
{
if(!XftColorAllocName(dpy, visual, colormap, s, color))
- errx(1, "cannot allocate color: %s", s);
+ errx(1, "could not allocate color: %s", s);
}
/* query monitor information and cursor position */
if ((info = XineramaQueryScreens(dpy, &nmons)) != NULL) {
int selmon = 0;
- if (!mflag || (mflag && (config.monitor < 0 || config.monitor >= nmons))) {
+ 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)) {
menu = menu->parent, i++)
;
if (menu == NULL)
- errx(1, "reached NULL menu");
+ errx(1, "improper indentation detected");
/* find last item in the new menu */
for (item = menu->list; item->next != NULL; item = item->next)
static XftFont *
getfontucode(FcChar32 ucode)
{
- FcCharSet *fccharset;
- FcPattern *fcpattern;
- FcPattern *match;
+ FcCharSet *fccharset = NULL;
+ FcPattern *fcpattern = NULL;
+ FcPattern *match = NULL;
+ XftFont *retfont = NULL;
XftResult result;
- XftFont *retfont;
size_t i;
for (i = 0; i < dc.nfonts; i++)
fccharset = FcCharSetCreate();
FcCharSetAddChar(fccharset, ucode);
- /* create a pattern akin to the dc.pattern but containing our code point */
- fcpattern = FcPatternDuplicate(dc.pattern);
- FcPatternAddCharSet(fcpattern, FC_CHARSET, fccharset);
+ /* create a pattern akin to the dc.pattern but containing our charset */
+ if (fccharset) {
+ fcpattern = FcPatternDuplicate(dc.pattern);
+ FcPatternAddCharSet(fcpattern, FC_CHARSET, fccharset);
+ }
/* find pattern matching fcpattern */
- FcConfigSubstitute(NULL, fcpattern, FcMatchPattern);
- FcDefaultSubstitute(fcpattern);
- match = XftFontMatch(dpy, screen, fcpattern, &result);
+ if (fcpattern) {
+ FcConfigSubstitute(NULL, fcpattern, FcMatchPattern);
+ FcDefaultSubstitute(fcpattern);
+ match = XftFontMatch(dpy, screen, fcpattern, &result);
+ }
/* if found a pattern, open its font */
if (match) {
if (retfont && XftCharExists(dpy, retfont, ucode) == FcTrue) {
if ((dc.fonts = realloc(dc.fonts, dc.nfonts+1)) == NULL)
err(1, "realloc");
- dc.fonts[dc.nfonts++] = retfont;
- return retfont;
+ dc.fonts[dc.nfonts] = retfont;
+ return dc.fonts[dc.nfonts++];
} else {
XftFontClose(dpy, retfont);
}
drawtext(XftDraw *draw, XftColor *color, int x, int y, unsigned h, const char *text)
{
int textwidth = 0;
- int texty;
-
- texty = y + (h - (dc.fonts[0]->ascent + dc.fonts[0]->descent))/2 + dc.fonts[0]->ascent;
while (*text) {
XftFont *currfont;
textwidth += ext.xOff;
if (draw) {
- if (!fflag)
- texty = y + (h - (currfont->ascent + currfont->descent))/2 + currfont->ascent;
+ int texty;
+
+ texty = y + (h - (currfont->ascent + currfont->descent))/2 + currfont->ascent;
XftDrawStringUtf8(draw, color, currfont, x, texty, (XftChar8 *)text, len);
x += ext.xOff;
}
return;
nanosleep(&ts, NULL);
}
- errx(1, "cannot grab keyboard");
+ errx(1, "could not grab pointer");
}
/* try to grab keyboard, we may have to wait for another process to ungrab */
return;
nanosleep(&ts, NULL);
}
- errx(1, "cannot grab keyboard");
+ errx(1, "could not grab keyboard");
}
/* load and scale icon */
icon = imlib_load_image(file);
if (icon == NULL)
- errx(1, "cannot load icon %s", file);
+ errx(1, "could not load icon %s", file);
imlib_context_set_image(icon);
static void
usage(void)
{
- (void)fprintf(stderr, "usage: xmenu [-fiw] [-p position] [title]\n");
+ (void)fprintf(stderr, "usage: xmenu [-iw] [-p position] [title]\n");
exit(1);
}