Subject: FVWM: Function to conditionally popup a window

From: stu <[email-masked]>
Date: Wed, 26 May 2004 14:24:19 +0200

Hi everyone

I have an app - multi-gnome-terminal - that can be started up in two
modes - 'factory' or 'client'. I want the first instance started of this
app to always be the 'factory', and all other instances to be the
'clients' ( doing it this way reduces memory usage ).

Unfortunately, this app is not intuitive enough to start a 'factory' if
one doesn't exist, and to connect to one if it does, with the same
command. Therefore I need to write a function to invoke this app that
checks if the 'factory' is running, and invokes it if it is not, and
invokes the 'client' if the factory is running ie

if (an instance of multi-gnome-terminal is running)
   # Start client
   Exec exec multi-gnome-terminal --use-factory
else
   # Start factory
   Exec exec multi-gnome-terminal --start-factory-server
fi

xwininfo gives the following :

xwininfo: Window id: 0x1e00011 "MGT - [ 1-Shell ]"

so, in an attempt to begin solving this, I created the following
function :

DestroyFunc FuncStartMGT
AddToFunc   FuncStartMGT
+ I WindowId $0 ("MGT*") Exec exec multi-gnome-terminal --use-factory

I use the * above because the name of this window changes, but always
begins with MGT. This would hopefully start my 'client' if an instance
of multi-gnome-terminal was already started. Unfortunately this does not
work.

I also tried this line in the function above to start the 'factory' if
no instance of multi-gnome-terminal was running :

+ I WindowId $0 ("MGT") (!CurrentGlobalPageAnyDesk)     Exec exec
multi-gnome-terminal --start-factory-server

This doesn't work either. 

I'm considering using PipeRead to call a script that does a ps to check
for an instance of multi-gnome-terminal, and that returns the applicable
parameters, but I was wondering if there was a native fvwm solution to
replicate the pseudo-code 'if' statement above?

BTW I'm running fvwm 2.5.8.

Thanks
-- 
Stuart Logie
Programmer

UNIVERSAL COMPUTER SERVICES (PTY) LTD
   
Powered by Debian GNU/Linux - testing/unstable

--
Visit the official FVWM web page at <URL: http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm" in the body of a
message to [email-masked].
To report problems, send mail to [email-masked].

---

From: Tavis Ormandy <[email-masked]>
Date: Wed, 26 May 2004 14:02:16 +0100

>    Exec exec multi-gnome-terminal --start-factory-server

AddToFunc StartMgt
+ I Any (MGT) Exec exec multi-gnome-terminal --use-factory
+ I TestRc (NoMatch) Exec exec multi-gnome-terminal --start-factory-server

or alternatively, None (MGT) Exec...

-- 
-------------------------------------
[email-masked] | finger me for my gpg key.
-------------------------------------------------------

---

From: Scott Smedley <[email-masked]>
Date: Thu, 27 May 2004 00:14:04 +1000

Hi Stuart,

: Therefore I need to write a function to invoke this app that
: checks if the 'factory' is running, and invokes it if it is not, and
: invokes the 'client' if the factory is running

This should work, but I haven't tested it:

AddToFunc FuncStartMGT
+ I Any (MGT*) Exec exec multi-gnome-terminal --use-factory
+ I None (MGT*) Exec exec multi-gnome-terminal --start-factory-server

: I'm considering using PipeRead to call a script that does a ps to check
: for an instance of multi-gnome-terminal, and that returns the applicable
: parameters

Yeah, that would work too:

PipeRead `if /sbin/pidof multi-gnome-terminal >& /dev/null ; then echo Exec exec  multi-gnome-terminal --use-factory ; else echo Exec exec multi-gnome-terminal --start-factory-server ; fi`

SCoTTie! :)

---

From: stu <[email-masked]>
Date: Wed, 26 May 2004 16:07:41 +0200

On Wed, 26 May 2004 14:02:16 +0100

> + I TestRc (NoMatch) Exec exec multi-gnome-terminal

Thanks Tavis. I added a * to (MGT) and it works perfectly.

- -- 
Stuart Logie
Programmer

---

From: Phil Stracchino <[email-masked]>
Date: Wed, 26 May 2004 14:10:43 -0400

>    Exec exec multi-gnome-terminal --start-factory-server

Have you considered using a wrapper script?  This is what I do with
Mozilla.  If there is no Mozilla process running, my wrapper launches
Mozilla; if Mozilla is already running, then the wrapper sends a command
to the running Mozilla process using the -remote interface to perform
the requested action.

-- 
 .*********  Fight Back!  It may not be just YOUR life at risk.  *********.
 : phil stracchino : unix ronin : renaissance man : mystic zen biker geek :
 :  [email-masked][email-masked][email-masked]  :
 :   2000 CBR929RR, 1991 VFR750F3 (foully murdered), 1986 VF500F (sold)   :
 :    Linux Now!   ...Because friends don't let friends use Microsoft.    :
--
Visit the official FVWM web page at <URL: http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm" in the body of a
message to [email-masked].
To report problems, send mail to [email-masked].

---

From: stu <[email-masked]>
Date: Thu, 27 May 2004 12:49:50 +0200

On Wed, 26 May 2004 14:10:43 -0400
Phil Stracchino <[email-masked]> wrote:

> > modes - 'factory' or 'client'. I want the first instance started of
> > this app to always be the 'factory', and all other instances to be
> > the'clients' ( doing it this way reduces memory usage ).
> > 
> > Unfortunately, this app is not intuitive enough to start a 'factory'
> > if one doesn't exist, and to connect to one if it does, with the
> > same command. Therefore I need to write a function to invoke this
> > app that checks if the 'factory' is running, and invokes it if it is
> > not, and invokes the 'client' if the factory is running ie
> > 
> Mozilla; if Mozilla is already running, then the wrapper sends a
> command to the running Mozilla process using the -remote interface to
> perform the requested action.

I did try that. Didn't succeed but was getting there before I adopted
this solution below, provided by Tavis :

AddToFunc StartMgt
+ I Any (MGT*)       Exec exec multi-gnome-terminal --use-factory
+ I TestRc (NoMatch) Exec exec multi-gnome-terminal \
                                           --start-factory-server

This works very well BUT, *blush* I have since discovered that if one
starts MGT like this :

multi-gnome-terminal --start-factory-server --use-factory

it IS intuitive enough to figure out what to do. Pity the man page
makes this fact as obscure as possible without hiding it completely.

Still, a good fvwm learning experience once again :)

- -- 
Stuart Logie
Programmer