Compare commits
41 Commits
Author | SHA1 | Date | |
---|---|---|---|
bbfd5391ac | |||
0e96ae6f48 | |||
989649b5a5 | |||
f8d2a29a20 | |||
3438af001a | |||
201b056e39 | |||
3dcdbe2a57 | |||
5336608a86 | |||
d398a2e318 | |||
2829009138 | |||
cae2fbdf38 | |||
225cd764c3 | |||
279966a16f | |||
9bd80b3968 | |||
65912f2a96 | |||
4bd3466215 | |||
e19e42adbb | |||
796c4fb9e5 | |||
93c3f930c5 | |||
c69f397bb9 | |||
b9fbd59c8a | |||
da2b90ddd1 | |||
dd7ee0dae1 | |||
250aa199bb | |||
5d43e9243c | |||
1026eb8308 | |||
c65fdd6252 | |||
8c20e5dbd3 | |||
26fbf124fa | |||
194d890517 | |||
f633276774 | |||
bb480fb4b0 | |||
95b19f75cc | |||
3d25a327aa | |||
d78bcf247f | |||
afaf66dc99 | |||
63be0ee22a | |||
ca973eb64e | |||
5fd7af18c6 | |||
02238725f6 | |||
2d5afd7c01 |
8
.hgtags
8
.hgtags
@ -8,3 +8,11 @@ d352e9dc112ee96aa5cad961a0ed880ae9ce7276 0.3
|
|||||||
409667a57221f7e50ba8b5248f638915cd61b366 0.8
|
409667a57221f7e50ba8b5248f638915cd61b366 0.8
|
||||||
d046c818ea467555cc338751c9bf3024609f1f12 0.9
|
d046c818ea467555cc338751c9bf3024609f1f12 0.9
|
||||||
9e11140d4cc3eecac3b0ab752f91528fd5e04be8 1.0
|
9e11140d4cc3eecac3b0ab752f91528fd5e04be8 1.0
|
||||||
|
e8c1e9733752db12f2dbd1fa93c46f5806242ba9 1.1
|
||||||
|
bee7fe6d1189174d0204ca3195b83cdc1bb4f82e 1.2
|
||||||
|
2eb9997be51cb1b11a8900728ccc0904f9371157 1.3
|
||||||
|
df3fbb050004c544d14e43c36f6a94cca6ed4a69 1.4
|
||||||
|
e071fb045bd9e8574947acff7196360bc0270e68 1.5
|
||||||
|
dcc5427f99f51a978386a0dd770467cd911ac84b 1.6
|
||||||
|
58dbef4aef3d45c7a3da6945e53c9667c0f02d5b 1.7
|
||||||
|
3696d77aaf02f5d15728dde3b9e35abcaf291496 1.7.1
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# dmenu version
|
# dmenu version
|
||||||
VERSION = 1.1
|
VERSION = 1.8
|
||||||
|
|
||||||
# Customize below to fit your system
|
# Customize below to fit your system
|
||||||
|
|
||||||
@ -20,6 +20,11 @@ LDFLAGS = ${LIBS}
|
|||||||
#CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\"
|
#CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\"
|
||||||
#LDFLAGS = -g ${LIBS}
|
#LDFLAGS = -g ${LIBS}
|
||||||
|
|
||||||
|
# Solaris
|
||||||
|
#CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\"
|
||||||
|
#LDFLAGS = ${LIBS}
|
||||||
|
#CFLAGS += -xtarget=ultra
|
||||||
|
|
||||||
# compiler and linker
|
# compiler and linker
|
||||||
CC = cc
|
CC = cc
|
||||||
LD = ${CC}
|
LD = ${CC}
|
||||||
|
41
dmenu.1
41
dmenu.1
@ -3,12 +3,14 @@
|
|||||||
dmenu \- dynamic menu
|
dmenu \- dynamic menu
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
.B dmenu
|
.B dmenu
|
||||||
.RB [ \-font <name> ]
|
.RB [ \-b ]
|
||||||
.RB [ \-normbg <color> ]
|
.RB [ \-fn " <font>"]
|
||||||
.RB [ \-normfg <color> ]
|
.RB [ \-nb " <color>"]
|
||||||
.RB [ \-selbg <color> ]
|
.RB [ \-nf " <color>"]
|
||||||
.RB [ \-selfg <color> ]
|
.RB [ \-p " <prompt>"]
|
||||||
.RB [ \-t <seconds> ]
|
.RB [ \-sb " <color>"]
|
||||||
|
.RB [ \-sf " <color>"]
|
||||||
|
.RB [ \-t " <seconds>"]
|
||||||
.RB [ \-v ]
|
.RB [ \-v ]
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
.SS Overview
|
.SS Overview
|
||||||
@ -18,19 +20,25 @@ It manages huge amounts (up to 10.000 and more) of user defined menu items
|
|||||||
efficiently.
|
efficiently.
|
||||||
.SS Options
|
.SS Options
|
||||||
.TP
|
.TP
|
||||||
.B \-font <name>
|
.B \-b
|
||||||
|
makes dmenu appear at the screen bottom (by default it appears at the screen top).
|
||||||
|
.TP
|
||||||
|
.B \-fn <font>
|
||||||
defines the font.
|
defines the font.
|
||||||
.TP
|
.TP
|
||||||
.B \-normbg <color>
|
.B \-nb <color>
|
||||||
defines the normal background color (#RGB, #RRGGBB, and color names are supported).
|
defines the normal background color (#RGB, #RRGGBB, and color names are supported).
|
||||||
.TP
|
.TP
|
||||||
.B \-normfg <color>
|
.B \-nf <color>
|
||||||
defines the normal foreground color (#RGB, #RRGGBB, and color names are supported).
|
defines the normal foreground color (#RGB, #RRGGBB, and color names are supported).
|
||||||
.TP
|
.TP
|
||||||
.B \-selbg <color>
|
.B \-p <prompt>
|
||||||
|
defines a prompt to be displayed before the input area.
|
||||||
|
.TP
|
||||||
|
.B \-sb <color>
|
||||||
defines the selected background color (#RGB, #RRGGBB, and color names are supported).
|
defines the selected background color (#RGB, #RRGGBB, and color names are supported).
|
||||||
.TP
|
.TP
|
||||||
.B \-selfg <color>
|
.B \-sf <color>
|
||||||
defines the selected foreground color (#RGB, #RRGGBB, and color names are supported).
|
defines the selected foreground color (#RGB, #RRGGBB, and color names are supported).
|
||||||
.TP
|
.TP
|
||||||
.B \-t <seconds>
|
.B \-t <seconds>
|
||||||
@ -40,7 +48,7 @@ defines the seconds to wait for standard input, before exiting (default is 3).
|
|||||||
prints version information to standard output, then exits.
|
prints version information to standard output, then exits.
|
||||||
.SH USAGE
|
.SH USAGE
|
||||||
dmenu reads a list of newline-separated items from standard input and creates a
|
dmenu reads a list of newline-separated items from standard input and creates a
|
||||||
menu. When the user selects an item or enters any text and presses Return, his
|
menu. When the user selects an item or enters any text and presses Return, his/her
|
||||||
choice is printed to standard output and dmenu terminates.
|
choice is printed to standard output and dmenu terminates.
|
||||||
.P
|
.P
|
||||||
dmenu is completely controlled by the keyboard. The following keys are recognized:
|
dmenu is completely controlled by the keyboard. The following keys are recognized:
|
||||||
@ -52,6 +60,12 @@ only items containing this text will be displayed.
|
|||||||
.B Left/Right
|
.B Left/Right
|
||||||
Select the previous/next item.
|
Select the previous/next item.
|
||||||
.TP
|
.TP
|
||||||
|
.B PageUp/PageDown
|
||||||
|
Select the first item of the previous/next 'page' of items.
|
||||||
|
.TP
|
||||||
|
.B Home/End
|
||||||
|
Select the first/last item.
|
||||||
|
.TP
|
||||||
.B Tab
|
.B Tab
|
||||||
Copy the selected item to the input field.
|
Copy the selected item to the input field.
|
||||||
.TP
|
.TP
|
||||||
@ -77,4 +91,5 @@ Remove enough characters from the input field to change its filtering effect.
|
|||||||
.B Control-u
|
.B Control-u
|
||||||
Remove all characters from the input field.
|
Remove all characters from the input field.
|
||||||
.SH SEE ALSO
|
.SH SEE ALSO
|
||||||
.BR dwm (1)
|
.BR dwm (1),
|
||||||
|
.BR wmii (1) .
|
||||||
|
8
dmenu.h
8
dmenu.h
@ -1,17 +1,15 @@
|
|||||||
/*
|
/* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
|
||||||
* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
|
|
||||||
* See LICENSE file for license details.
|
* See LICENSE file for license details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#include <X11/Xlocale.h>
|
|
||||||
|
|
||||||
#define FONT "fixed"
|
#define FONT "-*-fixed-medium-r-normal-*-13-*-*-*-*-*-*-*"
|
||||||
#define NORMBGCOLOR "#333366"
|
#define NORMBGCOLOR "#333366"
|
||||||
#define NORMFGCOLOR "#cccccc"
|
#define NORMFGCOLOR "#cccccc"
|
||||||
#define SELBGCOLOR "#666699"
|
#define SELBGCOLOR "#666699"
|
||||||
#define SELFGCOLOR "#eeeeee"
|
#define SELFGCOLOR "#eeeeee"
|
||||||
#define SPACE 30 /* px */
|
#define SPACE 30 /* px */
|
||||||
|
|
||||||
/* color */
|
/* color */
|
||||||
enum { ColFG, ColBG, ColLast };
|
enum { ColFG, ColBG, ColLast };
|
||||||
|
32
draw.c
32
draw.c
@ -1,11 +1,9 @@
|
|||||||
/*
|
/* (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
|
||||||
* (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
|
|
||||||
* See LICENSE file for license details.
|
* See LICENSE file for license details.
|
||||||
*/
|
*/
|
||||||
#include "dmenu.h"
|
#include "dmenu.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <X11/Xlocale.h>
|
|
||||||
|
|
||||||
/* static */
|
/* static */
|
||||||
|
|
||||||
@ -32,21 +30,17 @@ drawtext(const char *text, unsigned long col[ColLast]) {
|
|||||||
|
|
||||||
XSetForeground(dpy, dc.gc, col[ColBG]);
|
XSetForeground(dpy, dc.gc, col[ColBG]);
|
||||||
XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
|
XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
|
||||||
|
|
||||||
if(!text)
|
if(!text)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
w = 0;
|
w = 0;
|
||||||
olen = len = strlen(text);
|
olen = len = strlen(text);
|
||||||
if(len >= sizeof(buf))
|
if(len >= sizeof buf)
|
||||||
len = sizeof(buf) - 1;
|
len = sizeof buf - 1;
|
||||||
memcpy(buf, text, len);
|
memcpy(buf, text, len);
|
||||||
buf[len] = 0;
|
buf[len] = 0;
|
||||||
|
|
||||||
h = dc.font.ascent + dc.font.descent;
|
h = dc.font.ascent + dc.font.descent;
|
||||||
y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
|
y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
|
||||||
x = dc.x + (h / 2);
|
x = dc.x + (h / 2);
|
||||||
|
|
||||||
/* shorten text if necessary */
|
/* shorten text if necessary */
|
||||||
while(len && (w = textnw(buf, len)) > dc.w - h)
|
while(len && (w = textnw(buf, len)) > dc.w - h)
|
||||||
buf[--len] = 0;
|
buf[--len] = 0;
|
||||||
@ -58,10 +52,8 @@ drawtext(const char *text, unsigned long col[ColLast]) {
|
|||||||
if(len > 3)
|
if(len > 3)
|
||||||
buf[len - 3] = '.';
|
buf[len - 3] = '.';
|
||||||
}
|
}
|
||||||
|
|
||||||
if(w > dc.w)
|
if(w > dc.w)
|
||||||
return; /* too long */
|
return; /* too long */
|
||||||
|
|
||||||
gcv.foreground = col[ColFG];
|
gcv.foreground = col[ColFG];
|
||||||
if(dc.font.set) {
|
if(dc.font.set) {
|
||||||
XChangeGC(dpy, dc.gc, GCForeground, &gcv);
|
XChangeGC(dpy, dc.gc, GCForeground, &gcv);
|
||||||
@ -87,26 +79,19 @@ getcolor(const char *colstr) {
|
|||||||
|
|
||||||
void
|
void
|
||||||
setfont(const char *fontstr) {
|
setfont(const char *fontstr) {
|
||||||
char **missing, *def;
|
char *def, **missing;
|
||||||
int i, n;
|
int i, n;
|
||||||
|
|
||||||
missing = NULL;
|
missing = NULL;
|
||||||
setlocale(LC_ALL, "");
|
|
||||||
if(dc.font.set)
|
if(dc.font.set)
|
||||||
XFreeFontSet(dpy, dc.font.set);
|
XFreeFontSet(dpy, dc.font.set);
|
||||||
dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
|
dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
|
||||||
if(missing) {
|
if(missing)
|
||||||
XFreeStringList(missing);
|
XFreeStringList(missing);
|
||||||
if(dc.font.set) {
|
|
||||||
XFreeFontSet(dpy, dc.font.set);
|
|
||||||
dc.font.set = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(dc.font.set) {
|
if(dc.font.set) {
|
||||||
XFontSetExtents *font_extents;
|
XFontSetExtents *font_extents;
|
||||||
XFontStruct **xfonts;
|
XFontStruct **xfonts;
|
||||||
char **font_names;
|
char **font_names;
|
||||||
|
|
||||||
dc.font.ascent = dc.font.descent = 0;
|
dc.font.ascent = dc.font.descent = 0;
|
||||||
font_extents = XExtentsOfFontSet(dc.font.set);
|
font_extents = XExtentsOfFontSet(dc.font.set);
|
||||||
n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
|
n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
|
||||||
@ -122,11 +107,8 @@ setfont(const char *fontstr) {
|
|||||||
if(dc.font.xfont)
|
if(dc.font.xfont)
|
||||||
XFreeFont(dpy, dc.font.xfont);
|
XFreeFont(dpy, dc.font.xfont);
|
||||||
dc.font.xfont = NULL;
|
dc.font.xfont = NULL;
|
||||||
dc.font.xfont = XLoadQueryFont(dpy, fontstr);
|
if(!(dc.font.xfont = XLoadQueryFont(dpy, fontstr)))
|
||||||
if (!dc.font.xfont)
|
eprint("error, cannot load font: '%s'\n", fontstr);
|
||||||
dc.font.xfont = XLoadQueryFont(dpy, "fixed");
|
|
||||||
if (!dc.font.xfont)
|
|
||||||
eprint("error, cannot init 'fixed' font\n");
|
|
||||||
dc.font.ascent = dc.font.xfont->ascent;
|
dc.font.ascent = dc.font.xfont->ascent;
|
||||||
dc.font.descent = dc.font.xfont->descent;
|
dc.font.descent = dc.font.xfont->descent;
|
||||||
}
|
}
|
||||||
|
238
main.c
238
main.c
@ -1,19 +1,17 @@
|
|||||||
/*
|
/* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
|
||||||
* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
|
|
||||||
* (C)opyright MMVI Sander van Dijk <a dot h dot vandijk at gmail dot com>
|
* (C)opyright MMVI Sander van Dijk <a dot h dot vandijk at gmail dot com>
|
||||||
* See LICENSE file for license details.
|
* See LICENSE file for license details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "dmenu.h"
|
#include "dmenu.h"
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <locale.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <X11/cursorfont.h>
|
|
||||||
#include <X11/Xutil.h>
|
#include <X11/Xutil.h>
|
||||||
#include <X11/keysym.h>
|
#include <X11/keysym.h>
|
||||||
|
|
||||||
@ -27,10 +25,12 @@ struct Item {
|
|||||||
/* static */
|
/* static */
|
||||||
|
|
||||||
static char text[4096];
|
static char text[4096];
|
||||||
|
static char *prompt = NULL;
|
||||||
static int mx, my, mw, mh;
|
static int mx, my, mw, mh;
|
||||||
static int ret = 0;
|
static int ret = 0;
|
||||||
static int nitem = 0;
|
static int nitem = 0;
|
||||||
static unsigned int cmdw = 0;
|
static unsigned int cmdw = 0;
|
||||||
|
static unsigned int promptw = 0;
|
||||||
static Bool running = True;
|
static Bool running = True;
|
||||||
static Item *allitems = NULL; /* first of all items */
|
static Item *allitems = NULL; /* first of all items */
|
||||||
static Item *item = NULL; /* first of pattern matching items */
|
static Item *item = NULL; /* first of pattern matching items */
|
||||||
@ -47,8 +47,7 @@ calcoffsets(void) {
|
|||||||
|
|
||||||
if(!curr)
|
if(!curr)
|
||||||
return;
|
return;
|
||||||
|
w = promptw + cmdw + 2 * SPACE;
|
||||||
w = cmdw + 2 * SPACE;
|
|
||||||
for(next = curr; next; next=next->right) {
|
for(next = curr; next; next=next->right) {
|
||||||
tw = textw(next->text);
|
tw = textw(next->text);
|
||||||
if(tw > mw / 3)
|
if(tw > mw / 3)
|
||||||
@ -57,8 +56,7 @@ calcoffsets(void) {
|
|||||||
if(w > mw)
|
if(w > mw)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
w = promptw + cmdw + 2 * SPACE;
|
||||||
w = cmdw + 2 * SPACE;
|
|
||||||
for(prev = curr; prev && prev->left; prev=prev->left) {
|
for(prev = curr; prev && prev->left; prev=prev->left) {
|
||||||
tw = textw(prev->left->text);
|
tw = textw(prev->left->text);
|
||||||
if(tw > mw / 3)
|
if(tw > mw / 3)
|
||||||
@ -78,18 +76,22 @@ drawmenu(void) {
|
|||||||
dc.w = mw;
|
dc.w = mw;
|
||||||
dc.h = mh;
|
dc.h = mh;
|
||||||
drawtext(NULL, dc.norm);
|
drawtext(NULL, dc.norm);
|
||||||
|
/* print prompt? */
|
||||||
|
if(promptw) {
|
||||||
|
dc.w = promptw;
|
||||||
|
drawtext(prompt, dc.sel);
|
||||||
|
}
|
||||||
|
dc.x += promptw;
|
||||||
|
dc.w = mw - promptw;
|
||||||
/* print command */
|
/* print command */
|
||||||
if(cmdw && item)
|
if(cmdw && item)
|
||||||
dc.w = cmdw;
|
dc.w = cmdw;
|
||||||
drawtext(text[0] ? text : NULL, dc.norm);
|
drawtext(text[0] ? text : NULL, dc.norm);
|
||||||
dc.x += cmdw;
|
dc.x += cmdw;
|
||||||
|
|
||||||
if(curr) {
|
if(curr) {
|
||||||
dc.w = SPACE;
|
dc.w = SPACE;
|
||||||
drawtext((curr && curr->left) ? "<" : NULL, dc.norm);
|
drawtext((curr && curr->left) ? "<" : NULL, dc.norm);
|
||||||
dc.x += dc.w;
|
dc.x += dc.w;
|
||||||
|
|
||||||
/* determine maximum items */
|
/* determine maximum items */
|
||||||
for(i = curr; i != next; i=i->right) {
|
for(i = curr; i != next; i=i->right) {
|
||||||
dc.w = textw(i->text);
|
dc.w = textw(i->text);
|
||||||
@ -98,7 +100,6 @@ drawmenu(void) {
|
|||||||
drawtext(i->text, (sel == i) ? dc.sel : dc.norm);
|
drawtext(i->text, (sel == i) ? dc.sel : dc.norm);
|
||||||
dc.x += dc.w;
|
dc.x += dc.w;
|
||||||
}
|
}
|
||||||
|
|
||||||
dc.x = mw - SPACE;
|
dc.x = mw - SPACE;
|
||||||
dc.w = SPACE;
|
dc.w = SPACE;
|
||||||
drawtext(next ? ">" : NULL, dc.norm);
|
drawtext(next ? ">" : NULL, dc.norm);
|
||||||
@ -114,11 +115,9 @@ match(char *pattern) {
|
|||||||
|
|
||||||
if(!pattern)
|
if(!pattern)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
plen = strlen(pattern);
|
plen = strlen(pattern);
|
||||||
item = j = NULL;
|
item = j = NULL;
|
||||||
nitem = 0;
|
nitem = 0;
|
||||||
|
|
||||||
for(i = allitems; i; i=i->next)
|
for(i = allitems; i; i=i->next)
|
||||||
if(!plen || !strncmp(pattern, i->text, plen)) {
|
if(!plen || !strncmp(pattern, i->text, plen)) {
|
||||||
if(!j)
|
if(!j)
|
||||||
@ -142,7 +141,6 @@ match(char *pattern) {
|
|||||||
j = i;
|
j = i;
|
||||||
nitem++;
|
nitem++;
|
||||||
}
|
}
|
||||||
|
|
||||||
curr = prev = next = sel = item;
|
curr = prev = next = sel = item;
|
||||||
calcoffsets();
|
calcoffsets();
|
||||||
}
|
}
|
||||||
@ -156,13 +154,11 @@ kpress(XKeyEvent * e) {
|
|||||||
|
|
||||||
len = strlen(text);
|
len = strlen(text);
|
||||||
buf[0] = 0;
|
buf[0] = 0;
|
||||||
num = XLookupString(e, buf, sizeof(buf), &ksym, 0);
|
num = XLookupString(e, buf, sizeof buf, &ksym, 0);
|
||||||
|
|
||||||
if(IsFunctionKey(ksym) || IsKeypadKey(ksym)
|
if(IsFunctionKey(ksym) || IsKeypadKey(ksym)
|
||||||
|| IsMiscFunctionKey(ksym) || IsPFKey(ksym)
|
|| IsMiscFunctionKey(ksym) || IsPFKey(ksym)
|
||||||
|| IsPrivateKeypadKey(ksym))
|
|| IsPrivateKeypadKey(ksym))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* first check if a control mask is omitted */
|
/* first check if a control mask is omitted */
|
||||||
if(e->state & ControlMask) {
|
if(e->state & ControlMask) {
|
||||||
switch (ksym) {
|
switch (ksym) {
|
||||||
@ -182,45 +178,40 @@ kpress(XKeyEvent * e) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(e->state & Mod1Mask) {
|
||||||
|
switch(ksym) {
|
||||||
|
default: return;
|
||||||
|
case XK_h:
|
||||||
|
ksym = XK_Left;
|
||||||
|
break;
|
||||||
|
case XK_l:
|
||||||
|
ksym = XK_Right;
|
||||||
|
break;
|
||||||
|
case XK_j:
|
||||||
|
ksym = XK_Next;
|
||||||
|
break;
|
||||||
|
case XK_k:
|
||||||
|
ksym = XK_Prior;
|
||||||
|
break;
|
||||||
|
case XK_g:
|
||||||
|
ksym = XK_Home;
|
||||||
|
break;
|
||||||
|
case XK_G:
|
||||||
|
ksym = XK_End;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
switch(ksym) {
|
switch(ksym) {
|
||||||
case XK_Left:
|
default:
|
||||||
if(!(sel && sel->left))
|
if(num && !iscntrl((int) buf[0])) {
|
||||||
return;
|
buf[num] = 0;
|
||||||
sel=sel->left;
|
if(len > 0)
|
||||||
if(sel->right == curr) {
|
strncat(text, buf, sizeof text);
|
||||||
curr = prev;
|
else
|
||||||
calcoffsets();
|
strncpy(text, buf, sizeof text);
|
||||||
|
match(text);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case XK_Tab:
|
|
||||||
if(!sel)
|
|
||||||
return;
|
|
||||||
strncpy(text, sel->text, sizeof(text));
|
|
||||||
match(text);
|
|
||||||
break;
|
|
||||||
case XK_Right:
|
|
||||||
if(!(sel && sel->right))
|
|
||||||
return;
|
|
||||||
sel=sel->right;
|
|
||||||
if(sel == next) {
|
|
||||||
curr = next;
|
|
||||||
calcoffsets();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case XK_Return:
|
|
||||||
if((e->state & ShiftMask) && text)
|
|
||||||
fprintf(stdout, "%s", text);
|
|
||||||
else if(sel)
|
|
||||||
fprintf(stdout, "%s", sel->text);
|
|
||||||
else if(text)
|
|
||||||
fprintf(stdout, "%s", text);
|
|
||||||
fflush(stdout);
|
|
||||||
running = False;
|
|
||||||
break;
|
|
||||||
case XK_Escape:
|
|
||||||
ret = 1;
|
|
||||||
running = False;
|
|
||||||
break;
|
|
||||||
case XK_BackSpace:
|
case XK_BackSpace:
|
||||||
if((i = len)) {
|
if((i = len)) {
|
||||||
prev_nitem = nitem;
|
prev_nitem = nitem;
|
||||||
@ -231,15 +222,72 @@ kpress(XKeyEvent * e) {
|
|||||||
match(text);
|
match(text);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
case XK_End:
|
||||||
if(num && !iscntrl((int) buf[0])) {
|
if(!item)
|
||||||
buf[num] = 0;
|
return;
|
||||||
if(len > 0)
|
while(next) {
|
||||||
strncat(text, buf, sizeof(text));
|
sel = curr = next;
|
||||||
else
|
calcoffsets();
|
||||||
strncpy(text, buf, sizeof(text));
|
|
||||||
match(text);
|
|
||||||
}
|
}
|
||||||
|
while(sel && sel->right)
|
||||||
|
sel = sel->right;
|
||||||
|
break;
|
||||||
|
case XK_Escape:
|
||||||
|
ret = 1;
|
||||||
|
running = False;
|
||||||
|
break;
|
||||||
|
case XK_Home:
|
||||||
|
if(!item)
|
||||||
|
return;
|
||||||
|
sel = curr = item;
|
||||||
|
calcoffsets();
|
||||||
|
break;
|
||||||
|
case XK_Left:
|
||||||
|
if(!(sel && sel->left))
|
||||||
|
return;
|
||||||
|
sel=sel->left;
|
||||||
|
if(sel->right == curr) {
|
||||||
|
curr = prev;
|
||||||
|
calcoffsets();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case XK_Next:
|
||||||
|
if(!next)
|
||||||
|
return;
|
||||||
|
sel = curr = next;
|
||||||
|
calcoffsets();
|
||||||
|
break;
|
||||||
|
case XK_Prior:
|
||||||
|
if(!prev)
|
||||||
|
return;
|
||||||
|
sel = curr = prev;
|
||||||
|
calcoffsets();
|
||||||
|
break;
|
||||||
|
case XK_Return:
|
||||||
|
if((e->state & ShiftMask) && text)
|
||||||
|
fprintf(stdout, "%s", text);
|
||||||
|
else if(sel)
|
||||||
|
fprintf(stdout, "%s", sel->text);
|
||||||
|
else if(text)
|
||||||
|
fprintf(stdout, "%s", text);
|
||||||
|
fflush(stdout);
|
||||||
|
running = False;
|
||||||
|
break;
|
||||||
|
case XK_Right:
|
||||||
|
if(!(sel && sel->right))
|
||||||
|
return;
|
||||||
|
sel=sel->right;
|
||||||
|
if(sel == next) {
|
||||||
|
curr = next;
|
||||||
|
calcoffsets();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case XK_Tab:
|
||||||
|
if(!sel)
|
||||||
|
return;
|
||||||
|
strncpy(text, sel->text, sizeof text);
|
||||||
|
match(text);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
drawmenu();
|
drawmenu();
|
||||||
}
|
}
|
||||||
@ -252,7 +300,7 @@ readstdin(void) {
|
|||||||
Item *i, *new;
|
Item *i, *new;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while(fgets(buf, sizeof(buf), stdin)) {
|
while(fgets(buf, sizeof buf, stdin)) {
|
||||||
len = strlen(buf);
|
len = strlen(buf);
|
||||||
if (buf[len - 1] == '\n')
|
if (buf[len - 1] == '\n')
|
||||||
buf[len - 1] = 0;
|
buf[len - 1] = 0;
|
||||||
@ -261,7 +309,6 @@ readstdin(void) {
|
|||||||
maxname = p;
|
maxname = p;
|
||||||
max = len;
|
max = len;
|
||||||
}
|
}
|
||||||
|
|
||||||
new = emalloc(sizeof(Item));
|
new = emalloc(sizeof(Item));
|
||||||
new->next = new->left = new->right = NULL;
|
new->next = new->left = new->right = NULL;
|
||||||
new->text = p;
|
new->text = p;
|
||||||
@ -283,6 +330,7 @@ DC dc = {0};
|
|||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[]) {
|
main(int argc, char *argv[]) {
|
||||||
|
Bool bottom = False;
|
||||||
char *font = FONT;
|
char *font = FONT;
|
||||||
char *maxname;
|
char *maxname;
|
||||||
char *normbg = NORMBGCOLOR;
|
char *normbg = NORMBGCOLOR;
|
||||||
@ -300,25 +348,38 @@ main(int argc, char *argv[]) {
|
|||||||
timeout.tv_sec = 3;
|
timeout.tv_sec = 3;
|
||||||
/* command line args */
|
/* command line args */
|
||||||
for(i = 1; i < argc; i++)
|
for(i = 1; i < argc; i++)
|
||||||
if(!strncmp(argv[i], "-font", 6))
|
if(!strncmp(argv[i], "-b", 3)) {
|
||||||
font = argv[++i];
|
bottom = True;
|
||||||
else if(!strncmp(argv[i], "-normbg", 8))
|
}
|
||||||
normbg = argv[++i];
|
else if(!strncmp(argv[i], "-fn", 4)) {
|
||||||
else if(!strncmp(argv[i], "-normfg", 8))
|
if(++i < argc) font = argv[i];
|
||||||
normfg = argv[++i];
|
}
|
||||||
else if(!strncmp(argv[i], "-selbg", 7))
|
else if(!strncmp(argv[i], "-nb", 4)) {
|
||||||
selbg = argv[++i];
|
if(++i < argc) normbg = argv[i];
|
||||||
else if(!strncmp(argv[i], "-selfg", 7))
|
}
|
||||||
selfg = argv[++i];
|
else if(!strncmp(argv[i], "-nf", 4)) {
|
||||||
else if(!strncmp(argv[i], "-t", 3))
|
if(++i < argc) normfg = argv[i];
|
||||||
timeout.tv_sec = atoi(argv[++i]);
|
}
|
||||||
|
else if(!strncmp(argv[i], "-p", 3)) {
|
||||||
|
if(++i < argc) prompt = argv[i];
|
||||||
|
}
|
||||||
|
else if(!strncmp(argv[i], "-sb", 4)) {
|
||||||
|
if(++i < argc) selbg = argv[i];
|
||||||
|
}
|
||||||
|
else if(!strncmp(argv[i], "-sf", 4)) {
|
||||||
|
if(++i < argc) selfg = argv[i];
|
||||||
|
}
|
||||||
|
else if(!strncmp(argv[i], "-t", 3)) {
|
||||||
|
if(++i < argc) timeout.tv_sec = atoi(argv[i]);
|
||||||
|
}
|
||||||
else if(!strncmp(argv[i], "-v", 3)) {
|
else if(!strncmp(argv[i], "-v", 3)) {
|
||||||
fputs("dmenu-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout);
|
fputs("dmenu-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout);
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
eprint("usage: dmenu [-font <name>] [-{norm,sel}{bg,fg} <color>] [-t <seconds>] [-v]\n", stdout);
|
eprint("usage: dmenu [-b] [-fn <font>] [-nb <color>] [-nf <color>] [-p <prompt>]\n"
|
||||||
|
" [-sb <color>] [-sf <color>] [-t <seconds>] [-v]\n", stdout);
|
||||||
|
setlocale(LC_CTYPE, "");
|
||||||
dpy = XOpenDisplay(0);
|
dpy = XOpenDisplay(0);
|
||||||
if(!dpy)
|
if(!dpy)
|
||||||
eprint("dmenu: cannot open display\n");
|
eprint("dmenu: cannot open display\n");
|
||||||
@ -333,44 +394,42 @@ main(int argc, char *argv[]) {
|
|||||||
while(XGrabKeyboard(dpy, root, True, GrabModeAsync,
|
while(XGrabKeyboard(dpy, root, True, GrabModeAsync,
|
||||||
GrabModeAsync, CurrentTime) != GrabSuccess)
|
GrabModeAsync, CurrentTime) != GrabSuccess)
|
||||||
usleep(1000);
|
usleep(1000);
|
||||||
|
|
||||||
FD_ZERO(&rd);
|
FD_ZERO(&rd);
|
||||||
FD_SET(STDIN_FILENO, &rd);
|
FD_SET(STDIN_FILENO, &rd);
|
||||||
if(select(ConnectionNumber(dpy) + 1, &rd, NULL, NULL, &timeout) < 1)
|
if(select(ConnectionNumber(dpy) + 1, &rd, NULL, NULL, &timeout) < 1)
|
||||||
goto UninitializedEnd;
|
goto UninitializedEnd;
|
||||||
maxname = readstdin();
|
maxname = readstdin();
|
||||||
|
|
||||||
/* style */
|
/* style */
|
||||||
dc.norm[ColBG] = getcolor(normbg);
|
dc.norm[ColBG] = getcolor(normbg);
|
||||||
dc.norm[ColFG] = getcolor(normfg);
|
dc.norm[ColFG] = getcolor(normfg);
|
||||||
dc.sel[ColBG] = getcolor(selbg);
|
dc.sel[ColBG] = getcolor(selbg);
|
||||||
dc.sel[ColFG] = getcolor(selfg);
|
dc.sel[ColFG] = getcolor(selfg);
|
||||||
setfont(font);
|
setfont(font);
|
||||||
|
/* menu window */
|
||||||
wa.override_redirect = 1;
|
wa.override_redirect = 1;
|
||||||
wa.background_pixmap = ParentRelative;
|
wa.background_pixmap = ParentRelative;
|
||||||
wa.event_mask = ExposureMask | ButtonPressMask | KeyPressMask;
|
wa.event_mask = ExposureMask | ButtonPressMask | KeyPressMask;
|
||||||
|
|
||||||
mx = my = 0;
|
mx = my = 0;
|
||||||
mw = DisplayWidth(dpy, screen);
|
mw = DisplayWidth(dpy, screen);
|
||||||
mh = dc.font.height + 2;
|
mh = dc.font.height + 2;
|
||||||
|
if(bottom)
|
||||||
|
my += DisplayHeight(dpy, screen) - mh;
|
||||||
win = XCreateWindow(dpy, root, mx, my, mw, mh, 0,
|
win = XCreateWindow(dpy, root, mx, my, mw, mh, 0,
|
||||||
DefaultDepth(dpy, screen), CopyFromParent,
|
DefaultDepth(dpy, screen), CopyFromParent,
|
||||||
DefaultVisual(dpy, screen),
|
DefaultVisual(dpy, screen),
|
||||||
CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
|
CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
|
||||||
XDefineCursor(dpy, win, XCreateFontCursor(dpy, XC_xterm));
|
|
||||||
|
|
||||||
/* pixmap */
|
/* pixmap */
|
||||||
dc.drawable = XCreatePixmap(dpy, root, mw, mh, DefaultDepth(dpy, screen));
|
dc.drawable = XCreatePixmap(dpy, root, mw, mh, DefaultDepth(dpy, screen));
|
||||||
dc.gc = XCreateGC(dpy, root, 0, 0);
|
dc.gc = XCreateGC(dpy, root, 0, 0);
|
||||||
XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
|
XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
|
||||||
|
|
||||||
if(maxname)
|
if(maxname)
|
||||||
cmdw = textw(maxname);
|
cmdw = textw(maxname);
|
||||||
if(cmdw > mw / 3)
|
if(cmdw > mw / 3)
|
||||||
cmdw = mw / 3;
|
cmdw = mw / 3;
|
||||||
|
if(prompt)
|
||||||
|
promptw = textw(prompt);
|
||||||
|
if(promptw > mw / 5)
|
||||||
|
promptw = mw / 5;
|
||||||
text[0] = 0;
|
text[0] = 0;
|
||||||
match(text);
|
match(text);
|
||||||
XMapRaised(dpy, win);
|
XMapRaised(dpy, win);
|
||||||
@ -378,7 +437,7 @@ main(int argc, char *argv[]) {
|
|||||||
XSync(dpy, False);
|
XSync(dpy, False);
|
||||||
|
|
||||||
/* main event loop */
|
/* main event loop */
|
||||||
while(running && !XNextEvent(dpy, &ev)) {
|
while(running && !XNextEvent(dpy, &ev))
|
||||||
switch (ev.type) {
|
switch (ev.type) {
|
||||||
default: /* ignore all crap */
|
default: /* ignore all crap */
|
||||||
break;
|
break;
|
||||||
@ -390,8 +449,8 @@ main(int argc, char *argv[]) {
|
|||||||
drawmenu();
|
drawmenu();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
/* cleanup */
|
||||||
while(allitems) {
|
while(allitems) {
|
||||||
itm = allitems->next;
|
itm = allitems->next;
|
||||||
free(allitems->text);
|
free(allitems->text);
|
||||||
@ -408,6 +467,5 @@ main(int argc, char *argv[]) {
|
|||||||
UninitializedEnd:
|
UninitializedEnd:
|
||||||
XUngrabKeyboard(dpy, CurrentTime);
|
XUngrabKeyboard(dpy, CurrentTime);
|
||||||
XCloseDisplay(dpy);
|
XCloseDisplay(dpy);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
18
util.c
18
util.c
@ -1,5 +1,4 @@
|
|||||||
/*
|
/* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
|
||||||
* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
|
|
||||||
* See LICENSE file for license details.
|
* See LICENSE file for license details.
|
||||||
*/
|
*/
|
||||||
#include "dmenu.h"
|
#include "dmenu.h"
|
||||||
@ -10,20 +9,12 @@
|
|||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
/* static */
|
|
||||||
|
|
||||||
static void
|
|
||||||
badmalloc(unsigned int size) {
|
|
||||||
eprint("fatal: could not malloc() %u bytes\n", size);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* extern */
|
|
||||||
|
|
||||||
void *
|
void *
|
||||||
emalloc(unsigned int size) {
|
emalloc(unsigned int size) {
|
||||||
void *res = malloc(size);
|
void *res = malloc(size);
|
||||||
|
|
||||||
if(!res)
|
if(!res)
|
||||||
badmalloc(size);
|
eprint("fatal: could not malloc() %u bytes\n", size);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,7 +31,8 @@ eprint(const char *errstr, ...) {
|
|||||||
char *
|
char *
|
||||||
estrdup(const char *str) {
|
estrdup(const char *str) {
|
||||||
void *res = strdup(str);
|
void *res = strdup(str);
|
||||||
|
|
||||||
if(!res)
|
if(!res)
|
||||||
badmalloc(strlen(str));
|
eprint("fatal: could not malloc() %u bytes\n", strlen(str));
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user