Can fvwm limit application instantiation?

Hi –


I want to be able to limit the number of instances of an application, via FVWM, to only one instance. E.g., If an instance of an application already exists, then when a ‘new’ instance is selected, fvwm will simply bring the current instance into focus and not allow the creation of another instance. The problem that I have is the instantiation of these objects is happening through a third party application.

e.g., application foo has 2 buttons to launch applications A and B, the first time either button in foo is pressed, a new instance of A or B is created. the next time either button A or B is pressed in application foo, I want to know if fvwm can say “A-ha, A is already instantiated, let me bring that into focus for you…”

I don’t know if FVWM is even designed to do something like this, so I thought I would ask.


I think you can do something like this:

+ I Test (x app_name) Exec pidof app_name || exec app_name

Sure, something like this:

[code]AddToFunc StartOnce

  • I Any ($0) Next ($0) FlipFocus
  • I TestRc (NoMatch) Exec $0[/code]

Then you can do StartOnce mozilla or whatever.


Moderators: Please move this thread if it is no longer in the correct forum. If it is not, I apologize.

As I have spent more time looking at the problem I have of ‘controlling instantiation’ of an application, and limiting the number of instances of an application to 1 instance, I have decided to give a detailed explanation of my problem in hopes of someone having a good solution. I have not been clear enough in my previous posts.

Here is the best explanation I can give:

I have multiple applications controlled by FVWM. Some applications start at boot up time (lets call them primary apps), whereas others start only when needed. These secondary applications are my concern. I want to start up one of these secondary app’s via a third party application (not the FVWM).

EX: Foo is running via FVWM, I bring it into focus, and press a button on it that says, “turn on Sub_Foo” which starts up another application named Sub_Foo. This button that I pressed is not an FVWM button, it is a button within the Foo application (C, Java, whatever – it is just a button).

Now assigning this secondary application a desk to reside on, as well as some style about it is not the problem – I know how to do such a thing in .fvwm2rc. The problem that I have is as followsw:

The next time app Foo is brought into focus, and the Sub_Foo button is pressed, I want FVWM to dis-allow the instantiation of another Sub_Foo application, and simply bring the currently instantiated Sub_Foo into focus.

That is the whole thing (more or less). I just want FVWM to say, “let me check and see if there is another application with your name active… oops, there is one, let me bring it into focus”.

I just cannot seem to find a way to do so without using a button on the fvwm desktop. I need this type of functionality to be possible if Sub_Foo is started up by Foo, instead of the desktop (honestly, I don’t know if this is even possible).

It almost seems like the flow of control would go like this:

Xserver --> FVWM --> Foo --> FVWM --> Sub_Foo

And I just have the slightest idea how to do that, or if it is even possible.

If anyone has any ideas, please let me know.

It’ll do here.

OK, so some other application will be responsible for starting up an instance of these secondary applications…

Yep – that button will always remain so, unless you map it via FVWM, remember.

You’ll need to use FvwmEvent for this. I see some ‘suggestions’ have already been presented to you. Here’s mine:

DestroyModuleConfig FvwmEvent-subwins: *
*FvwmEvent-subwins: Cmd Function
*FvwmEvent-subwins: add_window runmyfunc

DestroyFunc myfunc
AddToFunc myfunc
+ I All (my_window, CurrentDesk) FlipFocus
+ I None (my_window) Exec exec my_window

Module FvwmEvent FvwmEvent-subwins

That (should) then check to see if a window is already present, and flipfocus, else it will launch it. Change to suit.

It won’t be – how would you know what your parent window was in this case? Think about why this is: if you operate X11 over a network, then the application might be anywhere.

The only time this is true, is when a window is transient.

But that’s how it works – any window that’s created always comes from FVWM in the end – how do you think the windows get their decoration? :slight_smile:

– Thomas Adam


I’m trying to incorporate FVWMEvent modules into my .fvwm2rc file and I’ve got a question.

To use an instance of FVWMEvent is it required that I assign/associate/link (whatever) the call/usage of that module to another FVWM Function?

