added ^K, optimisations 4983707c
Connor Lane Smith · 2010-06-20 00:44 1 file(s) · +15 −11
dmenu.c +15 −11
79 79
static int cmdw = 0;
80 80
static int promptw = 0;
81 81
static int ret = 0;
82 -
static int cursor = 0;
83 82
static int screen;
84 83
static unsigned int mw, mh;
84 +
static unsigned int cursor = 0;
85 85
static unsigned int numlockmask = 0;
86 86
static Bool running = True;
87 87
static Display *dpy;
338 338
void
339 339
kpress(XKeyEvent * e) {
340 340
	char buf[sizeof text];
341 -
	int i, num;
342 -
	unsigned int len;
341 +
	int num;
342 +
	unsigned int i, len;
343 343
	KeySym ksym;
344 344
345 345
	len = strlen(text);
380 380
		case XK_j:
381 381
		case XK_J:
382 382
			ksym = XK_Return;
383 +
			break;
384 +
		case XK_k:
385 +
		case XK_K:
386 +
			text[cursor] = '\0';
383 387
			break;
384 388
		case XK_u:
385 389
		case XK_U:
450 454
		}
451 455
		break;
452 456
	case XK_BackSpace:
453 -
		if(cursor > 0) {
454 -
			for(i = 1; cursor - i > 0 && !IS_UTF8_1ST_CHAR(text[cursor - i]); i++);
455 -
			memmove(text + cursor - i, text + cursor, sizeof text - cursor + i);
456 -
			cursor -= i;
457 -
			match(text);
458 -
		}
457 +
		if(cursor == 0)
458 +
			return;
459 +
		for(i = 1; cursor - i > 0 && !IS_UTF8_1ST_CHAR(text[cursor - i]); i++);
460 +
		memmove(text + cursor - i, text + cursor, sizeof text - cursor + i);
461 +
		cursor -= i;
462 +
		match(text);
459 463
		break;
460 464
	case XK_Delete:
461 465
		for(i = 1; cursor + i < len && !IS_UTF8_1ST_CHAR(text[cursor + i]); i++);
477 481
	case XK_Escape:
478 482
		ret = 1;
479 483
		running = False;
480 -
		break;
484 +
		return;
481 485
	case XK_Home:
482 486
		if(sel == item) {
483 487
			cursor = 0;
519 523
			fprintf(stdout, "%s", sel->text);
520 524
		fflush(stdout);
521 525
		running = False;
522 -
		break;
526 +
		return;
523 527
	case XK_Right:
524 528
	case XK_Down:
525 529
		if(cursor < len)