Problem with applications which have a system tray applet and secondary windows

Ingo Klöcker kloecker at
Sun Dec 7 22:58:35 GMT 2003

On Sunday 07 December 2003 19:24, David Faure wrote:
> On Sunday 07 December 2003 19:13, Ingo Klöcker wrote:
> > Hi!
> >
> > The situation (also see
> > KMail's (or Kontact's) main window is hidden (because the user hid
> > it by clicking on the system tray applet), but a secondary window
> > is still visible (e. g. a composer window or a separate message
> > viewer window). If the user now closes the secondary window then
> > the last visible window has been closed. Therefore in
> > KMainWindow::closeEvent() first queryExit() and then kapp->deref()
> > is called. IMO this is wrong. All applications which have a system
> > tray applet (another example is KSirc) have to invent complicated
> > workarounds for this "feature" in order to prevent itself from
> > exiting.
> >
> > One solution would be to not only look for visible KMainWindows but
> > also for a KSystemTray. If a KSystemTray is found then queryExit()
> > (and later kapp->deref()) shouldn't be called from
> > KMainWindow::closeEvent(). I realize that such a change isn't
> > possible before KDE 4.0.
> Why not simply call kapp->ref() from the systemtray (your derived
> class for now, the base one in kde-4 maybe), and deref in the dtor?
> Then the user has to close the systray thingie by whichever way,
> before the process exits.

Hah! I'm glad I'm not the only one that makes this mistake. That's what 
I tried first after I found out about kapp->ref(). But it doesn't work. 
Now, think again and tell me why it won't work. ;-)

Hint: kapp->deref() is called each time a last visible window is closed. 
And you can close a last visible window more than once.

> > Another solution would be to allow applications which know much
> > better than KMainWindow when they should be exited to disable the
> > automatism in KMainWindow. Something like
> > KMainWindow::setDontExitIfLastWindowIsClosed( bool ).
> This exists already, it's called kapp->ref().

I wished it was that easy. :-(

> > Furthermore I had to look at the implementation of KMainWindow in
> > order to find out what to do. That's not what application
> > programmers should have to do. They should only have to read the
> > API documentation.
> The API documentation of kapp ref/deref is quite clear .... but you
> need to know it exists, of course.

And that's the problem. It would help if it was mentioned in the 
documentation of KMainWindow together with a sentence that explains 
that an application is exited automatically if the last window is 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: signature
URL: <>

More information about the kde-core-devel mailing list