For example, the following is some code that Thomas Adam (who knows everything about FVWM, I swear) recommended that I use to solve a problem I had:

DestroyModuleConfig FE-notab: *
*FE-notab: Cmd Function
*FE-notab: add_window SomeFunc

# Start the module next time fvwm reloads.
AddToFunc StartFunction I Module FvwmEvent FE-notab

-- and then add whatever body of code I want to SomeFunc, and 

the above code will ensure that:

So, my question is, is it necessary to link/assign all of my FVWMEvent instances in like manner to another function using the AddToFunc tag? I just don’t know, and thought I would ask.

Thanks again to Thomas Adam for all his help, and thanks in advance to anyone with any ideas.

  • Skender

Heh. I certainly don’t know everything — I just help out where I can.

How do you mean? What the module configuration for FvwmEvent as you have it there is doing, is running “SomeFunc” everytime a window is mapped to the Xserver. What you put in “SomeFunc” is down to you. You could simply have a line which calls another function (there are some dangers to this – I call it “Event-function-chaining”, and will leave that for another time). If you try and call more than one function using the same event though, only the LAST function listed will get used. You can’t call more than one function on the same event (UNLESS you use module aliasing — that is, have several instances of FvwmEvent runnning — but if you do this, you’ll get a race condition).

If, what you meant, was whether you’re able to use different events to call the same function, then yes. You can continue them:

*FE-notab: add_window SomeFunc
*FE-notab: configure_window SomeFunc

You’re quite welcome.

– Thomas Adam

Thanks for the explanation Thomas. After reading your comments, I think I have a problem with my current .fvwm2rc file, as well as my approach to using FVWMEvent modules, and could use ANYONES feedback. I have detailed the background to my question/problem, my question, and the code I have been trying below. Please feel free to post any questions/comment/rude remarks :slight_smile:.


I have 2 applications (both java apps, but the type of application is not the important part). Both applications are being ‘called’/’started’/whatever remotely via rshell – and when the ‘call’ arrives via rshell to my system (literally a startup command ‘usr/bin/fooApp/startFoo_A’ or ‘usr/bin/fooApp/startFoo_B’), I want to check and see if an instance of the application already exists (e.g., this start command has already been sent via rshell at least 1 time before). If an instance does not exist, I want FVWM to instantiate an instance, and switch the focus to this application (which will run on it’s own desktop) – if an instance does exist, FVWM should NOT create another instance, and just switch focus to the desired application (have the app gain focus and move to the app’s specific desktop). I hope that makes sense…


Since both of these applications are going to rely on FVWMEvent instances to tell FVWM :
“aha, we have a request for Foo_A (or Foo_B), lets check and see if an instance exists, and if so, switch focus and the desktop to Foo_A/B, if not, instantiate an instance and then switch focus and desk to Foo_A/B.”

Is it possible to do this in a single FVWMEvent module? If not, how could something like this be done? I’ve read through the FVWMEvent MAN page and I can’t find anything that even comes close to this idea.

I am limited to sending calls via rshell, and I really need to make this kind of thing work. Below is the code that I have written to date (using code ideas/suggestions I have received from helpful people here on the forum) to check for “Foo_A” but I don’t know if it is complete and currently, it is not functioning (which I am not sure why).

DestroyModuleConfig FvwmEvent-winfoo: *
*FvwmEvent-winfoo: Cmd Function
*FvwmEvent-winfoo: add_window FuncFoo

Destroy FuncFoo
AddToFunc FuncFoo
+ I FuncSwitchFocus "Foo_A"

    Destroy FuncSwitchFocus
    AddToFunc FuncSwitchFocus
    + I All ($$0, CirculateHit) Function HelpSwitchFocus
    + I None ($$0) Exec exec $$0

    Destroy HelpSwitchFocus
    AddToFunc HelpSwitchFocus
    + I GoToDesk 1 0
    + I Focus
    + I Maximize ewmhia 100 100 true

