added Xinerama support to dmenu, reverted -b behavior, removed -x, -y, -w
1f6af5e7
3 file(s) · +43 −44
| 10 | 10 | X11INC = /usr/X11R6/include |
|
| 11 | 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 | 17 | # includes and libs |
|
| 14 | 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 | 21 | # flags |
|
| 18 | - | CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\" |
|
| 22 | + | CPPFLAGS = -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS} |
|
| 23 | + | CFLAGS = -Os ${INCS} ${CPPFLAGS} |
|
| 19 | 24 | LDFLAGS = -s ${LIBS} |
|
| 20 | 25 | #CFLAGS = -g -std=c99 -pedantic -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\" |
|
| 21 | 26 | #LDFLAGS = -g ${LIBS} |
| 4 | 4 | .SH SYNOPSIS |
|
| 5 | 5 | .B dmenu |
|
| 6 | 6 | .RB [ \-i ] |
|
| 7 | - | .RB [ \-x " <x>"] |
|
| 8 | - | .RB [ \-y " <y>"] |
|
| 9 | - | .RB [ \-w " <width>"] |
|
| 7 | + | .RB [ \-b ] |
|
| 10 | 8 | .RB [ \-fn " <font>"] |
|
| 11 | 9 | .RB [ \-nb " <color>"] |
|
| 12 | 10 | .RB [ \-nf " <color>"] |
|
| 22 | 20 | efficiently. |
|
| 23 | 21 | .SS Options |
|
| 24 | 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 | 23 | .B \-i |
|
| 37 | 24 | makes dmenu match menu entries case insensitively. |
|
| 25 | + | .TP |
|
| 26 | + | .B \-b |
|
| 27 | + | defines that dmenu appears at the bottom. |
|
| 38 | 28 | .TP |
|
| 39 | 29 | .B \-fn <font> |
|
| 40 | 30 | defines the font. |
|
| 1 | 1 | /* See LICENSE file for copyright and license details. */ |
|
| 2 | 2 | #include <ctype.h> |
|
| 3 | - | #include <limits.h> |
|
| 4 | 3 | #include <locale.h> |
|
| 5 | 4 | #include <stdarg.h> |
|
| 6 | 5 | #include <stdlib.h> |
|
| 10 | 9 | #include <X11/Xlib.h> |
|
| 11 | 10 | #include <X11/Xutil.h> |
|
| 12 | 11 | #include <X11/keysym.h> |
|
| 12 | + | #ifdef XINERAMA |
|
| 13 | + | #include <X11/extensions/Xinerama.h> |
|
| 14 | + | #endif |
|
| 13 | 15 | ||
| 14 | 16 | /* macros */ |
|
| 15 | 17 | #define CLEANMASK(mask) (mask & ~(numlockmask | LockMask)) |
|
| 57 | 59 | void match(char *pattern); |
|
| 58 | 60 | void readstdin(void); |
|
| 59 | 61 | void run(void); |
|
| 60 | - | void setup(int x, int y, int w); |
|
| 62 | + | void setup(Bool topbar); |
|
| 61 | 63 | unsigned int textnw(const char *text, unsigned int len); |
|
| 62 | 64 | unsigned int textw(const char *text); |
|
| 63 | 65 | ||
| 601 | 603 | } |
|
| 602 | 604 | ||
| 603 | 605 | void |
|
| 604 | - | setup(int x, int y, int w) { |
|
| 605 | - | unsigned int i, j; |
|
| 606 | + | setup(Bool topbar) { |
|
| 607 | + | int i, j, x, y; |
|
| 606 | 608 | XModifierKeymap *modmap; |
|
| 607 | 609 | XSetWindowAttributes wa; |
|
| 610 | + | #if XINERAMA |
|
| 611 | + | XineramaScreenInfo *info = NULL; |
|
| 612 | + | #endif |
|
| 608 | 613 | ||
| 609 | 614 | /* init modifier map */ |
|
| 610 | 615 | modmap = XGetModifierMapping(dpy); |
|
| 627 | 632 | wa.override_redirect = 1; |
|
| 628 | 633 | wa.background_pixmap = ParentRelative; |
|
| 629 | 634 | wa.event_mask = ExposureMask | ButtonPressMask | KeyPressMask; |
|
| 630 | - | mw = w ? w : DisplayWidth(dpy, screen); |
|
| 635 | + | ||
| 636 | + | /* menu window geometry */ |
|
| 631 | 637 | mh = dc.font.height + 2; |
|
| 632 | - | if(y < 0) { |
|
| 633 | - | if(y == INT_MIN) |
|
| 634 | - | y = DisplayHeight(dpy, screen) - mh; |
|
| 635 | - | else |
|
| 636 | - | y = (-1 * y) - mh; |
|
| 638 | + | #if XINERAMA |
|
| 639 | + | if(XineramaIsActive(dpy)) { |
|
| 640 | + | info = XineramaQueryScreens(dpy, &i); |
|
| 641 | + | x = info[0].x_org; |
|
| 642 | + | y = topbar ? info[0].y_org : info[0].y_org + info[0].height - mh; |
|
| 643 | + | mw = info[0].width; |
|
| 644 | + | XFree(info); |
|
| 637 | 645 | } |
|
| 646 | + | else |
|
| 647 | + | #endif |
|
| 648 | + | { |
|
| 649 | + | x = 0; |
|
| 650 | + | y = topbar ? 0 : DisplayHeight(dpy, screen) - mh; |
|
| 651 | + | mw = DisplayWidth(dpy, screen); |
|
| 652 | + | } |
|
| 653 | + | ||
| 638 | 654 | win = XCreateWindow(dpy, root, x, y, mw, mh, 0, |
|
| 639 | 655 | DefaultDepth(dpy, screen), CopyFromParent, |
|
| 640 | 656 | DefaultVisual(dpy, screen), |
|
| 677 | 693 | ||
| 678 | 694 | int |
|
| 679 | 695 | main(int argc, char *argv[]) { |
|
| 680 | - | int x = 0, y = 0, w = 0; |
|
| 681 | 696 | unsigned int i; |
|
| 697 | + | Bool topbar = True; |
|
| 682 | 698 | ||
| 683 | 699 | /* command line args */ |
|
| 684 | 700 | for(i = 1; i < argc; i++) |
|
| 686 | 702 | fstrncmp = strncasecmp; |
|
| 687 | 703 | fstrstr = cistrstr; |
|
| 688 | 704 | } |
|
| 705 | + | else if(!strcmp(argv[i], "-b")) |
|
| 706 | + | topbar = False; |
|
| 689 | 707 | else if(!strcmp(argv[i], "-fn")) { |
|
| 690 | 708 | if(++i < argc) font = argv[i]; |
|
| 691 | 709 | } |
|
| 704 | 722 | else if(!strcmp(argv[i], "-sf")) { |
|
| 705 | 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 | 725 | else if(!strcmp(argv[i], "-v")) |
|
| 721 | 726 | eprint("dmenu-"VERSION", © 2006-2008 dmenu engineers, see LICENSE for details\n"); |
|
| 722 | 727 | else |
|
| 723 | - | eprint("usage: dmenu [-i] [-fn <font>] [-nb <color>] [-nf <color>]\n" |
|
| 724 | - | " [-p <prompt>] [-sb <color>] [-sf <color>]\n" |
|
| 725 | - | " [-x <x>] [-y <y>] [-w <w>] [-v]\n"); |
|
| 728 | + | eprint("usage: dmenu [-i] [-b] [-fn <font>] [-nb <color>] [-nf <color>]\n" |
|
| 729 | + | " [-p <prompt>] [-sb <color>] [-sf <color>] [-v]\n"); |
|
| 726 | 730 | setlocale(LC_CTYPE, ""); |
|
| 727 | 731 | dpy = XOpenDisplay(0); |
|
| 728 | 732 | if(!dpy) |
|
| 739 | 743 | readstdin(); |
|
| 740 | 744 | } |
|
| 741 | 745 | ||
| 742 | - | setup(x, y, w); |
|
| 746 | + | setup(topbar); |
|
| 743 | 747 | drawmenu(); |
|
| 744 | 748 | XSync(dpy, False); |
|
| 745 | 749 | run(); |
|