Bug 56251 - libtaskmanager allocates kwin_module on load, making it rather hard to use -- w/ fix
Summary: libtaskmanager allocates kwin_module on load, making it rather hard to use --...
Status: RESOLVED FIXED
Alias: None
Product: kicker
Classification: Plasma
Component: general (show other bugs)
Version: unspecified
Platform: FreeBSD Ports FreeBSD
: NOR normal
Target Milestone: ---
Assignee: cbiffle
URL:
Keywords:
: 57230 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-03-22 20:04 UTC by cbiffle
Modified: 2003-04-14 20:58 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Patch to kdebase/kicker/taskmanager/taskmanager.cpp (855 bytes, patch)
2003-03-22 20:06 UTC, cbiffle
Details
Revision of earlier patch, now with comments. (855 bytes, patch)
2003-03-22 22:00 UTC, cbiffle
Details

Note You need to log in before you can comment on or make changes to this bug.
Description cbiffle 2003-03-22 20:04:42 UTC
Version:            (using KDE KDE 3.1)
Installed from:    FreeBSD Ports
Compiler:          gcc 3.2.2 
OS:          FreeBSD

I'm developing a program that uses libtaskmanager from kicker for task control and switching.  (It's a Pie-Menu replacement for the current Alt+Tab switcher, but that's irrelevant.)  When linking against libtaskmanager, whether or not I actually use it, I consistently get an error about creating a QPaintDevice without a QApplication.  This happens before my main() routine is even executed, and appears to be a result of something libtaskmanager is doing on load.

Glancing over the code, I noticed (on line 49 of kdebase/kicker/taskmanager/taskmanager.cpp) that a single instance of KWinModule was being allocated for the functions in the file.  Because this is being allocated globally, it's created on loading the library, before a client program can allocate a QApplication.  (There are ways around this, but they're more work than they're worth.)

The fix is simple: initialize the KWinModule pointer to NULL and use lazy creation in the TaskManager constructor.  This operates on one assumption, however: namely, that Task objects will never be allocated without an accompanying TaskManager.  The Task object code makes this same assumption, however, by not checking the TaskManager *parent for NULL, so I feel it's safe.

With this patch, arbitrary code is able to easily link to and use libtaskmanager to retrieve information about the windowed tasks on a KDE system.  (Though taskmanager.h has to be manually copied out of kdebase to make it useful -- why is this not installed?  Time for another bug!)

Patch attached.
Comment 1 cbiffle 2003-03-22 20:06:10 UTC
Created attachment 1218 [details]
Patch to kdebase/kicker/taskmanager/taskmanager.cpp

Adds lazy creation of kwin_module object.  Prevents it from being allocated
before linking apps can do their initialization.
Comment 2 John Firebaugh 2003-03-22 21:19:44 UTC
Thanks for the patch; looks good, please apply and update the comment above the declaration 
with the reasoning for the new behavior. 
Comment 3 cbiffle 2003-03-22 21:59:29 UTC
I've attached a new patch that revises the comments in the area to reflect the new behavior. 
Comment 4 cbiffle 2003-03-22 22:00:08 UTC
Created attachment 1219 [details]
Revision of earlier patch, now with comments.
Comment 5 John Firebaugh 2003-04-07 01:28:52 UTC
Subject: kdebase/kicker/taskmanager

CVS commit by firebaugh: 

Lazily allocate the kwin module.

CCMAIL: 56251-done@bugs.kde.org


  M +5 -2      taskmanager.cpp   1.59


--- kdebase/kicker/taskmanager/taskmanager.cpp  #1.58:1.59
@@ -47,9 +47,12 @@ template class QPtrList<Task>;
 // So, we'll leak a little memory, but it's better than crashing.
 // The real problem is that KWinModule should be a singleton.
-KWinModule* kwin_module = new KWinModule();
+KWinModule* kwin_module = NULL;
 
 TaskManager::TaskManager(QObject *parent, const char *name)
     : QObject(parent, name), _active(0), _startup_info( NULL )
 {
+    if ( kwin_module == NULL )
+        kwin_module = new KWinModule();
+
     KGlobal::locale()->insertCatalogue("libtaskmanager");
     connect(kwin_module, SIGNAL(windowAdded(WId)), SLOT(windowAdded(WId)));


Comment 6 Lubos Lunak 2003-04-14 20:58:36 UTC
*** Bug 57230 has been marked as a duplicate of this bug. ***