FVWMPERL(1)

✨ NAME ✨

FVWMPERL(1) β€” bestie, meet FvwmPerl: the fvwm perl manipulator and preprocessor πŸ’…


🌸 SYNOPSIS 🌸

okay so the whole tea is: FvwmPerl is meant to be spawned by fvwm(1) for normal functionality. That's its natural habitat, its main character era.

To run this module, you drop the command Module FvwmPerl [params] into fvwm's configuration file, and then you can start sending commands to FvwmPerl 🫢

Module FvwmPerl [params]

πŸ¦‹ DESCRIPTION πŸ¦‹

This module is literally here to extend fvwm commands with the power of perl scripting ✨

It lets you embed perl expressions right inside your fvwm config files and construct fvwm commands that way. it's giving "why do it the boring way when perl exists", no cap.


πŸŽ€ INVOCATION πŸŽ€

So if you want to invoke the one unique and persistent instance of FvwmPerl, the suggested move is to do it from the StartFunction 🫢 Calling it from the top is also possible, but ngl it comes with some issues that this page does not get into (not discussed here, bestie, we're keeping it cute and surface-level).

AddToFunc StartFunction I Module FvwmPerl

There are several command line switches, and here's the whole grammar of them, verbatim:

FvwmPerl [ --eval line ] [ --load file ] [ --preprocess [ --quote char ]
[ --winid wid ] [ --cmd ] [ --nosend ] [ --noremove ] [ line | file ] ]
[ --export [names] ] [ --stay ] [ --nolock ] [ alias ]

Heads up: long switches may be abbreviated to short one-letter switches ✨

  • -e, --eval line β€” evaluate the given perl code πŸ‘‘
  • -l, --load file β€” evaluate perl code in the given file πŸ“
  • -p, --preprocess [file] β€” preprocess the given fvwm config file πŸ’…

The following 5 options are only valid together with the --preprocess option (like, do not come for them on their own, they will not answer):

  • -c, --cmd line β€” an fvwm command to be preprocessed instead of file.
  • -q, --quote char β€” change the default % quote.
  • -w, --winid wid β€” set explicit window context (it should begin with a digit, and it may be in oct or hex form; this window id overwrites the implicit window context if there is any).
  • --nosend β€” do not send the preprocessed file to fvwm for Reading, the default is send. Useful for preprocessing non fvwm config files 🌈
  • --noremove β€” do not remove the preprocessed file after sending it to fvwm for Reading, the default is remove. Useful for debugging πŸ”₯
  • -x, --export [names] β€” define fvwm shortcut functions (by default, two functions named Eval and .). This option implies --stay.
  • -s, --stay β€” continues an execution after --eval, --load or --preprocess are processed. By default, the module is not persistent in this case, i.e. --nostay is assumed.
  • --nolock β€” when one of the 3 action options is given, this option causes unlocking fvwm immediately. By default the requested action is executed synchronously; this only makes a difference when it's invoked like this:
ModuleSynchronous FvwmPerl --preprocess someconfig.ppp

If --nolock is added here, ModuleSynchronous returns immediately πŸƒβ€β™€οΈπŸ’¨ Note that Module returns immediately regardless of this option.


πŸ’œ USING ALIAS πŸ’œ

Aliases allow one to have several module invocations and work separately with all invocations. here's an example, iykyk:

ModuleSynchronous FvwmPerl FvwmPerl-JustTest
SendToModule FvwmPerl-JustTest eval $a = 2 + 2; $b = $a SendToModule
FvwmPerl-JustTest eval cmd("Echo 2 + 2 = $b")
KillModule FvwmPerl FvwmPerl-JustTest

🌟 PREPROCESSING EXAMPLE 🌟

One of the effective proprocessing solutions is to pass the whole fvwm configuration with embedded perl code to FvwmPerl --preprocess. An alternative approach is to write a perl script that produces fvwm commands and sends them for execution β€” that script may be loaded using FvwmPerl --load πŸ’–

There are however intermediate solutions that preprocess only separate configuration lines (or alternatively, execute separate perl commands that produce fvwm commands).

The following code snippet adds the ability of arithmetics and string scripting to certain lines that need this ✨ To use this, you want to start FvwmPerl as your very first command so that other commands may be asked to be preprosessed πŸ‘‘

ModuleSynchronize FvwmPerl

AddToFunc .
+ I SendToModule FvwmPerl preprocess -c $*

. Exec exec xterm -name xterm-%{++$i}%   # use unique name

. GotoDesk 0 %{ $[desk.n] + 1 }%         # go to next desk

. Exec exec %{ -x "/usr/bin/X11/aterm" ? "aterm" : "xterm" }% -sb

# center a window
Next (MyWindow) . Move \
  %{($WIDTH - $[w.width]) / 2}%p %{($HEIGHT - $[w.height]) / 2}%p

. Exec exec xmessage %{2 + 2}%           # simple calculator

. %{main::show_message(2 + 2, "Yet another Calculator"); ""}%

πŸ‘‘ ACTIONS πŸ‘‘

There are several actions that FvwmPerl may perform:

  • eval perl-code β€” evaluate a line of perl code. A special function cmd(command...) may be used in perl code to send commands back to fvwm. If the perl code contains an error, it is printed to the standard error stream with the [FvwmPerl][eval]: header prepended 😭
  • load file-name β€” load a file of perl code. If the file is not fully qualified, it is searched in the user directory $FVWM_USERDIR (usually ~/.fvwm) and the system wide data directory $FVWM_DATADIR πŸ’… A special function cmd(command...) may be used in perl code to send commands back to fvwm. If the perl code contains an error, it is printed to the standard error stream with the [FvwmPerl][load]: header prepended.
  • preprocess [-q|--quote char] [-c|--cmd] [line | file] β€” preprocess an fvwm config file, or (if --cmd is given) a line. This file contains lines that are not touched (usually fvwm commands) and specially preformatted perl code that is processed and replaced 🧚

Text enclosed in %{ ... }% delimiters, which may start anywhere on the line and end anywhere on the same or another line, is perl code. The quote parameter changes the perl code delimiters. If a single char is given, like '@', the delimiters are @{ ... }@. If the given quote is 2 chars, like <>, the quotes are <{ ... }> The perl code is substituted for the result of its evaluation. I.e. %{$a = c; +$a}% is replaced with d.

The evaluation is, unlike eval and load, done under the package PreprocessNamespace and without use strict, so you are free to use any variable names without fear of conflicts πŸ’– Just don't use uninitialized variables to mean undef or empty list (they may be in fact initialized by the previous preprocess action), and do a clean-up if needed. The variables and function in the main package are still available, like ::cmd() or ::skip(), but it is just not a good idea to access them while preprocessing 🚫

There is a special function include(file) that loads a file, preprocesses it and returns the preprocessed result. Avoid recursion ⚠️

If any embedded perl code contains an error, it is printed to the standard error stream and prepended with the [FvwmPerl][preprocess]: header. The result of substitution is empty in this case πŸ’€

The following variables may be used in the perl code: $USER, $DISPLAY, $WIDTH, $HEIGHT, $FVWM_VERSION, $FVWM_MODULEDIR, $FVWM_DATADIR, $FVWM_USERDIR 🌈

The following line based directives are recognized when preprocessing. They are processed after the perl code (if any) is substituted πŸ‘‘

πŸŽ€ line based directives πŸŽ€

  • %Repeat count β€” causes the following lines to be repeated count times.
  • %ModuleConfig module-name [ destroy ] β€” causes the following lines to be interpreted as the given module configuration. If destroy is specified the previous module configuration is destroyed first.
  • %Prefix prefix β€” prefixes the following lines with the quoted prefix.
  • %End any-optional-comment β€” ends any of the directives described above, may be nested.
%Prefix "AddToFunc SwitchToWindow I"
    Iconify off
    WindowShade off
    Raise
    WarpToWindow 50 50
%End

%ModuleConfig FvwmPager destroy
    Colorset 0
    Font lucidasans-10
    DeskTopScale 28
    MiniIcons
%End ModuleConfig FvwmPager

%Prefix "All (MyWindowToAnimate) ResizeMove "
100 100 %{($WIDTH - 100) / 2}% %{($HEIGHT - 100) / 2}%
%Repeat %{$count}%
br w+2c w+2c w-1c w-1c
%End
%Repeat %{$count}%
br w-2c w-2c w+1c w+1c
%End
%End Prefix
  • export [func-names] β€” send to fvwm the definition of shortcut functions that help to activate different actions of the module (i.e. eval, load and preprocess). 🫢

Function names (func-names) may be separated by commas or/and whitespace. By default, two functions Eval and . are assumed.

The actual action defined in a function is guessed from the function name if possible, where function name . is reserved for the preprocess action ✨

For example, any of these two fvwm commands

SendToModule MyPerl export PerlEval,PP
FvwmPerl --export PerlEval,PPMyPerl

define the following two shortcut functions:

DestroyFunc PerlEval
AddToFunc I SendToModule MyPerl eval $*
DestroyFunc PP
AddToFunc I SendToModule MyPerl preprocessc-c $*

These 4 actions may be requested in one of 3 ways: 1) in the command line when FvwmPerl is invoked (in this case FvwmPerl is short-lived unless --stay or --export is also given), 2) by sending the corresponding message in fvwm config using SendToModule, 3) by calling the corresponding perl function in perl code.

