Skip to content

Commit faefe84

Browse files
committed
implement tornoff menus; move examples to examples/
1 parent ae6b62c commit faefe84

File tree

8 files changed

+471
-147
lines changed

8 files changed

+471
-147
lines changed

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ PROG = xmenu
22
OBJS = ${PROG:=.o} ctrlfnt.o
33
SRCS = ${OBJS:.o=.c}
44
MAN = ${PROG:=.1}
5+
DOC = README.md
56

67
PREFIX ?= /usr/local
78
MANPREFIX ?= ${PREFIX}/share/man
@@ -19,6 +20,16 @@ mandir = ${DESTDIR}${MANPREFIX}/man1
1920

2021
all: ${PROG}
2122

23+
# generate README.md from manual; you do not need to run this
24+
${DOC}: ${MAN}
25+
{ \
26+
cat README ; \
27+
mandoc -I os=UNIX -T ascii ${MAN} | \
28+
col -b | \
29+
expand -t 8 | \
30+
sed 's,^, ,' ; \
31+
} >${DOC}
32+
2233
${PROG}: ${OBJS}
2334
${CC} -o $@ ${OBJS} ${LIBS} ${LDFLAGS}
2435

README.md

Lines changed: 211 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ XMenu understand the following command-line options.
1717

1818
* `-N name`: Specify a resource/instance name for XMenu.
1919
* `-p position`: Specify a position to place XMenu.
20-
* `-t`: Enable menus to be torn off.
2120
* `-w`: Initiate XMenu as a regular window.
2221

2322
## Environment
@@ -50,6 +49,8 @@ Reboot reboot
5049

5150
![demo](./demo.png)
5251

52+
An example script can be found at `./examples/xmenu.sh`.
53+
5354
## Customization
5455
XMenu can be customized by setting the following X resources before
5556
invoking XMenu.
@@ -68,17 +69,21 @@ invoking XMenu.
6869
* `XMenu.opacity`: Background opacity (from 0.0 to 1.0).
6970
* `XMenu.separatorColor`: Separator color.
7071
* `XMenu.shadowThickness`: 3D relief size.
72+
* `XMenu.tearOff`: Enable menus to be torn off.
7173
* `XMenu.topShadowColor`, `XMenu.middleShadowColor`, `XMenu.bottomShadowColor`:
7274
Colors of the 3D relief.
7375

76+
An example style configurationcanbe found at `./examples/Xresources`.
77+
7478
## Installation
7579
Run `make all` to build, and `make install` to install the binary and
7680
the manual into `${PREFIX}` (`/usr/local`).
7781

78-
## Usage
82+
## Features
7983

