From: Michael Stapelberg Date: Wed, 11 Mar 2009 21:21:50 +0000 (+0100) Subject: Move i3lock in its own repository X-Git-Tag: 3.a~29 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=e1252b51da598739b827834103de99dd80c9262a;p=i3%2Fi3 Move i3lock in its own repository --- diff --git a/DEPENDS b/DEPENDS index 10ba2e4d..5285cc9b 100644 --- a/DEPENDS +++ b/DEPENDS @@ -7,8 +7,13 @@ In that case, please try using the versions mentioned below until a fix is provi * xcb-util-0.3.3 (2009-01-31) * Xlib, the one that comes with your X-Server * asciidoc >= 8.3.0 for docs/hacking-howto + * i3lock for locking your screen + * dmenu for launching applications Get the libraries from: http://xcb.freedesktop.org/dist/xcb-proto-1.3.tar.bz2 http://xcb.freedesktop.org/dist/libxcb-1.1.93.tar.bz2 http://xcb.freedesktop.org/dist/xcb-util-0.3.3.tar.bz2 + +git://code.stapelberg.de/i3lock +http://tools.suckless.org/dmenu diff --git a/Makefile b/Makefile index 3e1fa892..8f7ab4a1 100644 --- a/Makefile +++ b/Makefile @@ -40,16 +40,12 @@ src/%.o: src/%.c ${HEADERS} all: ${FILES} $(CC) -o i3 ${FILES} $(LDFLAGS) - $(MAKE) -C src/i3lock - $(MAKE) -C src/i3menu install: all $(INSTALL) -d -m 0755 $(DESTDIR)/usr/bin $(INSTALL) -d -m 0755 $(DESTDIR)/etc/i3 $(INSTALL) -m 0755 i3 $(DESTDIR)/usr/bin/ test -e $(DESTDIR)/etc/i3/config || $(INSTALL) -m 0644 i3.config $(DESTDIR)/etc/i3/config - $(MAKE) -C src/i3lock install - $(MAKE) -C src/i3menu install clean: rm -f src/*.o diff --git a/src/i3lock/LICENSE b/src/i3lock/LICENSE deleted file mode 100644 index faf1c092..00000000 --- a/src/i3lock/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT/X Consortium License - -© 2006-2008 Anselm R Garbe - -Permission is hereby granted, free of charge, to any person obtaining a -copy of this software and associated documentation files (the "Software"), -to deal in the Software without restriction, including without limitation -the rights to use, copy, modify, merge, publish, distribute, sublicense, -and/or sell copies of the Software, and to permit persons to whom the -Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/src/i3lock/Makefile b/src/i3lock/Makefile deleted file mode 100644 index 2036f04a..00000000 --- a/src/i3lock/Makefile +++ /dev/null @@ -1,50 +0,0 @@ -# slock - simple screen locker -# © 2006-2007 Anselm R. Garbe, Sander van Dijk - -include config.mk - -SRC = slock.c -OBJ = ${SRC:.c=.o} - -all: options slock - -options: - @echo slock build options: - @echo "CFLAGS = ${CFLAGS}" - @echo "LDFLAGS = ${LDFLAGS}" - @echo "CC = ${CC}" - -.c.o: - @echo CC $< - @${CC} -c ${CFLAGS} $< - -${OBJ}: config.mk - -slock: ${OBJ} - @echo CC -o $@ - @${CC} -o $@ ${OBJ} ${LDFLAGS} - -clean: - @echo cleaning - @rm -f slock ${OBJ} slock-${VERSION}.tar.gz - -dist: clean - @echo creating dist tarball - @mkdir -p slock-${VERSION} - @cp -R LICENSE Makefile README config.mk ${SRC} slock-${VERSION} - @tar -cf slock-${VERSION}.tar slock-${VERSION} - @gzip slock-${VERSION}.tar - @rm -rf slock-${VERSION} - -install: all - @echo installing executable file to ${DESTDIR}${PREFIX}/bin - @mkdir -p ${DESTDIR}${PREFIX}/bin - @cp -f slock ${DESTDIR}${PREFIX}/bin - @chmod 755 ${DESTDIR}${PREFIX}/bin/slock - @chmod u+s ${DESTDIR}${PREFIX}/bin/slock - -uninstall: - @echo removing executable file from ${DESTDIR}${PREFIX}/bin - @rm -f ${DESTDIR}${PREFIX}/bin/slock - -.PHONY: all options clean dist install uninstall diff --git a/src/i3lock/README b/src/i3lock/README deleted file mode 100644 index a81290d8..00000000 --- a/src/i3lock/README +++ /dev/null @@ -1,24 +0,0 @@ -slock - simple screen locker -============================ -simple screen locker utility for X. - - -Requirements ------------- -In order to build slock you need the Xlib header files. - - -Installation ------------- -Edit config.mk to match your local setup (slock is installed into -the /usr/local namespace by default). - -Afterwards enter the following command to build and install slock -(if necessary as root): - - make clean install - - -Running slock -------------- -Simply invoke the 'slock' command. To get out of it, enter your password. diff --git a/src/i3lock/config.mk b/src/i3lock/config.mk deleted file mode 100644 index cfa53694..00000000 --- a/src/i3lock/config.mk +++ /dev/null @@ -1,30 +0,0 @@ -# slock version -VERSION = 0.9 - -# Customize below to fit your system - -# paths -PREFIX = /usr/local - -X11INC = /usr/X11R6/include -X11LIB = /usr/X11R6/lib - -# includes and libs -INCS = -I. -I/usr/include -I${X11INC} -LIBS = -L/usr/lib -lc -lcrypt -L${X11LIB} -lX11 -lXext - -# flags -CPPFLAGS = -DVERSION=\"${VERSION}\" -DHAVE_SHADOW_H -CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS} -LDFLAGS = -s ${LIBS} - -# On *BSD remove -DHAVE_SHADOW_H from CPPFLAGS and add -DHAVE_BSD_AUTH -# On OpenBSD and Darwin remove -lcrypt from LIBS - -# compiler and linker -CC = cc - -# Install mode. On BSD systems MODE=2755 and GROUP=auth -# On others MODE=4755 and GROUP=root -#MODE=2755 -#GROUP=auth diff --git a/src/i3lock/slock.c b/src/i3lock/slock.c deleted file mode 100644 index a7297169..00000000 --- a/src/i3lock/slock.c +++ /dev/null @@ -1,174 +0,0 @@ -/* See LICENSE file for license details. */ -#define _XOPEN_SOURCE 500 -#if HAVE_SHADOW_H -#include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if HAVE_BSD_AUTH -#include -#include -#endif - -static void -die(const char *errstr, ...) { - va_list ap; - - va_start(ap, errstr); - vfprintf(stderr, errstr, ap); - va_end(ap); - exit(EXIT_FAILURE); -} - -#ifndef HAVE_BSD_AUTH -static const char * -get_password() { /* only run as root */ - const char *rval; - struct passwd *pw; - - if(geteuid() != 0) - die("slock: cannot retrieve password entry (make sure to suid slock)\n"); - pw = getpwuid(getuid()); - endpwent(); - rval = pw->pw_passwd; - -#if HAVE_SHADOW_H - { - struct spwd *sp; - sp = getspnam(getenv("USER")); - endspent(); - rval = sp->sp_pwdp; - } -#endif - - /* drop privileges */ - if(setgid(pw->pw_gid) < 0 || setuid(pw->pw_uid) < 0) - die("slock: cannot drop privileges\n"); - return rval; -} -#endif - -int -main(int argc, char **argv) { - char curs[] = {0, 0, 0, 0, 0, 0, 0, 0}; - char buf[32], passwd[256]; - int num, screen; - -#ifndef HAVE_BSD_AUTH - const char *pws; -#endif - unsigned int len; - Bool running = True; - Cursor invisible; - Display *dpy; - KeySym ksym; - Pixmap pmap; - Window root, w; - XColor black, dummy; - XEvent ev; - XSetWindowAttributes wa; - - if((argc == 2) && !strcmp("-v", argv[1])) - die("slock-"VERSION", © 2006-2008 Anselm R Garbe\n"); - else if(argc != 1) - die("usage: slock [-v]\n"); - -#ifndef HAVE_BSD_AUTH - pws = get_password(); -#endif - - if(!(dpy = XOpenDisplay(0))) - die("slock: cannot open display\n"); - screen = DefaultScreen(dpy); - root = RootWindow(dpy, screen); - - if (fork() != 0) - return 0; - - /* init */ - wa.override_redirect = 1; - wa.background_pixel = WhitePixel(dpy, screen); - w = XCreateWindow(dpy, root, 0, 0, DisplayWidth(dpy, screen), DisplayHeight(dpy, screen), - 0, DefaultDepth(dpy, screen), CopyFromParent, - DefaultVisual(dpy, screen), CWOverrideRedirect | CWBackPixel, &wa); - XAllocNamedColor(dpy, DefaultColormap(dpy, screen), "black", &black, &dummy); - pmap = XCreateBitmapFromData(dpy, w, curs, 8, 8); - invisible = XCreatePixmapCursor(dpy, pmap, pmap, &black, &black, 0, 0); - XDefineCursor(dpy, w, invisible); - XMapRaised(dpy, w); - for(len = 1000; len; len--) { - if(XGrabPointer(dpy, root, False, ButtonPressMask | ButtonReleaseMask | PointerMotionMask, - GrabModeAsync, GrabModeAsync, None, invisible, CurrentTime) == GrabSuccess) - break; - usleep(1000); - } - if((running = running && (len > 0))) { - for(len = 1000; len; len--) { - if(XGrabKeyboard(dpy, root, True, GrabModeAsync, GrabModeAsync, CurrentTime) - == GrabSuccess) - break; - usleep(1000); - } - running = (len > 0); - } - len = 0; - XSync(dpy, False); - - /* main event loop */ - while(running && !XNextEvent(dpy, &ev)) { - if(ev.type == KeyPress) { - buf[0] = 0; - num = XLookupString(&ev.xkey, buf, sizeof buf, &ksym, 0); - if(IsKeypadKey(ksym)) { - if(ksym == XK_KP_Enter) - ksym = XK_Return; - else if(ksym >= XK_KP_0 && ksym <= XK_KP_9) - ksym = (ksym - XK_KP_0) + XK_0; - } - if(IsFunctionKey(ksym) || IsKeypadKey(ksym) - || IsMiscFunctionKey(ksym) || IsPFKey(ksym) - || IsPrivateKeypadKey(ksym)) - continue; - switch(ksym) { - case XK_Return: - passwd[len] = 0; -#ifdef HAVE_BSD_AUTH - running = !auth_userokay(getlogin(), NULL, "auth-xlock", passwd); -#else - running = strcmp(crypt(passwd, pws), pws); -#endif - len = 0; - break; - case XK_Escape: - len = 0; - break; - case XK_BackSpace: - if(len) - --len; - break; - default: - if(num && !iscntrl((int) buf[0]) && (len + num < sizeof passwd)) { - memcpy(passwd + len, buf, num); - len += num; - } - break; - } - } - } - XUngrabPointer(dpy, CurrentTime); - XFreePixmap(dpy, pmap); - XDestroyWindow(dpy, w); - XCloseDisplay(dpy); - return 0; -} diff --git a/src/i3menu/LICENSE b/src/i3menu/LICENSE deleted file mode 100644 index 8f139184..00000000 --- a/src/i3menu/LICENSE +++ /dev/null @@ -1,23 +0,0 @@ -MIT/X Consortium License - -© 2006-2008 Anselm R. Garbe -© 2006-2008 Sander van Dijk -© 2006-2007 Michał Janeczek - -Permission is hereby granted, free of charge, to any person obtaining a -copy of this software and associated documentation files (the "Software"), -to deal in the Software without restriction, including without limitation -the rights to use, copy, modify, merge, publish, distribute, sublicense, -and/or sell copies of the Software, and to permit persons to whom the -Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/src/i3menu/Makefile b/src/i3menu/Makefile deleted file mode 100644 index e7df2d78..00000000 --- a/src/i3menu/Makefile +++ /dev/null @@ -1,58 +0,0 @@ -# dmenu - dynamic menu -# See LICENSE file for copyright and license details. - -include config.mk - -SRC = dmenu.c -OBJ = ${SRC:.c=.o} - -all: options dmenu - -options: - @echo dmenu build options: - @echo "CFLAGS = ${CFLAGS}" - @echo "LDFLAGS = ${LDFLAGS}" - @echo "CC = ${CC}" - -.c.o: - @echo CC $< - @${CC} -c ${CFLAGS} $< - -${OBJ}: config.h config.mk - -dmenu: ${OBJ} - @echo CC -o $@ - @${CC} -o $@ ${OBJ} ${LDFLAGS} - -clean: - @echo cleaning - @rm -f dmenu ${OBJ} dmenu-${VERSION}.tar.gz - -dist: clean - @echo creating dist tarball - @mkdir -p dmenu-${VERSION} - @cp -R LICENSE Makefile README config.mk dmenu.1 config.h dmenu_path dmenu_run ${SRC} dmenu-${VERSION} - @tar -cf dmenu-${VERSION}.tar dmenu-${VERSION} - @gzip dmenu-${VERSION}.tar - @rm -rf dmenu-${VERSION} - -install: all - @echo installing executable file to ${DESTDIR}${PREFIX}/bin - @mkdir -p ${DESTDIR}${PREFIX}/bin - @cp -f dmenu dmenu_path dmenu_run ${DESTDIR}${PREFIX}/bin - @chmod 755 ${DESTDIR}${PREFIX}/bin/dmenu - @chmod 755 ${DESTDIR}${PREFIX}/bin/dmenu_path - @chmod 755 ${DESTDIR}${PREFIX}/bin/dmenu_run - @echo installing manual page to ${DESTDIR}${MANPREFIX}/man1 - @mkdir -p ${DESTDIR}${MANPREFIX}/man1 - @sed "s/VERSION/${VERSION}/g" < dmenu.1 > ${DESTDIR}${MANPREFIX}/man1/dmenu.1 - @chmod 644 ${DESTDIR}${MANPREFIX}/man1/dmenu.1 - -uninstall: - @echo removing executable file from ${DESTDIR}${PREFIX}/bin - @rm -f ${DESTDIR}${PREFIX}/bin/dmenu ${DESTDIR}${PREFIX}/bin/dmenu_path - @rm -f ${DESTDIR}${PREFIX}/bin/dmenu ${DESTDIR}${PREFIX}/bin/dmenu_run - @echo removing manual page from ${DESTDIR}${MANPREFIX}/man1 - @rm -f ${DESTDIR}${MANPREFIX}/man1/dmenu.1 - -.PHONY: all options clean dist install uninstall diff --git a/src/i3menu/README b/src/i3menu/README deleted file mode 100644 index 6e841354..00000000 --- a/src/i3menu/README +++ /dev/null @@ -1,24 +0,0 @@ -dmenu - dynamic menu -==================== -dmenu is a generic and efficient menu for X. - - -Requirements ------------- -In order to build dmenu you need the Xlib header files. - - -Installation ------------- -Edit config.mk to match your local setup (dmenu is installed into -the /usr/local namespace by default). - -Afterwards enter the following command to build and install dmenu (if -necessary as root): - - make clean install - - -Running dmenu -------------- -See the man page for details. diff --git a/src/i3menu/config.h b/src/i3menu/config.h deleted file mode 100644 index 3e6c6167..00000000 --- a/src/i3menu/config.h +++ /dev/null @@ -1,9 +0,0 @@ -/* See LICENSE file for copyright and license details. */ - -/* appearance */ -static const char *font = "-*-terminus-medium-r-normal-*-14-*-*-*-*-*-*-*"; -static const char *normbgcolor = "#cccccc"; -static const char *normfgcolor = "#000000"; -static const char *selbgcolor = "#0066ff"; -static const char *selfgcolor = "#ffffff"; -static unsigned int spaceitem = 30; /* px between menu items */ diff --git a/src/i3menu/config.mk b/src/i3menu/config.mk deleted file mode 100644 index bd1ee6bc..00000000 --- a/src/i3menu/config.mk +++ /dev/null @@ -1,31 +0,0 @@ -# dmenu version -VERSION = 3.9 - -# Customize below to fit your system - -# paths -PREFIX = /usr/local -MANPREFIX = ${PREFIX}/share/man - -X11INC = /usr/X11R6/include -X11LIB = /usr/X11R6/lib - -# Xinerama, comment if you don't want it -XINERAMALIBS = -L${X11LIB} -lXinerama -XINERAMAFLAGS = -DXINERAMA - -# includes and libs -INCS = -I. -I/usr/include -I${X11INC} -LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 ${XINERAMALIBS} - -# flags -CPPFLAGS = -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS} -CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS} -LDFLAGS = -s ${LIBS} - -# Solaris -#CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\" -#LDFLAGS = ${LIBS} - -# compiler and linker -CC = cc diff --git a/src/i3menu/dmenu.1 b/src/i3menu/dmenu.1 deleted file mode 100644 index a0728839..00000000 --- a/src/i3menu/dmenu.1 +++ /dev/null @@ -1,98 +0,0 @@ -.TH DMENU 1 dmenu\-VERSION -.SH NAME -dmenu \- dynamic menu -.SH SYNOPSIS -.B dmenu -.RB [ \-i ] -.RB [ \-b ] -.RB [ \-fn " "] -.RB [ \-nb " "] -.RB [ \-nf " "] -.RB [ \-p " "] -.RB [ \-sb " "] -.RB [ \-sf " "] -.RB [ \-v ] -.SH DESCRIPTION -.SS Overview -dmenu is a generic menu for X, originally designed for -.BR dwm (1). -It manages huge amounts (up to 10.000 and more) of user defined menu items -efficiently. -.SS Options -.TP -.B \-i -makes dmenu match menu entries case insensitively. -.TP -.B \-b -defines that dmenu appears at the bottom. -.TP -.B \-fn -defines the font. -.TP -.B \-nb -defines the normal background color (#RGB, #RRGGBB, and color names are supported). -.TP -.B \-nf -defines the normal foreground color (#RGB, #RRGGBB, and color names are supported). -.TP -.B \-p -defines a prompt to be displayed before the input area. -.TP -.B \-sb -defines the selected background color (#RGB, #RRGGBB, and color names are supported). -.TP -.B \-sf -defines the selected foreground color (#RGB, #RRGGBB, and color names are supported). -.TP -.B \-v -prints version information to standard output, then exits. -.SH USAGE -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/her -choice is printed to standard output and dmenu terminates. -.P -dmenu is completely controlled by the keyboard. The following keys are recognized: -.TP -.B Any printable character -Appends the character to the text in the input field. This works as a filter: -only items containing this text will be displayed. -.TP -.B Left/Right (Mod1\-h/Mod1\-l) -Select the previous/next item. -.TP -.B PageUp/PageDown (Mod1\-k/Mod1\-j) -Select the first item of the previous/next 'page' of items. -.TP -.B Home/End (Mod1\-g/Mod1\-G) -Select the first/last item. -.TP -.B Tab (Control\-i) -Copy the selected item to the input field. -.TP -.B Return (Control\-j) -Confirm selection and quit (print the selected item to standard output). Returns -.B 0 -on termination. -.TP -.B Shift\-Return (Control\-Shift\-j) -Confirm selection and quit (print the text in the input field to standard output). -Returns -.B 0 -on termination. -.TP -.B Escape (Control\-bracketleft) -Quit without selecting an item. Returns -.B 1 -on termination. -.TP -.B Backspace (Control\-h) -Remove a character from the input field. -.TP -.B Control\-u -Remove all characters from the input field. -.TP -.B Control\-w -Remove all characters of current word from the input field. -.SH SEE ALSO -.BR dwm (1), -.BR wmii (1) . diff --git a/src/i3menu/dmenu.c b/src/i3menu/dmenu.c deleted file mode 100644 index c0addad8..00000000 --- a/src/i3menu/dmenu.c +++ /dev/null @@ -1,729 +0,0 @@ -/* See LICENSE file for copyright and license details. */ -#define _BSD_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef XINERAMA -#include -#endif - -/* macros */ -#define CLEANMASK(mask) (mask & ~(numlockmask | LockMask)) -#define INRECT(X,Y,RX,RY,RW,RH) ((X) >= (RX) && (X) < (RX) + (RW) && (Y) >= (RY) && (Y) < (RY) + (RH)) -#define MIN(a, b) ((a) < (b) ? (a) : (b)) - -/* enums */ -enum { ColFG, ColBG, ColLast }; - -/* typedefs */ -typedef struct { - int x, y, w, h; - unsigned long norm[ColLast]; - unsigned long sel[ColLast]; - Drawable drawable; - GC gc; - struct { - XFontStruct *xfont; - XFontSet set; - int ascent; - int descent; - int height; - } font; -} DC; /* draw context */ - -typedef struct Item Item; -struct Item { - char *text; - Item *next; /* traverses all items */ - Item *left, *right; /* traverses items matching current search pattern */ -}; - -/* forward declarations */ -static void appenditem(Item *i, Item **list, Item **last); -static void calcoffsets(void); -static char *cistrstr(const char *s, const char *sub); -static void cleanup(void); -static void drawmenu(void); -static void drawtext(const char *text, unsigned long col[ColLast]); -static void eprint(const char *errstr, ...); -static unsigned long getcolor(const char *colstr); -static Bool grabkeyboard(void); -static void initfont(const char *fontstr); -static void kpress(XKeyEvent * e); -static void match(char *pattern); -static void readstdin(void); -static void run(void); -static void setup(Bool topbar); -static int textnw(const char *text, unsigned int len); -static int textw(const char *text); - -#include "config.h" - -/* variables */ -static char *maxname = NULL; -static char *prompt = NULL; -static char text[4096]; -static int cmdw = 0; -static int promptw = 0; -static int ret = 0; -static int screen; -static unsigned int mw, mh; -static unsigned int numlockmask = 0; -static Bool running = True; -static Display *dpy; -static DC dc; -static Item *allitems = NULL; /* first of all items */ -static Item *item = NULL; /* first of pattern matching items */ -static Item *sel = NULL; -static Item *next = NULL; -static Item *prev = NULL; -static Item *curr = NULL; -static Window root, win; -static int (*fstrncmp)(const char *, const char *, size_t n) = strncmp; -static char *(*fstrstr)(const char *, const char *) = strstr; - -void -appenditem(Item *i, Item **list, Item **last) { - if(!(*last)) - *list = i; - else - (*last)->right = i; - i->left = *last; - i->right = NULL; - *last = i; -} - -void -calcoffsets(void) { - int tw; - unsigned int w; - - if(!curr) - return; - w = promptw + cmdw + 2 * spaceitem; - for(next = curr; next; next=next->right) { - tw = textw(next->text); - if(tw > mw / 3) - tw = mw / 3; - w += tw; - if(w > mw) - break; - } - w = promptw + cmdw + 2 * spaceitem; - for(prev = curr; prev && prev->left; prev=prev->left) { - tw = textw(prev->left->text); - if(tw > mw / 3) - tw = mw / 3; - w += tw; - if(w > mw) - break; - } -} - -char * -cistrstr(const char *s, const char *sub) { - int c, csub; - unsigned int len; - - if(!sub) - return (char *)s; - if((c = *sub++) != 0) { - c = tolower(c); - len = strlen(sub); - do { - do { - if((csub = *s++) == 0) - return (NULL); - } - while(tolower(csub) != c); - } - while(strncasecmp(s, sub, len) != 0); - s--; - } - return (char *)s; -} - -void -cleanup(void) { - Item *itm; - - while(allitems) { - itm = allitems->next; - free(allitems->text); - free(allitems); - allitems = itm; - } - if(dc.font.set) - XFreeFontSet(dpy, dc.font.set); - else - XFreeFont(dpy, dc.font.xfont); - XFreePixmap(dpy, dc.drawable); - XFreeGC(dpy, dc.gc); - XDestroyWindow(dpy, win); - XUngrabKeyboard(dpy, CurrentTime); -} - -void -drawmenu(void) { - Item *i; - - dc.x = 0; - dc.y = 0; - dc.w = mw; - dc.h = mh; - drawtext(NULL, dc.norm); - /* print prompt? */ - if(promptw) { - dc.w = promptw; - drawtext(prompt, dc.sel); - } - dc.x += promptw; - dc.w = mw - promptw; - /* print command */ - if(cmdw && item) - dc.w = cmdw; - drawtext(text[0] ? text : NULL, dc.norm); - dc.x += cmdw; - if(curr) { - dc.w = spaceitem; - 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); - if(dc.w > mw / 3) - dc.w = mw / 3; - drawtext(i->text, (sel == i) ? dc.sel : dc.norm); - dc.x += dc.w; - } - dc.x = mw - spaceitem; - dc.w = spaceitem; - drawtext(next ? ">" : NULL, dc.norm); - } - XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, mw, mh, 0, 0); - XFlush(dpy); -} - -void -drawtext(const char *text, unsigned long col[ColLast]) { - char buf[256]; - int i, x, y, h, len, olen; - XRectangle r = { dc.x, dc.y, dc.w, dc.h }; - - XSetForeground(dpy, dc.gc, col[ColBG]); - XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); - if(!text) - return; - olen = strlen(text); - 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 */ - for(len = MIN(olen, sizeof buf); len && textnw(text, len) > dc.w - h; len--); - if(!len) - return; - memcpy(buf, text, len); - if(len < olen) - for(i = len; i && i > len - 3; buf[--i] = '.'); - XSetForeground(dpy, dc.gc, col[ColFG]); - if(dc.font.set) - XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len); - else - XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len); -} - -void -eprint(const char *errstr, ...) { - va_list ap; - - va_start(ap, errstr); - vfprintf(stderr, errstr, ap); - va_end(ap); - exit(EXIT_FAILURE); -} - -unsigned long -getcolor(const char *colstr) { - Colormap cmap = DefaultColormap(dpy, screen); - XColor color; - - if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color)) - eprint("error, cannot allocate color '%s'\n", colstr); - return color.pixel; -} - -Bool -grabkeyboard(void) { - unsigned int len; - - for(len = 1000; len; len--) { - if(XGrabKeyboard(dpy, root, True, GrabModeAsync, GrabModeAsync, CurrentTime) - == GrabSuccess) - break; - usleep(1000); - } - return len > 0; -} - -void -initfont(const char *fontstr) { - char *def, **missing; - int i, n; - - if(!fontstr || fontstr[0] == '\0') - eprint("error, cannot load font: '%s'\n", fontstr); - missing = NULL; - dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def); - if(missing) - XFreeStringList(missing); - if(dc.font.set) { - 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); - for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) { - if(dc.font.ascent < (*xfonts)->ascent) - dc.font.ascent = (*xfonts)->ascent; - if(dc.font.descent < (*xfonts)->descent) - dc.font.descent = (*xfonts)->descent; - xfonts++; - } - } - else { - if(!(dc.font.xfont = XLoadQueryFont(dpy, fontstr)) - && !(dc.font.xfont = XLoadQueryFont(dpy, "fixed"))) - eprint("error, cannot load font: '%s'\n", fontstr); - dc.font.ascent = dc.font.xfont->ascent; - dc.font.descent = dc.font.xfont->descent; - } - dc.font.height = dc.font.ascent + dc.font.descent; -} - -void -kpress(XKeyEvent * e) { - char buf[32]; - int i, num; - unsigned int len; - KeySym ksym; - - len = strlen(text); - buf[0] = 0; - num = XLookupString(e, buf, sizeof buf, &ksym, 0); - if(IsKeypadKey(ksym)) { - if(ksym == XK_KP_Enter) - ksym = XK_Return; - else if(ksym >= XK_KP_0 && ksym <= XK_KP_9) - ksym = (ksym - XK_KP_0) + XK_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) { - default: /* ignore other control sequences */ - return; - case XK_bracketleft: - ksym = XK_Escape; - break; - case XK_h: - case XK_H: - ksym = XK_BackSpace; - break; - case XK_i: - case XK_I: - ksym = XK_Tab; - break; - case XK_j: - case XK_J: - ksym = XK_Return; - break; - case XK_u: - case XK_U: - text[0] = 0; - match(text); - drawmenu(); - return; - case XK_w: - case XK_W: - if(len) { - i = len - 1; - while(i >= 0 && text[i] == ' ') - text[i--] = 0; - while(i >= 0 && text[i] != ' ') - text[i--] = 0; - match(text); - drawmenu(); - } - return; - } - } - if(CLEANMASK(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) { - default: - if(num && !iscntrl((int) buf[0])) { - buf[num] = 0; - if(len > 0) - strncat(text, buf, sizeof text); - else - strncpy(text, buf, sizeof text); - match(text); - } - break; - case XK_BackSpace: - if(len) { - text[--len] = 0; - match(text); - } - break; - case XK_End: - if(!item) - return; - while(next) { - sel = curr = next; - calcoffsets(); - } - 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(); -} - -void -match(char *pattern) { - unsigned int plen; - Item *i, *itemend, *lexact, *lprefix, *lsubstr, *exactend, *prefixend, *substrend; - - if(!pattern) - return; - plen = strlen(pattern); - item = lexact = lprefix = lsubstr = itemend = exactend = prefixend = substrend = NULL; - for(i = allitems; i; i = i->next) - if(!fstrncmp(pattern, i->text, plen + 1)) - appenditem(i, &lexact, &exactend); - else if(!fstrncmp(pattern, i->text, plen)) - appenditem(i, &lprefix, &prefixend); - else if(fstrstr(i->text, pattern)) - appenditem(i, &lsubstr, &substrend); - if(lexact) { - item = lexact; - itemend = exactend; - } - if(lprefix) { - if(itemend) { - itemend->right = lprefix; - lprefix->left = itemend; - } - else - item = lprefix; - itemend = prefixend; - } - if(lsubstr) { - if(itemend) { - itemend->right = lsubstr; - lsubstr->left = itemend; - } - else - item = lsubstr; - } - curr = prev = next = sel = item; - calcoffsets(); -} - -void -readstdin(void) { - char *p, buf[1024]; - unsigned int len = 0, max = 0; - Item *i, *new; - - i = 0; - while(fgets(buf, sizeof buf, stdin)) { - len = strlen(buf); - if (buf[len - 1] == '\n') - buf[len - 1] = 0; - if(!(p = strdup(buf))) - eprint("fatal: could not strdup() %u bytes\n", strlen(buf)); - if(max < len) { - maxname = p; - max = len; - } - if((new = (Item *)malloc(sizeof(Item))) == NULL) - eprint("fatal: could not malloc() %u bytes\n", sizeof(Item)); - new->next = new->left = new->right = NULL; - new->text = p; - if(!i) - allitems = new; - else - i->next = new; - i = new; - } -} - -void -run(void) { - XEvent ev; - - /* main event loop */ - while(running && !XNextEvent(dpy, &ev)) - switch (ev.type) { - default: /* ignore all crap */ - break; - case KeyPress: - kpress(&ev.xkey); - break; - case Expose: - if(ev.xexpose.count == 0) - drawmenu(); - break; - } -} - -void -setup(Bool topbar) { - int i, j, x, y; -#if XINERAMA - int n; - XineramaScreenInfo *info = NULL; -#endif - XModifierKeymap *modmap; - XSetWindowAttributes wa; - - /* init modifier map */ - modmap = XGetModifierMapping(dpy); - for(i = 0; i < 8; i++) - for(j = 0; j < modmap->max_keypermod; j++) { - if(modmap->modifiermap[i * modmap->max_keypermod + j] - == XKeysymToKeycode(dpy, XK_Num_Lock)) - numlockmask = (1 << i); - } - XFreeModifiermap(modmap); - - /* style */ - dc.norm[ColBG] = getcolor(normbgcolor); - dc.norm[ColFG] = getcolor(normfgcolor); - dc.sel[ColBG] = getcolor(selbgcolor); - dc.sel[ColFG] = getcolor(selfgcolor); - initfont(font); - - /* menu window */ - wa.override_redirect = 1; - wa.background_pixmap = ParentRelative; - wa.event_mask = ExposureMask | ButtonPressMask | KeyPressMask; - - /* menu window geometry */ - mh = dc.font.height + 2; -#if XINERAMA - if(XineramaIsActive(dpy) && (info = XineramaQueryScreens(dpy, &n))) { - i = 0; - if(n > 1) { - int di; - unsigned int dui; - Window dummy; - if(XQueryPointer(dpy, root, &dummy, &dummy, &x, &y, &di, &di, &dui)) - for(i = 0; i < n; i++) - if(INRECT(x, y, info[i].x_org, info[i].y_org, info[i].width, info[i].height)) - break; - } - x = info[i].x_org; - y = topbar ? info[i].y_org : info[i].y_org + info[i].height - mh; - mw = info[i].width; - XFree(info); - } - else -#endif - { - x = 0; - y = topbar ? 0 : DisplayHeight(dpy, screen) - mh; - mw = DisplayWidth(dpy, screen); - } - - win = XCreateWindow(dpy, root, x, y, mw, mh, 0, - DefaultDepth(dpy, screen), CopyFromParent, - DefaultVisual(dpy, screen), - CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); - - /* 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(!dc.font.set) - XSetFont(dpy, dc.gc, dc.font.xfont->fid); - if(maxname) - cmdw = textw(maxname); - if(cmdw > mw / 3) - cmdw = mw / 3; - if(prompt) - promptw = textw(prompt); - if(promptw > mw / 5) - promptw = mw / 5; - text[0] = 0; - match(text); - XMapRaised(dpy, win); -} - -int -textnw(const char *text, unsigned int len) { - XRectangle r; - - if(dc.font.set) { - XmbTextExtents(dc.font.set, text, len, NULL, &r); - return r.width; - } - return XTextWidth(dc.font.xfont, text, len); -} - -int -textw(const char *text) { - return textnw(text, strlen(text)) + dc.font.height; -} - -int -main(int argc, char *argv[]) { - unsigned int i; - Bool topbar = True; - - /* command line args */ - for(i = 1; i < argc; i++) - if(!strcmp(argv[i], "-i")) { - fstrncmp = strncasecmp; - fstrstr = cistrstr; - } - else if(!strcmp(argv[i], "-b")) - topbar = False; - else if(!strcmp(argv[i], "-fn")) { - if(++i < argc) font = argv[i]; - } - else if(!strcmp(argv[i], "-nb")) { - if(++i < argc) normbgcolor = argv[i]; - } - else if(!strcmp(argv[i], "-nf")) { - if(++i < argc) normfgcolor = argv[i]; - } - else if(!strcmp(argv[i], "-p")) { - if(++i < argc) prompt = argv[i]; - } - else if(!strcmp(argv[i], "-sb")) { - if(++i < argc) selbgcolor = argv[i]; - } - else if(!strcmp(argv[i], "-sf")) { - if(++i < argc) selfgcolor = argv[i]; - } - else if(!strcmp(argv[i], "-v")) - eprint("dmenu-"VERSION", © 2006-2008 dmenu engineers, see LICENSE for details\n"); - else - eprint("usage: dmenu [-i] [-b] [-fn ] [-nb ] [-nf ]\n" - " [-p ] [-sb ] [-sf ] [-v]\n"); - if(!setlocale(LC_CTYPE, "") || !XSupportsLocale()) - fprintf(stderr, "warning: no locale support\n"); - if(!(dpy = XOpenDisplay(0))) - eprint("dmenu: cannot open display\n"); - screen = DefaultScreen(dpy); - root = RootWindow(dpy, screen); - - if(isatty(STDIN_FILENO)) { - readstdin(); - running = grabkeyboard(); - } - else { /* prevent keypress loss */ - running = grabkeyboard(); - readstdin(); - } - - setup(topbar); - drawmenu(); - XSync(dpy, False); - run(); - cleanup(); - XCloseDisplay(dpy); - return ret; -} diff --git a/src/i3menu/dmenu_path b/src/i3menu/dmenu_path deleted file mode 100755 index 7896a9e9..00000000 --- a/src/i3menu/dmenu_path +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh -CACHE=$HOME/.dmenu_cache -IFS=: - -uptodate() { - test -f "$CACHE" && - for dir in $PATH - do - test ! $dir -nt "$CACHE" || return 1 - done -} - -if ! uptodate -then - for dir in $PATH - do - cd "$dir" && - for file in * - do - test -x "$file" && echo "$file" - done - done | sort | uniq > "$CACHE".$$ && - mv "$CACHE".$$ "$CACHE" -fi - -cat "$CACHE" diff --git a/src/i3menu/dmenu_run b/src/i3menu/dmenu_run deleted file mode 100755 index 3e1e6e44..00000000 --- a/src/i3menu/dmenu_run +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -exe=`dmenu_path | dmenu ${1+"$@"}` && exec $exe