1. 程式人生 > >fvwm 使用者函式和系統指令碼命令

fvwm 使用者函式和系統指令碼命令

User Functions and Shell Commands


31.10.1. AddToFunc


AddToFunc [name [ I | M | C | H | D action ]]


Begins or adds to a function definition. Here is an example:


AddToFunc Move-or-Raise I Raise
 + M Move
 + D Lower
The function name is "Move-or-Raise", and it could be invoked from a menu or a mouse binding or key binding:


Mouse 1 TS A Move-or-Raise
The name must not contain embedded whitespace. No guarantees are made whether function names with embedded whitespace work or not. This behavior may also change in the future without further notice. The letter before the action tells what kind of action triggers the command which follows it. 'I' stands for "Immediate", and is executed as soon as the function is invoked. 'M' stands for "Motion", i.e. if the user starts moving the mouse. 'C' stands for "Click", i.e., if the user presses and releases the mouse button. 'H' stands for "Hold", i.e. if the user presses a mouse button and holds it down for more than ClickTime milliseconds. 'D' stands for "Double-click". The action 'I' causes an action to be performed on the button-press, if the function is invoked with prior knowledge of which window to act on.


There is a number of predefined symbols that are replaced by certain values if they appear on the command line. Please refer to the Command Expansion section for details.


Warning


Please read the comments on executing complex functions in the section Scripting and Complex Functions.
Examples:


If you call


Key F10 R A Function MailFunction xmh "-font fixed"
and "MailFunction" is


AddToFunc MailFunction
 + I Next ($0) Iconify off
 + I Next (AcceptsFocus, $0) Focus
 + I None ($0) Exec exec $0 $1
Then the last line of the function becomes


 + I None (xmh) Exec exec xmh -font fixed
The expansion is performed as the function is executed, so you can use the same function with all sorts of different arguments. You could use


Key F11 R A Function MailFunction zmail "-bg pink"
in the same config, if you wanted. An example of using "$[w.id]" is:


AddToFunc PrintFunction
 + I Raise
 + I Exec xdpr -id $[w.id]
Note that "$$" is expanded to '$'.


Another example: bind right mouse button within the window button number 6 (this is a minimize button for the win95 theme) to iconify all windows of the same resource:


AddToFunc FuncIconifySameResource "I" All ($0) Iconify on
Mouse 3 6 A FuncIconifySameResource $[w.resource]
31.10.2. Beep


Beep


As might be expected, this makes the terminal beep.


31.10.3. DestroyFunc


DestroyFunc function


Deletes a function, so that subsequent references to it are no longer valid. You can use this to change the contents of a function during a fvwm session. The function can be rebuilt using AddToFunc.


DestroyFunc PrintFunction
31.10.4. Echo


Echo string


Prints a message to stderr. Potentially useful for debugging things in your config.


Echo Beginning style definitions...
31.10.5. EchoFuncDefinition


EchoFuncDefinition function


The EchoFuncDefinition is similar to the Echo command but prints the definition for the given function to stderr. It is useful to find out how fvwm handles quoting and for debugging functions .


31.10.6. Exec


Exec command


Executes command. You should not use an ampersand '&' at the end of the command. You probably want to use an additional "exec" at the beginning of command. Without that, the shell that fvwm invokes to run your command stays until the command exits. In effect, you'll have twice as many processes running as you need. Note that some shells are smart enough to avoid this, but it never hurts to include the "exec" anyway.


The following example binds function key F1 in the root window, with no modifiers, to the exec function. The program rxvt is started with an assortment of options.


Key F1 R N Exec exec rxvt -fg yellow -bg blue \
  -e /bin/tcsh
Note that this function doesn't wait for command to complete, so things like:


Exec "echo AddToMenu ... > /tmp/file"
Read /tmp/file
do not work reliably (see the PipeRead command).


31.10.7. ExecUseShell


ExecUseShell [shell]


Makes the Exec command use the specified shell, or the value of the $SHELL environment variable if no shell is specified, instead of the default Bourne shell (/bin/sh).


ExecUseShell
ExecUseShell /usr/local/bin/tcsh
31.10.8. Function


Function FunctionName


Used to bind a previously defined function to a key or mouse button. The following example binds mouse button 1 to a function called "Move-or-Raise", whose definition was provided as an example earlier in this man page. After performing this binding fvwm executes the "move-or-raise" function whenever button 1 is pressed in a window's title-bar.


Mouse 1 T A Function Move-or-Raise
The keyword Function may be omitted if FunctionName does not coincide with an fvwm command.


