24 #include <tdeglobal.h>
25 #include <tdelocale.h>
27 #include <tdeconfig.h>
28 #include <kiconloader.h>
29 #include <twinmodule.h>
36 #include <X11/Xutil.h>
38 #include "taskmanager.h"
39 #include "taskmanager.moc"
41 template class TQPtrList<Task>;
49 KWinModule* twin_module = 0;
51 TaskManager::TaskManager(TQObject *parent,
const char *name)
52 : TQObject(parent, name), _active(0), _startup_info( NULL )
55 twin_module =
new KWinModule();
58 connect(twin_module, TQT_SIGNAL(windowAdded(WId)), TQT_SLOT(windowAdded(WId)));
59 connect(twin_module, TQT_SIGNAL(windowRemoved(WId)), TQT_SLOT(windowRemoved(WId)));
60 connect(twin_module, TQT_SIGNAL(activeWindowChanged(WId)), TQT_SLOT(activeWindowChanged(WId)));
61 connect(twin_module, TQT_SIGNAL(currentDesktopChanged(
int)), TQT_SLOT(currentDesktopChanged(
int)));
62 connect(twin_module, TQT_SIGNAL(windowChanged(WId,
unsigned int)), TQT_SLOT(windowChanged(WId,
unsigned int)));
65 const TQValueList<WId> windows = twin_module->windows();
66 TQValueList<WId>::ConstIterator end( windows.end() );
67 for (TQValueList<WId>::ConstIterator it = windows.begin(); it != end; ++it )
71 WId win = twin_module->activeWindow();
72 activeWindowChanged(win);
77 TaskManager::~TaskManager()
81 void TaskManager::configure_startup()
83 TDEConfig c(
"tdelaunchrc",
true);
84 c.setGroup(
"FeedbackStyle");
85 if (!c.readBoolEntry(
"TaskbarButton",
true))
87 _startup_info =
new TDEStartupInfo(
true,
this );
88 connect( _startup_info,
89 TQT_SIGNAL( gotNewStartup(
const TDEStartupInfoId&,
const TDEStartupInfoData& )),
90 TQT_SLOT( gotNewStartup(
const TDEStartupInfoId&,
const TDEStartupInfoData& )));
91 connect( _startup_info,
92 TQT_SIGNAL( gotStartupChange(
const TDEStartupInfoId&,
const TDEStartupInfoData& )),
93 TQT_SLOT( gotStartupChange(
const TDEStartupInfoId&,
const TDEStartupInfoData& )));
94 connect( _startup_info,
95 TQT_SIGNAL( gotRemoveStartup(
const TDEStartupInfoId&,
const TDEStartupInfoData& )),
96 TQT_SLOT( gotRemoveStartup(
const TDEStartupInfoId& )));
97 c.setGroup(
"TaskbarButtonSettings" );
98 _startup_info->setTimeout( c.readUnsignedNumEntry(
"Timeout", 30 ));
103 for (
Task* t = _tasks.first(); t != 0; t = _tasks.next())
104 if (t->window() == w || t->hasTransient(w))
110 #define NET_ALL_TYPES_MASK (NET::AllTypesMask)
112 #define NET_ALL_TYPES_MASK (-1LU)
115 void TaskManager::windowAdded(WId w )
117 NETWinInfo info(tqt_xdisplay(), w, tqt_xrootwin(),
118 NET::WMWindowType | NET::WMPid | NET::WMState );
120 NET::WindowType windowType = info.windowType(NET_ALL_TYPES_MASK);
122 NET::WindowType windowType = info.windowType();
125 if (windowType != NET::Normal && windowType != NET::Override
126 && windowType != NET::Unknown && windowType != NET::Dialog)
129 if ((info.state() & NET::SkipTaskbar) != 0)
131 _skiptaskbar_windows.push_front( w );
135 Window transient_for_tmp;
136 if (XGetTransientForHint(tqt_xdisplay(), (Window) w, &transient_for_tmp))
138 WId transient_for = (WId) transient_for_tmp;
141 if (_skiptaskbar_windows.contains(transient_for))
145 if (transient_for != tqt_xrootwin() && transient_for != 0 )
150 if (t->window() != w)
166 void TaskManager::windowRemoved(WId w )
168 _skiptaskbar_windows.remove( w );
173 if (t->window() == w) {
178 if(t == _active) _active = 0;
183 t->removeTransient( w );
190 if( dirty & NET::WMState ) {
191 NETWinInfo info ( tqt_xdisplay(), w, tqt_xrootwin(), NET::WMState );
192 if ( (info.state() & NET::SkipTaskbar) != 0 ) {
194 _skiptaskbar_windows.push_front( w );
198 _skiptaskbar_windows.remove( w );
205 if(!(dirty & (NET::WMVisibleName|NET::WMName|NET::WMState|NET::WMIcon|NET::XAWMState|NET::WMDesktop)) )
216 if (dirty & NET::WMIcon)
221 if(dirty & (NET::WMDesktop|NET::WMState|NET::XAWMState))
225 void TaskManager::activeWindowChanged(WId w )
232 _active->setActive(
false);
241 _active->setActive(
false);
244 _active->setActive(
true);
250 void TaskManager::currentDesktopChanged(
int desktop)
255 void TaskManager::gotNewStartup(
const TDEStartupInfoId&
id,
const TDEStartupInfoData& data )
263 void TaskManager::gotStartupChange(
const TDEStartupInfoId&
id,
const TDEStartupInfoData& data )
265 for(
Startup* s = _startups.first(); s != 0; s = _startups.next()) {
266 if ( s->id() ==
id ) {
273 void TaskManager::gotRemoveStartup(
const TDEStartupInfoId&
id )
278 void TaskManager::killStartup(
const TDEStartupInfoId&
id )
281 for(s = _startups.first(); s != 0; s = _startups.next()) {
287 _startups.removeRef(s);
292 void TaskManager::killStartup(
Startup* s)
296 _startups.removeRef(s);
303 return twin_module->desktopName(desk);
308 return twin_module->numberOfDesktops();
313 if(!task)
return false;
315 for (TQValueList<WId>::ConstIterator it = twin_module->stackingOrder().fromLast();
316 it != twin_module->stackingOrder().end(); --it ) {
317 for (
Task* t = _tasks.first(); t != 0; t = _tasks.next() ) {
318 if ( (*it) == t->window() ) {
331 Task::Task(WId win,
TaskManager * parent,
const char *name) :
332 TQObject(parent, name),
333 _active(false), _win(win),
334 _lastWidth(0), _lastHeight(0), _lastResize(false), _lastIcon(),
335 _thumbSize(0.2), _thumb(), _grab()
338 _info = KWin::windowInfo(_win, 0, 0);
340 _info = KWin::info(_win);
343 _pixmap = KWin::icon(_win, 16, 16,
true);
347 TDEGlobal::instance()->iconLoader()->loadIcon(className().lower(),
348 TDEIcon::Small,TDEIcon::Small,
349 TDEIcon::DefaultState, 0,
true);
352 if (_pixmap.isNull())
353 _pixmap = SmallIcon(
"kcmx");
360 void Task::refresh(
bool icon)
363 _info = KWin::windowInfo(_win, 0, 0);
365 _info = KWin::info(_win);
370 _pixmap = KWin::icon(_win, 16, 16,
true);
375 TDEGlobal::instance()->iconLoader()->loadIcon(className().
lower(),
376 TDEIcon::Small, TDEIcon::Small, TDEIcon::DefaultState, 0,
true);
380 if (_pixmap.isNull())
381 _pixmap = SmallIcon(
"kcmx");
383 _lastIcon.resize(0,0);
389 void Task::setActive(
bool a)
402 return(_info.state() & NET::Max);
404 return(_info.state & NET::Max);
411 return (_info.mappingState() == NET::Iconic);
413 return (_info.mappingState == NET::Iconic);
420 return (_info.state() & NET::StaysOnTop);
422 return (_info.state & NET::StaysOnTop);
429 return (_info.state() & NET::Shaded);
431 return (_info.state & NET::Shaded);
438 return (_info.onAllDesktops() || _info.desktop() == twin_module->currentDesktop());
440 return (_info.onAllDesktops || _info.desktop == twin_module->currentDesktop());
447 return _info.onAllDesktops();
449 return _info.onAllDesktops;
460 return taskManager()->
isOnTop(
this );
465 static TQString modStr = TQString::fromUtf8(
"[") + i18n(
"modified") + TQString::fromUtf8(
"]");
467 int modStrPos = _info.visibleName().find(modStr);
469 int modStrPos = _info.visibleName.find(modStr);
472 return ( modStrPos != -1 );
475 TQString Task::iconName()
const
477 NETWinInfo ni( tqt_xdisplay(), _win, tqt_xrootwin(), NET::WMIconName);
478 return TQString::fromUtf8(ni.iconName());
480 TQString Task::visibleIconName()
const
482 NETWinInfo ni( tqt_xdisplay(), _win, tqt_xrootwin(), NET::WMVisibleIconName);
483 return TQString::fromUtf8(ni.visibleIconName());
486 TQString Task::className()
489 if(XGetClassHint(tqt_xdisplay(), _win, &hint)) {
490 TQString nh( hint.res_name );
491 XFree( hint.res_name );
492 XFree( hint.res_class );
498 TQString Task::classClass()
501 if(XGetClassHint(tqt_xdisplay(), _win, &hint)) {
502 TQString ch( hint.res_class );
503 XFree( hint.res_name );
504 XFree( hint.res_class );
510 TQPixmap
Task::icon(
int width,
int height,
bool allowResize )
512 if ( (width == _lastWidth)
513 && (height == _lastHeight)
514 && (allowResize == _lastResize )
515 && (!_lastIcon.isNull()) )
518 TQPixmap newIcon = KWin::icon( _win, width, height, allowResize );
519 if ( !newIcon.isNull() ) {
522 _lastHeight = height;
523 _lastResize = allowResize;
532 isStaticIcon =
false;
535 case TDEIcon::SizeSmall:
541 pixmap = TDEGlobal::iconLoader()->loadIcon(
"go",
543 TDEIcon::SizeSmall );
548 case TDEIcon::SizeMedium:
556 if ( (
pixmap.width() != 34 ) || (
pixmap.height() != 34 ) ) {
557 if ( (
pixmap.width() != 32 ) || (
pixmap.height() != 32 ) ) {
564 pixmap = TDEGlobal::iconLoader()->loadIcon(
"go",
566 TDEIcon::SizeMedium );
571 case TDEIcon::SizeLarge:
578 pixmap = TDEGlobal::iconLoader()->loadIcon( className(),
581 TDEIcon::DefaultState,
590 isStaticIcon =
false;
595 pixmap = TDEGlobal::iconLoader()->loadIcon(
"go",
608 if ( id1.isEmpty() || id2.isEmpty() )
611 if ( id1.contains( id2 ) > 0 )
614 if ( id2.contains( id1 ) > 0 )
623 NETWinInfo ni( tqt_xdisplay(), _win, tqt_xrootwin(), NET::WMState);
624 ni.setState( NET::Max, NET::Max );
627 if (_info.mappingState() == NET::Iconic)
629 if (_info.mappingState == NET::Iconic)
636 NETWinInfo ni( tqt_xdisplay(), _win, tqt_xrootwin(), NET::WMState);
637 ni.setState( 0, NET::Max );
639 if (_info.mappingState() == NET::Iconic)
641 if (_info.mappingState == NET::Iconic)
648 XIconifyWindow( tqt_xdisplay(), _win, tqt_xscreen() );
653 NETRootInfo ri( tqt_xdisplay(), NET::CloseWindow );
654 ri.closeWindowRequest( _win );
660 XRaiseWindow( tqt_xdisplay(), _win );
666 XLowerWindow( tqt_xdisplay(), _win );
672 NETRootInfo ri( tqt_xdisplay(), 0 );
673 ri.setActiveWindow( _win );
689 NETWinInfo ni(tqt_xdisplay(), _win, tqt_xrootwin(), NET::WMDesktop);
693 if (_info.onAllDesktops())
695 ni.setDesktop(twin_module->currentDesktop());
696 KWin::forceActiveWindow(_win);
699 if (_info.onAllDesktops)
701 ni.setDesktop(twin_module->currentDesktop());
702 KWin::setActiveWindow(_win);
706 ni.setDesktop(NETWinInfo::OnAllDesktops);
710 if (desk == twin_module->currentDesktop())
712 KWin::forceActiveWindow(_win);
714 KWin::setActiveWindow(_win);
720 toDesktop(twin_module->currentDesktop());
725 NETWinInfo ni( tqt_xdisplay(), _win, tqt_xrootwin(), NET::WMState);
727 ni.setState( NET::StaysOnTop, NET::StaysOnTop );
729 ni.setState( 0, NET::StaysOnTop );
732 void Task::toggleAlwaysOnTop()
739 NETWinInfo ni( tqt_xdisplay(), _win, tqt_xrootwin(), NET::WMState);
741 ni.setState( NET::Shaded, NET::Shaded );
743 ni.setState( 0, NET::Shaded );
746 void Task::toggleShaded()
753 NETWinInfo ni( tqt_xdisplay(), _win, tqt_xrootwin(), NET::WMIconGeometry);
757 r.size.width = rect.width();
758 r.size.height = rect.height();
759 ni.setIconGeometry(r);
768 if ( !_grab.isNull() )
776 TQWidget *rootWin = TQT_TQWIDGET(tqApp->desktop());
777 TQRect geom = _info.geometry();
778 _grab = TQPixmap::grabWindow( rootWin->winId(),
780 geom.width(), geom.height() );
782 if ( !_grab.isNull() )
783 TQTimer::singleShot( 200,
this, TQT_SLOT( generateThumbnail() ) );
786 void Task::generateThumbnail()
788 if ( _grab.isNull() )
791 TQImage img = _grab.convertToImage();
793 double width = img.width();
794 double height = img.height();
795 width = width * _thumbSize;
796 height = height * _thumbSize;
798 img = img.smoothScale( (
int) width, (
int) height );
800 _grab.resize( 0, 0 );
805 Startup::Startup(
const TDEStartupInfoId&
id,
const TDEStartupInfoData& data,
806 TQObject * parent,
const char *name)
807 : TQObject(parent, name), _id( id ), _data( data )
816 void Startup::update(
const TDEStartupInfoData& data )
818 _data.update( data );
824 return twin_module->currentDesktop();