how to check if a certain window already exists?

Hello,

I have a fvwmscript that displays an icon. When I click on it, it opens a terminal and starts a program in it.
If I click on it again, it starts the program again. This is not what I want.
I want the script to check if the window is already open. If it is already open, it should raise the window, otherwise it should start the program.

how do I check if a certain window already exists?

thanks in advance

Johan

You want to call a function within the “Do {…}” command of the SingleClic event on the FvwmScript which looks something like this:

DestroyFunc LimitApplication
AddToFunc   LimitApplication
+ I Any (name_of_app, CurrentDesk) Raise
+ I TestRc (NoMatch) None (name_of_app, CurrentDesk) Exec exec name_of_app

Clearly you would replace ‘name_of_app’ with the name of the program you’re checking for.

HTH,

– Thomas Adam

thanks. I think this is what I need, but how do I call such a function, located somewhere in my config, from a fvwmscript.

I tried

Do{LimitApplication}

and

Do{exec LimitApplication}

but these don’t seem to work. I’m new to this and I only looked at some of the scripts on this forum, but could find the answer.

thanks in advance

Johan

Of course it works – I suspect your script is flawed. Here’s a contrived
example:

WindowTitle {PressMeExample}
WindowSize 100 32 
Font "xft:monospace:size=12"

Init
 Begin
End

Widget 1
Property 
 Size 34 6
 Position 1 1
 Flags NoReliefString
 Type PushButton
 Title {Press Me}
Main
 Case message of
  SingleClic :
  Begin
    Do {FvwmTitleRxvt} 
  End
End
End

Note the Do {} command is bound inside the single click of the button
widget. The function it is calling looks like this:

DestroyFunc FvwmTitleRxvt
AddToFunc   FvwmTitleRxvt
+ I Exec exec rxvt

If you’re still having problem, paste your entire script, and not some
random portion you think might pertain to your problem. In isolating the
area you think is not working, you’re not putting it into its in-situ
context.

– Thomas Adam

ok, got it almost working. There was a typo somewhere :blush:

The application now only opens if it is not open already. But when I click on the button again, the program should be raised (or closed) but that doesn’t seem to work.

this is the function:

DestroyFunc showplaylist
AddToFunc showplaylist
+ I Any (ncmpc, CurrentDesk) Raise
+ I TestRc (NoMatch) None (ncmpc, CurrentDesk) Exec exec $[TermName] -tr -bg black -fg white -trsb -sh 45 +sb -e ncmpc -m

it is being called via a Do{showplaylist} is a fvwmscript

I have no idea why it doesn’t work. In case it does matter, I use 4 desks of 1 page.

if I switch to another desk while ncmpc is open, it is opened again on the other desk. can this be changed to move the already existing instance to the other desk?

The “problem” is with “Any” which runs in a different context. Change it to “All”. (It runs in the context of the root window, so it might not do what you want it to).

You can use something like this:

All (ncmpc, !CurrentDesk) MoveToDesk $[desk.n]

– Thomas Adam