summary refs log tree commit diff
diff options
context:
space:
mode:
authorokan <okan>2022-10-15 16:06:07 +0000
committerokan <okan>2022-10-15 16:06:07 +0000
commit4a6128d5e461515b87da0dabf31dd1c7288b26db (patch)
tree9fc8bdb7b8e7128f52e70bb80176604444247790
parent4e73ce533c98c54a83fa24c71105bbb1b40a0803 (diff)
downloadcwm-4a6128d5e461515b87da0dabf31dd1c7288b26db.tar.gz
cwm-4a6128d5e461515b87da0dabf31dd1c7288b26db.tar.xz
cwm-4a6128d5e461515b87da0dabf31dd1c7288b26db.zip
Fix overlapping menu items as reported by kn@ and probably others at
some point; with op@ and Walter Alejandro Iglesias helping along the
way.  Consistently use font ascent+descent instead of an arbitrary font
height+1 for individual menu item rectangles and placement.

ok kn@ op@
-rw-r--r--menu.c25
1 files changed, 12 insertions, 13 deletions
diff --git a/menu.c b/menu.c
index 43b5de8..2279f12 100644
--- a/menu.c
+++ b/menu.c
@@ -355,7 +355,7 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq)
 	XftTextExtentsUtf8(X_Dpy, sc->xftfont,
 	    (const FcChar8*)mc->dispstr, strlen(mc->dispstr), &extents);
 	mc->geom.w = extents.xOff;
-	mc->geom.h = sc->xftfont->height + 1;
+	mc->geom.h = sc->xftfont->ascent + sc->xftfont->descent;
 	mc->num = 1;
 
 	TAILQ_FOREACH(mi, resultq, resultentry) {
@@ -364,7 +364,7 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq)
 		    (const FcChar8*)mi->print,
 		    MIN(strlen(mi->print), MENU_MAXENTRY), &extents);
 		mc->geom.w = MAX(mc->geom.w, extents.xOff);
-		mc->geom.h += sc->xftfont->height + 1;
+		mc->geom.h += sc->xftfont->ascent + sc->xftfont->descent;
 		mc->num++;
 	}
 
@@ -403,15 +403,15 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq)
 	    (const FcChar8*)mc->dispstr, strlen(mc->dispstr));
 
 	TAILQ_FOREACH(mi, resultq, resultentry) {
-		int y = n * (sc->xftfont->height + 1) + sc->xftfont->ascent + 1;
+		int y = n * (sc->xftfont->ascent + sc->xftfont->descent);
 
 		/* Stop drawing when menu doesn't fit inside the screen. */
-		if (mc->geom.y + y > area.h)
+		if (mc->geom.y + y >= area.h)
 			break;
 
 		XftDrawStringUtf8(mc->xftdraw,
 		    &sc->xftcolor[CWM_COLOR_MENU_FONT], sc->xftfont,
-		    0, y,
+		    0, y + sc->xftfont->ascent,
 		    (const FcChar8*)mi->print, strlen(mi->print));
 		n++;
 	}
@@ -425,7 +425,7 @@ menu_draw_entry(struct menu_ctx *mc, struct menu_q *resultq,
 {
 	struct screen_ctx	*sc = mc->sc;
 	struct menu		*mi;
-	int			 color, i = 1;
+	int			 color, i = 1, y;
 
 	TAILQ_FOREACH(mi, resultq, resultentry)
 		if (entry == i++)
@@ -433,14 +433,13 @@ menu_draw_entry(struct menu_ctx *mc, struct menu_q *resultq,
 	if (mi == NULL)
 		return;
 
+	y = entry * (sc->xftfont->ascent + sc->xftfont->descent);
 	color = (active) ? CWM_COLOR_MENU_FG : CWM_COLOR_MENU_BG;
-	XftDrawRect(mc->xftdraw, &sc->xftcolor[color], 0,
-	    (sc->xftfont->height + 1) * entry, mc->geom.w,
-	    (sc->xftfont->height + 1) + sc->xftfont->descent);
+	XftDrawRect(mc->xftdraw, &sc->xftcolor[color], 0, y,
+	    mc->geom.w, sc->xftfont->ascent + sc->xftfont->descent);
 	color = (active) ? CWM_COLOR_MENU_FONT_SEL : CWM_COLOR_MENU_FONT;
 	XftDrawStringUtf8(mc->xftdraw,
-	    &sc->xftcolor[color], sc->xftfont,
-	    0, (sc->xftfont->height + 1) * entry + sc->xftfont->ascent + 1,
+	    &sc->xftcolor[color], sc->xftfont, 0, y + sc->xftfont->ascent,
 	    (const FcChar8*)mi->print, strlen(mi->print));
 }
 
@@ -487,11 +486,11 @@ menu_calc_entry(struct menu_ctx *mc, int x, int y)
 	struct screen_ctx	*sc = mc->sc;
 	int			 entry;
 
-	entry = y / (sc->xftfont->height + 1);
+	entry = y / (sc->xftfont->ascent + sc->xftfont->descent);
 
 	/* in bounds? */
 	if (x < 0 || x > mc->geom.w || y < 0 ||
-	    y > (sc->xftfont->height + 1) * mc->num ||
+	    y > (sc->xftfont->ascent + sc->xftfont->descent) * mc->num ||
 	    entry < 0 || entry >= mc->num)
 		entry = -1;