aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dinput.c31
-rw-r--r--dmenu.c21
2 files changed, 20 insertions, 32 deletions
diff --git a/dinput.c b/dinput.c
index 4c90cd7..0d0adeb 100644
--- a/dinput.c
+++ b/dinput.c
@@ -21,9 +21,8 @@
21 21
22/* forward declarations */ 22/* forward declarations */
23static void cleanup(void); 23static void cleanup(void);
24static void drawcursor(void);
25static void drawinput(void); 24static void drawinput(void);
26static Bool grabkeyboard(void); 25static void grabkeyboard(void);
27static void kpress(XKeyEvent *e); 26static void kpress(XKeyEvent *e);
28static void run(void); 27static void run(void);
29static void setup(void); 28static void setup(void);
@@ -35,7 +34,7 @@ static char *prompt = NULL;
35static char text[4096]; 34static char text[4096];
36static int promptw = 0; 35static int promptw = 0;
37static int screen; 36static int screen;
38static unsigned int cursor = 0; 37static size_t cursor = 0;
39static unsigned int numlockmask = 0; 38static unsigned int numlockmask = 0;
40static unsigned int mw, mh; 39static unsigned int mw, mh;
41static unsigned long normcol[ColLast]; 40static unsigned long normcol[ColLast];
@@ -54,46 +53,36 @@ cleanup(void) {
54} 53}
55 54
56void 55void
57drawcursor(void) {
58 XRectangle r = { dc.x, dc.y + 2, 1, dc.font.height - 2 };
59
60 r.x += textnw(&dc, text, cursor) + dc.font.height / 2;
61
62 XSetForeground(dpy, dc.gc, normcol[ColFG]);
63 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
64}
65
66void
67drawinput(void) 56drawinput(void)
68{ 57{
69 dc.x = 0; 58 dc.x = 0;
70 dc.y = 0; 59 dc.y = 0;
71 dc.w = mw; 60 dc.w = mw;
72 dc.h = mh; 61 dc.h = mh;
73 drawtext(&dc, NULL, normcol, False); 62 drawtext(&dc, NULL, normcol);
74 /* print prompt? */ 63 /* print prompt? */
75 if(prompt) { 64 if(prompt) {
76 dc.w = promptw; 65 dc.w = promptw;
77 drawtext(&dc, prompt, selcol, False); 66 drawtext(&dc, prompt, selcol);
78 dc.x += dc.w; 67 dc.x += dc.w;
79 } 68 }
80 dc.w = mw - dc.x; 69 dc.w = mw - dc.x;
81 drawtext(&dc, *text ? text : NULL, normcol, False); 70 drawtext(&dc, text, normcol);
82 drawcursor(); 71 drawcursor(&dc, text, cursor, normcol);
83 XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, mw, mh, 0, 0); 72 commitdraw(&dc, win);
84} 73}
85 74
86Bool 75void
87grabkeyboard(void) { 76grabkeyboard(void) {
88 unsigned int len; 77 unsigned int len;
89 78
90 for(len = 1000; len; len--) { 79 for(len = 1000; len; len--) {
91 if(XGrabKeyboard(dpy, root, True, GrabModeAsync, GrabModeAsync, CurrentTime) 80 if(XGrabKeyboard(dpy, root, True, GrabModeAsync, GrabModeAsync, CurrentTime)
92 == GrabSuccess) 81 == GrabSuccess)
93 break; 82 return;
94 usleep(1000); 83 usleep(1000);
95 } 84 }
96 return len > 0; 85 exit(EXIT_FAILURE);
97} 86}
98 87
99void 88void
diff --git a/dmenu.c b/dmenu.c
index 2cc2cad..c612dbe 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -162,25 +162,25 @@ drawmenu(void) {
162 dc.y = 0; 162 dc.y = 0;
163 dc.w = mw; 163 dc.w = mw;
164 dc.h = mh; 164 dc.h = mh;
165 drawtext(&dc, NULL, normcol, False); 165 drawtext(&dc, NULL, normcol);
166 dc.h = dc.font.height + 2; 166 dc.h = dc.font.height + 2;
167 dc.y = topbar ? 0 : mh - dc.h; 167 dc.y = topbar ? 0 : mh - dc.h;
168 /* print prompt? */ 168 /* print prompt? */
169 if(prompt) { 169 if(prompt) {
170 dc.w = promptw; 170 dc.w = promptw;
171 drawtext(&dc, prompt, selcol, False); 171 drawtext(&dc, prompt, selcol);
172 dc.x += dc.w; 172 dc.x += dc.w;
173 } 173 }
174 dc.w = mw - dc.x; 174 dc.w = mw - dc.x;
175 /* print command */ 175 /* print command */
176 if(cmdw && item && lines == 0) 176 if(cmdw && item && lines == 0)
177 dc.w = cmdw; 177 dc.w = cmdw;
178 drawtext(&dc, *text ? text : NULL, normcol, False); 178 drawtext(&dc, text, normcol);
179 if(lines > 0) 179 if(lines > 0)
180 drawmenuv(); 180 drawmenuv();
181 else if(curr) 181 else if(curr)
182 drawmenuh(); 182 drawmenuh();
183 XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, mw, mh, 0, 0); 183 commitdraw(&dc, win);
184} 184}
185 185
186void 186void
@@ -189,16 +189,16 @@ drawmenuh(void) {
189 189
190 dc.x += cmdw; 190 dc.x += cmdw;
191 dc.w = spaceitem; 191 dc.w = spaceitem;
192 drawtext(&dc, curr->left ? "<" : NULL, normcol, False); 192 drawtext(&dc, curr->left ? "<" : NULL, normcol);
193 dc.x += dc.w; 193 dc.x += dc.w;
194 for(i = curr; i != next; i = i->right) { 194 for(i = curr; i != next; i = i->right) {
195 dc.w = MIN(textw(&dc, i->text), mw / 3); 195 dc.w = MIN(textw(&dc, i->text), mw / 3);
196 drawtext(&dc, i->text, (sel == i) ? selcol : normcol, False); 196 drawtext(&dc, i->text, (sel == i) ? selcol : normcol);
197 dc.x += dc.w; 197 dc.x += dc.w;
198 } 198 }
199 dc.w = spaceitem; 199 dc.w = spaceitem;
200 dc.x = mw - dc.w; 200 dc.x = mw - dc.w;
201 drawtext(&dc, next ? ">" : NULL, normcol, False); 201 drawtext(&dc, next ? ">" : NULL, normcol);
202} 202}
203 203
204void 204void
@@ -209,7 +209,7 @@ drawmenuv(void) {
209 dc.y = topbar ? dc.h : 0; 209 dc.y = topbar ? dc.h : 0;
210 dc.w = mw - dc.x; 210 dc.w = mw - dc.x;
211 for(i = curr; i != next; i = i->right) { 211 for(i = curr; i != next; i = i->right) {
212 drawtext(&dc, i->text, (sel == i) ? selcol : normcol, False); 212 drawtext(&dc, i->text, (sel == i) ? selcol : normcol);
213 dc.y += dc.h; 213 dc.y += dc.h;
214 } 214 }
215 if(!XGetWindowAttributes(dpy, win, &wa)) 215 if(!XGetWindowAttributes(dpy, win, &wa))
@@ -224,11 +224,10 @@ grabkeyboard(void) {
224 for(len = 1000; len; len--) { 224 for(len = 1000; len; len--) {
225 if(XGrabKeyboard(dpy, root, True, GrabModeAsync, GrabModeAsync, CurrentTime) 225 if(XGrabKeyboard(dpy, root, True, GrabModeAsync, GrabModeAsync, CurrentTime)
226 == GrabSuccess) 226 == GrabSuccess)
227 break; 227 return;
228 usleep(1000); 228 usleep(1000);
229 } 229 }
230 if(!len) 230 exit(EXIT_FAILURE);
231 exit(EXIT_FAILURE);
232} 231}
233 232
234void 233void