1
0

resizing vlist, new dinput binding

This commit is contained in:
Connor Lane Smith 2010-06-30 00:52:14 +01:00
parent cc8b3b999b
commit 7afd296c40

26
dmenu.c
View File

@ -109,6 +109,7 @@ calcoffsetsv(void) {
next = prev = curr; next = prev = curr;
for(i = 0; i < lines && next; i++) for(i = 0; i < lines && next; i++)
next = next->right; next = next->right;
mh = (dc.font.height + 2) * (i + 1);
for(i = 0; i < lines && prev && prev->left; i++) for(i = 0; i < lines && prev && prev->left; i++)
prev = prev->left; prev = prev->left;
} }
@ -166,6 +167,8 @@ drawmenu(void) {
dc.w = mw; dc.w = mw;
dc.h = mh; dc.h = mh;
drawtext(&dc, NULL, normcol, False); drawtext(&dc, NULL, normcol, False);
dc.h = dc.font.height + 2;
dc.y = topbar ? 0 : mh - dc.h;
/* print prompt? */ /* print prompt? */
if(prompt) { if(prompt) {
dc.w = promptw; dc.w = promptw;
@ -177,12 +180,10 @@ drawmenu(void) {
if(cmdw && item && lines == 0) if(cmdw && item && lines == 0)
dc.w = cmdw; dc.w = cmdw;
drawtext(&dc, *text ? text : NULL, normcol, False); drawtext(&dc, *text ? text : NULL, normcol, False);
if(curr) {
if(lines > 0) if(lines > 0)
drawmenuv(); drawmenuv();
else else
drawmenuh(); drawmenuh();
}
XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, mw, mh, 0, 0); XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, mw, mh, 0, 0);
XFlush(dpy); XFlush(dpy);
} }
@ -193,7 +194,7 @@ drawmenuh(void) {
dc.x += cmdw; dc.x += cmdw;
dc.w = spaceitem; dc.w = spaceitem;
drawtext(&dc, curr->left ? "<" : NULL, normcol, False); drawtext(&dc, curr && curr->left ? "<" : NULL, normcol, False);
dc.x += dc.w; dc.x += dc.w;
for(i = curr; i != next; i = i->right) { for(i = curr; i != next; i = i->right) {
dc.w = MIN(textw(&dc, i->text), mw / 3); dc.w = MIN(textw(&dc, i->text), mw / 3);
@ -208,16 +209,17 @@ drawmenuh(void) {
void void
drawmenuv(void) { drawmenuv(void) {
Item *i; Item *i;
XWindowAttributes wa;
dc.y = topbar ? dc.h : 0;
dc.w = mw - dc.x; dc.w = mw - dc.x;
dc.h = dc.font.height + 2;
dc.y = dc.h;
for(i = curr; i != next; i = i->right) { for(i = curr; i != next; i = i->right) {
drawtext(&dc, i->text, (sel == i) ? selcol : normcol, False); drawtext(&dc, i->text, (sel == i) ? selcol : normcol, False);
dc.y += dc.h; dc.y += dc.h;
} }
dc.h = mh - dc.y; if(!XGetWindowAttributes(dpy, win, &wa))
drawtext(&dc, NULL, normcol, False); eprint("cannot get window attributes");
XMoveResizeWindow(dpy, win, wa.x, wa.y + (topbar ? 0 : wa.height - mh), mw, mh);
} }
Bool Bool
@ -299,9 +301,6 @@ kpress(XKeyEvent *e) {
text[++i] = '\0'; text[++i] = '\0';
match(text); match(text);
break; break;
case XK_x:
dinput();
break;
} }
} }
switch(ksym) { switch(ksym) {
@ -360,10 +359,9 @@ kpress(XKeyEvent *e) {
calcoffsets(); calcoffsets();
break; break;
case XK_Return: case XK_Return:
if((e->state & ShiftMask) || !sel) if(e->state & ShiftMask)
fprintf(stdout, "%s", text); dinput();
else fprintf(stdout, "%s", sel ? sel->text : text);
fprintf(stdout, "%s", sel->text);
fflush(stdout); fflush(stdout);
running = False; running = False;
return; return;