1FvwmScript(1) Fvwm Modules FvwmScript(1)
2
3
4
6 FvwmScript - module to build graphic user interface
7
8
10 FvwmScript must be spawned by Fvwm. It will not work from the command
11 line.
12
13
15 FvwmScript is a module which allows you to build many graphical appli‐
16 cations such as desktop accessories, button panel with pop up menus,
17 modal dialogs... At the startup, FvwmScript reads the file which is
18 specified on the command line. This file contains the script. This
19 script is not included in the configuration file of Fvwm.
20
21 An FvwmScript script is fully controllable by using the keyboard.
22 (Shift)-Tab circulates around the widgets, Return simulates a mouse
23 click, the arrows move the cursor or change the values of the widget
24 and Escape "cancels" for Menu and PopupMenu.
25
26
28 FvwmScript can be invoked by inserting the line `Module FvwmScript
29 name_of_script' in the .fvwm2rc file. The file "name_of_script" can
30 start with a slash, in which case, it's a fully qualified path, and the
31 file is read. If "name_of_script" does not start with a slash, Fvwm‐
32 Script will look in a few different places. If the .fvwm2rc con‐
33 tained the command line `*FvwmScript: Path
34 path_of_the_script_directory', FvwmScript will try that directory. If
35 that doesn't work, FvwmScript tries the system configuration directory
36 and the user configuration directory as described under the "Read" com‐
37 mand in the fvwm man page.
38
39 The command to start FvwmScript can be placed on a line by itself, if
40 FvwmScript is to be spawned during fvwm's initialization, or can be
41 bound to a menu or mouse button or keystroke to invoke it later.
42
43
45 The following commands can be used in the config file (see fvwm(1),
46 section MODULE COMMANDS for details). They are used only if the corre‐
47 sponding script commands are not used in the script.
48
49
50 *FvwmScript: DefaultFont font
51 Specifies the default font to be used. If not specified with
52 this command or in the script with the Font command, fixed font
53 is assumed.
54
55
56 *FvwmScript: DefaultFore color
57 Specifies the default foreground color to be used. If not speci‐
58 fied with this command or in the script with the ForeColor com‐
59 mand, black is used.
60
61
62 *FvwmScript: DefaultBack color
63 Specifies the default background color to be used. If not speci‐
64 fied with this command or in the script with the BackColor com‐
65 mand, grey85 is used.
66
67
68 *FvwmScript: DefaultHilight color
69 Specifies the default hilight color to be used. If not specified
70 with this command or in the script with the HilightColor com‐
71 mand, grey100 is used.
72
73
74 *FvwmScript: DefaultShadow color
75 Specifies the default shadow color to be used. If not specified
76 with this command or in the script with the ShadowColor command,
77 grey55 is used.
78
79
80 *FvwmScript: DefaultColorset colorset
81 Tells the module to use colorset colorset as the default col‐
82 orset. Refer to the FvwmTheme man page for details about col‐
83 orsets.
84
85
87 FvwmScript uses a particular programming language. A script is composed
88 of five parts. Heading contains general characteristics of the window
89 and default properties for all widgets. The second part contains
90 instructions whom are executed at the startup of the script. The third
91 part contains periodic tasks which are executed every second. The
92 fourth part contains instructions which are executed at exit. And the
93 last part contains the description of widgets. A widget consists of
94 eleven types of items: text labels, single-line text inputs, radio but‐
95 tons, checkbox, push buttons, horizontal and vertical scrollbars, rec‐
96 tangles, pop up menus, swallowexecs and mini scrollbars.
97
98
100 The syntax is as follows:
101
102
103 WindowTitle string
104 This option sets the window title.
105
106
107 WindowSize width height
108 This option sets window size. width and height are numerical
109 value.
110
111
112 WindowPosition x y
113 This option sets window position. x and y are numerical value.
114
115
116 ForeColor {color}
117 This option sets the default foreground color for all widgets.
118
119
120 BackColor {color}
121 This option sets the default background color for all widgets.
122
123
124 HilightColor {color}
125 This option sets the default hilight color for all widgets.
126
127
128 ShadowColor {color}
129 This option sets the default shadow color for all widgets.
130
131
132 Colorset {n}
133 This option sets the default colorset for all widgets.
134
135
136 Font {font}
137 This option sets the default font for all widgets.
138
139
140 UseGettext [locale_path]
141 Enable the use of the gettext mechanism which is used by the
142 WindowLocaleTitle, LocaleTitle, ChangeLocaleTitle instructions
143 and the Gettext function. If no argument is given, the default
144 FvwmScript locale catalog is used. This catalog is under the
145 locale fvwm installation directory and the text domain is Fvwm‐
146 Script (install_prefix/share/locale/*/LC_MESSAGES/Fvwm‐
147 Script.mo). You can reset this catalog or add some catalogs
148 exactly in the same way than with the LocalePath fvwm command
149 (see the fvwm manual page). This instruction should be placed
150 before the WindowLocaleTitle instruction.
151
152
153 WindowLocaleTitle string
154 This option sets the window title, but use the locale catalog(s)
155 defined with UseGettext.
156
157
159 This part contains instructions which will be executed at the startup.
160 For example:
161 Init
162 Begin
163 Do "Exec cat tada.voc > /dev/dsp"
164 WarpPointer 1
165 Set $ToDo=Restart
166 End
167 These instructions are used to play a sound, move the pointer to widget
168 1 and to initialize $ToDo to "Restart" at every startup.
169
170
172 This part of the script contains instructions that are executed every
173 second. For example:
174 PeriodicTasks
175 Begin
176 If (RemainderOfDiv (GetTime) 10)==0 Then
177 Do {Exec xcalc}
178 End
179 This example shows how to launch xcalc every 10 seconds.
180
181
183 This part of the script contains instructions that are executed when
184 the script exits (after the Quit instruction or if you close the window
185 with the Close, Delete or Destroy fvwm command). For Example
186 QuitFunc
187 Begin
188 Do {Echo bye, bye}
189 End
190 Be aware that if you used the KillModule fvwm command to close the
191 script, some instructions or functions which rely on the existence of a
192 communication link between the script and fvwm will not be executed
193 (for example the Do command). To smoothly kill a script with an fvwm
194 command see the COMMANDS section.
195
196
198 The second part of the script contains the description for every widget
199 in the script. Each widget description has two parts. The first part
200 describes initial properties, the second part contains instructions
201 that are executed when the widget receives messages. All widgets can
202 send and receive messages. All messages are identified by a number.
203 The message "UserAction" is sent to a widget when the user operates the
204 widget. The syntax for the first part is:
205 Widget id # A number between 1 and 999 inclusive
206 Property
207 Type string
208 Size width height
209 Position x y
210 Title { string }
211 Value int
212 MaxValue int
213 MinValue int
214 Font string
215 ForeColor { color }
216 BackColor { color }
217 HilightColor { color }
218 ShadowColor { color }
219 Colorset int
220 Flags flagsOpt
221 The flagsOpt option to Flags is a space separated list containing one
222 or more of the keywords Hidden, NoReliefString, NoFocus, Left / Cen‐
223 ter / Right. Hidden is used to specify if the widget is hidden at
224 startup. NoReliefString specifies if strings are drawn with relief or
225 not. NoFocus specifies if the widget can get the keyboard focus or
226 not. By default all widgets take focus, except Rectangle, HDipstick
227 and VDipstick which cannot. Moreover, the NoFocus widgets are skipped
228 when you circulate around the widgets with the (Shift-)Tab short cut.
229 Left / Center / Right specifies the text position. These apply only to
230 ItemDraw, List, Menu, PopupMenu and PushButton. The default is Center
231 for ItemDraw and PushButton and Left for the other widgets.
232
233 LocaleTitle can be used in place of Title, for using the locale cata‐
234 log(s) defined with UseGettext.
235
236 The position of every widget must be specified.
237
238 The syntax for the second part is:
239 Main
240 Case message of
241 SingleClic:
242 Begin
243 # list of instructions which will be
244 # executed when widget receives
245 # message "SingleClic". This message is
246 # generated by the user.
247 End
248 1 :
249 Begin
250 # list of instructions which will be
251 # executed when widget receives
252 # message 1
253 End
254 End
255
256
258 There is fifteen types of widgets.
259
260
261 CheckBox: Display check box with a string.
262
263 Title: title of the check box.
264
265 Value: if Value is equal to 1, the box is checked else it is
266 not.
267
268 The Size property is ignored.
269
270
271 HDipstick: Display a horizontal dipstick.
272 This widget can be used to display disk usage.
273
274 Value: specify the current value of the dipstick.
275
276 MinValue: specify the minimum value of the dipstick.
277
278 MaxValue: specify the maximum value of the dipstick.
279
280 A minimum size of 30x11 is imposed.
281
282
283 HScrollBar: Display an horizontal scrollbar.
284
285 Value: position of the thumb.
286
287 MaxValue: upper limit of Value.
288
289 MinValue: lower limit of Value.
290
291 The height property is ignored and a minimum width is imposed.
292 The width should be at least the range plus 37 if all values are
293 to be selectable e.g. a min of 0 and max of 10 has a range of
294 11 and therefore should have a minimum width of 48.
295
296
297 ItemDraw: Display an icon and/or a string.
298
299 Title: string to display.
300
301 Icon: icon to display.
302
303 MaxValue: x coordinate of the cursor.
304
305 MinValue: y coordinate of the cursor.
306
307 The size is made large enough to contain the title and/or the
308 icon.
309
310
311 List: Display a list.
312 List lets user to choose between various options.
313
314 Value: specify which option is selected.
315
316 MinValue: First visible option.
317
318 Title: title contains options displayed in the list. The syntax
319 is the following: {Option 1|Option 2|...|Option N}. All menus
320 are displayed at the top of window.
321
322 A minimum height of three items is imposed and the width is made
323 to be at least 108.
324
325
326 Menu: Display a menu whom lets user to choose a option.
327 Items of type Menu are layed out from left to right along the
328 top of the window. The size and position properties are ignored.
329
330 Value: specify which option is selected.
331
332 Title: title contains options displayed in the menu. The syntax
333 is the following: {Option 1|Option 2|...|Option N}.
334
335
336 MiniScroll: Display a very small vertical scrollbar.
337
338 Value: position of the thumb.
339
340 MaxValue: upper limit of Value.
341
342 MinValue: lower limit of Value.
343
344 The size is set to 19x34.
345
346
347 PopupMenu: Display a pop up menu.
348
349 Value: specify what option is selected.
350
351 Title: the title has the following syntax: {Option 1|Option
352 2|...|Option N}."Option 1|Option 2|...|Option N" is the pop up
353 menu which is displayed when pressing mouse button.
354
355 The size property is ignored.
356
357
358 PushButton: Display push button with an icon and/or a string.
359
360 Title: this string has the following syntax {Title of the but‐
361 ton|Option 1|Option 2|Option3|...|Option N}. "Option 1|Option
362 2|...|Option N" is the pop up menu which is displayed when
363 pressing the right button.
364
365 Icon: icon to display.
366
367 The button is made large enough to fit the icon and or label.
368
369
370 RadioButton: Display radio button with a string.
371
372 Title: title of the radio button.
373
374 Value: if Value is equal to 1, the box is checked else it is
375 not.
376
377 The size property is ignored
378
379
380 Rectangle: Display a rectangle.
381 This type of widget can be used to decorate window.
382
383
384 SwallowExec
385 This type of widget causes FvwmScript to spawn an process, and
386 capture the first window whose name or resource is equal to
387 Title, and display it in the script window.
388
389 Title: specify the window name which be captured and displayed
390 in the script window.
391
392 SwallowExec: specify the command line to execute to spawn the
393 process. Modules can also be swallowed.
394
395 Value: specify the looking of the border. Possible value: -1, 0,
396 1.
397
398 The size is made to be at least 30x30
399
400
401 TextField: Display a text input field.
402 The text input field can be used to edit a single-line string.
403
404 Title: content of text field.
405
406 Value: position of the insert point.
407
408 MinValue: position of the end of the selection.
409
410 MaxValue: first visible character of the title
411
412 The height property is ignored, the width is made to be at least
413 40 pixels wider than the initial contents.
414
415
416 VDipstick: Display a vertical dipstick.
417
418 Value: specify the current value of the dipstick.
419
420 MinValue: specify the minimum value of the dipstick.
421
422 MaxValue: specify the maximum value of the dipstick.
423
424 The size is made to be at least 11x30.
425
426
427 VScrollBar: Display a vertical scrollbar.
428
429 Value: position of the thumb.
430
431 MaxValue: upper limit of Value.
432
433 MinValue: lower limit of Value.
434
435 The width property is ignored and a minimum height is imposed.
436 The height should be at least the range plus 37 if all values
437 are to be selectable e.g. a min of 0 and max of 10 has a range
438 of 11 and therefore should have a minimum height of 48.
439
440
442 Here is the description of all instructions.
443
444
445 HideWidget id : hide the widget numbered id.
446
447
448 ShowWidget id: show the widget numbered id.
449
450
451 ChangeValue id1 id2
452 Set the value of the widget numbered id1 to id2.
453
454
455 ChangeMaxValue id1 id2
456 Set the maximum value of the widget numbered id1 to id2.
457
458
459 ChangeMinValue id1 id2
460 Set the minimum value of the widget numbered id1 to id2.
461
462
463 ChangeTitle id1 id2
464 Set the title of the widget numbered id1 to id2.
465
466
467 ChangeWindowTitle string
468 Set the title of the window to string.
469
470
471 ChangeWindowTitleFromArg numarg
472 Set the title of the window to the value of the numarg-th script
473 argument.
474
475
476 ChangeLocaleTitle id1 id2
477 As ChangeTitle but use the locale catalog(s) defined with
478 UseGettext.
479
480
481 ChangeIcon id1 id2
482 Set the icon of the widget numbered id1 to id2.
483
484
485 ChangeForeColor id1 {color}
486 Set the foreground color of the widget numbered id1 to {color}.
487
488
489 ChangeBackColor id1 {color}
490 Set the background color of the widget numbered id1 to {color}.
491
492
493 ChangeColorSet id1 id2
494 Set the colorset of the widget numbered id1 to id2. Specifying
495 widget 0 sets the main window colorset.
496
497
498 ChangePosition id1 x y
499 Move the widget numbered id1 to position (x,y).
500
501
502 ChangeSize id1 width height
503 Set the size of the widget numbered id1 to (width,height).
504
505
506 ChangeFont id1 newfont
507 Set the font of the widget numbered id1 to newfont.
508
509
510 WarpPointer id
511 Warp the mouse pointer into the widget numbered id.
512
513
514 WriteToFile filename {str1} {str2} etc
515 Write to the file filename the string which is the concatenation
516 of all arguments str1, str2, etc.
517
518
519 Do {command args}
520 Execute the fvwm command inside the Do block. Any fvwm command
521 as described in the fvwm2 man page can be used. Commands are
522 sent from this module to the fvwm main program for processing.
523 The length of the command and arguments can not exceed 988 char‐
524 acters.
525
526
527 Set $var={str1} {str2} etc
528 Concatenate all arguments to a string and set the variable $var
529 to this string.
530
531
532 Quit: quit the program.
533
534
535 SendSignal id1 id2
536 Send a message numbered id2 to widget id1.
537
538
539 SendToScript id_script {str11} {str2} etc
540 Send a message to the script identified by id_script. The mes‐
541 sage is the concatenation of str1, str2...
542
543
544 Key Keyname Modifier id sig str1 str2 etc
545 Binds a keyboard key to the instruction
546
547 SendSignal id sig
548
549 and sets the "last string" to the concatenation of str1, str2...
550 (see the LastString function). The Keyname and Modifiers fields
551 are defined as in the fvwm Key command.
552
553
555 Most of commands use arguments. There are two kinds of arguments: num‐
556 bers and strings. A numerical argument is a value which is between
557 -32000 and +32000. A string is always surrounded with braces. Variables
558 always begin with the character "$" and can contain both numbers and
559 strings.
560
561
563 All functions use arguments. Functions can return both a string and a
564 number. The syntax is:
565 (function argument1 argument2 etc)
566 Here is the complete list of arguments:
567
568
569 (GetTitle id)
570 Return the title of the widget numbered id.
571
572
573 (GetValue id)
574 Return the current value of the widget numbered id.
575
576
577 (GetMinValue id)
578 Return the current Min value of the widget numbered id.
579
580
581 (GetMaxValue id)
582 Return the current Max value of the widget numbered id.
583
584
585 (GetFore id)
586 Return the current RGB foreground value of the widget numbered
587 id in the hex format RRGGBB.
588
589
590 (GetBack id)
591 Return the current RGB background value of the widget numbered
592 id in the hex format RRGGBB.
593
594
595 (GetHilight id)
596 Return the current RGB hilight value of the widget numbered id
597 in the hex format RRGGBB.
598
599
600 (GetShadow id)
601 Return the current RGB shadow value of the widget numbered id in
602 the hex format RRGGBB.
603
604
605 (GetOutput {str} int1 int2)
606 Executes the command str, gets the standard output and returns
607 the word which is in the line int1 and in the position int2. If
608 int2 is equal to -1, GetOutput returns the complete line.
609
610
611 (NumToHex int)
612 Return the hexadecimal value of int.
613
614
615 (HexToNum {str})
616 Return the decimal value of str, str must be an hexadecimal
617 value.
618
619
620 (Add int1 int2)
621 Return the result of (int1+int2).
622
623
624 (Mult int1 int2)
625 Return the result of (int1*int2).
626
627
628 (Div int1 int2)
629 Return the result of (int1/int2).
630
631
632 (StrCopy {str} int1 int2)
633 Return the string whom is between position int1 and int2. For
634 example, (StrCopy {Hello} 1 2) returns {He}
635
636
637 (LaunchScript {str})
638 This function launches the script named str and returns an iden‐
639 tification number. This number is necessary to use the func‐
640 tions SendToScript and ReceiveFromScript. The string str con‐
641 tains the script name and some arguments.
642
643
644 (GetScriptArgument {int})
645 This function returns the argument script used in the function
646 LaunchScript. If int is equal to zero, GetScriptArgument
647 returns the name of the script.
648
649
650 (GetScriptFather)
651 This function returns the identification number of the script
652 father.
653
654
655 (ReceivFromScript {int})
656 This function returns the message sent by the script numbered
657 int.
658
659
660 (RemainderOfDiv {int1 int2}): t
661 This function returns the remainder of the division (int1/int2).
662
663
664 (GetTime)
665 This function returns the time in seconds.
666
667
668 (GetPid)
669 This function returns the process id of the script.
670
671
672 (Gettext {str})
673 This function return the translation of str by using the locale
674 catalog(s) defined with UseGettext.
675
676
677 (SendMsgAndGet {comId} {cmd} bool)
678 Sends the command cmd with identifier comId to an external pro‐
679 gram ready to communicate with the script using a protocol spe‐
680 cific to FvwmScript. If bool is 0 FvwmScript does not wait for
681 an answer from the external program. In this case the returned
682 value is 1 if the message can be sent to the external program
683 and 0 if this is not the case. If bool is 1, then FvwmScript
684 waits for an answer from the external program and the return
685 value is this answer (a line of no more than 32000 characters).
686 If the communication fails, the returned value is 0. See the
687 section A COMMUNICATION PROTOCOL for a description of the commu‐
688 nication protocol used.
689
690
691 (Parse {str} int)
692 where str must be a string of the form:
693 X1S1X2S2X3S3...SnXn
694 where the Xn are numbers containing four decimal digits and
695 where Sn are strings of length exactly Xn. The returned value is
696 the string Sint. If int is out of range (e.g., >n) the returned
697 value is the empty string. If str is not of the specified form,
698 the return value is unpredictable (but empty in the average).
699 This function is useful to handle strings returned by the
700 SendMsgAndGet function.
701
702
703 (LastString)
704 This function returns the "current working string" for the Key
705 instruction and the SendString command (see the COMMANDS sec‐
706 tion). At startup this string is empty, but when a Key binding
707 is detected (respectively, a SendString command is received),
708 then this string is set to the string associated to the instruc‐
709 tion (respectively, to the command).
710
711
713 There are three kinds of conditional loops. The instruction "If-Then-
714 Else" has the following syntax:
715 If $ToDo=={Open xcalc} Then
716 Do {Exec xcalc &} # List of instructions
717 Else
718 Begin
719 Do {Exec killall xcalc &} # List of instructions
720 Do {Exec echo xcalc killed > /dev/console}
721 End
722 The second part "Else-Begin-End" is optional. If the loop contains only
723 one instruction, Begin and End can be omitted. The instruction "While-
724 Do" has the following syntax:
725 While $i<5 Do
726 Begin
727 Set $i=(Add i 1) # List of instructions
728 End
729 Two strings can be compared with "==" and two numbers can be compared
730 with "<", "<=", "==", ">=", ">". The loop "For-Do-Begin-End" has the
731 following syntax:
732 For $i=1 To 20 Do
733 Begin
734 Do {Exec xcalc &} # List of instructions
735 End
736
737
739 The following fvwm command may be executed at any time
740
741 SendToModule ScriptName SendString id sig str
742
743 it sends to any module with alias or name which matches ScriptName the
744 string
745
746 SendString id sig str
747
748 When an FvwmScript receives such a message it sends to the Widget id
749 the signal numbered sig and the string str can be obtained with the
750 LastString function. Let us give an example. Say that you have a
751 script MyScript with the widget:
752 Widget 50
753 Property
754 Type PushButton
755 Title {Quit}
756 ...
757 Main
758 Case message of
759
760 SingleClic:
761 Begin
762 Quit
763 End
764
765 1 :
766 Begin
767 Set $str = (LastString)
768 If $str == {Quit} Then
769 Quit
770 Else
771 ChangeTitle 33 $str
772 End
773
774 End
775 Then the command
776 SendToModule MyScript SendString 50 1 str
777 forces MyScript to exit if str is equal to "Quit" and if not it changes
778 the title of Widget 33 to str.
779
780
781 This command can be used to change the window title
782
783 SendToModule ScriptName ChangeWindowTitle newTitle [oldTitle]
784
785 it causes that any module with alias or name which matches ScriptName
786 changes its associated window title to newTitle. The optional argument
787 oldTitle makes sense when there are several instances of the same
788 script. It permits to avoid changing the name of all these instances
789 by specifying the name of the window associated to the target script
790 (see the example below).
791
792 + I Module FvwmScript FvwmStorageSend "/dev/hda6"
793 + I Wait FvwmStorageSend
794 + I SendToModule FvwmStorageSend ChangeWindowTitle HDA6
795 + I Module FvwmScript FvwmStorageSend "/dev/hda1"
796 + I Wait FvwmStorageSend
797 + I SendToModule FvwmStorageSend ChangeWindowTitle HDA1 FvwmStorageSend
798
799 Without the FvwmStorageSend argument in the last case, the SendToModule
800 command would have changed to HDA1 the name of both instances of Fvwm‐
801 StorageSend.
802
803
804
806 You will find examples of scripts in the fvwm configuration directory.
807
808 FvwmScript-BellSetup, FvwmScript-KeyboardSetup, FvwmScript-PointerSetup
809 and FvwmScript-ScreenSetup are a set of scripts that modify X settings.
810 These scripts save preferences into a file named ~/.xinit-fvwmrc (If
811 you want to use another file name, give it as the first argument of the
812 script). If you want to load these preferences at every startup, you
813 have to include the line ".xinit-fvwmrc" in your .xinitrc (or .xses‐
814 sion) file before starting fvwm.
815
816 FvwmScript-BaseConfig modifies fvwm focus and paging mouse policy, win‐
817 dow placement, opacity and other features of the move and resize com‐
818 mands, snap attraction and shading animation. This script saves pref‐
819 erences into a file named .FvwmBaseConfig in the user's data directory
820 (i.e., $HOME/.fvwm or $FVWM_USERDIR if set). If you want to load these
821 preferences at every startup you must add the line "Read .FvwmBaseCon‐
822 fig" in your fvwm configuration file. If you want to use another file
823 name, give it as the first argument of the script. When you click on
824 Ok or Apply an fvwm function that you may define named BaseConfigOkFunc
825 or BaseConfigApplyFunc is called. This allows for reloading specific
826 application styles that the script has destroyed (e.g., AddToFunc
827 BaseConfigOkFunc I Read MyAppStyle).
828
829 FvwmScript-Buttons is a buttons panel which can replace FvwmButtons
830 (this script supports popup menus and requires xload, xclock, Fvwm‐
831 Pager, TkDesk). FvwmScript-Colorset allows you to edit your colorset
832 (see FvwmTheme). FvwmScript-Date allows you to set date and time.
833 FvwmScript-FileBrowser is a file browser used by the other scripts.
834 FvwmScript-Find is an elementary front-end to find. FvwmScript-Quit
835 allows to quit fvwm, restart fvwm or some other window manager, or shut
836 down and reboot the computer. FvwmScript-ScreenDump is a screen
837 dumper. FvwmScript-WidgetDemo is a pure example script. See the next
838 section for FvwmScript-ComExample.
839
840
842 FvwmScript is a weak (but simple) programming language. If you need to
843 deal with a lot of data and/or you need to use complex algorithms you
844 should use an external program (in perl for example) and "send" the
845 desired information to your FvwmScript script. The first approach is to
846 use the GetOutput function. This is simple but you should rerun your
847 external program each time you need information from it (and this may
848 cause performances problems). The second approach is to use the
849 SendMsgAndGet function which extends FvwmScript by using any program‐
850 ming language which can deal with named pipes (fifos). We describe this
851 solution in this section. (A third approach is to use fvwm-themes-com
852 from the fvwm-themes package, but in fact the SendMsgAndGet method is
853 an implementation of fvwm-themes-com inside FvwmScript and this gives
854 better performance).
855
856 Basically, you start an "external" program (the program for short) from
857 your FvwmScript script (the script for short). This program runs in the
858 background and you use the SendMsgAndGet function in your script to ask
859 questions or to give instructions to the program. The program must
860 strictly respect a certain communication protocol. First of all there
861 is an identifier comId for the communication, it should contain the
862 process id of the script for a good implementation of the protocol (use
863 the GetPid function and pass the comId via an option to the program).
864 The protocol uses two fifos, in the fvwm user directory, named: .tmp-
865 com-in-comId and .tmp-com-out-comId. The program should create and
866 listen on the .tmp-com-in-comId fifo. Then, when FvwmScript executes a
867 function of the form:
868
869 Set $answer = (SendMsgAndGet {comId} {cmd} bool)
870
871 FvwmScript writes the cmd on this fifo. This way the program can read
872 the cmd and can execute the appropriate action (it should remove the in
873 fifo to support multi-communications). If bool is 0, FvwmScript does
874 not wait for an answer from the program and return 1 if the previous
875 actions succeed and 0 if they failed (then the program should "go back"
876 to the in fifo). If bool is 1, then FvwmScript waits (20 sec) for an
877 answer from the program and in turn returns the answer to the script
878 (note that bool is not passed to the program as it must know which com‐
879 mands need an answer). To answer, the program creates the .tmp-com-out-
880 comId fifo and writes the answer on it. The program should wait until
881 FvwmScript reads the answer and then it should remove the out fifo and
882 go back to the in fifo. The answer should consist of one line of no
883 more than 32000 characters (take a look at the Parse function to handle
884 multiple lines as one line).
885
886 A simple way to understand this protocol and to write scripts and pro‐
887 grams that use it is to take a look at the (not useful) example Fvwm‐
888 Script-ComExample and fvwm-script-ComExample.pl (that can found in the
889 fvwm data directory). Moreover, this implementation of the protocol
890 solves questions as: What to do if the script exits for a bad reason?
891 What to do if the program exits for a bad reason? ...etc.
892
893
895 FvwmScript crashes if widgets are accessed that have not been defined.
896
897
899 Frederic Cordier (cordie97@cui.unige.ch or f-cord96@univ-
900 lyon1.fr).
901
902
904 Eddy J. Gurney (eddy@gizmo.aa.ans.net).
905
906
907
9083rd Berkeley Distribution 24 November 2007 (2.5.24) FvwmScript(1)