Need API for single instance apps (was Re: Only one instance of a capplet should be allowed)

On 2/21/06, Havoc Pennington <hp redhat com> wrote:
> 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.

One of those complexities is focus stealing prevention; this
hand-rolling of solutions for all single-instance apps (each and every
app I've looked at for this issue has had almost entirely different
code than the others[1]) is a pain and is why e.g. mozilla[2],
firefox[2], evolution[3] (and until recently yelp[4]), and probably
other apps are still buggy.  This is an area that I hear KDE has a
nice solution for, in a lib named something like KUniqueApp.  I agree
with Havoc that we really need something like this too[5].  It's
somewhere on my TODO list (along with individually fixing all those
other bugs in the footnotes of this email and a few dozen other
things), though my time is much more limited right now.  So I'm hoping
a hero steps up to the plate to do this for us.  *hint* *hint*  ;-) 
I'll be available for questions with the forwarding of
startup-notification information end of things if needed.  Also,
someone on IRC mentioned that Evince's code for this is really nice
and clean, and may be able to be used as a starting point.


[1] gnome-terminal, gedit, nautilus, epiphany/galeon, mozilla/firefox,
evolution, yelp, possibly others I'm forgetting
[5] We even have a bug about the need for such API:

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