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

David Faure faure at kde.org
Sun Dec 7 18:24:06 GMT 2003


On Sunday 07 December 2003 19:13, Ingo Klöcker wrote:
> Hi!
> 
> The situation (also see http://bugs.kde.org/show_bug.cgi?id=69656):
> 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.

> 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().

> 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.

> But  
> unfortunately the documentation doesn't provide a solution for the 
> above problem. In fact the documentation even confuses the reader by 
> saying:
> "Called before the very last window is closed, either by the user or 
> indirectly by the session manager."
> This should be changed to the more correct
> "Called before the very last not hidden window is closed, either by the 
> user or indirectly by the session manager."

queryExit() has very blurred semantics, Seli wants to get rid of it,
I think, and I wouldn't mind either. All of this could be done without
queryExit() existing at all.

-- 
David FAURE, faure at kde.org, sponsored by Trolltech to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).




More information about the kde-core-devel mailing list