[Contents] [Index] [Next] [Previous]

Creating New Menus


To create a completely new menu, use the general menu syntax as a model and follow these steps:

  1. Fill in a menu name
  2. Create the item names
  3. Choose a mnemonic and accelerator (optional)
  4. Give each item a function to perform (refer to the list of mwm functions)

Menu Items

An item can be either a character string or a graphic representation (bitmap).

A character string for items must be compatible with the menu font that is used. Character strings must be typed precisely using one of the following styles:

A bitmap for an item can be created using the X bitmap client. Using the @ (at sign) in the menu syntax tells the window manager that what follows is the pathname for a bitmap file:

@bitmapfile function [argument]

The following is an example of a newly created menu. The menu is named Graphics Projects. The menu items are all bitmaps symbolizing different graphics projects. The bitmaps are kept in the directory /users/pat/bits. When the user selects a symbol, the graphics program starts and opens the appropriate graphics file.

Menu "Graphics Projects";
{
"Graphics Projects"          f.title
@/users/pat/bits/fusel.bits  f.exec "cad /spacestar/fusel.e12"
@/users/pat/bits/lwing.bits  f.exec "cad /spacestar/lwing.s05"
@/users/pat/bits/rwing.bits  f.exec "cad /spacestar/rwing.s04"
@/users/pat/bits/nose.bits   f.exec "cad /spacestar/nose.e17"
}

Another method for specifying the pathname is to replace /users/pat/ with the ~/ (tilde and slash) characters. The ~/ specifies the user's home directory. Another method is to use the bitmapDirectory resource. If the bitmapDirectory resource is set to /users/pat/bits, then a menu item could be specified as follows:

fusel.bits                   f.exec "cad /spacestar/fusel.e12"

Mnemonics and Accelerators

You can use mnemonics and keyboard accelerators in the menus that you create. Mnemonics are functional only when the menu is posted; accelerators are functional whether or not the menu is posted. A mnemonic specification has the following syntax:

mnemonic = _character

The _ (underbar) is placed under the first matching character in the label. If there is no matching character in the label, no mnemonic is registered with the window manager for that label. The accelerator specification is a key action with the same syntax as is used for binding keys to window manager functions:

key context function [argument]

When choosing accelerators, be careful not to use key actions that are already used in key bindings. (See the Keyboard Bindings section for information about keyboard bindings.)

The following line from the default Window menu illustrates mnemonic and accelerator syntax:

Restore _R Alt<Key>F5 f.normalize

Functions

The predefined Motif Window Manager functions are listed earlier. Each mwm function operates in one or more of the following contexts:
root
Operates the function when the workspace or root window is selected.

window
Operates the function when a client window is selected. All subparts of a window are considered as windows for function contexts. Note that some functions operate only when the window is in its normalized or iconified state (for example f.maximize), or its maximized or iconified state (for example f.normalize).

frame
Operates the function when the window border or title is selected.

icon
Operates the function when an icon is selected.

title
Operates the function when the title bar of the window frame is selected.

border
Operates the function when the window frame only is selected.

application
Operates the function when the application window or client area, excluding the window frame, is selected.

Each function is activated by one or more of the following devices:

Any selection that uses an invalid context, an invalid function, or a function that does not apply to the current context is grayed out. For example, the Restore selection on a terminal window's Window menu and the Minimize selection on an icon's menu are invalid. Also, menu items are grayed out if they are assigned the f.nop (no operation performed) function.

If you want your new menu to appear whenever a certain mouse button or keyboard key is pressed, follow these steps:

  1. Choose the mouse button or keyboard key that you want to use
  2. Choose the action on the button or key that causes the menu to appear
  3. Choose the context in which the menu is to appear
  4. Use the f.menu function with the new menu's name as an argument to bind the menu to the button or key

For example, you may want to create a workspace menu that gives some control over the entire workspace (screen area). The definition of a workspace menu might look as follows:

Menu WorkspaceMenu
{
"Workspace Menu"  f.title
"New Window"      f.exec "mterm"
"Mail"            f.exec "mail"
"Editor"          f.exec "editor"
"Refresh"         f.refresh
no-label          f.separator
"Restart"         f.restart
}

Once you have defined the menu, you need to bind the menu to a mouse button in your .mwmrc file:

<Btn3Down> root f.menu WorkspaceMenu