Discussion:
FVWM: Function To Manage FvwmButtons Instances
Jamie Griffin
2014-08-16 07:05:11 UTC
Permalink
Hi, I wonder if someone might be able to help me with a function i'm
trying to create.

I have two fvwmbuttons instances, a taskbar at the top of screen and a
dock at the bottom. I don't really want to use both at the same time but
I do want to be able to switch between the two.

So, I would like the function to stop the currently open instance and
start the other and have that bound to a single key stroke or menu option.

What I've got so far is two functions: one that checks the top taskbar,
stops it if it's open and then opens the bottom dock; the other function
does the same but for the other fvwmbuttons dock. Here they are:

DestroyFunc OpenDock
AddToFunc OpenDock
+ I All (Panel) Close
+ I TestRc (NoMatch) KillModule Panel
+ I TestRc (Match) Module FvwmButtons Dock -g +300-0

DestroyFunc OpenPanel
AddToFunc OpenPanel
+ I All (Dock) Close
+ I TestRc (NoMatch) KillModule Dock
+ I TestRc (Match) Module FvwmButtons Panel -g $[vp.width]x24+0+0

The problem with this approach is I have to have them bound to separate
key strokes. When I first create the keybindings it's possible I might
forget which one is which and so if I press the wrong one, it doesn't
handle that well. I'd much prefer it to be bound to a single key stroke
and have it check which instance is open, then close the open
fvwmbuttons and start the other, as I mentioned.

I'd be very grateful if anyone could offer a solution or some help.

Best wishes, Jamie.
Dominik Vogt
2014-08-16 07:40:26 UTC
Permalink
Post by Jamie Griffin
What I've got so far is two functions: one that checks the top
taskbar, stops it if it's open and then opens the bottom dock; the
other function does the same but for the other fvwmbuttons dock.
DestroyFunc OpenDock
AddToFunc OpenDock
+ I All (Panel) Close
+ I TestRc (NoMatch) KillModule Panel
Is there a specific reason why you try to kill the module in two
different ways? The first line might also kill other windows.
Anyway, for the scripting you might want to give the modules a
unique name.
Post by Jamie Griffin
+ I TestRc (Match) Module FvwmButtons Dock -g +300-0
DestroyFunc OpenPanel
AddToFunc OpenPanel
+ I All (Dock) Close
+ I TestRc (NoMatch) KillModule Dock
+ I TestRc (Match) Module FvwmButtons Panel -g $[vp.width]x24+0+0
The problem with this approach is I have to have them bound to
separate key strokes. When I first create the keybindings it's
possible I might forget which one is which and so if I press the
wrong one, it doesn't handle that well. I'd much prefer it to be
bound to a single key stroke and have it check which instance is
open, then close the open fvwmbuttons and start the other, as I
mentioned.
I'd be very grateful if anyone could offer a solution or some help.
You can use a wrapper function:

DestroyFunc ClosePanelOpenDock
AddToFunc ClosePanelOpenDock
+ I All (Panel) Close
...

(Better use killmodule instead of close.)

DestroyFunc CloseDockOpenPanel
AddToFunc CloseDockOpenPanel
+ I All (Dock) Close
...

DestroyFunc SwitchPanelOrDock
AddToFunc SwitchPanelOrDock
+ I Next (Panel) ClosePanelOpenDock
+ I TestRc (nomatch) CloseDockOpenPanel

key f1 a n switchpanelordock

As a little example for advanced scripting in complex functions:
THere is a function in my config that (1) starts a certain
application if it's not already running, (2) closes it if it's
running, on the current page and not iconified, shaded etc., (3)
makes the window visible on the current page if the application is
running but not on the current page, or iconified, shaded etc.

#//
#// Application toggling function
#//
#// first argument is the window name, second argument is the command to start
#// the application.
AddToFunc ToggleWindow
+ I None ($$0, CirculateHit) $$1
+ I TestRc (Match) Break
+ I Next (currentpage, visible, !iconic, $$0, CirculateHit) Close
+ I TestRc (Match) Break
+ I Next ($$0, CirculateHit) Function MakeVisible

AddToFunc MakeVisible
+ I MoveToDesk
+ I MoveToPage
+ I MoveToScreen
+ I Iconify off
+ I WindowShade off
+ I Raise

Example uses:

AddToFunc ToggleFvwmConsole
+ I ToggleWindow FvwmConsole "Module FvwmConsole"

More complex example:

AddToFunc RunXMessages
+ I Exec rxvt -geometry -0-0 -T XMessages -n XMessages -e tail -f ~/.X.err

AddToFunc ToggleXMessages
+ I ToggleWindow XMessages "Function RunXMessages"

Ciao

Dominik ^_^ ^_^
--
Dominik Vogt
Jamie Griffin
2014-08-16 08:50:15 UTC
Permalink
Post by Dominik Vogt
AddToFunc ToggleWindow
+ I None ($$0, CirculateHit) $$1
+ I TestRc (Match) Break
+ I Next (currentpage, visible, !iconic, $$0, CirculateHit) Close
+ I TestRc (Match) Break
+ I Next ($$0, CirculateHit) Function MakeVisible
AddToFunc MakeVisible
+ I MoveToDesk
+ I MoveToPage
+ I MoveToScreen
+ I Iconify off
+ I WindowShade off
+ I Raise
AddToFunc ToggleFvwmConsole
+ I ToggleWindow FvwmConsole "Module FvwmConsole"
AddToFunc RunXMessages
+ I Exec rxvt -geometry -0-0 -T XMessages -n XMessages -e tail -f ~/.X.err
AddToFunc ToggleXMessages
+ I ToggleWindow XMessages "Function RunXMessages"
Thanks Dominik, That's helpful. So, wrt to my function, it would look
like this:

