aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoranselm@anselm1 <unknown>2008-05-19 20:29:32 +0100
committeranselm@anselm1 <unknown>2008-05-19 20:29:32 +0100
commit1f6af5e78f74c80fcb9853dcc2fc7940538808b0 (patch)
tree1d4cc2be30da7b359f3a6f1047d6333a87245d3a
parentf3617bd7caf83a6e184cbdfeeebed0be88f158fa (diff)
added Xinerama support to dmenu, reverted -b behavior, removed -x, -y, -w
-rw-r--r--config.mk9
-rw-r--r--dmenu.118
-rw-r--r--dmenu.c60
3 files changed, 43 insertions, 44 deletions
diff --git a/config.mk b/config.mk
index 30e8b64..c3ed11b 100644
--- a/config.mk
+++ b/config.mk
@@ -10,12 +10,17 @@ MANPREFIX = ${PREFIX}/share/man
10X11INC = /usr/X11R6/include 10X11INC = /usr/X11R6/include
11X11LIB = /usr/X11R6/lib 11X11LIB = /usr/X11R6/lib
12 12
13# Xinerama, comment if you don't want it
14XINERAMALIBS = -L${X11LIB} -lXinerama
15XINERAMAFLAGS = -DXINERAMA
16
13# includes and libs 17# includes and libs
14INCS = -I. -I/usr/include -I${X11INC} 18INCS = -I. -I/usr/include -I${X11INC}
15LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 19LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 ${XINERAMALIBS}
16 20
17# flags 21# flags
18CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\" 22CPPFLAGS = -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
23CFLAGS = -Os ${INCS} ${CPPFLAGS}
19LDFLAGS = -s ${LIBS} 24LDFLAGS = -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}
diff --git a/dmenu.1 b/dmenu.1
index 8eecf8e..a072883 100644
--- a/dmenu.1
+++ b/dmenu.1
@@ -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
22efficiently. 20efficiently.
23.SS Options 21.SS Options
24.TP 22.TP
25.B \-x
26defines the x coordinate dmenu appears at (0 by default).
27.TP
28.B \-y
29defines the y coordinate dmenu appears at (0 by default). If it is negative,
30dmenu 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
34defines the width of the dmenu window (screen width by default).
35.TP
36.B \-i 23.B \-i
37makes dmenu match menu entries case insensitively. 24makes dmenu match menu entries case insensitively.
38.TP 25.TP
26.B \-b
27defines that dmenu appears at the bottom.
28.TP
39.B \-fn <font> 29.B \-fn <font>
40defines the font. 30defines the font.
41.TP 31.TP
diff --git a/dmenu.c b/dmenu.c
index 3d3a928..0faa02e 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -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);
57void match(char *pattern); 59void match(char *pattern);
58void readstdin(void); 60void readstdin(void);
59void run(void); 61void run(void);
60void setup(int x, int y, int w); 62void setup(Bool topbar);
61unsigned int textnw(const char *text, unsigned int len); 63unsigned int textnw(const char *text, unsigned int len);
62unsigned int textw(const char *text); 64unsigned int textw(const char *text);
63 65
@@ -601,10 +603,13 @@ run(void) {
601} 603}
602 604
603void 605void
604setup(int x, int y, int w) { 606setup(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
678int 694int
679main(int argc, char *argv[]) { 695main(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();