NAME
FvwmScript - module to build graphic user interfaceSYNOPSIS
FvwmScript must be spawned by Fvwm. It will not work from the command line.DESCRIPTION
FvwmScript is a module which allows you to build many graphical applications such as desktop accessories, button panel with pop up menus, modal dialogs... At the startup, FvwmScript reads the file which is specified on the command line. This file contains the script. This script is not included in the configuration file of Fvwm.INVOCATION
FvwmScript can be invoked by inserting the line `Module FvwmScript name_of_script' in the .fvwm2rc file. The file "name_of_script" can start with a slash, in which case, it’s a fully qualified path, and the file is read. If "name_of_script" does not start with a slash, FvwmScript will look in a few different places. If the .fvwm2rc contained the command line `*FvwmScript: Path path_of_the_script_directory', FvwmScript will try that directory. If that doesn’t work, FvwmScript tries the system configuration directory and the user configuration directory as described under the "Read" command in the fvwm man page.CONFIGURATION OPTIONS
The following commands can be used in the config file (see fvwm(1), section MODULE COMMANDS for details). They are used only if the corresponding script commands are not used in the script.Specifies the default font to be used. If not
specified with this command or in the script with the Font command, fixed font
is assumed.
Specifies the default foreground color to be
used. If not specified with this command or in the script with the ForeColor
command, black is used.
Specifies the default background color to be
used. If not specified with this command or in the script with the BackColor
command, grey85 is used.
Specifies the default hilight color to be
used. If not specified with this command or in the script with the
HilightColor command, grey100 is used.
Specifies the default shadow color to be used.
If not specified with this command or in the script with the ShadowColor
command, grey55 is used.
Tells the module to use colorset
colorset as the default colorset.
Tells the module to use X11 cursor
cursor as the default for all widgets. Cursor names are those defined
in the include file X11/cursorfont.h but without XC_ prefix.
ANATOMY OF A SCRIPT
FvwmScript uses a particular programming language. A script is composed of five parts. Heading contains general characteristics of the window and default properties for all widgets. The second part contains instructions whom are executed at the startup of the script. The third part contains periodic tasks which are executed every second. The fourth part contains instructions which are executed at exit. And the last part contains the description of widgets. A widget consists of eleven types of items: text labels, single-line text inputs, radio buttons, checkbox, push buttons, horizontal and vertical scrollbars, rectangles, pop up menus, swallowexecs and mini scrollbars.HEADING OF A SCRIPT
The syntax is as follows:This option sets the window title.
This option sets window size. width and
height are numerical value.
This option sets window position. x and
y are numerical value.
This option sets the default foreground color
for all widgets.
This option sets the default background color
for all widgets.
This option sets the default hilight color for
all widgets.
This option sets the default shadow color for
all widgets.
This option sets the default colorset for all
widgets.
This option sets the default font for all
widgets.
Enable the use of the gettext mechanism which
is used by the WindowLocaleTitle, LocaleTitle, ChangeLocaleTitle instructions
and the Gettext function. If no argument is given, the default FvwmScript
locale catalog is used. This catalog is under the locale fvwm installation
directory and the text domain is FvwmScript
(install_prefix/share/locale/*/LC_MESSAGES/FvwmScript.mo). You can reset this
catalog or add some catalogs exactly in the same way than with the
LocalePath fvwm command (see the fvwm manual page). This instruction
should be placed before the WindowLocaleTitle instruction.
This option sets the window title, but use the
locale catalog(s) defined with UseGettext.
INITIALISATION
This part contains instructions which will be executed at the startup. For example: Init Begin Do "Exec cat tada.voc > /dev/dsp" WarpPointer 1 Set $ToDo=Restart EndPERIODIC TASKS
This part of the script contains instructions that are executed every second. For example:PeriodicTasks Begin If (RemainderOfDiv (GetTime) 10)==0 Then Do {Exec xcalc} End
THE QUIT FUNCTION
This part of the script contains instructions that are executed when the script exits (after the Quit instruction or if you close the window with the Close, Delete or Destroy fvwm command). For ExampleQuitFunc Begin Do {Echo bye, bye} End
MAIN OF A SCRIPT
The second part of the script contains the description for every widget in the script. Each widget description has two parts. The first part describes initial properties, the second part contains instructions that are executed when the widget receives messages. All widgets can send and receive messages. All messages are identified by a number. The message "UserAction" is sent to a widget when the user operates the widget. The syntax for the first part is:Widget id # A number between 1 and 999 inclusive Property Type string Size width height Position x y Title { string } Value int MaxValue int MinValue int Font string ForeColor { color } BackColor { color } HilightColor { color } ShadowColor { color } Colorset int Flags flagsOpt
Main Case message of SingleClic: Begin # list of instructions which will be # executed when widget receives # message "SingleClic". This message is # generated by the user. End 1 : Begin # list of instructions which will be # executed when widget receives # message 1 End End
LIST OF WIDGETS
There is fifteen types of widgets.
Title: title of the check box.
Value: if Value is equal to 1, the box is checked else it is not.
This widget can be used to display disk usage.
Value: specify the current value of the dipstick.
MinValue: specify the minimum value of the dipstick.
MaxValue: specify the maximum value of the dipstick.
Value: position of the thumb.
MaxValue: upper limit of Value.
MinValue: lower limit of Value.
The height property is ignored and a minimum width is imposed. The width should
be at least the range plus 37 if all values are to be selectable e.g. a min of
0 and max of 10 has a range of 11 and therefore should have a minimum width of
48.
Title: string to display.
Icon: icon to display.
MaxValue: x coordinate of the cursor.
MinValue: y coordinate of the cursor.
The size is made large enough to contain the title and/or the icon.
List lets user to choose between various
options.
Value: specify which option is selected.
MinValue: First visible option.
Title: title contains options displayed in the list. The syntax is the
following: {Option 1|Option 2|...|Option N}. All menus are displayed at the
top of window.
A minimum height of three items is imposed and the width is made to be at least
108.
Items of type Menu are layed out from left to
right along the top of the window. The size and position properties are
ignored.
Value: specify which option is selected.
Title: title contains options displayed in the menu. The syntax is the
following: {Option 1|Option 2|...|Option N}.
Value: position of the thumb.
MaxValue: upper limit of Value.
MinValue: lower limit of Value.
The size is set to 19x34.
Value: specify what option is selected.
Title: the title has the following syntax: {Option 1|Option 2|...|Option
N}."Option 1|Option 2|...|Option N" is the pop up menu which is
displayed when pressing mouse button.
The size property is ignored.
Title: this string has the following
syntax {Title of the button|Option 1|Option 2|Option3|...|Option N}.
"Option 1|Option 2|...|Option N" is the pop up menu which is
displayed when pressing the right button.
Icon: icon to display.
The button is made large enough to fit the icon and or label.
Title: title of the radio button.
Value: if Value is equal to 1, the box is checked else it is not.
The size property is ignored
This type of widget can be used to decorate
window.
This type of widget causes FvwmScript to spawn
an process, and capture the first window whose name or resource is equal to
Title, and display it in the script window.
Title: specify the window name which be captured and displayed in the
script window.
SwallowExec: specify the command line to execute to spawn the process.
Modules can also be swallowed.
Value: specify the looking of the border. Possible value: -1, 0, 1.
The size is made to be at least 30x30
The text input field can be used to edit a
single-line string.
Title: content of text field.
Value: position of the insert point.
MinValue: position of the end of the selection.
MaxValue: first visible character of the title
The height property is ignored, the width is made to be at least 40 pixels wider
than the initial contents.
Value: specify the current value of the
dipstick.
MinValue: specify the minimum value of the dipstick.
MaxValue: specify the maximum value of the dipstick.
The size is made to be at least 11x30.
Value: position of the thumb.
MaxValue: upper limit of Value.
MinValue: lower limit of Value.
The width property is ignored and a minimum height is imposed. The height should
be at least the range plus 37 if all values are to be selectable e.g. a min of
0 and max of 10 has a range of 11 and therefore should have a minimum height
of 48.
INSTRUCTIONS
Here is the description of all instructions.Set the value of the widget numbered
id1 to id2.
Set the maximum value of the widget numbered
id1 to id2.
Set the minimum value of the widget numbered
id1 to id2.
Set the title of the widget numbered
id1 to id2.
Set the title of the window to
string.
Set the title of the window to the value of
the numarg-th script argument.
As ChangeTitle but use the locale catalog(s)
defined with UseGettext.
Set the icon of the widget numbered id1
to id2.
Set the foreground color of the widget
numbered id1 to {color}.
Set the background color of the widget
numbered id1 to {color}.
Set the colorset of the widget numbered
id1 to id2. Specifying widget 0 sets the main window
colorset.
Move the widget numbered id1 to
position ( x,y).
Set the size of the widget numbered id1
to ( width,height).
Set the font of the widget numbered id1
to newfont.
Warp the mouse pointer into the widget
numbered id.
Write to the file filename the string
which is the concatenation of all arguments str1, str2,
etc.
Execute the fvwm command inside the Do block.
Any fvwm command as described in the fvwm man page can be used. Commands are
sent from this module to the fvwm main program for processing. The length of
the command and arguments can not exceed 988 characters.
Concatenate all arguments to a string and set
the variable $ var to this string.
Send a message numbered id2 to widget
id1.
Send a message to the script identified by
id_script. The message is the concatenation of str1, str2...
Binds a keyboard key to the instruction
SendSignal id sig
and sets the "last string" to the concatenation of str1, str2... (see
the LastString function). The Keyname and Modifiers fields are
defined as in the fvwm Key command.
ARGUMENTS
Most of commands use arguments. There are two kinds of arguments: numbers and strings. A numerical argument is a value which is between -32000 and +32000. A string is always surrounded with braces. Variables always begin with the character "$" and can contain both numbers and strings.FUNCTIONS
All functions use arguments. Functions can return both a string and a number. The syntax is: (function argument1 argument2 etc)Return the title of the widget numbered
id.
Return the current value of the widget
numbered id.
Return the current Min value of the widget
numbered id.
Return the current Max value of the widget
numbered id.
Return the current RGB foreground value of the
widget numbered id in the hex format RRGGBB.
Return the current RGB background value of the
widget numbered id in the hex format RRGGBB.
Return the current RGB hilight value of the
widget numbered id in the hex format RRGGBB.
Return the current RGB shadow value of the
widget numbered id in the hex format RRGGBB.
Executes the command str, gets the
standard output and returns the word which is in the line int1 and in
the position int2. If int2 is equal to -1, GetOutput returns the
complete line.
Return the hexadecimal value of
int.
Return the decimal value of str,
str must be an hexadecimal value.
Return the result of
(int1+int2).
Return the result of
(int1*int2).
Return the result of
(int1/int2).
Return the string whom is between position
int1 and int2. For example, (StrCopy {Hello} 1 2) returns {He}
This function launches the script named str
and returns an identification number. This number is necessary to use the
functions SendToScript and ReceiveFromScript. The string str contains the
script name and some arguments.
This function returns the argument script used
in the function LaunchScript. If int is equal to zero, GetScriptArgument
returns the name of the script.
This function returns the identification
number of the script father.
This function returns the message sent by the
script numbered int.
This function returns the remainder of the
division ( int1/int2).
This function returns the time in
seconds.
This function returns the process id of the
script.
This function return the translation of
str by using the locale catalog(s) defined with UseGettext.
Sends the command cmd with identifier
comId to an external program ready to communicate with the script using
a protocol specific to FvwmScript. If bool is 0 FvwmScript does not
wait for an answer from the external program. In this case the returned value
is 1 if the message can be sent to the external program and 0 if this is not
the case. If bool is 1, then FvwmScript waits for an answer from the
external program and the return value is this answer (a line of no more than
32000 characters). If the communication fails, the returned value is 0. See
the section A COMMUNICATION PROTOCOL for a description of the
communication protocol used.
where str must be a string of the form:
X1S1X2S2X3S3...SnXn
where the Xn are numbers containing four decimal digits and where Sn are strings
of length exactly Xn. The returned value is the string S int. If
int is out of range (e.g., >n) the returned value is the empty
string. If str is not of the specified form, the return value is
unpredictable (but empty in the average). This function is useful to handle
strings returned by the SendMsgAndGet function.
This function returns the "current
working string" for the Key instruction and the SendString command (see
the COMMANDS section). At startup this string is empty, but when a Key
binding is detected (respectively, a SendString command is received), then
this string is set to the string associated to the instruction (respectively,
to the command).
CONDITIONAL LOOPS
There are three kinds of conditional loops. The instruction "If-Then-Else" has the following syntax:If $ToDo=={Open xcalc} Then Do {Exec xcalc &} # List of instructions Else Begin Do {Exec killall xcalc &} # List of instructions Do {Exec echo xcalc killed >/dev/console} End
While $i<5 Do Begin Set $i=(Add i 1) # List of instructions End
For $i=1 To 20 Do Begin Do {Exec xcalc &} # List of instructions End
COMMANDS
The following fvwm command may be executed at any timeWidget 50 Property Type PushButton Title {Quit} ... Main Case message of SingleClic: Begin Quit End 1 : Begin Set $str = (LastString) If $str == {Quit} Then Quit Else ChangeTitle 33 $str End End
SendToModule MyScript SendString 50 1 str
+ I Module FvwmScript FvwmStorageSend "/dev/hda6" + I Wait FvwmStorageSend + I SendToModule FvwmStorageSend ChangeWindowTitle HDA6 + I Module FvwmScript FvwmStorageSend "/dev/hda1" + I Wait FvwmStorageSend + I SendToModule FvwmStorageSend ChangeWindowTitle HDA1 FvwmStorageSend
EXAMPLES
You will find examples of scripts in the fvwm configuration directory.A COMMUNICATION PROTOCOL
FvwmScript is a weak (but simple) programming language. If you need to deal with a lot of data and/or you need to use complex algorithms you should use an external program (in perl for example) and "send" the desired information to your FvwmScript script. The first approach is to use the GetOutput function. This is simple but you should rerun your external program each time you need information from it (and this may cause performances problems). The second approach is to use the SendMsgAndGet function which extends FvwmScript by using any programming language which can deal with named pipes (fifos). We describe this solution in this section. (A third approach is to use fvwm-themes-com from the fvwm-themes package, but in fact the SendMsgAndGet method is an implementation of fvwm-themes-com inside FvwmScript and this gives better performance).BUGS
FvwmScript crashes if widgets are accessed that have not been defined.AUTHOR
Frederic Cordier ( <[email protected]> or ). <[email protected]>CONTRIBUTOR
Eddy J. Gurney (). <[email protected]>2023-01-17 |