Re: Only one instance of a capplet should be allowed



On Tue, 2006-02-21 at 21:44 +0100, Jaap A. Haitsma wrote:
> Hi,
> 
> Currently it is possible to fire up a capplet multiple times. This can 
> be confusing for users [1]. It would be better if a capplet was launched 
> for the second time that the window of the currently running applet was 
> raised.
> 
> In [1] it is suggested to use a dbus server for this, but this seems 
> overkill to me.
> 
> Is there another easy way to do this?

Virtually all apps really should be single-instance (though they often
allow multiple document windows). There should be an API in GTK for it,
in fact ignoring back compat, single-instance ought to be the default
behavior for a GNOME application unless the programmer does something
special. Probably too late to make it the default, but it should at
least be easy.

Since arg parsing/handling is different for single-instance apps
(certain kinds of arg don't make sense for instances after the first,
such as --display) gtk could offer a gtk_init() alternative perhaps. The
API would let an app register a "new instance" callback essentially,
which would be called when the app is first launched, and also if it's
launched again and forwarded to an existing instance.

Something like:

int
new_launch_callback(int argc, char **argv)
{

}

int main(int argc, char **argv)
{
  gtk_set_instance_handler(new_launch_callback);

  return gtk_invoke_instance(&argc, &argv);
}

If the app is already running, then the callback is not invoked in this
process but instead invoked again in the existing process. If the app is
not already running, callback is invoked in the current process.

There are a variety of complexities, but this is a pretty longstanding
thing nobody has ever fixed... every app is hand-rolling some wacky
solution.

Havoc





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]