If anyone has any suggestions on how I can make this kind of thing work, specically for both a Foo_A and a Foo_B application and/or point out where I am going wrong in my FVWMEvent module, I would really, really appreciate it.

Thanks in advance,

If you wanted to post your fvwm2rc file, do so. I’m quite happy to take a look at it.

It does make sense, and you’ve been given two different solutions to achieve the goal.

You can do this two ways — and it depends on the event that’s generated, I suppose. In the general sense, all events that are generated via FVWM have a context associated with them — typically, they’re acted upon an application. Whenever an event is received via FvwmEvent for an application, the windowID is sent along with it to the underlying task that’s associated with the event. So, as has been demonstrated in the past:

*FE: Cmd Function

# Typically, this line is no longer needed.
*FE: PassID

*FE: add_window SomeFunc

Whenever a window is mapped to the Xserver, FvwmEvent realises this, and calls the function “SomeFunc” (this you already know). What happens then (as an implicit action) is that the WindowID is sent along to the function. Hence, our function might be:

DestroyFunc SomeFunc
AddToFunc SomeFunc
+ I WindowId $0 (....) [...]

But I am not understanding what it is the suggestions presented to you are not doing — are they somehow not working?

I must be misunderstanding you, Skender. The solutions already given should work.

I agree with the double “$$” — the interpolation will complete. You should note though, Skender, that there’s about a dozen ways one can approach the solution to this. As yet another variation upon a theme, try the following (I am unable to test this, being on Windows at the moment):

DestroyModuleConfig FvwmEvent-winfoo: *
*FvwmEvent-winfoo: Cmd Function
*FvwmEvent-winfoo: PassId
*FvwmEvent-winfoo: add_window FuncFoo

Destroy FuncFoo
AddToFunc FuncFoo
+ I None ($0, CurrentDesk) Exec exec Foo_A  
+ I TestRc (Match) Break
+ I Next ($0) FlipFocus

Playing about with the various commands often helps, I find. :slight_smile:

– Thomas Adam

Ok, so I’m lame…

I have been trying to get the FvwmEvent stuff to work, but the whole day I have been dealing with another (perhaps related?) oddity.

when I include a reference to my FvwmEvent instance in my StartFunction, the computer halts in boot up at an empty desktop (desk 0), and the mouse pointer turns into a wierd looking little Lion-looking thing… and this occurs ONLY when I include my reference to the FvwmEvent instance as so:

# FVWM Event functions
#DestoryModuleConfig FE-flipFoo: *
FE-flipFoo: Cmd Function
FE-flipFoo: PassId
FE-flipFoo: add_window FuncFlipFoo

Destroy   FuncFlipFoo
AddToFunc FuncFlipFoo
+ I Break
#+ I Next ($0) FlipFocus

# Startup Functions
DestroyFunc StartFunction
AddToFunc   StartFunction
+ I Module FvwmEvent FE-flipFoo
+ .....

as you can see, I tried removing any logic to the function FuncFlipFoo, and just placed a + I Break in there, but the pausing/stalling/hanging is still occuring, and I have no idea why this is happening…

any thoughts?

You’ve probably got a race-condition. What I would do, is comment out the module startup completely for now, and let FVWM load up as per nomal. Then what I would do to test it, is something like this:

DestroyModuleConfig FE-test: *
*FE-test: Cmd Function
*FE-test: add_window foofoo

DestroyFunc foofoo
AddToFunc foofoo
+ I Exec exec xmessage "Got a new window"

… and then start up an xterm one after the other, so you know it works. As for fixing it so that the module doesn’t load too early, you’re going to have to wait for a window to load. I suspect what’s happening is that you have several applications started up as FVWM loads? In which case, you can do something like this:

AddToFunctioon StartFunction
+ I Exec exec some_app
+ I Wait some_app
+ I Next (some_app) Module FvwmEvent FE-flipFoo

… or some such. Note that you can always tell FVWM to “unpause” itself, by pressing CTRL-ALT-ESC.

– Thomas Adam