thingmenu

A simple graphical menu launcher for X11.
git clone git://r-36.net/thingmenu
Log | Files | Refs | LICENSE

commit 2e6e710ce313489069e9de6905e1e7f91499910f
parent 9f2398547291d67362c3c6499f64deed736ef424
Author: Christoph Lohmann <20h@r-36.net>
Date:   Sat,  2 Jul 2011 12:14:12 +0200

Adding horizontal and manpage.

Diffstat:
Makefile | 8+++++++-
README.md | 26--------------------------
thingmenu.1 | 123+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
thingmenu.c | 84++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------
4 files changed, 192 insertions(+), 49 deletions(-)

diff --git a/Makefile b/Makefile @@ -36,7 +36,7 @@ clean: dist: clean @echo creating dist tarball @mkdir -p ${NAME}-${VERSION} - @cp -R LICENSE Makefile README.md config.mk \ + @cp -R LICENSE Makefile ${NAME}.1 README.md config.mk \ ${SRC} *.h ${NAME}-${VERSION} @tar -cf ${NAME}-${VERSION}.tar ${NAME}-${VERSION} @gzip ${NAME}-${VERSION}.tar @@ -52,9 +52,15 @@ install: all @mkdir -p ${DESTDIR}${PREFIX}/bin @cp -f ${NAME} ${DESTDIR}${PREFIX}/bin @chmod 755 ${DESTDIR}${PREFIX}/bin/${NAME} + @echo installing manual page to ${DESTDIR}${MANPREFIX}/man1 + @mkdir -p ${DESTDIR}${MANPREFIX}/man1 + @cp -f ${NAME}.1 ${DESTDIR}${MANPREFIX}/man1 + @chmod 644 ${DESTDIR}${MANPREFIX}/man1/${NAME}.1 uninstall: @echo removing executable file from ${DESTDIR}${PREFIX}/bin @rm -f ${DESTDIR}${PREFIX}/bin/${NAME} + @echo removing manual page from ${DESTDIR}${PREFIX}/man1 + @rm -f ${DESTDIR}${MANPREFIX}/man1/${NAME}.1 .PHONY: all options clean dist install uninstall diff --git a/README.md b/README.md @@ -1,26 +0,0 @@ -# Thingmenu - a simple X11 menu - -This application evolved out of the need to be able to run commands -in a touchscreen environment. - -## Installation - - % tar -xzvf thingmenu-*.tar.gz - % cd thingmenu - % make - % sudo PREFIX=/usr make install - -## Usage - - # This will open a 300px wide menu, which is showing an - # entry "Reboot now". When being clicked this entry will run - # "reboot". After that the menu will not exit (-s). - % thingmenu -s -ww 300 -- "Reboot now:reboot" - - # This will create a centered menu, which is aligned based - # on the length of the label texts. After the first clicked - # entry it will exit. - % thingmenu "Force reboot:reboot -f" "Shutdown:shutdown" - -Have fun! - diff --git a/thingmenu.1 b/thingmenu.1 @@ -0,0 +1,123 @@ +.Dd July 02, 2011 +.Dt THINGMENU 1 +.Os +. +.Sh NAME +.Nm thingmenu +.Nd a simple menu for X11 +. +.Sh SYNOPSIS +.Nm +.Bk -words +.Op Fl x +.Op Fl s +.Op Fl o +.Op Fl wh Ar height +.Op Fl ww Ar width +.Op Fl wx Ar x position +.Op Fl wy Ar y position +.Op Fl - +.Ar [label:]cmd ... +.Ek +. +.Sh DESCRIPTION +.Bd -filled +.Nm +is a simple menu for X11. The menu can be displayed in a horizontal or +a vertical layout. The manual specification of the parameters of the +menu makes it flexible to be used in many circumstances. +.Ed +. +.Sh IMPLEMENTATION +.Bd -filled +Installation is as straighforward as grabbing the tar.gz file, extracting +it and running +.Qq "make; make install;" +inside the +.Qq "thingmenu-*" +directory. +The prefix for the installation can easily set using +.Qq "PREFIX=/usr make install". +.Ed +. +.Sh OPTIONS +.Nm +options and default settings. +.Pp +.Bl -tag -width ".Fl test Ao Ar string Ac" +. +.It Fl x +Do not append a +.Qq "Cancel" +menu item. +. +.Bd -filled +.It Fl s +Disable the oneshot behaviour. After one button click +.Nm +won't exit, +except when the +.Qq "Cancel" +button is clicked. +.Ed +. +.It Fl o +Use the horizontal layout. +. +.It Fl wh +Define the overall window height. +. +.It Fl ww +Define the overall window width. +. +.It Fl wx +Define the absolute x position. +. +.It Fl wy +Define the absolute y position. +. +.El +. +.Sh CUSTOMIZATION +.Bd -filled +.Nm +is customized by creating a custom config.h and (re)compiling the +source code. +.Ed +. +.Sh EXAMPLES +.Bd -filled +Open a 300px wide menu, which is showing an entry +.Qq "Reboot now". +When being clicked this entry will run +.Qq "reboot". +After that the menu will not exit (-s). +.Ed +.Bd -literal + % thingmenu -s -ww 300 -- "Reboot now:reboot" + +.Ed +.Bd -filled +This will create a centered menu, which is aligned based on the length of the +label texts. After the first clicked entry it will exit. +.Ed +.Bd -literal + % thingmenu "Force reboot:reboot -f" "Shutdown:shutdown" + +.Ed +. +.Sh FILES +LICENSE, thingmenu-menu.sh, config.def.h, config.h +. +.Sh AUTHORS +See LICENSE file for authors in the distribution. +. +.Sh LICENSE +.Nm +is released under the MIT/X Consortium License. +. +.Sh BUGS +.Ss "Reporting Bugs" +Report bugs to: +.An "Christoph Lohmann" Aq 20h@R-36.net + diff --git a/thingmenu.c b/thingmenu.c @@ -91,8 +91,12 @@ static void (*handler[LASTEvent]) (XEvent *) = { static Display *dpy; static DC dc; static Window root, win; -static Bool running = True; -static int ww = 0, wh = 0, wx = 0, wy = 0; +static Bool running = True, horizontal = False; +/* + * ww = window width; www = wanted width window; wh = window height; + * wx = window x position; wy = window y position; + */ +static int ww = 0, www = 0, wh = 0, wx = 0, wy = 0; static char *name = "thingmenu"; Entry **entries = NULL; @@ -384,17 +388,28 @@ setup(void) /* init appearance */ + for (i = 0, www = 0; i < nentries; i++) { + ls = textnw(entries[i]->label, + strlen(entries[i]->label)); + if (ls > www) + www = ls; + } + www *= 1.5; + if (ww == 0) { - for (i = 0, ww = 0; i < nentries; i++) { - ls = textnw(entries[i]->label, - strlen(entries[i]->label)); - if (ls > ww) - ww = ls; + if (horizontal) { + ww = www * nentries; + } else { + ww = www; + } + } + if (wh == 0) { + if (horizontal) { + wh = dc.font.height * 2; + } else { + wh = nentries * (dc.font.height * 2); } - ww *= 1.5; } - if (wh == 0) - wh = (nentries + 2) * dc.font.height + 4; if (wy == 0) wy = (sh - wh) / 2; if (wx == 0) @@ -473,22 +488,35 @@ unpress() void updateentries(void) { - int i, y = 0, h; + int i, x, y, h, w; - h = wh / nentries; + x = 0; + y = 0; + + if (horizontal) { + h = wh; + w = www; + } else { + h = wh / nentries; + w = ww; + } for(i = 0; i < nentries; i++) { - entries[i]->x = 0; + entries[i]->x = x; entries[i]->y = y; - entries[i]->w = ww; + entries[i]->w = w; entries[i]->h = h; - y += h; + if (horizontal) { + x += w; + } else { + y += h; + } } } void usage(char *argv0) { - fprintf(stderr, "usage: %s [-hs] [-wh height] [-ww width] " + fprintf(stderr, "usage: %s [-hxso] [-wh height] [-ww width] " "[-wx x position] [-wy y position] [--] " "label:cmd ...\n", argv0); exit(1); @@ -497,9 +525,13 @@ usage(char *argv0) int main(int argc, char *argv[]) { + Bool addexit; char *label, *cmd; int i; + + addexit = True; + if (argc < 2) usage(argv[0]); i = 1; @@ -515,6 +547,9 @@ main(int argc, char *argv[]) switch (argv[i][1]) { case 'h': usage(argv[0]); + case 'o': + horizontal = True; + break; case 's': oneshot = 0; break; @@ -540,6 +575,9 @@ main(int argc, char *argv[]) usage(argv[0]); } break; + case 'x': + addexit = False; + break; default: usage(argv[0]); } @@ -568,12 +606,14 @@ main(int argc, char *argv[]) if (nentries < 1) usage(argv[0]); - entries = realloc(entries, sizeof(entries[0])*(++nentries)); - entries[nentries-1] = malloc(sizeof(*entries[0])); - bzero(entries[nentries-1], sizeof(*entries[0])); - entries[nentries-1]->label = strdup("cancel"); - entries[nentries-1]->cmd = "exit"; - entries[nentries-1]->forceexit = True; + if (addexit) { + entries = realloc(entries, sizeof(entries[0])*(++nentries)); + entries[nentries-1] = malloc(sizeof(*entries[0])); + bzero(entries[nentries-1], sizeof(*entries[0])); + entries[nentries-1]->label = strdup("cancel"); + entries[nentries-1]->cmd = "exit"; + entries[nentries-1]->forceexit = True; + } if(!setlocale(LC_CTYPE, "") || !XSupportsLocale()) fprintf(stderr, "warning: no locale support\n");