Configuring height directly by setting the height.

Rather than setting the padding.
This commit is contained in:
phillbush 2020-06-12 11:37:13 -03:00
parent 5a83c7dce2
commit 685ca30d8d
3 changed files with 26 additions and 19 deletions

View File

@ -11,10 +11,15 @@ static const char *border_color = "#E6E6E6";
/* sizes in pixels */ /* sizes in pixels */
static int width_pixels = 130; /* minimum width of a menu */ static int width_pixels = 130; /* minimum width of a menu */
static int padding_pixels = 4; /* padding around label in a item */ static int height_pixels = 25; /* height of a single menu item */
static int border_pixels = 1; /* menu border */ static int border_pixels = 1; /* menu border */
static int separator_pixels = 3; /* space around separator */ static int separator_pixels = 3; /* space around separator */
/* the variables below cannot be set by X resources */
/* geometry of the right-pointing isoceles triangle for submenus */ /* geometry of the right-pointing isoceles triangle for submenus */
static const int triangle_width = 3; static const int triangle_width = 3;
static const int triangle_height = 7; static const int triangle_height = 7;
/* padding of the area around the icon */
static const int iconpadding = 4;

View File

@ -99,8 +99,8 @@ The color of the separator between items in the menu.
.B xmenu.width .B xmenu.width
The minimum width, in pixels, of the items in the menu. The minimum width, in pixels, of the items in the menu.
.TP .TP
.B xmenu.padding .B xmenu.height
The size in pixels of the padding around the label text in items in the menu. The size in pixels of the height of a single menu item.
.TP .TP
.B xmenu.borderWidth .B xmenu.borderWidth
The size in pixels of the border around the menu. The size in pixels of the border around the menu.

26
xmenu.c
View File

