diff options
| -rw-r--r-- | config.mk | 9 | ||||
| -rw-r--r-- | dmenu.1 | 18 | ||||
| -rw-r--r-- | dmenu.c | 60 |
3 files changed, 43 insertions, 44 deletions
| @@ -10,12 +10,17 @@ MANPREFIX = ${PREFIX}/share/man | |||
| 10 | X11INC = /usr/X11R6/include | 10 | X11INC = /usr/X11R6/include |
| 11 | X11LIB = /usr/X11R6/lib | 11 | X11LIB = /usr/X11R6/lib |
| 12 | 12 | ||
| 13 | # Xinerama, comment if you don't want it | ||
| 14 | XINERAMALIBS = -L${X11LIB} -lXinerama | ||
| 15 | XINERAMAFLAGS = -DXINERAMA | ||
| 16 | |||
| 13 | # includes and libs | 17 | # includes and libs |
| 14 | INCS = -I. -I/usr/include -I${X11INC} | 18 | INCS = -I. -I/usr/include -I${X11INC} |
| 15 | LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 | 19 | LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 ${XINERAMALIBS} |
| 16 | 20 | ||
| 17 | # flags | 21 | # flags |
| 18 | CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\" | 22 | CPPFLAGS = -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS} |
| 23 | CFLAGS = -Os ${INCS} ${CPPFLAGS} | ||
| 19 | LDFLAGS = -s ${LIBS} | 24 | LDFLAGS = -s ${LIBS} |
| 20 | #CFLAGS = -g -std=c99 -pedantic -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\" | 25 | #CFLAGS = -g -std=c99 -pedantic -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\" |
| 21 | #LDFLAGS = -g ${LIBS} | 26 | #LDFLAGS = -g ${LIBS} |
| @@ -4,9 +4,7 @@ dmenu \- dynamic menu | |||
| 4 | .SH SYNOPSIS | 4 | .SH SYNOPSIS |
| 5 | .B dmenu | 5 | .B dmenu |
| 6 | .RB [ \-i ] | 6 | .RB [ \-i ] |
| 7 | .RB [ \-x " <x>"] | 7 | .RB [ \-b ] |
| 8 | .RB [ \-y " <y>"] | ||
| 9 | .RB [ \-w " <width>"] | ||
| 10 | .RB [ \-fn " <font>"] | 8 | .RB [ \-fn " <font>"] |
| 11 | .RB [ \-nb " <color>"] | 9 | .RB [ \-nb " <color>"] |
| 12 | .RB [ \-nf " <color>"] | 10 | .RB [ \-nf " <color>"] |
| @@ -22,20 +20,12 @@ It manages huge amounts (up to 10.000 and more) of user defined menu items | |||
| 22 | efficiently. | 20 | efficiently. |
| 23 | .SS Options | 21 | .SS Options |
| 24 | .TP | 22 | .TP |
| 25 | .B \-x | ||
| 26 | defines the x coordinate dmenu appears at (0 by default). | ||
| 27 | .TP | ||
| 28 | .B \-y | ||
| 29 | defines the y coordinate dmenu appears at (0 by default). If it is negative, | ||
| 30 | dmenu will appear with the bottom at the given positive coordinate. If it is | ||
| 31 | -0, dmenu appears at the screen bottom. | ||
| 32 | .TP | ||
| 33 | .B \-w | ||
| 34 | defines the width of the dmenu window (screen width by default). | ||
| 35 | .TP | ||
| 36 | .B \-i | 23 | .B \-i |
| 37 | makes dmenu match menu entries case insensitively. | 24 | makes dmenu match menu entries case insensitively. |
| 38 | .TP | 25 | .TP |
| 26 | .B \-b | ||
| 27 | defines that dmenu appears at the bottom. | ||
| 28 | .TP | ||
| 39 | .B \-fn <font> | 29 | .B \-fn <font> |
| 40 | defines the font. | 30 | defines the font. |
| 41 | .TP | 31 | .TP |
| @@ -1,6 +1,5 @@ | |||
| 1 | /* See LICENSE file for copyright and license details. */ | 1 | /* See LICENSE file for copyright and license details. */ |
| 2 | #include <ctype.h> | 2 | #include <ctype.h> |
| 3 | #include <limits.h> | ||
| 4 | #include <locale.h> | 3 | #include <locale.h> |
| 5 | #include <stdarg.h> | 4 | #include <stdarg.h> |
| 6 | #include <stdlib.h> | 5 | #include <stdlib.h> |
| @@ -10,6 +9,9 @@ | |||
| 10 | #include <X11/Xlib.h> | 9 | #include <X11/Xlib.h> |
| 11 | #include <X11/Xutil.h> | 10 | #include <X11/Xutil.h> |
| 12 | #include <X11/keysym.h> | 11 | #include <X11/keysym.h> |
| 12 | #ifdef XINERAMA | ||
| 13 | #include <X11/extensions/Xinerama.h> | ||
| 14 | #endif | ||
| 13 | 15 | ||
| 14 | /* macros */ | 16 | /* macros */ |
| 15 | #define CLEANMASK(mask) (mask & ~(numlockmask | LockMask)) | 17 | #define CLEANMASK(mask) (mask & ~(numlockmask | LockMask)) |
| @@ -57,7 +59,7 @@ void kpress(XKeyEvent * e); | |||
| 57 | void match(char *pattern); | 59 | void match(char *pattern); |
| 58 | void readstdin(void); | 60 | void readstdin(void); |
| 59 | void run(void); | 61 | void run(void); |
| 60 | void setup(int x, int y, int w); | 62 | void setup(Bool topbar); |
| 61 | unsigned int textnw(const char *text, unsigned int len); | 63 | unsigned int textnw(const char *text, unsigned int len); |
| 62 | unsigned int textw(const char *text); | 64 | unsigned int textw(const char *text); |
| 63 | 65 | ||
| @@ -601,10 +603,13 @@ run(void) { | |||
| 601 | } | 603 | } |
| 602 | 604 | ||
| 603 | void | 605 | void |
| 604 | setup(int x, int y, int w) { | 606 | setup(Bool topbar) { |
| 605 | unsigned int i, j; | 607 | int i, j, x, y; |
| 606 | XModifierKeymap *modmap; | 608 | XModifierKeymap *modmap; |
| 607 | XSetWindowAttributes wa; | 609 | XSetWindowAttributes wa; |
| 610 | #if XINERAMA | ||
| 611 | XineramaScreenInfo *info = NULL; | ||
| 612 | #endif | ||
| 608 | 613 | ||
| 609 | /* init modifier map */ | 614 | /* init modifier map */ |
| 610 | modmap = XGetModifierMapping(dpy); | 615 | modmap = XGetModifierMapping(dpy); |
| @@ -627,14 +632,25 @@ setup(int x, int y, int w) { | |||
| 627 | wa.override_redirect = 1; | 632 | wa.override_redirect = 1; |
| 628 | wa.background_pixmap = ParentRelative; | 633 | wa.background_pixmap = ParentRelative; |
| 629 | wa.event_mask = ExposureMask | ButtonPressMask | KeyPressMask; | 634 | wa.event_mask = ExposureMask | ButtonPressMask | KeyPressMask; |
| 630 | mw = w ? w : DisplayWidth(dpy, screen); | 635 | |
| 636 | /* menu window geometry */ | ||
| 631 | mh = dc.font.height + 2; | 637 | mh = dc.font.height + 2; |
| 632 | if(y < 0) { | 638 | #if XINERAMA |
| 633 | if(y == INT_MIN) | 639 | if(XineramaIsActive(dpy)) { |
| 634 | y = DisplayHeight(dpy, screen) - mh; | 640 | info = XineramaQueryScreens(dpy, &i); |
| 635 | else | 641 | x = info[0].x_org; |
| 636 | y = (-1 * y) - mh; | 642 | y = topbar ? info[0].y_org : info[0].y_org + info[0].height - mh; |
| 643 | mw = info[0].width; | ||
| 644 | XFree(info); | ||
| 645 | } | ||
| 646 | else | ||
| 647 | #endif | ||
| 648 | { | ||
| 649 | x = 0; | ||
| 650 | y = topbar ? 0 : DisplayHeight(dpy, screen) - mh; | ||
| 651 | mw = DisplayWidth(dpy, screen); | ||
| 637 | } | 652 | } |
| 653 | |||
| 638 | win = XCreateWindow(dpy, root, x, y, mw, mh, 0, | 654 | win = XCreateWindow(dpy, root, x, y, mw, mh, 0, |
| 639 | DefaultDepth(dpy, screen), CopyFromParent, | 655 | DefaultDepth(dpy, screen), CopyFromParent, |
| 640 | DefaultVisual(dpy, screen), | 656 | DefaultVisual(dpy, screen), |
| @@ -677,8 +693,8 @@ textw(const char *text) { | |||
| 677 | 693 | ||
| 678 | int | 694 | int |
| 679 | main(int argc, char *argv[]) { | 695 | main(int argc, char *argv[]) { |
| 680 | int x = 0, y = 0, w = 0; | ||
| 681 | unsigned int i; | 696 | unsigned int i; |
| 697 | Bool topbar = True; | ||
| 682 | 698 | ||
| 683 | /* command line args */ | 699 | /* command line args */ |
| 684 | for(i = 1; i < argc; i++) | 700 | for(i = 1; i < argc; i++) |
| @@ -686,6 +702,8 @@ main(int argc, char *argv[]) { | |||
| 686 | fstrncmp = strncasecmp; | 702 | fstrncmp = strncasecmp; |
| 687 | fstrstr = cistrstr; | 703 | fstrstr = cistrstr; |
| 688 | } | 704 | } |
| 705 | else if(!strcmp(argv[i], "-b")) | ||
| 706 | topbar = False; | ||
| 689 | else if(!strcmp(argv[i], "-fn")) { | 707 | else if(!strcmp(argv[i], "-fn")) { |
| 690 | if(++i < argc) font = argv[i]; | 708 | if(++i < argc) font = argv[i]; |
| 691 | } | 709 | } |
| @@ -704,25 +722,11 @@ main(int argc, char *argv[]) { | |||
| 704 | else if(!strcmp(argv[i], "-sf")) { | 722 | else if(!strcmp(argv[i], "-sf")) { |
| 705 | if(++i < argc) selfg = argv[i]; | 723 | if(++i < argc) selfg = argv[i]; |
| 706 | } | 724 | } |
| 707 | else if(!strcmp(argv[i], "-x")) { | ||
| 708 | if(++i < argc) x = atoi(argv[i]); | ||
| 709 | } | ||
| 710 | else if(!strcmp(argv[i], "-y")) { | ||
| 711 | if(++i < argc) | ||
| 712 | if(!strcmp(argv[i], "-0")) | ||
| 713 | y = INT_MIN; | ||
| 714 | else | ||
| 715 | y = atoi(argv[i]); | ||
| 716 | } | ||
| 717 | else if(!strcmp(argv[i], "-w")) { | ||
| 718 | if(++i < argc) w = atoi(argv[i]); | ||
| 719 | } | ||
| 720 | else if(!strcmp(argv[i], "-v")) | 725 | else if(!strcmp(argv[i], "-v")) |
| 721 | eprint("dmenu-"VERSION", © 2006-2008 dmenu engineers, see LICENSE for details\n"); | 726 | eprint("dmenu-"VERSION", © 2006-2008 dmenu engineers, see LICENSE for details\n"); |
| 722 | else | 727 | else |
| 723 | eprint("usage: dmenu [-i] [-fn <font>] [-nb <color>] [-nf <color>]\n" | 728 | eprint("usage: dmenu [-i] [-b] [-fn <font>] [-nb <color>] [-nf <color>]\n" |
| 724 | " [-p <prompt>] [-sb <color>] [-sf <color>]\n" | 729 | " [-p <prompt>] [-sb <color>] [-sf <color>] [-v]\n"); |
| 725 | " [-x <x>] [-y <y>] [-w <w>] [-v]\n"); | ||
| 726 | setlocale(LC_CTYPE, ""); | 730 | setlocale(LC_CTYPE, ""); |
| 727 | dpy = XOpenDisplay(0); | 731 | dpy = XOpenDisplay(0); |
| 728 | if(!dpy) | 732 | if(!dpy) |
| @@ -739,7 +743,7 @@ main(int argc, char *argv[]) { | |||
| 739 | readstdin(); | 743 | readstdin(); |
| 740 | } | 744 | } |
| 741 | 745 | ||
| 742 | setup(x, y, w); | 746 | setup(topbar); |
| 743 | drawmenu(); | 747 | drawmenu(); |
| 744 | XSync(dpy, False); | 748 | XSync(dpy, False); |
| 745 | run(); | 749 | run(); |
