aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dmenu.c41
1 files changed, 20 insertions, 21 deletions
diff --git a/dmenu.c b/dmenu.c
index 9f29c19..f93407d 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -91,11 +91,10 @@ static Item *sel = NULL;
91static Item *next = NULL; 91static Item *next = NULL;
92static Item *prev = NULL; 92static Item *prev = NULL;
93static Item *curr = NULL; 93static Item *curr = NULL;
94static Window root, win; 94static Window parent, win;
95static int (*fstrncmp)(const char *, const char *, size_t n) = strncmp; 95static int (*fstrncmp)(const char *, const char *, size_t n) = strncmp;
96static char *(*fstrstr)(const char *, const char *) = strstr; 96static char *(*fstrstr)(const char *, const char *) = strstr;
97static Bool vlist = False; 97static unsigned int lines = 0;
98static unsigned int lines = 5;
99static void (*calcoffsets)(void) = calcoffsetsh; 98static void (*calcoffsets)(void) = calcoffsetsh;
100 99
101void 100void
@@ -220,13 +219,12 @@ drawmenu(void) {
220 dc.x += promptw; 219 dc.x += promptw;
221 dc.w = mw - promptw; 220 dc.w = mw - promptw;
222 /* print command */ 221 /* print command */
223 if(cmdw && item && !vlist) 222 if(cmdw && item && lines == 0)
224 dc.w = cmdw; 223 dc.w = cmdw;
225 drawtext(text[0] ? text : NULL, dc.norm); 224 drawtext(text[0] ? text : NULL, dc.norm);
226 drawcursor(); 225 drawcursor();
227 dc.x += cmdw;
228 if(curr) { 226 if(curr) {
229 if(vlist) 227 if(lines > 0)
230 drawmenuv(); 228 drawmenuv();
231 else 229 else
232 drawmenuh(); 230 drawmenuh();
@@ -239,8 +237,9 @@ void
239drawmenuh(void) { 237drawmenuh(void) {
240 Item *i; 238 Item *i;
241 239
240 dc.x += cmdw;
242 dc.w = spaceitem; 241 dc.w = spaceitem;
243 drawtext((curr && curr->left) ? "<" : NULL, dc.norm); 242 drawtext(curr->left ? "<" : NULL, dc.norm);
244 dc.x += dc.w; 243 dc.x += dc.w;
245 /* determine maximum items */ 244 /* determine maximum items */
246 for(i = curr; i != next; i=i->right) { 245 for(i = curr; i != next; i=i->right) {
@@ -321,7 +320,7 @@ grabkeyboard(void) {
321 unsigned int len; 320 unsigned int len;
322 321
323 for(len = 1000; len; len--) { 322 for(len = 1000; len; len--) {
324 if(XGrabKeyboard(dpy, root, True, GrabModeAsync, GrabModeAsync, CurrentTime) 323 if(XGrabKeyboard(dpy, parent, True, GrabModeAsync, GrabModeAsync, CurrentTime)
325 == GrabSuccess) 324 == GrabSuccess)
326 break; 325 break;
327 usleep(1000); 326 usleep(1000);
@@ -675,6 +674,7 @@ setup(Bool topbar) {
675#endif 674#endif
676 XModifierKeymap *modmap; 675 XModifierKeymap *modmap;
677 XSetWindowAttributes wa; 676 XSetWindowAttributes wa;
677 XWindowAttributes pwa;
678 678
679 /* init modifier map */ 679 /* init modifier map */
680 modmap = XGetModifierMapping(dpy); 680 modmap = XGetModifierMapping(dpy);
@@ -699,16 +699,15 @@ setup(Bool topbar) {
699 wa.event_mask = ExposureMask | ButtonPressMask | KeyPressMask | VisibilityChangeMask; 699 wa.event_mask = ExposureMask | ButtonPressMask | KeyPressMask | VisibilityChangeMask;
700 700
701 /* menu window geometry */ 701 /* menu window geometry */
702 mh = dc.font.height + 2; 702 mh = (dc.font.height + 2) * (lines + 1);
703 mh = vlist ? mh * (lines+1) : mh;
704#if XINERAMA 703#if XINERAMA
705 if(XineramaIsActive(dpy) && (info = XineramaQueryScreens(dpy, &n))) { 704 if(parent == RootWindow(dpy, screen) && XineramaIsActive(dpy) && (info = XineramaQueryScreens(dpy, &n))) {
706 i = 0; 705 i = 0;
707 if(n > 1) { 706 if(n > 1) {
708 int di; 707 int di;
709 unsigned int dui; 708 unsigned int dui;
710 Window dummy; 709 Window dummy;
711 if(XQueryPointer(dpy, root, &dummy, &dummy, &x, &y, &di, &di, &dui)) 710 if(XQueryPointer(dpy, parent, &dummy, &dummy, &x, &y, &di, &di, &dui))
712 for(i = 0; i < n; i++) 711 for(i = 0; i < n; i++)
713 if(INRECT(x, y, info[i].x_org, info[i].y_org, info[i].width, info[i].height)) 712 if(INRECT(x, y, info[i].x_org, info[i].y_org, info[i].width, info[i].height))
714 break; 713 break;
@@ -721,19 +720,20 @@ setup(Bool topbar) {
721 else 720 else
722#endif 721#endif
723 { 722 {
723 XGetWindowAttributes(dpy, parent, &pwa);
724 x = 0; 724 x = 0;
725 y = topbar ? 0 : DisplayHeight(dpy, screen) - mh; 725 y = topbar ? 0 : pwa.height - mh;
726 mw = DisplayWidth(dpy, screen); 726 mw = pwa.width;
727 } 727 }
728 728
729 win = XCreateWindow(dpy, root, x, y, mw, mh, 0, 729 win = XCreateWindow(dpy, parent, x, y, mw, mh, 0,
730 DefaultDepth(dpy, screen), CopyFromParent, 730 DefaultDepth(dpy, screen), CopyFromParent,
731 DefaultVisual(dpy, screen), 731 DefaultVisual(dpy, screen),
732 CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); 732 CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
733 733
734 /* pixmap */ 734 /* pixmap */
735 dc.drawable = XCreatePixmap(dpy, root, mw, mh, DefaultDepth(dpy, screen)); 735 dc.drawable = XCreatePixmap(dpy, parent, mw, mh, DefaultDepth(dpy, screen));
736 dc.gc = XCreateGC(dpy, root, 0, NULL); 736 dc.gc = XCreateGC(dpy, parent, 0, NULL);
737 XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter); 737 XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
738 if(!dc.font.set) 738 if(!dc.font.set)
739 XSetFont(dpy, dc.gc, dc.font.xfont->fid); 739 XSetFont(dpy, dc.gc, dc.font.xfont->fid);
@@ -776,10 +776,9 @@ main(int argc, char *argv[]) {
776 else if(!strcmp(argv[i], "-b")) 776 else if(!strcmp(argv[i], "-b"))
777 topbar = False; 777 topbar = False;
778 else if(!strcmp(argv[i], "-e")) { 778 else if(!strcmp(argv[i], "-e")) {
779 if(++i < argc) root = atoi(argv[i]); 779 if(++i < argc) parent = atoi(argv[i]);
780 } 780 }
781 else if(!strcmp(argv[i], "-l")) { 781 else if(!strcmp(argv[i], "-l")) {
782 vlist = True;
783 calcoffsets = calcoffsetsv; 782 calcoffsets = calcoffsetsv;
784 if(++i < argc) lines = atoi(argv[i]); 783 if(++i < argc) lines = atoi(argv[i]);
785 } 784 }
@@ -811,8 +810,8 @@ main(int argc, char *argv[]) {
811 if(!(dpy = XOpenDisplay(NULL))) 810 if(!(dpy = XOpenDisplay(NULL)))
812 eprint("dmenu: cannot open display\n"); 811 eprint("dmenu: cannot open display\n");
813 screen = DefaultScreen(dpy); 812 screen = DefaultScreen(dpy);
814 if(!root) 813 if(!parent)
815 root = RootWindow(dpy, screen); 814 parent = RootWindow(dpy, screen);
816 815
817 readstdin(); 816 readstdin();
818 running = grabkeyboard(); 817 running = grabkeyboard();