@ -13,7 +13,6 @@
#define PROGNAME "xmenu" #define PROGNAME "xmenu"
#define ITEMPREV 0 #define ITEMPREV 0
#define ITEMNEXT 1 #define ITEMNEXT 1
#define IMGPADDING 8
/* macros */ /* macros */
#define LEN(x) (sizeof (x) / sizeof (x[0])) #define LEN(x) (sizeof (x) / sizeof (x[0]))
@ -79,6 +78,7 @@ static struct Item *allocitem(const char *label, const char *output, char *file)
static struct Menu *allocmenu(struct Menu *parent, struct Item *list, unsigned level); static struct Menu *allocmenu(struct Menu *parent, struct Item *list, unsigned level);
static struct Menu *buildmenutree(unsigned level, const char *label, const char *output, char *file); static struct Menu *buildmenutree(unsigned level, const char *label, const char *output, char *file);
static struct Menu *parsestdin(void); static struct Menu *parsestdin(void);
static Imlib_Image loadicon(const char *file, int size);
static void setupmenusize(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 setupmenupos(struct Geometry *geom, struct Menu *menu);
static void setupmenu(struct Geometry *geom, struct Menu *menu, XClassHint *classh); static void setupmenu(struct Geometry *geom, struct Menu *menu, XClassHint *classh);
@ -207,9 +207,9 @@ getresources(void)
if (XrmGetResource(xdb, "xmenu.separatorWidth", "*", &type, &xval) == True) if (XrmGetResource(xdb, "xmenu.separatorWidth", "*", &type, &xval) == True)
if ((n = strtol(xval.addr, NULL, 10)) > 0) if ((n = strtol(xval.addr, NULL, 10)) > 0)
separator_pixels = n; separator_pixels = n;
if (XrmGetResource(xdb, "xmenu.padding", "*", &type, &xval) == True) if (XrmGetResource(xdb, "xmenu.height", "*", &type, &xval) == True)
if ((n = strtol(xval.addr, NULL, 10)) > 0) if ((n = strtol(xval.addr, NULL, 10)) > 0)
padding_pixels = n; height_pixels = n;
if (XrmGetResource(xdb, "xmenu.width", "*", &type, &xval) == True) if (XrmGetResource(xdb, "xmenu.width", "*", &type, &xval) == True)
if ((n = strtol(xval.addr, NULL, 10)) > 0) if ((n = strtol(xval.addr, NULL, 10)) > 0)
width_pixels = n; width_pixels = n;
@ -270,7 +270,7 @@ calcgeom(struct Geometry *geom)
XQueryPointer(dpy, rootwin, &w1, &w2, &geom->cursx, &geom->cursy, &a, &b, &mask); XQueryPointer(dpy, rootwin, &w1, &w2, &geom->cursx, &geom->cursy, &a, &b, &mask);
geom->screenw = DisplayWidth(dpy, screen); geom->screenw = DisplayWidth(dpy, screen);
geom->screenh = DisplayHeight(dpy, screen); geom->screenh = DisplayHeight(dpy, screen);
geom->itemh = dc.font->height + padding_pixels * 2; geom->itemh = height_pixels;
geom->itemw = width_pixels; geom->itemw = width_pixels;
geom->border = border_pixels; geom->border = border_pixels;
geom->separator = separator_pixels; geom->separator = separator_pixels;
@ -499,12 +499,14 @@ setupmenusize(struct Geometry *geom, struct Menu *menu)
/* get length of item->label rendered in the font */ /* get length of item->label rendered in the font */
XftTextExtentsUtf8(dpy, dc.font, (XftChar8 *)item->label, XftTextExtentsUtf8(dpy, dc.font, (XftChar8 *)item->label,
item->labellen, &ext); item->labellen, &ext);
labelwidth = ext.xOff + dc.font->height * 2 + IMGPADDING * 2;
/* set menu width */
labelwidth = ext.xOff + item->h * 2;
menu->w = MAX(menu->w, labelwidth); menu->w = MAX(menu->w, labelwidth);
/* create icon */ /* create icon */
if (item->file != NULL) if (item->file != NULL)
item->icon = loadicon(item->file, dc.font->height); item->icon = loadicon(item->file, item->h - iconpadding * 2);
} }
} }
@ -734,16 +736,16 @@ drawitem(struct Menu *menu, struct Item *item, XftColor *color)
{ {
int x, y; int x, y;
x = dc.font->height + IMGPADDING; x = item->h;
y = item->y + item->h/2 + dc.font->ascent/2 - 1; y = item->y + (item->h + dc.font->ascent) / 2;
XSetForeground(dpy, dc.gc, color[ColorFG].pixel); XSetForeground(dpy, dc.gc, color[ColorFG].pixel);
XftDrawStringUtf8(menu->draw, &color[ColorFG], dc.font, XftDrawStringUtf8(menu->draw, &color[ColorFG], dc.font,
x, y, item->label, item->labellen); x, y, item->label, item->labellen);
/* draw triangle, if item contains a submenu */ /* draw triangle, if item contains a submenu */
if (item->submenu != NULL) { if (item->submenu != NULL) {
x = menu->w - dc.font->height/2 - IMGPADDING/2 - triangle_width/2 - 1; x = menu->w - (item->h + triangle_width + 1) / 2;
y = item->y + item->h/2 - triangle_height/2 - 1; y = item->y + (item->h - triangle_height + 1) / 2;
XPoint triangle[] = { XPoint triangle[] = {
{x, y}, {x, y},
@ -758,8 +760,8 @@ drawitem(struct Menu *menu, struct Item *item, XftColor *color)
/* draw icon */ /* draw icon */
if (item->file != NULL) { if (item->file != NULL) {
x = IMGPADDING / 2; x = iconpadding;
y = item->y + (item->h - dc.font->height) / 2; y = item->y + iconpadding;
imlib_context_set_drawable(menu->pixmap); imlib_context_set_drawable(menu->pixmap);
imlib_context_set_image(item->icon); imlib_context_set_image(item->icon);
imlib_render_image_on_drawable(x, y); imlib_render_image_on_drawable(x, y);