Sawfish comes with ready-made popup menus. This section describes how you can modify them.
An entire popup menu is specified by a list. Each element corresponds to a menu item, in the displayed order from top to bottom. Example:
(("Item _1" command-1) ;; list for a command. ("Item _2" . submenu-2) ;; cons for a submenu. () ;; nil makes a seperator line ("_xterm" (system "xterm &")) ;; lisp expression is possible too.
Each menu item is typically specified by a list with two elements. The first is the name; it’s a string, and displayed in the menu. An underscore (_) before a character defines an accelerator, or a shortcut key.
The second element specifies the action to take. Possible choices are:
If it’s a command name (a symbol), then that command is invoked. In the window operation menu, if that command takes a window as the argument, it’s passed.
If it’s a lisp expression, then it’s evaluated inside of the
If it’s a function (a closure or a subr), then it’s invoked with no argument.
If an item is nil (instead of a list with two elements), then it’s printed as a seperator line.
An item can invoke a submenu. In this case, the item is a cons. The car is the printed name. The cdr is a symbol which is the name of a variable. That variable specifies another menu’s contents. Or the variable refers to a function, it’s invoked, and the return value is used. Notice that this variable has to be special, or dynamically scoped, so that its value can be seen inside of the involved module.
It’s possible to pass a list with more than two elements as an item, but it is not explained. (Read the code and please tell us the usage.)
Let’s see one more example:
(("Workspaces" . workspace-menu) ("Windows" . window-menu) ("Programs" . apps-menu) ("Customize" . custom-menu) ("About..." (customize 'about)) () ; Separation horizontal bar. ("Restart" restart) ("Quit" quit))
This is the old definition of Sawfish’s root menu. We can see that four submenus are created by seeing the value of variables. They contain functions, and they’re invoked.
Displays a menu defined by the list of item definitions spec.
Contains the root menu definition.
The variable containing the definition of all window operations.
Popup menu is made by making a seperate process.
Location of the program implementing Sawfish’s menu interface.
Mainly for developers, one more esoteric thing, “toggle menu”, is explained.
The toggle type submenu of window operations, like “sticky” or “shaded”. By selecting items in this menu, a user can turn the flags on and off for a given window.
Add an item to
window-ops-toggle-menu. The command is a
function (or a symbol pointing to a function) that gets run when the
menu item is selected.
If predicate is non-nil, it must be a function taking a window as argument. If predicate return true, the menu item will have a check mark next to it.