aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConnor Lane Smith <cls@lubutu.com>2010-06-30 00:52:14 +0100
committerConnor Lane Smith <cls@lubutu.com>2010-06-30 00:52:14 +0100
commit7afd296c40a2e8af9477add1c3d02a7c4b444747 (patch)
tree8e10e6ec9563db529686c34bfb5e28f0b3f000a2
parentcc8b3b999ba0153029b1e5a97ebbd59563f9e7bb (diff)
resizing vlist, new dinput binding
-rw-r--r--dmenu.c34
1 files changed, 16 insertions, 18 deletions
diff --git a/dmenu.c b/dmenu.c
index 2d53f9b..764e0f0 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -109,6 +109,7 @@ calcoffsetsv(void) {
109 next = prev = curr; 109 next = prev = curr;
110 for(i = 0; i < lines && next; i++) 110 for(i = 0; i < lines && next; i++)
111 next = next->right; 111 next = next->right;
112 mh = (dc.font.height + 2) * (i + 1);
112 for(i = 0; i < lines && prev && prev->left; i++) 113 for(i = 0; i < lines && prev && prev->left; i++)
113 prev = prev->left; 114 prev = prev->left;
114} 115}
@@ -166,6 +167,8 @@ drawmenu(void) {
166 dc.w = mw; 167 dc.w = mw;
167 dc.h = mh; 168 dc.h = mh;
168 drawtext(&dc, NULL, normcol, False); 169 drawtext(&dc, NULL, normcol, False);
170 dc.h = dc.font.height + 2;
171 dc.y = topbar ? 0 : mh - dc.h;
169 /* print prompt? */ 172 /* print prompt? */
170 if(prompt) { 173 if(prompt) {
171 dc.w = promptw; 174 dc.w = promptw;
@@ -177,12 +180,10 @@ drawmenu(void) {
177 if(cmdw && item && lines == 0) 180 if(cmdw && item && lines == 0)
178 dc.w = cmdw; 181 dc.w = cmdw;
179 drawtext(&dc, *text ? text : NULL, normcol, False); 182 drawtext(&dc, *text ? text : NULL, normcol, False);
180 if(curr) { 183 if(lines > 0)
181 if(lines > 0) 184 drawmenuv();
182 drawmenuv(); 185 else
183 else 186 drawmenuh();
184 drawmenuh();
185 }
186 XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, mw, mh, 0, 0); 187 XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, mw, mh, 0, 0);
187 XFlush(dpy); 188 XFlush(dpy);
188} 189}
@@ -193,7 +194,7 @@ drawmenuh(void) {
193 194
194 dc.x += cmdw; 195 dc.x += cmdw;
195 dc.w = spaceitem; 196 dc.w = spaceitem;
196 drawtext(&dc, curr->left ? "<" : NULL, normcol, False); 197 drawtext(&dc, curr && curr->left ? "<" : NULL, normcol, False);
197 dc.x += dc.w; 198 dc.x += dc.w;
198 for(i = curr; i != next; i = i->right) { 199 for(i = curr; i != next; i = i->right) {
199 dc.w = MIN(textw(&dc, i->text), mw / 3); 200 dc.w = MIN(textw(&dc, i->text), mw / 3);
@@ -208,16 +209,17 @@ drawmenuh(void) {
208void 209void
209drawmenuv(void) { 210drawmenuv(void) {
210 Item *i; 211 Item *i;
212 XWindowAttributes wa;
211 213
214 dc.y = topbar ? dc.h : 0;
212 dc.w = mw - dc.x; 215 dc.w = mw - dc.x;
213 dc.h = dc.font.height + 2;
214 dc.y = dc.h;
215 for(i = curr; i != next; i = i->right) { 216 for(i = curr; i != next; i = i->right) {
216 drawtext(&dc, i->text, (sel == i) ? selcol : normcol, False); 217 drawtext(&dc, i->text, (sel == i) ? selcol : normcol, False);
217 dc.y += dc.h; 218 dc.y += dc.h;
218 } 219 }
219 dc.h = mh - dc.y; 220 if(!XGetWindowAttributes(dpy, win, &wa))
220 drawtext(&dc, NULL, normcol, False); 221 eprint("cannot get window attributes");
222 XMoveResizeWindow(dpy, win, wa.x, wa.y + (topbar ? 0 : wa.height - mh), mw, mh);
221} 223}
222 224
223Bool 225Bool
@@ -299,9 +301,6 @@ kpress(XKeyEvent *e) {
299 text[++i] = '\0'; 301 text[++i] = '\0';
300 match(text); 302 match(text);
301 break; 303 break;
302 case XK_x:
303 dinput();
304 break;
305 } 304 }
306 } 305 }
307 switch(ksym) { 306 switch(ksym) {
@@ -360,10 +359,9 @@ kpress(XKeyEvent *e) {
360 calcoffsets(); 359 calcoffsets();
361 break; 360 break;
362 case XK_Return: 361 case XK_Return:
363 if((e->state & ShiftMask) || !sel) 362 if(e->state & ShiftMask)
364 fprintf(stdout, "%s", text); 363 dinput();
365 else 364 fprintf(stdout, "%s", sel ? sel->text : text);
366 fprintf(stdout, "%s", sel->text);
367 fflush(stdout); 365 fflush(stdout);
368 running = False; 366 running = False;
369 return; 367 return;