mirror of
https://github.com/leahneukirchen/cwm.git
synced 2023-08-10 21:13:12 +03:00
cvsimport
* refs/heads/master: 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.
This commit is contained in:
commit
481894147a
25
menu.c
25
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,
|
XftTextExtentsUtf8(X_Dpy, sc->xftfont,
|
||||||
(const FcChar8*)mc->dispstr, strlen(mc->dispstr), &extents);
|
(const FcChar8*)mc->dispstr, strlen(mc->dispstr), &extents);
|
||||||
mc->geom.w = extents.xOff;
|
mc->geom.w = extents.xOff;
|
||||||
mc->geom.h = sc->xftfont->height + 1;
|
mc->geom.h = sc->xftfont->ascent + sc->xftfont->descent;
|
||||||
mc->num = 1;
|
mc->num = 1;
|
||||||
|
|
||||||
TAILQ_FOREACH(mi, resultq, resultentry) {
|
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,
|
(const FcChar8*)mi->print,
|
||||||
MIN(strlen(mi->print), MENU_MAXENTRY), &extents);
|
MIN(strlen(mi->print), MENU_MAXENTRY), &extents);
|
||||||
mc->geom.w = MAX(mc->geom.w, extents.xOff);
|
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++;
|
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));
|
(const FcChar8*)mc->dispstr, strlen(mc->dispstr));
|
||||||
|
|
||||||
TAILQ_FOREACH(mi, resultq, resultentry) {
|
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. */
|
/* 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;
|
break;
|
||||||
|
|
||||||
XftDrawStringUtf8(mc->xftdraw,
|
XftDrawStringUtf8(mc->xftdraw,
|
||||||
&sc->xftcolor[CWM_COLOR_MENU_FONT], sc->xftfont,
|
&sc->xftcolor[CWM_COLOR_MENU_FONT], sc->xftfont,
|
||||||
0, y,
|
0, y + sc->xftfont->ascent,
|
||||||
(const FcChar8*)mi->print, strlen(mi->print));
|
(const FcChar8*)mi->print, strlen(mi->print));
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
@ -425,7 +425,7 @@ menu_draw_entry(struct menu_ctx *mc, struct menu_q *resultq,
|
|||||||
{
|
{
|
||||||
struct screen_ctx *sc = mc->sc;
|
struct screen_ctx *sc = mc->sc;
|
||||||
struct menu *mi;
|
struct menu *mi;
|
||||||
int color, i = 1;
|
int color, i = 1, y;
|
||||||
|
|
||||||
TAILQ_FOREACH(mi, resultq, resultentry)
|
TAILQ_FOREACH(mi, resultq, resultentry)
|
||||||
if (entry == i++)
|
if (entry == i++)
|
||||||
@ -433,14 +433,13 @@ menu_draw_entry(struct menu_ctx *mc, struct menu_q *resultq,
|
|||||||
if (mi == NULL)
|
if (mi == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
y = entry * (sc->xftfont->ascent + sc->xftfont->descent);
|
||||||
color = (active) ? CWM_COLOR_MENU_FG : CWM_COLOR_MENU_BG;
|
color = (active) ? CWM_COLOR_MENU_FG : CWM_COLOR_MENU_BG;
|
||||||
XftDrawRect(mc->xftdraw, &sc->xftcolor[color], 0,
|
XftDrawRect(mc->xftdraw, &sc->xftcolor[color], 0, y,
|
||||||
(sc->xftfont->height + 1) * entry, mc->geom.w,
|
mc->geom.w, sc->xftfont->ascent + sc->xftfont->descent);
|
||||||
(sc->xftfont->height + 1) + sc->xftfont->descent);
|
|
||||||
color = (active) ? CWM_COLOR_MENU_FONT_SEL : CWM_COLOR_MENU_FONT;
|
color = (active) ? CWM_COLOR_MENU_FONT_SEL : CWM_COLOR_MENU_FONT;
|
||||||
XftDrawStringUtf8(mc->xftdraw,
|
XftDrawStringUtf8(mc->xftdraw,
|
||||||
&sc->xftcolor[color], sc->xftfont,
|
&sc->xftcolor[color], sc->xftfont, 0, y + sc->xftfont->ascent,
|
||||||
0, (sc->xftfont->height + 1) * entry + sc->xftfont->ascent + 1,
|
|
||||||
(const FcChar8*)mi->print, strlen(mi->print));
|
(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;
|
struct screen_ctx *sc = mc->sc;
|
||||||
int entry;
|
int entry;
|
||||||
|
|
||||||
entry = y / (sc->xftfont->height + 1);
|
entry = y / (sc->xftfont->ascent + sc->xftfont->descent);
|
||||||
|
|
||||||
/* in bounds? */
|
/* in bounds? */
|
||||||
if (x < 0 || x > mc->geom.w || y < 0 ||
|
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 < 0 || entry >= mc->num)
|
||||||
entry = -1;
|
entry = -1;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user