portability 11ea52d1
Connor Lane Smith · 2011-05-15 21:54 3 file(s) · +19 −15
config.mk +1 −1
18 18
19 19
# flags
20 20
CPPFLAGS = -D_BSD_SOURCE -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
21 -
CFLAGS   = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
21 +
CFLAGS   = -ansi -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
22 22
LDFLAGS  = -s ${LIBS}
23 23
24 24
# compiler and linker
dmenu.c +12 −9
3 3
#include <stdio.h>
4 4
#include <stdlib.h>
5 5
#include <string.h>
6 +
#include <strings.h>
6 7
#include <unistd.h>
7 8
#include <X11/Xlib.h>
8 9
#include <X11/Xatom.h>
231 232
void
232 233
keypress(XKeyEvent *ev) {
233 234
	char buf[32];
234 -
	size_t len;
235 235
	KeySym ksym;
236 236
237 -
	len = strlen(text);
238 237
	XLookupString(ev, buf, sizeof buf, &ksym, NULL);
239 -
	if(ev->state & ControlMask)
240 -
		switch(tolower(ksym)) {
238 +
	if(ev->state & ControlMask) {
239 +
		KeySym lower, upper;
240 +
241 +
		XConvertCase(ksym, &lower, &upper);
242 +
		switch(lower) {
241 243
		default:
242 244
			return;
243 245
		case XK_a:
290 292
			XConvertSelection(dc->dpy, XA_PRIMARY, utf8, utf8, win, CurrentTime);
291 293
			return;
292 294
		}
295 +
	}
293 296
	switch(ksym) {
294 297
	default:
295 298
		if(!iscntrl(*buf))
296 299
			insert(buf, strlen(buf));
297 300
		break;
298 301
	case XK_Delete:
299 -
		if(cursor == len)
302 +
		if(text[cursor] == '\0')
300 303
			return;
301 304
		cursor = nextrune(+1);
302 305
	case XK_BackSpace:
304 307
			insert(NULL, nextrune(-1) - cursor);
305 308
		break;
306 309
	case XK_End:
307 -
		if(cursor < len) {
308 -
			cursor = len;
310 +
		if(text[cursor] != '\0') {
311 +
			cursor = strlen(text);
309 312
			break;
310 313
		}
311 314
		if(next) {
358 361
		fputs((sel && !(ev->state & ShiftMask)) ? sel->text : text, stdout);
359 362
		exit(EXIT_SUCCESS);
360 363
	case XK_Right:
361 -
		if(cursor < len) {
364 +
		if(text[cursor] != '\0') {
362 365
			cursor = nextrune(+1);
363 366
			break;
364 367
		}
385 388
match(Bool sub) {
386 389
	size_t len = strlen(text);
387 390
	Item *lexact, *lprefix, *lsubstr, *exactend, *prefixend, *substrend;
388 -
	Item *item, *next = NULL;
391 +
	Item *item, *next;
389 392
390 393
	lexact = lprefix = lsubstr = exactend = prefixend = substrend = NULL;
391 394
	for(item = sub ? matches : items; item && item->text; item = next) {
draw.c +6 −5
15 15
16 16
void
17 17
drawrect(DC *dc, int x, int y, unsigned int w, unsigned int h, Bool fill, unsigned long color) {
18 -
	XRectangle r = { dc->x + x, dc->y + y, w, h };
18 +
	XRectangle r;
19 +
20 +
	r.x = dc->x + x;
21 +
	r.y = dc->y + y;
22 +
	r.width  = fill ? w : w-1;
23 +
	r.height = fill ? h : h-1;
19 24
20 -
	if(!fill) {
21 -
		r.width -= 1;
22 -
		r.height -= 1;
23 -
	}
24 25
	XSetForeground(dc->dpy, dc->gc, color);
25 26
	(fill ? XFillRectangles : XDrawRectangles)(dc->dpy, dc->canvas, dc->gc, &r, 1);
26 27
}