Xmenu now has a man page.
authorphillbush <phillbush@cock.li>
Sun, 17 May 2020 03:08:23 +0000 (00:08 -0300)
committerphillbush <phillbush@cock.li>
Sun, 17 May 2020 03:08:23 +0000 (00:08 -0300)
README
xmenu.1 [new file with mode: 0644]
xmenu.c
xmenu.sh

diff --git a/README b/README
index fe95e7c..4df29b9 100644 (file)
--- a/README
+++ b/README
@@ -24,3 +24,5 @@ of tabs.  Lines without labels are menu separators.
 
 See the script ./xmenu.sh for an example of how xmenu can be used to
 draw a simple menu with submenus and separators.
 
 See the script ./xmenu.sh for an example of how xmenu can be used to
 draw a simple menu with submenus and separators.
+
+Read the manual for more information on running xmenu.
diff --git a/xmenu.1 b/xmenu.1
new file mode 100644 (file)
index 0000000..0e01c44
--- /dev/null
+++ b/xmenu.1
@@ -0,0 +1,66 @@
+.TH PROG 1
+.SH NAME
+xmenu \- menu utility for X
+.SH SYNOPSIS
+.B xmenu
+.RB [ \-w ]
+.SH DESCRIPTION
+.B xmenu
+is a menu for X,
+it reads a list of newline-separated items from stdin,
+shows a menu for the user to select one of the items,
+and outputs the item selected to stdout.
+.PP
+The options are as follows:
+.TP
+.B -w
+Asks the window manager to draw a border around the menus.
+Without this options, the menus do not have border drawn by the window manager.
+.PP
+Each item read from stdin has the following format:
+.IP
+.EX
+ITEM := TABS LABEL TABS COMMAND NEWLINE
+.EE
+.PP
+That means, each item is composed by
+tabs, followed by a label, followed by more tabs, followed by a command,
+and ended by a newline.
+.IP
+The initial tabs indicate the menu hierarchy:
+items indented with a tab is shown in a submenu of the preceding item not indented.
+.IP
+The label is the string that will be shown as a item in the menu.
+An item without label is considered a separator and is drawn as a thin line in the menu
+separating the item above from the item below.
+.IP
+The command is the string that will be output after selecting the item.
+.IP
+The newline terminates the item specification.
+.SH EXAMPLES
+The following is an script exemplifying the use
+.BR xmenu .
+The output is redirected to xargs to make a command to be run by the shell.
+.IP
+.EX
+#!/bin/sh
+
+cat <<EOF | ./xmenu | xargs sh -c
+Applications
+       Web Browser     firefox
+       Image editor    gimp
+Terminal (xterm)       xterm
+Terminal (urxvt)       urxvt
+Terminal (st)          st
+
+Shutdown                       poweroff
+Reboot                 reboot
+EOF
+.EE
+.PP
+For example, by selecting \(lqApplications\(rq, a new menu will appear.
+Selecting \(lqWeb Browser\(rq in the new menu will open firefox.
+.SH SEE ALSO
+.IR dmenu (1),
+.IR 9menu (1),
+.IR thingmenu (1)
diff --git a/xmenu.c b/xmenu.c
index 88b3d53..41303cc 100644 (file)
--- a/xmenu.c
+++ b/xmenu.c
@@ -79,7 +79,7 @@ static void setcurrmenu(struct Menu *currmenu_new);
 static void parsestdin(void);
 static void run(void);
 static void freewindow(struct Menu *menu);
 static void parsestdin(void);
 static void run(void);
 static void freewindow(struct Menu *menu);
-static void cleanupexit(void);
+static void cleanup(void);
 static void usage(void);
 
 /* X variables */
 static void usage(void);
 
 /* X variables */
@@ -146,7 +146,9 @@ main(int argc, char *argv[])
        /* run event loop */
        run();
 
        /* run event loop */
        run();
 
-       return 1;   /* UNREACHABLE */
+       cleanup();
+
+       return 0;
 }
 
 /* get color from color string */
 }
 
 /* get color from color string */
@@ -576,8 +578,6 @@ run(void)
        struct Item *previtem = NULL;
        XEvent ev;
 
        struct Item *previtem = NULL;
        XEvent ev;
 
-       setcurrmenu(rootmenu);
-
        while (!XNextEvent(dpy, &ev)) {
                switch(ev.type) {
                case Expose:
        while (!XNextEvent(dpy, &ev)) {
                switch(ev.type) {
                case Expose:
@@ -608,11 +608,11 @@ run(void)
                                        setcurrmenu(item->submenu);
                                } else {
                                        printf("%s\n", item->output);
                                        setcurrmenu(item->submenu);
                                } else {
                                        printf("%s\n", item->output);
-                                       cleanupexit();
+                                       return;
                                }
                                drawmenu();
                        } else {
                                }
                                drawmenu();
                        } else {
-                               cleanupexit();
+                               return;
                        }
                        break;
                case LeaveNotify:
                        }
                        break;
                case LeaveNotify:
@@ -639,19 +639,18 @@ freewindow(struct Menu *menu)
 
 /* cleanup and exit */
 static void
 
 /* cleanup and exit */
 static void
-cleanupexit(void)
+cleanup(void)
 {
        freewindow(rootmenu);
        XFreeFont(dpy, dc.font);
        XFreeGC(dpy, dc.gc);
        XCloseDisplay(dpy);
 {
        freewindow(rootmenu);
        XFreeFont(dpy, dc.font);
        XFreeGC(dpy, dc.gc);
        XCloseDisplay(dpy);
-       exit(0);
 }
 
 /* show usage */
 static void
 usage(void)
 {
 }
 
 /* show usage */
 static void
 usage(void)
 {
-       (void)fprintf(stderr, "usage: xmenu [-w] menuname\n");
+       (void)fprintf(stderr, "usage: xmenu [-w]\n");
        exit(1);
 }
        exit(1);
 }
index e3f3279..b1abab3 100755 (executable)
--- a/xmenu.sh
+++ b/xmenu.sh
@@ -11,4 +11,3 @@ Terminal (st)         st
 Shutdown               poweroff
 Reboot                 reboot
 EOF
 Shutdown               poweroff
 Reboot                 reboot
 EOF
-