karm Library API Documentation

desktoptracker.cpp

00001 #include <algorithm>            // std::find
00002 
00003 #include "desktoptracker.h"
00004 
00005 DesktopTracker::DesktopTracker ()
00006 {
00007   // Setup desktop change handling
00008   connect( &kWinModule, SIGNAL( currentDesktopChanged(int) ),
00009            this, SLOT( handleDesktopChange(int) ));
00010 
00011   _desktopCount = kWinModule.numberOfDesktops();
00012   _previousDesktop = kWinModule.currentDesktop()-1;
00013   // TODO: removed? fixed by Lubos?
00014   // currentDesktop will return 0 if no window manager is started
00015   if( _previousDesktop < 0 ) _previousDesktop = 0;
00016 }
00017 
00018 void DesktopTracker::handleDesktopChange(int desktop)
00019 {
00020   desktop--; // desktopTracker starts with 0 for desktop 1
00021   // notify start all tasks setup for running on desktop
00022   TaskVector::iterator it;
00023 
00024   // stop trackers for _previousDesktop
00025   TaskVector tv = desktopTracker[_previousDesktop];
00026   for (it = tv.begin(); it != tv.end(); it++) {
00027     emit leftActiveDesktop(*it);
00028   }
00029 
00030   // start trackers for desktop
00031   tv = desktopTracker[desktop];
00032   for (it = tv.begin(); it != tv.end(); it++) {
00033     emit reachedtActiveDesktop(*it);
00034   }
00035   _previousDesktop = desktop;
00036 
00037   // emit updateButtons();
00038 }
00039 
00040 void DesktopTracker::startTracking()
00041 {
00042   int currentDesktop = kWinModule.currentDesktop() -1;
00043   // TODO: removed? fixed by Lubos?
00044   // currentDesktop will return 0 if no window manager is started
00045   if ( currentDesktop < 0 ) currentDesktop = 0;
00046 
00047   TaskVector &tv = desktopTracker[ currentDesktop ];
00048   TaskVector::iterator tit = tv.begin();
00049   while(tit!=tv.end()) {
00050     emit reachedtActiveDesktop(*tit);
00051     tit++;
00052   }
00053 }
00054 
00055 void DesktopTracker::registerForDesktops( Task* task, DesktopList desktopList)
00056 {
00057   // if no desktop is marked, disable auto tracking for this task
00058   if (desktopList.size()==0) {
00059     for (int i=0; i<16; i++) {
00060       TaskVector *v = &(desktopTracker[i]);
00061       TaskVector::iterator tit = std::find(v->begin(), v->end(), task);
00062       if (tit != v->end())
00063         desktopTracker[i].erase(tit);
00064         // if the task was priviously tracking this desktop then
00065         // emit a signal that is not tracking it any more
00066         if( i == kWinModule.currentDesktop() -1)
00067           emit leftActiveDesktop(task);
00068     }
00069 
00070     return;
00071   }
00072 
00073   // If desktop contains entries then configure desktopTracker
00074   // If a desktop was disabled, it will not be stopped automatically.
00075   // If enabled: Start it now.
00076   if (desktopList.size()>0) {
00077     for (int i=0; i<16; i++) {
00078       TaskVector& v = desktopTracker[i];
00079       TaskVector::iterator tit = std::find(v.begin(), v.end(), task);
00080       // Is desktop i in the desktop list?
00081       if ( std::find( desktopList.begin(), desktopList.end(), i)
00082            != desktopList.end()) {
00083         if (tit == v.end())  // not yet in start vector
00084           v.push_back(task); // track in desk i
00085       }
00086       else { // delete it
00087         if (tit != v.end()) // not in start vector any more
00088         {
00089           v.erase(tit); // so we delete it from desktopTracker
00090           // if the task was priviously tracking this desktop then
00091           // emit a signal that is not tracking it any more
00092           if( i == kWinModule.currentDesktop() -1)
00093             emit leftActiveDesktop(task);
00094         }
00095       }
00096     }
00097     startTracking();
00098   }
00099 }
00100 
00101 void DesktopTracker::printTrackers() {
00102   TaskVector::iterator it;
00103   for (int i=0; i<16; i++) {
00104     TaskVector& start = desktopTracker[i];
00105     it = start.begin();
00106     while (it != start.end()) {
00107       it++;
00108     }
00109   }
00110 }
00111 #include "desktoptracker.moc"
KDE Logo
This file is part of the documentation for karm Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:37:52 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003