✨ FUNCTIONS ✨

okay bestie, your perl code can call these bad boys directly:

  • cmd($fvwm_command) β€” with eval or load, this sends the string $fvwm_command straight back to fvwm. With preprocess, it appends the string $fvwm_command onto the output of the embedded perl code 🫢 (same function name, whole different job depending on mode, iykyk)
  • do_eval($perl_code) β€” literally the same thing as the eval functionality on the string $perl_code, which we already talked about above πŸ’…
  • load($filename) β€” same as the load functionality on the file $filename, described above. periodt.
  • preprocess(@params, ["-c $command"] [$filename]) β€” does exactly what preprocess does, with the parameters you give it plus the file $filename, as described above ✨
  • export($func_names, [$do_unexport]) β€” equivalent to the export functionality with the given $func_names, described above. It can also unexport those function names if the second parameter is true πŸ”₯ Function names need to be separated by commas or/and whitespace. And if $func_names is empty, the functions Eval and . are assumed πŸ‘‘
  • stop() β€” kills the module. bye bestie πŸ’€
  • skip() β€” skips the rest of the event callback code, so the module goes back to just chillin' and listening for new module events 😌
  • unlock() β€” unsynchronizes the event callback from fvwm. this is lowkey useful for dodging deadlocks: normally fvwm straight-up kills a non-responding module if the event callback hasn't finished within ModuleTimeout seconds, and this prevents that πŸ™ˆ Check the example β€” it makes FvwmPerl pause its execution for one minute:
