In multiline mode the prompt is above the input

This commit is contained in:
Андреев Григорий 2025-04-02 13:56:58 +03:00
parent 5573f5bd23
commit 9fbfcdcee2

21
dmenu.c
View File

@ -170,21 +170,26 @@ drawmenu(void)
int x = 0, y = 0, w; int x = 0, y = 0, w;
drw_setscheme(drw, scheme[SchemeNorm]); drw_setscheme(drw, scheme[SchemeNorm]);
drw_rect(drw, 0, 0, mw, mh, 1, 1); drw_rect(drw, x, y, mw, mh, 1, 1);
if (prompt && *prompt) { if (prompt && *prompt) {
drw_setscheme(drw, scheme[SchemeSel]); drw_setscheme(drw, scheme[SchemeSel]);
x = drw_text(drw, x, 0, promptw, bh, lrpad / 2, prompt, 0); int prompt_x = drw_text(drw, x, y, promptw, bh, lrpad / 2, prompt, 0);
if (lines > 0) {
y += bh;
} else {
x += prompt_x;
}
} }
/* draw input field */ /* draw input field */
w = (lines > 0 || !matches) ? mw - x : inputw; w = (lines > 0 || !matches) ? mw - x : inputw;
drw_setscheme(drw, scheme[SchemeNorm]); drw_setscheme(drw, scheme[SchemeNorm]);
drw_text(drw, x, 0, w, bh, lrpad / 2, text, 0); drw_text(drw, x, y, w, bh, lrpad / 2, text, 0);
curpos = TEXTW(text) - TEXTW(&text[cursor]); curpos = TEXTW(text) - TEXTW(&text[cursor]);
if ((curpos += lrpad / 2 - 1) < w) { if ((curpos += lrpad / 2 - 1) < w) {
drw_setscheme(drw, scheme[SchemeCaret]); drw_setscheme(drw, scheme[SchemeCaret]);
drw_rect(drw, x + curpos, 2, 2, bh - 4, 1, 0); drw_rect(drw, x + curpos, y + 2, 2, bh - 4, 1, 0);
} }
if (lines > 0) { if (lines > 0) {
@ -203,15 +208,15 @@ drawmenu(void)
w = TEXTW("<"); w = TEXTW("<");
if (curr->left) { if (curr->left) {
drw_setscheme(drw, scheme[SchemeNorm]); drw_setscheme(drw, scheme[SchemeNorm]);
drw_text(drw, x, 0, w, bh, lrpad / 2, "<", 0); drw_text(drw, x, y, w, bh, lrpad / 2, "<", 0);
} }
x += w; x += w;
for (item = curr; item != next; item = item->right) for (item = curr; item != next; item = item->right)
x = drawitem(item, x, 0, textw_clamp(item->stext, mw - x - TEXTW(">"))); x = drawitem(item, x, y, textw_clamp(item->stext, mw - x - TEXTW(">")));
if (next) { if (next) {
w = TEXTW(">"); w = TEXTW(">");
drw_setscheme(drw, scheme[SchemeNorm]); drw_setscheme(drw, scheme[SchemeNorm]);
drw_text(drw, mw - w, 0, w, bh, lrpad / 2, ">", 0); drw_text(drw, mw - w, y, w, bh, lrpad / 2, ">", 0);
} }
} }
drw_map(drw, win, 0, 0, mw, mh); drw_map(drw, win, 0, 0, mw, mh);
@ -715,7 +720,7 @@ setup(void)
/* calculate menu geometry */ /* calculate menu geometry */
bh = drw->fonts->h + 2; bh = drw->fonts->h + 2;
lines = MAX(lines, 0); lines = MAX(lines, 0);
mh = (lines + 1) * bh; mh = (lines + 1 + (lines ? 1 : 0)) * bh;
promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0; promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
#ifdef XINERAMA #ifdef XINERAMA
i = 0; i = 0;