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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
diff --git a/config.def.h b/config.def.h
index be1b4cad2c..6b0a32704d 100644
--- a/config.def.h
+++ b/config.def.h
@@ -5,6 +5,7 @@
static int centered = 0; /* -c option; centers dmenu on screen */
static int min_width = 500; /* minimum width when centered */
static const float menu_height_ratio = 4.0f; /* This is the ratio used in the original calculation */
+static int draw_input = 1; /* -noi option; if 0, the input will not be drawn by default */
/* -fn option overrides fonts[0]; default X11 font or font set */
static const char *fonts[] = {
"monospace:size=10"
diff --git a/dmenu.c b/dmenu.c
index ceb52c70ca..bafda5af1f 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -157,30 +157,32 @@
{
unsigned int curpos;
struct item *item;
- int x = 0, y = 0, w;
+ int x = 0, y = 0, w = 0;
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);
+ x = drw_text(drw, x, 0, !draw_input ? mw : 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 (draw_input) {
+ w = (lines > 0 || !matches) ? mw - x : inputw;
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);
+
+ curpos = TEXTW(text) - TEXTW(&text[cursor]);
+ if ((curpos += lrpad / 2 - 1) < w) {
+ drw_setscheme(drw, scheme[SchemeNorm]);
+ drw_rect(drw, x + curpos, 2, 2, bh - 4, 1, 0);
+ }
}
if (lines > 0) {
/* draw vertical list */
for (item = curr; item != next; item = item->right)
- drawitem(item, x, y += bh, mw - x);
+ drawitem(item, (!draw_input && prompt && *prompt) ? x - mw : x - promptw, y += bh, mw);
} else if (matches) {
/* draw horizontal list */
x += inputw;
@@ -188,8 +190,8 @@
if (curr->left) {
drw_setscheme(drw, scheme[SchemeNorm]);
drw_text(drw, x, 0, w, bh, lrpad / 2, "<", 0);
+ x += w;
}
- x += w;
for (item = curr; item != next; item = item->right)
x = drawitem(item, x, 0, textw_clamp(item->text, mw - x - TEXTW(">")));
if (next) {
@@ -368,16 +370,19 @@
case XK_p: ksym = XK_Up; break;
case XK_k: /* delete right */
- text[cursor] = '\0';
- match();
+ if (draw_input) {
+ text[cursor] = '\0';
+ match();
+ }
break;
case XK_u: /* delete left */
- insert(NULL, 0 - cursor);
+ if (draw_input)
+ insert(NULL, 0 - cursor);
break;
case XK_w: /* delete word */
- while (cursor > 0 && strchr(worddelimiters, text[nextrune(-1)]))
+ while (cursor > 0 && strchr(worddelimiters, text[nextrune(-1)]) && draw_input)
insert(NULL, nextrune(-1) - cursor);
- while (cursor > 0 && !strchr(worddelimiters, text[nextrune(-1)]))
+ while (cursor > 0 && !strchr(worddelimiters, text[nextrune(-1)]) && draw_input)
insert(NULL, nextrune(-1) - cursor);
break;
case XK_y: /* paste selection */
@@ -424,23 +429,23 @@
switch(ksym) {
default:
insert:
- if (!iscntrl((unsigned char)*buf))
+ if (!iscntrl((unsigned char)*buf) && draw_input)
insert(buf, len);
break;
case XK_Delete:
case XK_KP_Delete:
- if (text[cursor] == '\0')
+ if (text[cursor] == '\0' || !draw_input)
return;
cursor = nextrune(+1);
/* fallthrough */
case XK_BackSpace:
- if (cursor == 0)
+ if (cursor == 0 || !draw_input)
return;
insert(NULL, nextrune(-1) - cursor);
break;
case XK_End:
case XK_KP_End:
- if (text[cursor] != '\0') {
+ if (text[cursor] != '\0' && draw_input) {
cursor = strlen(text);
break;
}
@@ -524,7 +529,7 @@
}
break;
case XK_Tab:
- if (!sel)
+ if (!sel || !draw_input)
return;
cursor = strnlen(sel->text, sizeof text - 1);
memcpy(text, sel->text, cursor);
@@ -703,7 +708,7 @@
}
}
promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
- inputw = mw / 3; /* input width: ~33% of monitor width */
+ inputw = !draw_input ? 0 : mw / 3; /* input width: ~33% of monitor width */
match();
/* create menu window */
@@ -740,7 +745,7 @@
static void
usage(void)
{
- die("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
+ die("usage: dmenu [-bfiv] [-noi] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
" [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]");
}
@@ -761,6 +766,8 @@
fast = 1;
else if (!strcmp(argv[i], "-c")) /* centers dmenu on screen */
centered = 1;
+ else if (!strcmp(argv[i], "-noi")) /* no input field. intended to be used with a prompt */
+ draw_input = 0;
else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */
fstrncmp = strncasecmp;
fstrstr = cistrstr;
|