simplifications caf52462
Connor Lane Smith · 2010-08-10 13:38 2 file(s) · +14 −19
config.mk +0 −1
7 7
PREFIX = /usr/local
8 8
MANPREFIX = ${PREFIX}/share/man
9 9
10 -
# Xlib
11 10
X11INC = /usr/X11R6/include
12 11
X11LIB = /usr/X11R6/lib
13 12
dmenu.c +14 −18
4 4
#include <stdlib.h>
5 5
#include <string.h>
6 6
#include <unistd.h>
7 -
#include <X11/Xatom.h>
8 7
#include <X11/Xlib.h>
8 +
#include <X11/Xatom.h>
9 9
#include <X11/Xutil.h>
10 10
#ifdef XINERAMA
11 11
#include <X11/extensions/Xinerama.h>
13 13
#include <draw.h>
14 14
15 15
#define INRECT(x,y,rx,ry,rw,rh) ((x) >= (rx) && (x) < (rx)+(rw) && (y) >= (ry) && (y) < (ry)+(rh))
16 +
#define LINEH                   (dc->font.height + 2)
16 17
#define MIN(a,b)                ((a) < (b) ? (a) : (b))
17 18
#define MAX(a,b)                ((a) > (b) ? (a) : (b))
18 19
#define UTF8_CODEPOINT(c)       (((c) & 0xc0) != 0x80)
38 39
static void setup(void);
39 40
static void usage(void);
40 41
41 -
static char text[4096];
42 +
static char text[BUFSIZ];
42 43
static size_t cursor = 0;
43 44
static const char *prompt = NULL;
44 45
static const char *normbgcolor = "#cccccc";
74 75
75 76
void
76 77
calcoffsets(void) {
77 -
	unsigned int h, i, n;
78 +
	unsigned int i, n;
78 79
79 -
	h = dc->font.height+2;
80 80
	if(lines > 0)
81 -
		n = lines * h;
81 +
		n = lines * LINEH;
82 82
	else
83 83
		n = mw - (promptw + inputw + textw(dc, "<") + textw(dc, ">"));
84 84
85 -
	prev = next = curr;
86 -
	for(i = 0; next; next = next->right)
87 -
		if((i += (lines > 0) ? h : MIN(textw(dc, next->text), mw/3)) > n)
88 -
			break;
89 -
	for(i = 0; prev && prev->left; prev = prev->left)
90 -
		if((i += (lines > 0) ? h : MIN(textw(dc, prev->left->text), mw/3)) > n)
91 -
			break;
85 +
	for(i = 0, next = curr; i <= n && next; next = next->right)
86 +
		i += (lines > 0) ? LINEH : MIN(textw(dc, next->text), mw/3);
87 +
88 +
	for(i = 0, prev = curr; i <= n && prev && prev->left; prev = prev->left)
89 +
		i += (lines > 0) ? LINEH : MIN(textw(dc, prev->left->text), mw/3);
92 90
}
93 91
94 92
char *
108 106
109 107
	dc->x = 0;
110 108
	dc->y = 0;
109 +
	dc->h = LINEH;
111 110
	drawrect(dc, 0, 0, mw, mh, BG(dc, normcol));
112 -
	dc->h = dc->font.height + 2;
113 -
	dc->y = topbar ? 0 : mh - dc->h;
114 111
115 112
	if(prompt) {
116 113
		dc->w = promptw;
123 120
		drawrect(dc, curpos, 2, 1, dc->h - 4, FG(dc, normcol));
124 121
125 122
	if(lines > 0) {
126 -
		dc->y = topbar ? dc->h : 0;
127 123
		dc->w = mw - dc->x;
128 124
		for(item = curr; item != next; item = item->right) {
125 +
			dc->y += dc->h;
129 126
			drawtext(dc, item->text, (item == sel) ? selcol : normcol);
130 -
			dc->y += dc->h;
131 127
		}
132 128
	}
133 129
	else if(matches) {
237 233
	}
238 234
	switch(ksym) {
239 235
	default:
240 -
		if(!iscntrl((int)*buf))
236 +
		if(isprint(*buf))
241 237
			insert(buf, MIN(strlen(buf), sizeof text - cursor));
242 238
		break;
243 239
	case XK_BackSpace:
451 447
	selcol[ColFG] = getcolor(dc, selfgcolor);
452 448
453 449
	/* menu geometry */
454 -
	mh = (dc->font.height + 2) * (lines + 1);
450 +
	mh = (lines + 1) * LINEH;
455 451
#ifdef XINERAMA
456 452
	if((info = XineramaQueryScreens(dc->dpy, &n))) {
457 453
		int i, di;