28 #include <kiconloader.h>
29 #include <kwinmodule.h>
36 #include <X11/Xutil.h>
38 #include "taskmanager.h"
39 #include "taskmanager.moc"
41 template class TQPtrList<Task>;
49 KWinModule* kwin_module = 0;
51 TaskManager::TaskManager(TQObject *parent,
const char *name)
52 : TQObject(parent, name), _active(0), _startup_info( NULL )
55 kwin_module =
new KWinModule();
58 connect(kwin_module, TQT_SIGNAL(windowAdded(WId)), TQT_SLOT(windowAdded(WId)));
59 connect(kwin_module, TQT_SIGNAL(windowRemoved(WId)), TQT_SLOT(windowRemoved(WId)));
60 connect(kwin_module, TQT_SIGNAL(activeWindowChanged(WId)), TQT_SLOT(activeWindowChanged(WId)));
61 connect(kwin_module, TQT_SIGNAL(currentDesktopChanged(
int)), TQT_SLOT(currentDesktopChanged(
int)));
62 connect(kwin_module, TQT_SIGNAL(windowChanged(WId,
unsigned int)), TQT_SLOT(windowChanged(WId,
unsigned int)));
65 const TQValueList<WId> windows = kwin_module->windows();
66 TQValueList<WId>::ConstIterator end( windows.end() );
67 for (TQValueList<WId>::ConstIterator it = windows.begin(); it != end; ++it )
71 WId win = kwin_module->activeWindow();
72 activeWindowChanged(win);
77 TaskManager::~TaskManager()
81 void TaskManager::configure_startup()
83 KConfig c(
"klaunchrc",
true);
84 c.setGroup(
"FeedbackStyle");
85 if (!c.readBoolEntry(
"TaskbarButton",
true))
87 _startup_info =
new KStartupInfo(
true,
this );
88 connect( _startup_info,
89 TQT_SIGNAL( gotNewStartup(
const KStartupInfoId&,
const KStartupInfoData& )),
90 TQT_SLOT( gotNewStartup(
const KStartupInfoId&,
const KStartupInfoData& )));
91 connect( _startup_info,
92 TQT_SIGNAL( gotStartupChange(
const KStartupInfoId&,
const KStartupInfoData& )),
93 TQT_SLOT( gotStartupChange(
const KStartupInfoId&,
const KStartupInfoData& )));
94 connect( _startup_info,
95 TQT_SIGNAL( gotRemoveStartup(
const KStartupInfoId&,
const KStartupInfoData& )),
96 TQT_SLOT( gotRemoveStartup(
const KStartupInfoId& )));
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(qt_xdisplay(), w, qt_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(qt_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 != qt_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 ( qt_xdisplay(), w, qt_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 KStartupInfoId&
id,
const KStartupInfoData& data )
263 void TaskManager::gotStartupChange(
const KStartupInfoId&
id,
const KStartupInfoData& data )
265 for(
Startup* s = _startups.first(); s != 0; s = _startups.next()) {
266 if ( s->id() == id ) {
273 void TaskManager::gotRemoveStartup(
const KStartupInfoId&
id )
278 void TaskManager::killStartup(
const KStartupInfoId&
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 kwin_module->desktopName(desk);
308 return kwin_module->numberOfDesktops();
313 if(!task)
return false;
315 for (TQValueList<WId>::ConstIterator it = kwin_module->stackingOrder().fromLast();
316 it != kwin_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 KGlobal::instance()->iconLoader()->loadIcon(className().lower(),
348 KIcon::Small,KIcon::Small,
349 KIcon::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);
375 KGlobal::instance()->iconLoader()->loadIcon(className().
lower(),
376 KIcon::Small, KIcon::Small, KIcon::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() == kwin_module->currentDesktop());
440 return (_info.onAllDesktops || _info.desktop == kwin_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( qt_xdisplay(), _win, qt_xrootwin(), NET::WMIconName);
478 return TQString::fromUtf8(ni.iconName());
480 TQString Task::visibleIconName()
const
482 NETWinInfo ni( qt_xdisplay(), _win, qt_xrootwin(), NET::WMVisibleIconName);
483 return TQString::fromUtf8(ni.visibleIconName());
486 TQString Task::className()
489 if(XGetClassHint(qt_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(qt_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 KIcon::SizeSmall:
537 pixmap =
icon( 16, 16,
true );
540 if( pixmap.isNull() ) {
541 pixmap = KGlobal::iconLoader()->loadIcon(
"go",
548 case KIcon::SizeMedium:
554 pixmap =
icon( 34, 34,
false );
556 if ( ( pixmap.width() != 34 ) || ( pixmap.height() != 34 ) ) {
557 if ( ( pixmap.width() != 32 ) || ( pixmap.height() != 32 ) ) {
558 pixmap =
icon( 32, 32,
true );
563 if( pixmap.isNull() ) {
564 pixmap = KGlobal::iconLoader()->loadIcon(
"go",
571 case KIcon::SizeLarge:
574 pixmap =
icon( size, size,
false );
577 if ( pixmap.isNull() || pixmap.width() != size || pixmap.height() != size ) {
578 pixmap = KGlobal::iconLoader()->loadIcon( className(),
588 if ( pixmap.isNull() || ( pixmap.width() != size ) || ( pixmap.height() != size ) ) {
589 pixmap =
icon( size, size,
true );
590 isStaticIcon =
false;
594 if( pixmap.isNull() ) {
595 pixmap = KGlobal::iconLoader()->loadIcon(
"go",
608 if ( id1.isEmpty() || id2.isEmpty() )
611 if ( id1.contains( id2 ) > 0 )
614 if ( id2.contains( id1 ) > 0 )
623 NETWinInfo ni( qt_xdisplay(), _win, qt_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( qt_xdisplay(), _win, qt_xrootwin(), NET::WMState);
637 ni.setState( 0, NET::Max );
639 if (_info.mappingState() == NET::Iconic)
641 if (_info.mappingState == NET::Iconic)
648 XIconifyWindow( qt_xdisplay(), _win, qt_xscreen() );
653 NETRootInfo ri( qt_xdisplay(), NET::CloseWindow );
654 ri.closeWindowRequest( _win );
660 XRaiseWindow( qt_xdisplay(), _win );
666 XLowerWindow( qt_xdisplay(), _win );
672 NETRootInfo ri( qt_xdisplay(), 0 );
673 ri.setActiveWindow( _win );
689 NETWinInfo ni(qt_xdisplay(), _win, qt_xrootwin(), NET::WMDesktop);
693 if (_info.onAllDesktops())
695 ni.setDesktop(kwin_module->currentDesktop());
696 KWin::forceActiveWindow(_win);
699 if (_info.onAllDesktops)
701 ni.setDesktop(kwin_module->currentDesktop());
702 KWin::setActiveWindow(_win);
706 ni.setDesktop(NETWinInfo::OnAllDesktops);
710 if (desk == kwin_module->currentDesktop())
712 KWin::forceActiveWindow(_win);
714 KWin::setActiveWindow(_win);
720 toDesktop(kwin_module->currentDesktop());
725 NETWinInfo ni( qt_xdisplay(), _win, qt_xrootwin(), NET::WMState);
727 ni.setState( NET::StaysOnTop, NET::StaysOnTop );
729 ni.setState( 0, NET::StaysOnTop );
732 void Task::toggleAlwaysOnTop()
739 NETWinInfo ni( qt_xdisplay(), _win, qt_xrootwin(), NET::WMState);
741 ni.setState( NET::Shaded, NET::Shaded );
743 ni.setState( 0, NET::Shaded );
746 void Task::toggleShaded()
753 NETWinInfo ni( qt_xdisplay(), _win, qt_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 KStartupInfoId&
id,
const KStartupInfoData& data,
806 TQObject * parent,
const char *name)
807 : TQObject(parent, name), _id( id ), _data( data )
816 void Startup::update(
const KStartupInfoData& data )
818 _data.update( data );
824 return kwin_module->currentDesktop();