8084
* XMenu reads something in and prints something out, the UNIX way.
8185
* Submenus (some menu entries can spawn another menu).
86+
* Torn off menus (menus can be managed by the window manager like a regular window).
8287
* Separators (menu entries can be separated by a line).
8388
* Icons (menu entries can be preceded by an icon image).
8489
* X resources support (you don't need to recompile xmenu for configuring it).
@@ -88,5 +93,207 @@ the manual into `${PREFIX}` (`/usr/local`).
8893
The code and manual are under the MIT/X license.
8994
See `./LICENSE` for more information.
9095

91-
## Epilogue
92-
**Read the manual.**
96+
## Manual
97+
98+
XMENU(1) General Commands Manual XMENU(1)
99+
100+
NAME
101+
xmenu - menu utility for X
102+
103+
SYNOPSIS
104+
xmenu [-w] [-N name] [-p position] [title]
105+
106+
DESCRIPTION
107+
xmenu is a menu for X. It reads a list of newline-separateditems from
108+
standard input; shows a menu for the user to select one of the items; and
109+
writes the selected item into standard output.
110+
111+
The options are as follows:
112+
113+
-N name
114+
Specifiy the res_name member of the XClassHint(3) property. Ar
115+
name is used to retrieve resources. If not specified, defaults
116+
to the command that xmenu was invoked as (that is, the
117+
basename(3) of its argv[0]).
118+
119+
-p position
120+
Set the position to spawn xmenu. Without this option, xmenu
121+
spawns next to the cursor. Position is a string of the form
122+
GEOMETRY[:MONITOR], where GEOMETRY is a geometry parsed by
123+
XParseGeometry(3). MONITOR is the number of the monitor the
124+
geometry is relative to (counting from 0); it can instead be a
125+
string like "current" or "cursor", specifyingthe monitor where
126+
the cursor is on.
127+
128+
-w Asks the window manager to draw a border around the menu. This
129+
makes xmenu start torn off.
130+
131+
Each item read from standard input has the following format (bracket
132+
groups optional elements):
133+
134+
[TABS] [IMAGE TABS] LABEL [TABS OUTPUT] NEWLINE
135+
or
136+
137+
[TABS] [:] NEWLINE
138+
139+
The components are as follows:
140+
141+
o The initial tabs indicate the menu hierarchy: items indented with a
142+
tab are placed in a submenu of the preceding item not indented. An
143+
item without initial tabs is a top-level item.
144+
145+
o The image is a string of the form "IMG:/path/to/image.png". It
146+
specifies the path to an image file to be shown as icon at the left
147+
of the entry. If the path does not begin with "/", "./", or "../",
148+
the file is searched on the paths specified in the ICONPATH
149+
environment variable.
150+
151+
o The label is the string that will be shown as an item in the menu.
152+
An item without label or with a single colon (:) as label is
153+
considered a separator and is drawn as a thin line in the menu
154+
separating the item above from the item below.
155+
156+
o The output is the string that will be output after selecting the
157+
item. If an item does not have tabs after the label, its label is
158+
used as its output. If the output is empty or is a colon (:), the
159+
item cannot be selected.
160+
161+
o The newline terminates the item specification.
162+
163+
If the argument title is given, the title of the menu window is set to
164+
it.
165+
166+
USAGE
167+
xmenu is controlled by the mouse, but can also be controlled by the
168+
keyboard. Items can be selected using the arrow keys. Tab (with and
169+
without Shift), Home, End, Enter and Esc, and 1-9 keys. Itams can also
170+
be selected by typing the first several characters in it.
171+
172+
Down Cycle through the items in the regular direction.
173+
174+
End Selects the last item in the menu.
175+
176+
Esc Go to the menu above in the hierarchy or exit xmenu.
177+
178+
Home Selects the first item in the menu.
179+
180+
Left Go to the menu above in the hierarchy.
181+
182+
Right, Enter
183+
Select the highlighted item.
184+
185+
Shift-Tab
186+
Cycle through the items in the reverse direction. When the type-
187+
to-select feature is active, cycle through matching items
188+
instead.
189+
190+
Tab Cycle through the items in the regular direction. When the type-
191+
to-select feature is active, cycle through matching items
192+
instead.
193+
194+
Up Cycle through the items in the reverse direction.
195+
196+
Additional key bindings can be set at compile time by changing the
197+
config.h file.
198+
199+
RESOURCES
200+
xmenu understands the following X resources. They must be prefixed with
201+
either the "XMenu" class, or the name given with the -N command-line
202+
option, followed by a period.
203+
204+
activeBackground
205+
The backround color of selected items in the menu.
206+
207+
activeForeground
208+
The color of the label text of selected items in the menu.
209+
210+
alignment
211+
If set to "left", "center", or "right", text is aligned to the
212+
left, center, or right of the menu, respectively. By default,
213+
text is aligned to the left.
214+
215+
background
216+
The background color of non-selected items in the menu.
217+
218+
borderColor
219+
The color of the border around the menu.
220+
221+
borderWidth
222+
The size in pixels of the border around the menu.
223+
224+
faceName
225+
Font for drawing text. If the value is prefixed with "xft:"
226+
(case insensitive), then xmenu uses the Xft(3) library for
227+
drawing text; and fallback fonts can be specified by delimiting
228+
the fonts with commas. If the value is prefixed with "x:" or
229+
"x11:" (case insensitive), then xmenu uses the X11 library for
230+
drawing text.
231+
232+
faceSize
233+
The size, in points of the font. This only affects Xft(3) fonts.
234+
235+
foreground
236+
The color of the label text of non-selected items in the menu.
237+
238+
gap The gap, in pixels, between the menus.
239+
240+
maxItems
241+
Maximum number of items to be displayed in a menu. If a menu has
242+
more than this number of items, they will be scrolled with arrow
243+
buttons.
244+
245+
opacity
246+
Background opacity as a floating point number between 0.0 and 1.0
247+
inclusive.
248+
249+
separatorColor
250+
The color of the separator between items in the menu.
251+
252+
shadowThickness
253+
The size in pixels of the Motif-like 3D relief.
254+
255+
tearOff
256+
If set to "True", "On", or "Enable", creates a dashed line on the
257+
top of each non-windowed menu to tear them off into a new
258+
windowed menu.
259+
260+
topShadowColor, middleShadowColor, bottomShadowColor
261+
The color of the top/light, middle and bottom/dark parts of the
262+
Motif-like 3D relief. Setting these resources override
263+
background and separateColor.
264+
265+
ENVIRONMENT
266+
The following environment variables affect the execution of xmenu.
267+
268+
DISPLAY
269+
The display to start xmenu on.
270+
271+
ICONPATH
272+
A colon-separated list of directories used to search for the
273+
location of image files.
274+
275+
EXAMPLES
276+
The following script illustrates the use of xmenu. The output is
277+
redirected to sh(1), creating a command to be run by the shell.
278+
279+
$!/bin/sh
280+
281+
xmenu <<EOF | sh &
282+
Applications
283+
IMG:./web.png Web Browser firefox
284+
IMG:./gimp.png Image Editor gimp
285+
Terminal (xterm) xterm
286+
Terminal (urxvt) urxvt
287+
Terminal (st) st
288+
289+
Shutdown poweroff
290+
Reboot reboot
291+
EOF
292+
293+
For example, by selecting "Applications", a new menu will appear.
294+
Selecting "Web Browser" in the new menu opens firefox.
295+
296+
SEE ALSO
297+
xclickroot(1), X(7)
298+
299+
UNIX July 9, 2023 UNIX

ctrlfnt.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,18 @@ ctrlfnt_free(CtrlFontSet *fontset)
691691
free(fontset);
692692
}
693693

