From 11b64016687f01e6498b7d1433ae334adf473804 Mon Sep 17 00:00:00 2001 From: "arg@mmvi" Date: Sat, 16 Sep 2006 11:20:54 +0200 Subject: [PATCH 01/16] Added tag 1.0 for changeset 9e11140d4cc3eecac3b0ab752f91528fd5e04be8 --- .hgtags | 1 + 1 file changed, 1 insertion(+) diff --git a/.hgtags b/.hgtags index a2534f7..26a7db1 100644 --- a/.hgtags +++ b/.hgtags @@ -7,3 +7,4 @@ d352e9dc112ee96aa5cad961a0ed880ae9ce7276 0.3 5fc20d7158bd16b4d5f8d1c25e177680b6d54252 0.7 409667a57221f7e50ba8b5248f638915cd61b366 0.8 d046c818ea467555cc338751c9bf3024609f1f12 0.9 +9e11140d4cc3eecac3b0ab752f91528fd5e04be8 1.0 -- 2.20.1 From 1716159e05e712962c3a4c60091f6cd6b573461f Mon Sep 17 00:00:00 2001 From: "arg@mmvi" Date: Mon, 25 Sep 2006 08:29:20 +0200 Subject: [PATCH 02/16] applied something similiar to Jukkas patch --- main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index 60567b2..3203014 100644 --- a/main.c +++ b/main.c @@ -42,7 +42,7 @@ static Window root; static Window win; static void -calcoffsets() { +calcoffsets(void) { unsigned int tw, w; if(!curr) @@ -70,7 +70,7 @@ calcoffsets() { } static void -drawmenu() { +drawmenu(void) { Item *i; dc.x = 0; @@ -247,7 +247,7 @@ kpress(XKeyEvent * e) { } static char * -readstdin() { +readstdin(void) { static char *maxname = NULL; char *p, buf[1024]; unsigned int len = 0, max = 0; -- 2.20.1 From c9465859a6eac7763d0b9049dca6bd34c163d8f6 Mon Sep 17 00:00:00 2001 From: "arg@wmii.de" Date: Tue, 26 Sep 2006 08:43:41 +0200 Subject: [PATCH 03/16] applied a change made by Uriel to dmenu (though I didn't applied everything) --- main.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/main.c b/main.c index 3203014..77a61b9 100644 --- a/main.c +++ b/main.c @@ -120,19 +120,8 @@ match(char *pattern) { nitem = 0; for(i = allitems; i; i=i->next) - if(!plen || !strncmp(pattern, i->text, plen)) { - if(!j) - item = i; - else - j->right = i; - i->left = j; - i->right = NULL; - j = i; - nitem++; - } - for(i = allitems; i; i=i->next) - if(plen && strncmp(pattern, i->text, plen) - && strstr(i->text, pattern)) { + if(plen ? !strncmp(pattern, i->text, plen) : + strncmp(pattern, i->text, plen) && strstr(i->text, pattern)) { if(!j) item = i; else @@ -208,10 +197,8 @@ kpress(XKeyEvent * e) { } break; case XK_Return: - if(e->state & ShiftMask) { - if(text) - fprintf(stdout, "%s", text); - } + if((e->state & ShiftMask) && text) + fprintf(stdout, "%s", text); else if(sel) fprintf(stdout, "%s", sel->text); else if(text) -- 2.20.1 From e0fe9f2fcac32f04f7fda5236f48d1a705cbdcce Mon Sep 17 00:00:00 2001 From: "arg@mmvi" Date: Tue, 26 Sep 2006 08:47:10 +0200 Subject: [PATCH 04/16] uriel didn't understood dmenu code, he broke nearly everything --- main.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 77a61b9..170a3e0 100644 --- a/main.c +++ b/main.c @@ -120,8 +120,19 @@ match(char *pattern) { nitem = 0; for(i = allitems; i; i=i->next) - if(plen ? !strncmp(pattern, i->text, plen) : - strncmp(pattern, i->text, plen) && strstr(i->text, pattern)) { + if(!plen || !strncmp(pattern, i->text, plen)) { + if(!j) + item = i; + else + j->right = i; + i->left = j; + i->right = NULL; + j = i; + nitem++; + } + for(i = allitems; i; i=i->next) + if(plen && strncmp(pattern, i->text, plen) + && strstr(i->text, pattern)) { if(!j) item = i; else -- 2.20.1 From 5c0d28e4ff9909059ac1247aa71f9b1e906fea3a Mon Sep 17 00:00:00 2001 From: "arg@mmvi" Date: Tue, 26 Sep 2006 13:20:47 +0200 Subject: [PATCH 05/16] removed config.h stuff, made dwm configurable due to command line options --- Makefile | 6 +----- config.arg.h | 11 ---------- config.default.h | 11 ---------- config.mk | 2 +- dmenu.1 | 27 ++++++++++++++++++++++--- dmenu.h | 6 +++++- main.c | 52 +++++++++++++++++++++++++++++++++--------------- 7 files changed, 67 insertions(+), 48 deletions(-) delete mode 100644 config.arg.h delete mode 100644 config.default.h diff --git a/Makefile b/Makefile index 2fa60d4..5a8f21a 100644 --- a/Makefile +++ b/Makefile @@ -19,11 +19,7 @@ options: @echo CC $< @${CC} -c ${CFLAGS} $< -${OBJ}: dmenu.h config.h config.mk - -config.h: - @echo creating $@ from config.default.h - @cp config.default.h $@ +${OBJ}: dmenu.h config.mk dmenu: ${OBJ} @echo LD $@ diff --git a/config.arg.h b/config.arg.h deleted file mode 100644 index 5b99a2c..0000000 --- a/config.arg.h +++ /dev/null @@ -1,11 +0,0 @@ -/* - * (C)opyright MMVI Anselm R. Garbe - * See LICENSE file for license details. - */ - -#define FONT "-*-terminus-medium-*-*-*-12-*-*-*-*-*-iso10646-*" -#define SELBGCOLOR "#333366" -#define SELFGCOLOR "#eeeeee" -#define NORMBGCOLOR "#333333" -#define NORMFGCOLOR "#dddddd" -#define STDIN_TIMEOUT 3 /* seconds */ diff --git a/config.default.h b/config.default.h deleted file mode 100644 index 0bae3a1..0000000 --- a/config.default.h +++ /dev/null @@ -1,11 +0,0 @@ -/* - * (C)opyright MMVI Anselm R. Garbe - * See LICENSE file for license details. - */ - -#define FONT "fixed" -#define SELBGCOLOR "#666699" -#define SELFGCOLOR "#eeeeee" -#define NORMBGCOLOR "#333366" -#define NORMFGCOLOR "#cccccc" -#define STDIN_TIMEOUT 3 /* seconds */ diff --git a/config.mk b/config.mk index 3af05bd..8440322 100644 --- a/config.mk +++ b/config.mk @@ -1,5 +1,5 @@ # dmenu version -VERSION = 1.0 +VERSION = 1.1 # Customize below to fit your system diff --git a/dmenu.1 b/dmenu.1 index 7495ef3..cfe16b4 100644 --- a/dmenu.1 +++ b/dmenu.1 @@ -3,6 +3,12 @@ dmenu \- dynamic menu .SH SYNOPSIS .B dmenu +.RB [ \-font ] +.RB [ \-normbg ] +.RB [ \-normfg ] +.RB [ \-selbg ] +.RB [ \-selfg ] +.RB [ \-t ] .RB [ \-v ] .SH DESCRIPTION .SS Overview @@ -12,6 +18,24 @@ It manages huge amounts (up to 10.000 and more) of user defined menu items efficiently. .SS Options .TP +.B \-font +defines the font. +.TP +.B \-normbg +defines the normal background color (#RGB, #RRGGBB, and color names are supported). +.TP +.B \-normfg +defines the normal foreground color (#RGB, #RRGGBB, and color names are supported). +.TP +.B \-selbg +defines the selected background color (#RGB, #RRGGBB, and color names are supported). +.TP +.B \-selfg +defines the selected foreground color (#RGB, #RRGGBB, and color names are supported). +.TP +.B \-t +defines the seconds to wait for standard input, before exiting (default is 3). +.TP .B \-v prints version information to standard output, then exits. .SH USAGE @@ -52,8 +76,5 @@ Remove enough characters from the input field to change its filtering effect. .TP .B Control-u Remove all characters from the input field. -.SH CUSTOMIZATION -dmenu is customized by creating a custom config.h and (re)compiling the source -code. This keeps it fast, secure and simple. .SH SEE ALSO .BR dwm (1) diff --git a/dmenu.h b/dmenu.h index eed5689..d4065d2 100644 --- a/dmenu.h +++ b/dmenu.h @@ -3,10 +3,14 @@ * See LICENSE file for license details. */ -#include "config.h" #include #include +#define FONT "fixed" +#define NORMBGCOLOR "#333366" +#define NORMFGCOLOR "#cccccc" +#define SELBGCOLOR "#666699" +#define SELFGCOLOR "#eeeeee" #define SPACE 30 /* px */ /* color */ diff --git a/main.c b/main.c index 170a3e0..27b28af 100644 --- a/main.c +++ b/main.c @@ -283,19 +283,41 @@ DC dc = {0}; int main(int argc, char *argv[]) { + char *font = FONT; char *maxname; + char *normbg = NORMBGCOLOR; + char *normfg = NORMFGCOLOR; + char *selbg = SELBGCOLOR; + char *selfg = SELFGCOLOR; fd_set rd; + int i; struct timeval timeout; - Item *i; + Item *itm; XEvent ev; XSetWindowAttributes wa; - if(argc == 2 && !strncmp("-v", argv[1], 3)) { - fputs("dmenu-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout); - exit(EXIT_SUCCESS); - } - else if(argc != 1) - eprint("usage: dmenu [-v]\n"); + timeout.tv_usec = 0; + timeout.tv_sec = 3; + /* command line args */ + for(i = 1; i < argc; i++) + if(!strncmp(argv[i], "-font", 6)) + font = argv[++i]; + else if(!strncmp(argv[i], "-normbg", 8)) + normbg = argv[++i]; + else if(!strncmp(argv[i], "-normfg", 8)) + normfg = argv[++i]; + else if(!strncmp(argv[i], "-selbg", 7)) + selbg = argv[++i]; + else if(!strncmp(argv[i], "-selfg", 7)) + selfg = argv[++i]; + else if(!strncmp(argv[i], "-t", 3)) + timeout.tv_sec = atoi(argv[++i]); + else if(!strncmp(argv[i], "-v", 3)) { + fputs("dmenu-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout); + exit(EXIT_SUCCESS); + } + else + eprint("usage: dmenu [-font ] [-{norm,sel}{bg,fg} ] [-t ] [-v]\n", stdout); dpy = XOpenDisplay(0); if(!dpy) @@ -312,8 +334,6 @@ main(int argc, char *argv[]) { GrabModeAsync, CurrentTime) != GrabSuccess) usleep(1000); - timeout.tv_usec = 0; - timeout.tv_sec = STDIN_TIMEOUT; FD_ZERO(&rd); FD_SET(STDIN_FILENO, &rd); if(select(ConnectionNumber(dpy) + 1, &rd, NULL, NULL, &timeout) < 1) @@ -321,11 +341,11 @@ main(int argc, char *argv[]) { maxname = readstdin(); /* style */ - dc.sel[ColBG] = getcolor(SELBGCOLOR); - dc.sel[ColFG] = getcolor(SELFGCOLOR); - dc.norm[ColBG] = getcolor(NORMBGCOLOR); - dc.norm[ColFG] = getcolor(NORMFGCOLOR); - setfont(FONT); + dc.sel[ColBG] = getcolor(selbg); + dc.sel[ColFG] = getcolor(selfg); + dc.norm[ColBG] = getcolor(normbg); + dc.norm[ColFG] = getcolor(normfg); + setfont(font); wa.override_redirect = 1; wa.background_pixmap = ParentRelative; @@ -373,10 +393,10 @@ main(int argc, char *argv[]) { } while(allitems) { - i = allitems->next; + itm = allitems->next; free(allitems->text); free(allitems); - allitems = i; + allitems = itm; } if(dc.font.set) XFreeFontSet(dpy, dc.font.set); -- 2.20.1 From 3b590beda2fb23400f74394badd7a5231d4d7920 Mon Sep 17 00:00:00 2001 From: "arg@mmvi" Date: Tue, 26 Sep 2006 13:37:36 +0200 Subject: [PATCH 06/16] added fallback to color initialization --- dmenu.h | 3 ++- draw.c | 5 +++-- main.c | 8 ++++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/dmenu.h b/dmenu.h index d4065d2..b58a32b 100644 --- a/dmenu.h +++ b/dmenu.h @@ -43,7 +43,8 @@ extern DC dc; /* global drawing context */ /* draw.c */ extern void drawtext(const char *text, unsigned long col[ColLast]); /* draws text with the defined color tuple */ -extern unsigned long getcolor(const char *colstr); /* returns color of colstr */ +extern unsigned long getcolor( + const char *colstr, const char *alternate); /* returns color of colstr */ extern void setfont(const char *fontstr); /* sets global font */ extern unsigned int textw(const char *text); /* returns width of text in px */ diff --git a/draw.c b/draw.c index 10a011d..dafc107 100644 --- a/draw.c +++ b/draw.c @@ -76,11 +76,12 @@ drawtext(const char *text, unsigned long col[ColLast]) { } unsigned long -getcolor(const char *colstr) { +getcolor(const char *colstr, const char *alternate) { Colormap cmap = DefaultColormap(dpy, screen); XColor color; - XAllocNamedColor(dpy, cmap, colstr, &color, &color); + if(XAllocNamedColor(dpy, cmap, colstr, &color, &color) != Success) + XAllocNamedColor(dpy, cmap, alternate, &color, &color); return color.pixel; } diff --git a/main.c b/main.c index 27b28af..5a9b3b9 100644 --- a/main.c +++ b/main.c @@ -341,10 +341,10 @@ main(int argc, char *argv[]) { maxname = readstdin(); /* style */ - dc.sel[ColBG] = getcolor(selbg); - dc.sel[ColFG] = getcolor(selfg); - dc.norm[ColBG] = getcolor(normbg); - dc.norm[ColFG] = getcolor(normfg); + dc.norm[ColBG] = getcolor(normbg, NORMBGCOLOR); + dc.norm[ColFG] = getcolor(normfg, NORMFGCOLOR); + dc.sel[ColBG] = getcolor(selbg, SELBGCOLOR); + dc.sel[ColFG] = getcolor(selfg, SELFGCOLOR); setfont(font); wa.override_redirect = 1; -- 2.20.1 From 14133be5bd4d819579d62ad99c2b6de20040ff13 Mon Sep 17 00:00:00 2001 From: "arg@mmvi" Date: Tue, 26 Sep 2006 13:39:00 +0200 Subject: [PATCH 07/16] reverting --- dmenu.h | 3 +-- draw.c | 5 ++--- main.c | 8 ++++---- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/dmenu.h b/dmenu.h index b58a32b..d4065d2 100644 --- a/dmenu.h +++ b/dmenu.h @@ -43,8 +43,7 @@ extern DC dc; /* global drawing context */ /* draw.c */ extern void drawtext(const char *text, unsigned long col[ColLast]); /* draws text with the defined color tuple */ -extern unsigned long getcolor( - const char *colstr, const char *alternate); /* returns color of colstr */ +extern unsigned long getcolor(const char *colstr); /* returns color of colstr */ extern void setfont(const char *fontstr); /* sets global font */ extern unsigned int textw(const char *text); /* returns width of text in px */ diff --git a/draw.c b/draw.c index dafc107..10a011d 100644 --- a/draw.c +++ b/draw.c @@ -76,12 +76,11 @@ drawtext(const char *text, unsigned long col[ColLast]) { } unsigned long -getcolor(const char *colstr, const char *alternate) { +getcolor(const char *colstr) { Colormap cmap = DefaultColormap(dpy, screen); XColor color; - if(XAllocNamedColor(dpy, cmap, colstr, &color, &color) != Success) - XAllocNamedColor(dpy, cmap, alternate, &color, &color); + XAllocNamedColor(dpy, cmap, colstr, &color, &color); return color.pixel; } diff --git a/main.c b/main.c index 5a9b3b9..f1bba6b 100644 --- a/main.c +++ b/main.c @@ -341,10 +341,10 @@ main(int argc, char *argv[]) { maxname = readstdin(); /* style */ - dc.norm[ColBG] = getcolor(normbg, NORMBGCOLOR); - dc.norm[ColFG] = getcolor(normfg, NORMFGCOLOR); - dc.sel[ColBG] = getcolor(selbg, SELBGCOLOR); - dc.sel[ColFG] = getcolor(selfg, SELFGCOLOR); + dc.norm[ColBG] = getcolor(normbg); + dc.norm[ColFG] = getcolor(normfg); + dc.sel[ColBG] = getcolor(selbg); + dc.sel[ColFG] = getcolor(selfg); setfont(font); wa.override_redirect = 1; -- 2.20.1 From c02da9f87e5925ecbe7b3c75c14727508a0426c8 Mon Sep 17 00:00:00 2001 From: "arg@mmvi" Date: Tue, 26 Sep 2006 13:41:51 +0200 Subject: [PATCH 08/16] foo --- draw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/draw.c b/draw.c index 10a011d..0459392 100644 --- a/draw.c +++ b/draw.c @@ -78,7 +78,7 @@ drawtext(const char *text, unsigned long col[ColLast]) { unsigned long getcolor(const char *colstr) { Colormap cmap = DefaultColormap(dpy, screen); - XColor color; + XColor color = {0}; XAllocNamedColor(dpy, cmap, colstr, &color, &color); return color.pixel; -- 2.20.1 From b661ca75deda910fbbba38970b58a867c13a59a0 Mon Sep 17 00:00:00 2001 From: "arg@mmvi" Date: Tue, 26 Sep 2006 13:45:41 +0200 Subject: [PATCH 09/16] error handling --- draw.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/draw.c b/draw.c index 0459392..68b8cb7 100644 --- a/draw.c +++ b/draw.c @@ -78,9 +78,10 @@ drawtext(const char *text, unsigned long col[ColLast]) { unsigned long getcolor(const char *colstr) { Colormap cmap = DefaultColormap(dpy, screen); - XColor color = {0}; + XColor color; - XAllocNamedColor(dpy, cmap, colstr, &color, &color); + if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color)) + eprint("error, cannot allocate color '%s'\n", colstr); return color.pixel; } -- 2.20.1 From e7ecae0d58b33b5c6afb4b6c14fc1347072f976d Mon Sep 17 00:00:00 2001 From: "arg@mmvi" Date: Tue, 26 Sep 2006 14:30:48 +0200 Subject: [PATCH 10/16] removed crap from Makefile --- Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 5a8f21a..d208dbb 100644 --- a/Makefile +++ b/Makefile @@ -33,8 +33,7 @@ clean: dist: clean @echo creating dist tarball @mkdir -p dmenu-${VERSION} - @cp -R LICENSE Makefile README config.*.h config.mk \ - dmenu.1 dmenu.h ${SRC} dmenu-${VERSION} + @cp -R LICENSE Makefile README config.mk dmenu.1 dmenu.h ${SRC} dmenu-${VERSION} @tar -cf dmenu-${VERSION}.tar dmenu-${VERSION} @gzip dmenu-${VERSION}.tar @rm -rf dmenu-${VERSION} -- 2.20.1 From f7615e220e980524bf4051bb181952e0afcbf9a9 Mon Sep 17 00:00:00 2001 From: "arg@mmvi" Date: Tue, 26 Sep 2006 14:31:42 +0200 Subject: [PATCH 11/16] updated README --- README | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/README b/README index d66a689..6e84135 100644 --- a/README +++ b/README @@ -1,5 +1,5 @@ dmenu - dynamic menu --------------------- +==================== dmenu is a generic and efficient menu for X. @@ -22,9 +22,3 @@ necessary as root): Running dmenu ------------- See the man page for details. - - -Configuration -------------- -The configuration of dmenu is done by creating a custom config.h -and (re)compiling the source code. -- 2.20.1 From 2d5afd7c01150b9fa60de1c746205c72d75c9b68 Mon Sep 17 00:00:00 2001 From: "arg@zarathustra" Date: Tue, 26 Sep 2006 17:39:04 +0200 Subject: [PATCH 12/16] Added tag 1.1 for changeset e8c1e9733752db12f2dbd1fa93c46f5806242ba9 --- .hgtags | 1 + 1 file changed, 1 insertion(+) diff --git a/.hgtags b/.hgtags index 26a7db1..e7b12bc 100644 --- a/.hgtags +++ b/.hgtags @@ -8,3 +8,4 @@ d352e9dc112ee96aa5cad961a0ed880ae9ce7276 0.3 409667a57221f7e50ba8b5248f638915cd61b366 0.8 d046c818ea467555cc338751c9bf3024609f1f12 0.9 9e11140d4cc3eecac3b0ab752f91528fd5e04be8 1.0 +e8c1e9733752db12f2dbd1fa93c46f5806242ba9 1.1 -- 2.20.1 From 02238725f6b580ea8b6356377e359f933c5ca720 Mon Sep 17 00:00:00 2001 From: "arg@zarathustra" Date: Tue, 26 Sep 2006 17:51:22 +0200 Subject: [PATCH 13/16] small update to man page (backported) --- dmenu.1 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dmenu.1 b/dmenu.1 index cfe16b4..c47044a 100644 --- a/dmenu.1 +++ b/dmenu.1 @@ -3,12 +3,12 @@ dmenu \- dynamic menu .SH SYNOPSIS .B dmenu -.RB [ \-font ] -.RB [ \-normbg ] -.RB [ \-normfg ] -.RB [ \-selbg ] -.RB [ \-selfg ] -.RB [ \-t ] +.RB [ \-font " "] +.RB [ \-normbg " "] +.RB [ \-normfg " "] +.RB [ \-selbg " "] +.RB [ \-selfg " "] +.RB [ \-t " "] .RB [ \-v ] .SH DESCRIPTION .SS Overview -- 2.20.1 From 5fd7af18c6b24bffd4701156feffcbc0db3b1d69 Mon Sep 17 00:00:00 2001 From: "Anselm R. Garbe" Date: Fri, 6 Oct 2006 11:52:57 +0200 Subject: [PATCH 14/16] removed useless newlines --- dmenu.h | 3 +-- draw.c | 10 +--------- main.c | 27 +++------------------------ util.c | 5 +++-- 4 files changed, 8 insertions(+), 37 deletions(-) diff --git a/dmenu.h b/dmenu.h index d4065d2..1eb57ba 100644 --- a/dmenu.h +++ b/dmenu.h @@ -1,5 +1,4 @@ -/* - * (C)opyright MMVI Anselm R. Garbe +/* (C)opyright MMVI Anselm R. Garbe * See LICENSE file for license details. */ diff --git a/draw.c b/draw.c index 68b8cb7..14bb801 100644 --- a/draw.c +++ b/draw.c @@ -1,5 +1,4 @@ -/* - * (C)opyright MMIV-MMVI Anselm R. Garbe +/* (C)opyright MMIV-MMVI Anselm R. Garbe * See LICENSE file for license details. */ #include "dmenu.h" @@ -32,21 +31,17 @@ drawtext(const char *text, unsigned long col[ColLast]) { XSetForeground(dpy, dc.gc, col[ColBG]); XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); - if(!text) return; - w = 0; olen = len = strlen(text); if(len >= sizeof(buf)) len = sizeof(buf) - 1; memcpy(buf, text, len); buf[len] = 0; - h = dc.font.ascent + dc.font.descent; y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent; x = dc.x + (h / 2); - /* shorten text if necessary */ while(len && (w = textnw(buf, len)) > dc.w - h) buf[--len] = 0; @@ -58,10 +53,8 @@ drawtext(const char *text, unsigned long col[ColLast]) { if(len > 3) buf[len - 3] = '.'; } - if(w > dc.w) return; /* too long */ - gcv.foreground = col[ColFG]; if(dc.font.set) { XChangeGC(dpy, dc.gc, GCForeground, &gcv); @@ -106,7 +99,6 @@ setfont(const char *fontstr) { XFontSetExtents *font_extents; XFontStruct **xfonts; char **font_names; - dc.font.ascent = dc.font.descent = 0; font_extents = XExtentsOfFontSet(dc.font.set); n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names); diff --git a/main.c b/main.c index f1bba6b..7b4365e 100644 --- a/main.c +++ b/main.c @@ -1,5 +1,4 @@ -/* - * (C)opyright MMVI Anselm R. Garbe +/* (C)opyright MMVI Anselm R. Garbe * (C)opyright MMVI Sander van Dijk * See LICENSE file for license details. */ @@ -47,7 +46,6 @@ calcoffsets(void) { if(!curr) return; - w = cmdw + 2 * SPACE; for(next = curr; next; next=next->right) { tw = textw(next->text); @@ -57,7 +55,6 @@ calcoffsets(void) { if(w > mw) break; } - w = cmdw + 2 * SPACE; for(prev = curr; prev && prev->left; prev=prev->left) { tw = textw(prev->left->text); @@ -78,18 +75,15 @@ drawmenu(void) { dc.w = mw; dc.h = mh; drawtext(NULL, dc.norm); - /* print command */ if(cmdw && item) dc.w = cmdw; drawtext(text[0] ? text : NULL, dc.norm); dc.x += cmdw; - if(curr) { dc.w = SPACE; drawtext((curr && curr->left) ? "<" : NULL, dc.norm); dc.x += dc.w; - /* determine maximum items */ for(i = curr; i != next; i=i->right) { dc.w = textw(i->text); @@ -98,7 +92,6 @@ drawmenu(void) { drawtext(i->text, (sel == i) ? dc.sel : dc.norm); dc.x += dc.w; } - dc.x = mw - SPACE; dc.w = SPACE; drawtext(next ? ">" : NULL, dc.norm); @@ -114,11 +107,9 @@ match(char *pattern) { if(!pattern) return; - plen = strlen(pattern); item = j = NULL; nitem = 0; - for(i = allitems; i; i=i->next) if(!plen || !strncmp(pattern, i->text, plen)) { if(!j) @@ -142,7 +133,6 @@ match(char *pattern) { j = i; nitem++; } - curr = prev = next = sel = item; calcoffsets(); } @@ -157,12 +147,10 @@ kpress(XKeyEvent * e) { len = strlen(text); buf[0] = 0; num = XLookupString(e, buf, sizeof(buf), &ksym, 0); - if(IsFunctionKey(ksym) || IsKeypadKey(ksym) || IsMiscFunctionKey(ksym) || IsPFKey(ksym) || IsPrivateKeypadKey(ksym)) return; - /* first check if a control mask is omitted */ if(e->state & ControlMask) { switch (ksym) { @@ -261,7 +249,6 @@ readstdin(void) { maxname = p; max = len; } - new = emalloc(sizeof(Item)); new->next = new->left = new->right = NULL; new->text = p; @@ -318,7 +305,6 @@ main(int argc, char *argv[]) { } else eprint("usage: dmenu [-font ] [-{norm,sel}{bg,fg} ] [-t ] [-v]\n", stdout); - dpy = XOpenDisplay(0); if(!dpy) eprint("dmenu: cannot open display\n"); @@ -333,44 +319,37 @@ main(int argc, char *argv[]) { while(XGrabKeyboard(dpy, root, True, GrabModeAsync, GrabModeAsync, CurrentTime) != GrabSuccess) usleep(1000); - FD_ZERO(&rd); FD_SET(STDIN_FILENO, &rd); if(select(ConnectionNumber(dpy) + 1, &rd, NULL, NULL, &timeout) < 1) goto UninitializedEnd; maxname = readstdin(); - /* style */ dc.norm[ColBG] = getcolor(normbg); dc.norm[ColFG] = getcolor(normfg); dc.sel[ColBG] = getcolor(selbg); dc.sel[ColFG] = getcolor(selfg); setfont(font); - + /* menu window */ wa.override_redirect = 1; wa.background_pixmap = ParentRelative; wa.event_mask = ExposureMask | ButtonPressMask | KeyPressMask; - mx = my = 0; mw = DisplayWidth(dpy, screen); mh = dc.font.height + 2; - win = XCreateWindow(dpy, root, mx, my, mw, mh, 0, DefaultDepth(dpy, screen), CopyFromParent, DefaultVisual(dpy, screen), CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); XDefineCursor(dpy, win, XCreateFontCursor(dpy, XC_xterm)); - /* pixmap */ dc.drawable = XCreatePixmap(dpy, root, mw, mh, DefaultDepth(dpy, screen)); dc.gc = XCreateGC(dpy, root, 0, 0); XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter); - if(maxname) cmdw = textw(maxname); if(cmdw > mw / 3) cmdw = mw / 3; - text[0] = 0; match(text); XMapRaised(dpy, win); @@ -392,6 +371,7 @@ main(int argc, char *argv[]) { } } + /* cleanup */ while(allitems) { itm = allitems->next; free(allitems->text); @@ -408,6 +388,5 @@ main(int argc, char *argv[]) { UninitializedEnd: XUngrabKeyboard(dpy, CurrentTime); XCloseDisplay(dpy); - return ret; } diff --git a/util.c b/util.c index d0444c5..b4b163a 100644 --- a/util.c +++ b/util.c @@ -1,5 +1,4 @@ -/* - * (C)opyright MMVI Anselm R. Garbe +/* (C)opyright MMVI Anselm R. Garbe * See LICENSE file for license details. */ #include "dmenu.h" @@ -22,6 +21,7 @@ badmalloc(unsigned int size) { void * emalloc(unsigned int size) { void *res = malloc(size); + if(!res) badmalloc(size); return res; @@ -40,6 +40,7 @@ eprint(const char *errstr, ...) { char * estrdup(const char *str) { void *res = strdup(str); + if(!res) badmalloc(strlen(str)); return res; -- 2.20.1 From ca973eb64e9303b9bc5d84062189e397726e1fdd Mon Sep 17 00:00:00 2001 From: "Anselm R. Garbe" Date: Fri, 6 Oct 2006 12:39:06 +0200 Subject: [PATCH 15/16] changing version info --- config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.mk b/config.mk index 8440322..c7d3cc7 100644 --- a/config.mk +++ b/config.mk @@ -1,5 +1,5 @@ # dmenu version -VERSION = 1.1 +VERSION = 1.2 # Customize below to fit your system -- 2.20.1 From 63be0ee22abf2293062d612cfc656e568f79e2a1 Mon Sep 17 00:00:00 2001 From: "Anselm R. Garbe" Date: Fri, 6 Oct 2006 12:40:49 +0200 Subject: [PATCH 16/16] small change --- main.c | 1 - 1 file changed, 1 deletion(-) diff --git a/main.c b/main.c index 7b4365e..fcb9295 100644 --- a/main.c +++ b/main.c @@ -2,7 +2,6 @@ * (C)opyright MMVI Sander van Dijk * See LICENSE file for license details. */ - #include "dmenu.h" #include -- 2.20.1