I have this script where I am trying to get the viewport width for an info window, but I can’t get it to work.
WindowTitle {Info}
WindowSize 160 300
Init
Begin
Set $width = (GetOutput {echo $[vp.width]} 1 -1)
ChangeTitle 1 $width
End
Widget 1
Property
Position 0 0
Size 120 20
Type ItemDraw
Flags NoReliefString
Title {}
Main
Case message of
SingleClic :
Begin
End
End
I have tried 4 different things in GetOutput, but none of them seem to work:
echo $[vp.width]
echo $vp.width
echo $($[vp.width])
echo $(perl -e 'printf($[vp.width])')
I tested the perl method with numbers, so I know that using inline perl works like in the CLI.
I am starting to believe that using the command expansion that is provided with fvwm isn’t possible to use in FvwmScript. If it isn’t, I would at least want to know
GetOutput
runs a command in a shell (not via fvwm), so the echo
command is just the shell echo, and the shell doesn’t know how to expand variables internal to fvwm’s variable expansion. I was looking through the FvwmScript
manual page, and didn’t see any way to send commands to fvwm directly, but you could do this via FvwmCommand
or FvwmPrompt
(depending on which one you have built).
So in theory you could call FvwmCommand 'Echo $[vp.width]'
(or FvwmPrompt
), to let fvwm expand the variable, but fvwm3 will output this to a logfile (only if logging is turned on), and then you’ll have to parse the tail of the log to get the value. (fvwm2 will output this to stderr which is often ~/.xsession-errors and you’ll still have to parse the file from that).
You might want to look into other xorg shell tools that allow you to get information about the current size of the view port. So maybe parsing the output of xrandr -q
would work better.
So what you’re saying is that the only way of doing this at the moment is through some hacky means, but that it should theoretically be possible?
Modules can’t expand fvwm variables. Note you could send the FvwmScript parameters, and thus when you launch the script from fvwm, expand the variable, FvwmScript ScriptName $[vp.width]
, and then use the parameter in the script.
Thanks for the idea. I think this will be my solution to this problem
Is there any way to mark this as solved?
This isn’t an issue but a discussion, just leave it for others, it will eventually lock itself after enough time has passed.
I never succeeded to send another parameter to FvwmScript than its Scriptname. But you can use echo to echo a var env into a script variable:
Set $SCRIPTWIDTH = (GetOutput {echo "$MYWIDTH"} 1 -1)
With fvwm variables like $vp.width, the issue is that echo into most (all?) user shells don’t understand their names and issue errors. In such cases, one can do:
Setenv MYWIDTH "$[vp.width]"
before running the script with a Module command.
When the variable is into the environment:
Set $SCRIPTWIDTH = {$MYWITH}
works too.