static void usage(void);
/* global variables (X stuff and geometries) */
-static Colormap colormap;
static Display *dpy;
+static int screen;
static Visual *visual;
static Window rootwin;
-static int screen;
+static Colormap colormap;
static struct DC dc;
static struct Geometry geom;
argc -= optind;
argv += optind;
+ if (argc != 0)
+ usage();
+
/* open connection to server and set X variables */
if ((dpy = XOpenDisplay(NULL)) == NULL)
errx(1, "cannot open display");
static struct Menu *
parsestdin(void)
{
- struct Menu *rootmenu;
char *s, buf[BUFSIZ];
char *label, *output;
unsigned level = 0;
unsigned i;
struct Item *curritem = NULL; /* item currently being read */
struct Menu *prevmenu = NULL; /* menu the previous item was added to */
- struct Item *item; /* dummy item for for loops */
- struct Menu *menu; /* dummy menu for for loops */
- size_t count = 0; /* number of items in the current menu */
+ struct Item *item; /* dummy item for loops */
+ struct Menu *menu; /* dummy menu for loops */
+ struct Menu *rootmenu; /* menu to be returned */
rootmenu = NULL;
menu = allocmenu(NULL, curritem, level);
rootmenu = menu;
prevmenu = menu;
- count = 1;
curritem->prev = NULL;
curritem->next = NULL;
} else if (level < prevmenu->level) { /* item is continuation of a parent menu*/
prevmenu = menu;
}
- count++;
}
return rootmenu;
/* if this is the first time mapping, skip calculations */
if (prevmenu == NULL) {
XMapWindow(dpy, currmenu->win);
- goto done;
+ prevmenu = currmenu;
+ return;
}
/* find lowest common ancestor menu */
XMapWindow(dpy, menu->win);
}
-done:
prevmenu = currmenu;
}
{
int x, y;
- x = 0 + dc.font->height;
+ x = dc.font->height;
y = item->y + item->h/2 + dc.font->ascent/2 - 1;
XSetForeground(dpy, dc.gc, color[ColorFG].pixel);
XftDrawStringUtf8(menu->draw, &color[ColorFG], dc.font,
case MotionNotify:
menu = getmenu(currmenu, ev.xbutton.window);
item = getitem(menu, ev.xbutton.y);
- if (menu == NULL || item == NULL)
+ if (menu == NULL || item == NULL || previtem == item)
break;
- if (previtem != item) {
- previtem = item;
- menu->selected = item;
- if (item->submenu != NULL) {
- currmenu = item->submenu;
- currmenu->selected = NULL;
- } else {
- currmenu = menu;
- }
- mapmenu(currmenu);
- drawmenu(currmenu);
+ previtem = item;
+ menu->selected = item;
+ if (item->submenu != NULL) {
+ currmenu = item->submenu;
+ currmenu->selected = NULL;
+ } else {
+ currmenu = menu;
}
+ mapmenu(currmenu);
+ drawmenu(currmenu);
break;
case ButtonRelease:
menu = getmenu(currmenu, ev.xbutton.window);
static void
usage(void)
{
- (void)fprintf(stderr, "usage: xmenu title...\n");
+ (void)fprintf(stderr, "usage: xmenu\n");
exit(1);
}