1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
From 5a2f518818431f74f291facf2c5503735b85e5a9 Mon Sep 17 00:00:00 2001
From: Daan Blom <contact@daanblom.com>
Date: Thu, 21 Aug 2025 12:13:03 +0200
Subject: [PATCH] Show prompt as placeholder inside input field instead of
before it
---
config.def.h | 1 +
dmenu.c | 25 ++++++++++++++-----------
2 files changed, 15 insertions(+), 11 deletions(-)
diff --git a/config.def.h b/config.def.h
index 1edb647..c4c8b72 100644
--- a/config.def.h
+++ b/config.def.h
@@ -12,6 +12,7 @@ static const char *colors[SchemeLast][2] = {
[SchemeNorm] = { "#bbbbbb", "#222222" },
[SchemeSel] = { "#eeeeee", "#005577" },
[SchemeOut] = { "#000000", "#00ffff" },
+ [SchemePrompt] = { "#444444", "#222222" },
};
/* -l option; if nonzero, dmenu uses vertical list with given number of lines */
static unsigned int lines = 0;
diff --git a/dmenu.c b/dmenu.c
index fd49549..a58a28b 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -25,7 +25,7 @@
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
/* enums */
-enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */
+enum { SchemeNorm, SchemeSel, SchemeOut, SchemePrompt, SchemeLast }; /* color schemes */
struct item {
char *text;
@@ -152,21 +152,24 @@ drawmenu(void)
drw_setscheme(drw, scheme[SchemeNorm]);
drw_rect(drw, 0, 0, mw, mh, 1, 1);
- if (prompt && *prompt) {
- drw_setscheme(drw, scheme[SchemeSel]);
- x = drw_text(drw, x, 0, promptw, bh, lrpad / 2, prompt, 0);
- }
- /* draw input field */
w = (lines > 0 || !matches) ? mw - x : inputw;
- drw_setscheme(drw, scheme[SchemeNorm]);
- drw_text(drw, x, 0, w, bh, lrpad / 2, text, 0);
- curpos = TEXTW(text) - TEXTW(&text[cursor]);
- if ((curpos += lrpad / 2 - 1) < w) {
+ if (text[0] == '\0' && prompt && *prompt) {
+ drw_setscheme(drw, scheme[SchemePrompt]);
+ /* If vertical list: use full width (w), else just promptw */
+ drw_text(drw, x, 0, (lines > 0 ? w : promptw), bh, lrpad / 2, prompt, 0);
+ } else {
drw_setscheme(drw, scheme[SchemeNorm]);
- drw_rect(drw, x + curpos, 2, 2, bh - 4, 1, 0);
+ drw_text(drw, x, 0, w, bh, lrpad / 2, text, 0);
}
+ if (text[0] != '\0') {
+ curpos = TEXTW(text) - TEXTW(&text[cursor]);
+ if ((curpos += lrpad / 2 - 1) < w) {
+ drw_setscheme(drw, scheme[SchemeNorm]);
+ drw_rect(drw, x + curpos, 1, 2, bh - 4, 1, 0);
+ }
+ }
if (lines > 0) {
/* draw vertical list */
for (item = curr; item != next; item = item->right)
--
2.50.1
|