SendModule FvwmPerl eval unlock(); sleep(60);

But fr fr, verify there's no way a new message gets sent by fvwm while the module is busy and fvwm stays locked on that new message for too long. If you need long-lasting operations, look at the detach solution instead πŸ‘€

  • detach() β€” forks and detaches the rest of the event callback code from the main process πŸ¦‹ This may be useful to prevent the module from being killed if its event callback is gonna take a long while and it can finish in the detached child. The detached child may still send commands to fvwm (but don't rely on that), and it can't receive events, obviously β€” it exits immediately once the callback execution is done. If you use detach(), it's better to only send commands to fvwm from one process (either the main one or the detached one); doing otherwise may often cause conflicts 😭
  • show_message($msg, $title[, $use_stderr_too=1]) β€” pops up a dialog window with the given message, using whichever X tool it can find on the system πŸ’– For more info, see FVWM::Module::Toolkit::show_message

πŸ’œ VARIABLES πŸ’œ

There are several global variables in the main namespace that your perl code is welcome to use:

$a, $b, ... $h @a, @b, ... @h %a, %b, ... %h

They're all initialized to the empty value, and you can use them to store state between different calls to FvwmPerl actions (eval and load) πŸŽ€

If you want more readable variable names, either write no strict 'vars'; at the start of every perl code, or use a hash for it, like:

$h{id} = $h{first_name} . " " . $h{second_name}

or use a package name, like:

@MyMenu::terminals = qw( xterm rxvt );
$MyMenu::item_num = @MyMenu::terminals;

There may be a configuration option to turn strictness on and off πŸ‘‘ (may be, bestie, don't come for me)


πŸ“¬ MESSAGES πŸ“¬

FvwmPerl can receive messages with the fvwm command SendToModule. The names, meanings and parameters of the messages are the same as the corresponding actions described above ✨

On top of that:

  • a message stop makes the module quit 🫢
  • a message unexport [func-names] undoes the effect of export, described in the ACTIONS section πŸ’…
  • a message dump dumps the contents of the changed variables β€” well, not yet πŸ™ˆ (the man page said so, not me)

🌈 EXAMPLES 🌈

A lil simple test to vibe check everything:

SendToModule FvwmPerl eval $h\{dir} = $ENV\{HOME}
SendToModule FvwmPerl eval load($h\{dir} . "/test.fpl")
SendToModule FvwmPerl load $[HOME]/test.fpl
SendToModule FvwmPerl preprocess config.ppp
SendToModule FvwmPerl export Eval,PerlEval,PerlLoad,PerlPP
SendToModulecFvwmPerl unexport PerlEval,PerlLoad,PerlPP
SendToModule FvwmPerl stop

(yes, SendToModulecFvwmPerl up there is exactly what the page says β€” copy it character for character at your own risk, bestie πŸ’€)

Here's the main-character example: handling root backgrounds in fvwmrc. All of these commands can go in StartFunction πŸ’–

Module FvwmPerl --export PerlEval

# find all background pixmaps for a later use
PerlEval $a = $ENV\{HOME} . "/bg"; \
   opendir DIR, $a; @b = grep \{ /xpm$/ } readdir(DIR); closedir DIR

# build a menu of background pixmaps
AddToMenu MyBackgrounds "My Backgrounds" Title
PerlEval foreach $b (@b) \
   { cmd("AddToMenu MyBackgrounds $b Exec fvwm-root $a/$b") }

# choose a random background to load on start-up
PerlEval cmd("AddToFunc \
    InitFunction + I Exec exec fvwm-root $a/" . $b[int(random(@b))])

πŸ¦‹ ESCAPING πŸ¦‹

SendToModule, just like literally any other fvwm command, expands a bunch of dollar-prefixed variables πŸ’€ and that clashes with the dollars perl uses. No worries though β€” you can dodge it by prefixing SendToModule with a leading dash. In each pair below, the two lines are equivalent ✨

SendToModule FvwmPerl eval $$d = "$[DISPLAY]"
-SendToModule FvwmPerl eval $d = "$ENV\{DISPLAY}"
SendToModule FvwmPerl eval \
    cmd("Echo desk=$d, display=$$d")
SendToModule FvwmPerl preprocess -c \
    Echo desk=%("$d")%, display=%\{$$d}%

Another solution to avoid escaping special symbols like dollars and backslashes is to create a perl file in ~/.fvwm and then load it:

SendToModule FvwmPerl load build-menus.fpl

And if you need to preprocess one command that starts with a dash, you should precede it using "-- 2. πŸ‘‘

# this prints the current desk, i.e. "0"
SendToModule FvwmPerl preprocess -c Echo "$%\{$a = "c"; ++$a}%"

# this prints "$d"
SendToModule FvwmPerl preprocess -c -- -Echo "$%\{"d"}%"

# this prints "$d" (SendToModule expands $$ to $)
SendToModule FvwmPerl preprocess -c -- -Echo "$$%\{"d"}%"

# this prints "$$d"
-SendToModule FvwmPerl preprocess -c -- -Echo "$$%\{"d"}%"

And again, for real: it's suggested you put your command(s) into a file and preprocess the file instead πŸ™


⚠️ CAVEATS ⚠️

FvwmPerl is written in perl and deals with perl, so it follows that famous perl motto: There's more than one way to do it β€” so bestie, the choice is yours πŸ’…

Here are more pairs of equivalent lines:

Module FvwmPerl --load "my.fpl" --stay
Module FvwmPerl -e load("my.fpl") -s

SendToModule FvwmPerl preprocess --quote @ my.pp
SendToModule FvwmPerl eval preprocess(\{quote => @}, "my.ppp");
⚠️ Warning: you may affect the way FvwmPerl works by evaluating appropriate perl code. This is considered a feature, not a bug πŸ’€ But please don't do this β€” write your own fvwm module in perl instead. no cap.

πŸ‘€ SEE ALSO πŸ‘€

The fvwm (1) man page describes all the available commands πŸ“–

Basically, in your perl code you may use any function or class method from the perl library installed with fvwm β€” go check the man pages of the perl packages General::FileSystem, General::Parse and FVWM::Module ✨


🌸 AUTHOR 🌸

Mikhael Goikhman migo@homemail.com πŸ’–


okay that's the whole page, we ate and left no crumbs πŸ‘‘ this was FVWMPERL(1) from 2026-07-31 β€” go forth and preprocess, bestie, you've got this πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from