694+
void
695+
ctrlfnt__free(CtrlFontSet *fontset)
696+
{
697+
if (fontset == NULL)
698+
return;
699+
if (fontset->xft_fontset != NULL) {
700+
free(fontset->xft_fontset->fonts);
701+
free(fontset->xft_fontset);
702+
}
703+
free(fontset);
704+
}
705+
694706
void
695707
ctrlfnt_init(void)
696708
{

ctrlfnt.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ int ctrlfnt_height(CtrlFontSet *fontset);
2525
void ctrlfnt_free(CtrlFontSet *fontset);
2626
void ctrlfnt_init(void);
2727
void ctrlfnt_term(void);
28+
29+
/* like ctrlfnt_free, but do not destroy X objects */
30+
void ctrlfnt__free(CtrlFontSet *fontset);

demo.png

4.9 KB
Loading
File renamed without changes.

xmenu.1

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
.Dd July 4, 2023
1+
.Dd July 9, 2023
22
.Dt XMENU 1
33
.Os
44
.Sh NAME
55
.Nm xmenu
66
.Nd menu utility for X
77
.Sh SYNOPSIS
88
.Nm xmenu
9-
.Op Fl tw
9+
.Op Fl w
1010
.Op Fl N Ar name
1111
.Op Fl p Ar position
12-
.Op Fl x Ar button
1312
.Op Ar title
1413
.Sh DESCRIPTION
1514
.Nm
@@ -28,8 +27,9 @@ member of the
2827
property.
2928
Ar name
3029
is used to retrieve resources.
31-
If not specified, defaults to the command
32-
.Nm was invoked as
30+
If not specified, defaults to the command that
31+
.Nm
32+
was invoked as
3333
(that is, the
3434
.Xr basename 3
3535
of its
@@ -53,38 +53,11 @@ it can instead be a string like
5353
or
5454
.Qq Cm cursor ,
5555
specifyingthe monitor where the cursor is on.
56-
.It Fl t
57-
Add a entry at the top of the menu to torn it off.
5856
.It Fl w
5957
Asks the window manager to draw a border around the menu.
6058
This makes
6159
.Nm
62-
istart torn off.
63-
.It Fl x Ar button
64-
This option requires an argument of the form
65-
.Cm "[MODIFIER-]BUTTON" ;
66-
where
67-
.Cm MODIFIER
68-
is
69-
.Cm Mod1
70-
to
71-
.Cm Mod5 ,
72-
or
73-
.Cm Alt
74-
(equivalent to
75-
.Cm Mod1 ) ,
76-
or
77-
.Cm Super
78-
(equivalent to
79-
.Cm Mod4 ) ;
80-
and
81-
.Cm BUTTON
82-
is the number of a mouse button.
83-
When this option is used,
84-
.Nm
85-
listens to button presses on the root window,
86-
and shows the menu when the given button is pressed on the root window,
87-
or (together with the modifier) on any window.
60+
start torn off.
8861
.El
8962
.Pp
9063
Each item read from standard input has the following format
@@ -229,6 +202,13 @@ Background opacity as a floating point number between 0.0 and 1.0 inclusive.
229202
The color of the separator between items in the menu.
230203
.It Ic shadowThickness
231204
The size in pixels of the Motif-like 3D relief.
205+
.It Ic tearOff
206+
If set to
207+
.Qq Ic True ,
208+
.Qq Ic On ,
209+
or
210+
.Qq Ic Enable ,
211+
creates a dashed line on the top of each non-windowed menu to tear them off into a new windowed menu.
232212
.It Ic topShadowColor , middleShadowColor , bottomShadowColor
233213
The color of the top/light, middle and bottom/dark parts of the Motif-like 3D relief.
234214
Setting these resources override
@@ -272,6 +252,5 @@ EOF
272252
For example, by selecting "Applications", a new menu will appear.
273253
Selecting "Web Browser" in the new menu opens firefox.
274254
.Sh SEE ALSO
275-
.Xr 9menu 1 ,
276-
.Xr dmenu 1 ,
277-
.Xr thingmenu 1
255+
.Xr xclickroot 1 ,
256+
.Xr X 7

0 commit comments

Comments
 (0)