Warning: Please read the comments on executing complex functions in the section Scripting and Complex Functions.


31.10.9. Nop


Nop


Does nothing. This is used to insert a blank line or separator in a menu. If the menu item specification is


AddToMenu MyMenu " " Nop
then a blank line is inserted. If it looks like


+ "" Nop
then a separator line is inserted. Can also be used as the double-click action for Menu or Popup.


31.10.10. PipeRead


PipeRead command [quiet]


Causes fvwm to read commands from the output of the command. This command is executed by /bin/sh as if you typed it on the command line. If the command consists of more than one word it must be quoted. Useful for building up dynamic menu entries based on a directories contents, for example. If the keyword Quiet follows the command no message is produced if the command is not found.


Example:


AddToMenu HomeDirMenu
PipeRead 'for i in $HOME/*; \
  do echo "+ $i Exec xterm -e vi $i"; done'
Note: The PipeRead changes the pointer to a watch cursor by default during execution. However, some commands, for example xwd, need to take control of the pointer themselves and do not work. To disable the watch cursor, use the command prior to PipeRead


BusyCursor Read off
The PipeRead command executes synchronously. If you want to Exec something, but need the command to run synchronously, you might do something like:


PipeRead 'command 1>&2'
The redirection causes any output from the program to go to stderr instead of being read as a sequence of commands by fvwm. PipeRead returns 1 if the given command could be executed or -1 if not (see the section Conditional Commands for the meaning of return codes).


31.10.11. Read


Read filename [quiet]


Causes fvwm to read commands from the file named filename. If the keyword Quiet follows the command no message is produced if the file is not found. If the file name does not begin with a slash ('/'), fvwm looks in the user's data directory, then the system data directory. The user's data directory is by default $HOME/.fvwm. It can be overridden by exporting FVWM_USERDIR set to any other directory. The Read command returns 1 if the given file could be read or -1 if not (see the section Conditional Commands for the meaning of return codes).


31.10.12. SetEnv


SetEnv variable value


Set an environment variable to a new value, similar to the shell's export or setenv command. The variable and its value are inherited by processes started directly by fvwm. This can be especially useful in conjunction with the FvwmM4 module. For example:


SetEnv height HEIGHT
makes the FvwmM4 set variable HEIGHT usable by processes started by fvwm as the environment variable $height. If value includes whitespace, you should enclose it in quotes. If no value is given, the variable is deleted.


31.10.13. Silent


Silent command


A number of commands require a window to operate on. If no window was selected when such a function is invoked the user is asked to select a window. Sometimes this behavior is unwanted, for example if the function was called by a module and the window that was selected at first does not exist anymore. You can prevent this by putting Silent in front of the fvwm command. If a function that needs a window is called with Silent without a window selected, it simply returns without doing anything. If Silent is used on a user defined function it affects all function and sub function calls until the original function exits.


Another usage of Silent is with binding commands Key, PointerKey and Mouse, this disables error messages.


Silent also disables the error message for non-existent commands. Note: This command is treated as a prefix to its command. Expansion of the command line is done as if Silent was not there.


Examples:


Silent Move 0 0
Silent User_defined_function
# do not complain on keyboards without "Help" key
Silent Key Help R A Popup HelpMenu
31.10.14. UnsetEnv


UnsetEnv [variable]


Unset an environment variable, similar to shell's export or unsetenv command. The variable then is removed from the environment array inherited by processes started directly by fvwm.


31.10.15. Wait


Wait window


This command is intended to be used in fvwm functions only. It causes execution of a function to pause until a new window matching window appears. This can be a window's name, class, or resource string. It may contain the wildcards '*' and '?', which are matched in the usual Unix filename manner. This is particularly useful in the "InitFunction" if you are trying to start windows on specific desktops:


AddToFunc InitFunction
 + I Exec exec xterm -geometry 80x64+0+0
 + I Wait xterm
 + I GotoDesk 0 2
 + I Exec exec xmh -font fixed -geometry \
       507x750+0+0
 + I Wait xmh
 + I GotoDesk 0 0
The above function starts an xterm on the current desk, waits for it to map itself, then switches to desk 2 and starts an xmh. After the xmh window appears control moves to desk 0.


Fvwm remains partially functional during a wait, but any input from the modules is queued up and processed only after the window appears or the command is aborted. For example, windows can not be focused with FvwmTaskBar or FvwmWinList during a wait.


You can escape from a Wait pause by pressing Ctrl-Alt-Escape (where Alt is the first modifier). To redefine this key sequence see the EscapeFunc command.