DestroyFunc ClosePanelOpenDock
AddToFunc ClosePanelOpenDock
+ I All (Panel) KillModule
+ I TestRc (Match) Module FvwmButtons Dock -g +300-0

DestroyFunc CloseDockOpenPanel
AddToFunc CloseDockOpenPanel
+ I All (Dock) KillModule
+ I TestRc (Match) Module FvwmButtons Panel -g $[vp.width]x24+0+0

DestroyFunc SwitchPanelOrDock
AddToFunc SwitchPanelOrDock
+ I Next (Panel) ClosePanelOpenDock
+ I TestRc (NoMatch) CloseDockOpenPanel

Aside from any errors, would you have any recommendations to improve
what i'm trying to achieve?

One idea I had was to have a form of some kind pop-up when I start the
fvwm session asking which, if any, panel/dock i'd like to start.
Dominik Vogt
2014-08-16 09:30:04 UTC
Permalink
Post by Jamie Griffin
Aside from any errors, would you have any recommendations to improve
what i'm trying to achieve?
In my eyes, this is a good approach. Well, in the CloseFooOpenBar
function you might want to check whether Bar is already open and
only start it if it's not.

+ I none (Bar) <command to start Bar>

This way you can also call the function elsewhere without creating
duplicate instances of the dock or panel, e.g. when you restart
fvwm.
Post by Jamie Griffin
One idea I had was to have a form of some kind pop-up when I start
the fvwm session asking which, if any, panel/dock i'd like to start.
This will probably annoy you very quickly. Just choose a default
you want and start that during fvwm startup. If it's not what you
want sometimes, just press the key to switch.

Ciao

Dominik ^_^ ^_^
--
Dominik Vogt
Jamie Griffin
2014-08-16 11:11:28 UTC
Permalink
Post by Dominik Vogt
Post by Jamie Griffin
Aside from any errors, would you have any recommendations to improve
what i'm trying to achieve?
In my eyes, this is a good approach. Well, in the CloseFooOpenBar
function you might want to check whether Bar is already open and
only start it if it's not.
+ I none (Bar) <command to start Bar>
This way you can also call the function elsewhere without creating
duplicate instances of the dock or panel, e.g. when you restart
fvwm.
Post by Jamie Griffin
One idea I had was to have a form of some kind pop-up when I start
the fvwm session asking which, if any, panel/dock i'd like to start.
This will probably annoy you very quickly. Just choose a default
you want and start that during fvwm startup. If it's not what you
want sometimes, just press the key to switch.
Ciao
Dominik ^_^ ^_^
Hi,

Thanks again for your help and suggestions. I got it working by swapping
out Next with None in the wrapper function.

One thing i've considered is, having changed my taskbar/panel/dock if I
want to keep that layout for next session could this be easily
integrated with the FvwmSaveDesk module?
Dominik Vogt
2014-08-16 12:45:36 UTC
Permalink
Post by Jamie Griffin
Post by Dominik Vogt
Post by Jamie Griffin
Aside from any errors, would you have any recommendations to improve
what i'm trying to achieve?
In my eyes, this is a good approach. Well, in the CloseFooOpenBar
function you might want to check whether Bar is already open and
only start it if it's not.
+ I none (Bar) <command to start Bar>
This way you can also call the function elsewhere without creating
duplicate instances of the dock or panel, e.g. when you restart
fvwm.
Post by Jamie Griffin
One idea I had was to have a form of some kind pop-up when I start
the fvwm session asking which, if any, panel/dock i'd like to start.
This will probably annoy you very quickly. Just choose a default
you want and start that during fvwm startup. If it's not what you
want sometimes, just press the key to switch.
Thanks again for your help and suggestions. I got it working by
swapping out Next with None in the wrapper function.
Oh, I meant you should an additional "None" in the inner function
so that you can call the inner functions without the wrapper at
startup.
Post by Jamie Griffin
One thing i've considered is, having changed my taskbar/panel/dock
if I want to keep that layout for next session could this be easily
integrated with the FvwmSaveDesk module?
FvwmSaveDesk hasn't been maintained in decades, you should rather
not use it. But you can easily do something like

.fvwm2rc:

Read $HOME/.fvwm/setup_dock_or_panel

Then add

addtofunc closedockopenpanel
...
+ i exec exec echo clodedockopenpanel > $HOME/.fvwm/setup_dock_or_panel

And the other way round in the other function. But make sure that
you don't use a file in a publicly writeable location because then
someone else could put his own fvwm commands in there.

Ciao

Dominik ^_^ ^_^
--
Dominik Vogt
Jamie Griffin
2014-08-16 09:29:38 UTC
Permalink
Post by Jamie Griffin
+ I TestRc (NoMatch) KillModule Dock
I've had a go at using your suggestion but it does not work for me?
Loading...