updated to new libdraw 29e8faed
Connor Lane Smith · 2010-07-02 05:50 2 file(s) · +20 −32
dinput.c +10 −21
21 21
22 22
/* forward declarations */
23 23
static void cleanup(void);
24 -
static void drawcursor(void);
25 24
static void drawinput(void);
26 -
static Bool grabkeyboard(void);
25 +
static void grabkeyboard(void);
27 26
static void kpress(XKeyEvent *e);
28 27
static void run(void);
29 28
static void setup(void);
35 34
static char text[4096];
36 35
static int promptw = 0;
37 36
static int screen;
38 -
static unsigned int cursor = 0;
37 +
static size_t cursor = 0;
39 38
static unsigned int numlockmask = 0;
40 39
static unsigned int mw, mh;
41 40
static unsigned long normcol[ColLast];
54 53
}
55 54
56 55
void
57 -
drawcursor(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 -
66 -
void
67 56
drawinput(void)
68 57
{
69 58
	dc.x = 0;
70 59
	dc.y = 0;
71 60
	dc.w = mw;
72 61
	dc.h = mh;
73 -
	drawtext(&dc, NULL, normcol, False);
62 +
	drawtext(&dc, NULL, normcol);
74 63
	/* print prompt? */
75 64
	if(prompt) {
76 65
		dc.w = promptw;
77 -
		drawtext(&dc, prompt, selcol, False);
66 +
		drawtext(&dc, prompt, selcol);
78 67
		dc.x += dc.w;
79 68
	}
80 69
	dc.w = mw - dc.x;
81 -
	drawtext(&dc, *text ? text : NULL, normcol, False);
82 -
	drawcursor();
83 -
	XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, mw, mh, 0, 0);
70 +
	drawtext(&dc, text, normcol);
71 +
	drawcursor(&dc, text, cursor, normcol);
72 +
	commitdraw(&dc, win);
84 73
}
85 74
86 -
Bool
75 +
void
87 76
grabkeyboard(void) {
88 77
	unsigned int len;
89 78
90 79
	for(len = 1000; len; len--) {
91 80
		if(XGrabKeyboard(dpy, root, True, GrabModeAsync, GrabModeAsync, CurrentTime)
92 81
		== GrabSuccess)
93 -
			break;
82 +
			return;
94 83
		usleep(1000);
95 84
	}
96 -
	return len > 0;
85 +
	exit(EXIT_FAILURE);
97 86
}
98 87
99 88
void
dmenu.c +10 −11
162 162
	dc.y = 0;
163 163
	dc.w = mw;
164 164
	dc.h = mh;
165 -
	drawtext(&dc, NULL, normcol, False);
165 +
	drawtext(&dc, NULL, normcol);
166 166
	dc.h = dc.font.height + 2;
167 167
	dc.y = topbar ? 0 : mh - dc.h;
168 168
	/* print prompt? */
169 169
	if(prompt) {
170 170
		dc.w = promptw;
171 -
		drawtext(&dc, prompt, selcol, False);
171 +
		drawtext(&dc, prompt, selcol);
172 172
		dc.x += dc.w;
173 173
	}
174 174
	dc.w = mw - dc.x;
175 175
	/* print command */
176 176
	if(cmdw && item && lines == 0)
177 177
		dc.w = cmdw;
178 -
	drawtext(&dc, *text ? text : NULL, normcol, False);
178 +
	drawtext(&dc, text, normcol);
179 179
	if(lines > 0)
180 180
		drawmenuv();
181 181
	else if(curr)
182 182
		drawmenuh();
183 -
	XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, mw, mh, 0, 0);
183 +
	commitdraw(&dc, win);
184 184
}
185 185
186 186
void
189 189
190 190
	dc.x += cmdw;
191 191
	dc.w = spaceitem;
192 -
	drawtext(&dc, curr->left ? "<" : NULL, normcol, False);
192 +
	drawtext(&dc, curr->left ? "<" : NULL, normcol);
193 193
	dc.x += dc.w;
194 194
	for(i = curr; i != next; i = i->right) {
195 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 197
		dc.x += dc.w;
198 198
	}
199 199
	dc.w = spaceitem;
200 200
	dc.x = mw - dc.w;
201 -
	drawtext(&dc, next ? ">" : NULL, normcol, False);
201 +
	drawtext(&dc, next ? ">" : NULL, normcol);
202 202
}
203 203
204 204
void
209 209
	dc.y = topbar ? dc.h : 0;
210 210
	dc.w = mw - dc.x;
211 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 213
		dc.y += dc.h;
214 214
	}
215 215
	if(!XGetWindowAttributes(dpy, win, &wa))
224 224
	for(len = 1000; len; len--) {
225 225
		if(XGrabKeyboard(dpy, root, True, GrabModeAsync, GrabModeAsync, CurrentTime)
226 226
		== GrabSuccess)
227 -
			break;
227 +
			return;
228 228
		usleep(1000);
229 229
	}
230 -
	if(!len)
231 -
		exit(EXIT_FAILURE);
230 +
	exit(EXIT_FAILURE);
232 231
}
233 232
234 233
void