summary |
tags |
clone url |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
0dfd6fa)
Renaming calcmenu() to setupmenu() and shrinking it by calling two
new functions: setupmenusize() and setupmenupos().
static struct Menu *allocmenu(struct Menu *parent, struct Item *list, unsigned level);
static struct Menu *buildmenutree(unsigned level, const char *label, const char *output);
static struct Menu *parsestdin(void);
static struct Menu *allocmenu(struct Menu *parent, struct Item *list, unsigned level);
static struct Menu *buildmenutree(unsigned level, const char *label, const char *output);
static struct Menu *parsestdin(void);
-static void calcmenu(struct Geometry *geom, struct Menu *menu);
+static void setupmenusize(struct Geometry *geom, struct Menu *menu);
+static void setupmenupos(struct Geometry *geom, struct Menu *menu);
+static void setupmenu(struct Geometry *geom, struct Menu *menu);
static void grabpointer(void);
static void grabkeyboard(void);
static struct Menu *getmenu(struct Menu *currmenu, Window win);
static void grabpointer(void);
static void grabkeyboard(void);
static struct Menu *getmenu(struct Menu *currmenu, Window win);
setupdc();
calcgeom(&geom);
setupdc();
calcgeom(&geom);
- /* generate menus and recalculate them */
+ /* generate menus and set them up */
rootmenu = parsestdin();
if (rootmenu == NULL)
errx(1, "no menu generated");
rootmenu = parsestdin();
if (rootmenu == NULL)
errx(1, "no menu generated");
- calcmenu(&geom, rootmenu);
+ setupmenu(&geom, rootmenu);
/* grab mouse and keyboard */
grabpointer();
/* grab mouse and keyboard */
grabpointer();
menu->list = list;
menu->caller = NULL;
menu->selected = NULL;
menu->list = list;
menu->caller = NULL;
menu->selected = NULL;
- menu->w = 0; /* calculated by calcmenu() */
- menu->h = 0; /* calculated by calcmenu() */
- menu->x = 0; /* calculated by calcmenu() */
- menu->y = 0; /* calculated by calcmenu() */
+ menu->w = 0; /* calculated by setupmenu() */
+ menu->h = 0; /* calculated by setupmenu() */
+ menu->x = 0; /* calculated by setupmenu() */
+ menu->y = 0; /* calculated by setupmenu() */
menu->level = level;
swa.override_redirect = True;
menu->level = level;
swa.override_redirect = True;
-/* recursivelly calculate menu geometry and set window hints */
+/* setup the size of a menu and the position of its items */
-calcmenu(struct Geometry *geom, struct Menu *menu)
+setupmenusize(struct Geometry *geom, struct Menu *menu)
- static XClassHint classh = {PROGNAME, PROGNAME};
- XWindowChanges changes;
- XSizeHints sizeh;
XGlyphInfo ext;
struct Item *item;
int labelwidth;
XGlyphInfo ext;
struct Item *item;
int labelwidth;
- /* calculate items positions and menu width and height */
menu->w = geom->itemw;
for (item = menu->list; item != NULL; item = item->next) {
item->y = menu->h;
menu->w = geom->itemw;
for (item = menu->list; item != NULL; item = item->next) {
item->y = menu->h;
item->h = geom->itemh;
menu->h += item->h;
item->h = geom->itemh;
menu->h += item->h;
+ /* get length of item->label rendered in the font */
XftTextExtentsUtf8(dpy, dc.font, (XftChar8 *)item->label,
item->labellen, &ext);
labelwidth = ext.xOff + dc.font->height * 2;
menu->w = MAX(menu->w, labelwidth);
}
XftTextExtentsUtf8(dpy, dc.font, (XftChar8 *)item->label,
item->labellen, &ext);
labelwidth = ext.xOff + dc.font->height * 2;
menu->w = MAX(menu->w, labelwidth);
}
+}
+
+/* setup the position of a menu */
+static void
+setupmenupos(struct Geometry *geom, struct Menu *menu)
+{
+ int width, height;
- /* calculate menu's x and y positions */
width = menu->w + geom->border * 2;
height = menu->h + geom->border * 2;
if (menu->parent == NULL) { /* if root menu, calculate in respect to cursor */
width = menu->w + geom->border * 2;
height = menu->h + geom->border * 2;
if (menu->parent == NULL) { /* if root menu, calculate in respect to cursor */
else if (geom->screenh > height)
menu->y = geom->screenh - height;
}
else if (geom->screenh > height)
menu->y = geom->screenh - height;
}
+}
+
+/* recursivelly setup menu configuration and its pixmap */
+static void
+setupmenu(struct Geometry *geom, struct Menu *menu)
+{
+ struct Item *item;
+ static XClassHint classh = {PROGNAME, PROGNAME};
+ XWindowChanges changes;
+ XSizeHints sizeh;
+
+ /* setup size and position of menus */
+ setupmenusize(geom, menu);
+ setupmenupos(geom, menu);
/* update menu geometry */
changes.border_width = geom->border;
/* update menu geometry */
changes.border_width = geom->border;
/* calculate positions of submenus */
for (item = menu->list; item != NULL; item = item->next) {
if (item->submenu != NULL)
/* calculate positions of submenus */
for (item = menu->list; item != NULL; item = item->next) {
if (item->submenu != NULL)
- calcmenu(geom, item->submenu);
+ setupmenu(geom, item->submenu);