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, TQ_SIGNAL(windowAdded(WId)), TQ_SLOT(windowAdded(WId)));
59 connect(twin_module, TQ_SIGNAL(windowRemoved(WId)), TQ_SLOT(windowRemoved(WId)));
60 connect(twin_module, TQ_SIGNAL(activeWindowChanged(WId)), TQ_SLOT(activeWindowChanged(WId)));
61 connect(twin_module, TQ_SIGNAL(currentDesktopChanged(
int)), TQ_SLOT(currentDesktopChanged(
int)));
62 connect(twin_module, TQ_SIGNAL(windowChanged(WId,
unsigned int)), TQ_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 TQ_SIGNAL( gotNewStartup(
const TDEStartupInfoId&,
const TDEStartupInfoData& )),
90 TQ_SLOT( gotNewStartup(
const TDEStartupInfoId&,
const TDEStartupInfoData& )));
91 connect( _startup_info,
92 TQ_SIGNAL( gotStartupChange(
const TDEStartupInfoId&,
const TDEStartupInfoData& )),
93 TQ_SLOT( gotStartupChange(
const TDEStartupInfoId&,
const TDEStartupInfoData& )));
94 connect( _startup_info,
95 TQ_SIGNAL( gotRemoveStartup(
const TDEStartupInfoId&,
const TDEStartupInfoData& )),
96 TQ_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 )
147 Task* t = findTask(transient_for);
150 if (t->window() != w)
166 void TaskManager::windowRemoved(WId w )
168 _skiptaskbar_windows.remove( w );
170 Task* t = findTask(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)) )
209 Task* t = findTask( w );
216 if (dirty & NET::WMIcon)
221 if(dirty & (NET::WMDesktop|NET::WMState|NET::XAWMState))
222 emit windowChanged(w);
225 void TaskManager::activeWindowChanged(WId w )
229 Task* t = findTask( w );
232 _active->setActive(
false);
236 emit activeTaskChanged(0);
241 _active->setActive(
false);
244 _active->setActive(
true);
246 emit activeTaskChanged(_active);
250 void TaskManager::currentDesktopChanged(
int desktop)
252 emit desktopChanged(desktop);
255 void TaskManager::gotNewStartup(
const TDEStartupInfoId&
id,
const TDEStartupInfoData& data )
260 emit startupAdded(s);
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);
288 emit startupRemoved(s);
292 void TaskManager::killStartup(
Startup* s)
296 _startups.removeRef(s);
297 emit startupRemoved(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() ) {
321 if ( !t->isIconified() && (t->isAlwaysOnTop() == task->
isAlwaysOnTop()) )
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:
537 pixmap = icon( 16, 16,
true );
540 if( pixmap.isNull() ) {
541 pixmap = TDEGlobal::iconLoader()->loadIcon(
"go",
543 TDEIcon::SizeSmall );
548 case TDEIcon::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 = TDEGlobal::iconLoader()->loadIcon(
"go",
566 TDEIcon::SizeMedium );
571 case TDEIcon::SizeLarge:
574 pixmap = icon( size, size,
false );
577 if ( pixmap.isNull() || pixmap.width() != size || pixmap.height() != size ) {
578 pixmap = TDEGlobal::iconLoader()->loadIcon( className(),
581 TDEIcon::DefaultState,
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 = 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 );
678 if ( !isActive() || isIconified() ) {
680 }
else if ( !isOnTop() ) {
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()
734 setAlwaysOnTop( !isAlwaysOnTop() );
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()
748 setShaded( !isShaded() );
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);
764 if ( !isOnCurrentDesktop() )
768 if ( !_grab.isNull() )
776 TQWidget *rootWin = 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, TQ_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 );
802 emit thumbnailChanged();
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();
TQPixmap bestIcon(int size, bool &isStaticIcon)
Returns the best icon for any of the TDEIcon::StdSizes.
void setAlwaysOnTop(bool)
If true, the task's window will remain at the top of the stacking order.
void activateRaiseOrIconify()
Perform the action that is most appropriate for this task.
bool isOnTop(const Task *)
Returns true if the specified task is on top.
int currentDesktop() const
Returns the number of the current desktop.
void maximize()
Maximise the main window of this task.
void toDesktop(int)
Moves the task's window to the specified virtual desktop.
Represents a task which is in the process of starting.
bool isOnCurrentDesktop() const
Returns true if the task's window is on the current virtual desktop.
bool isOnAllDesktops() const
Returns true if the task's window is on all virtual desktops.
TQPixmap icon(int width, int height, bool allowResize=false)
Tries to find an icon for the task with the specified size.
A generic API for task managers.
bool isIconified() const
Returns true if the task's window is iconified.
bool isAlwaysOnTop() const
Returns true if the task's window will remain at the top of the stacking order.
bool isOnTop() const
Returns true if the task's window is the topmost non-iconified, non-always-on-top window...
Task * findTask(WId w)
Returns the task for a given WId, or 0 if there is no such task.
void setShaded(bool)
If true then the task's window will be shaded.
void publishIconGeometry(TQRect)
This method informs the window manager of the location at which this task will be displayed when icon...
bool isShaded() const
Returns true if the task's window is shaded.
int numberOfDesktops() const
Returns the number of virtual desktops.
static bool idMatch(const TQString &, const TQString &)
Returns true iff the windows with the specified ids should be grouped together in the task list...
void close()
Activate the task's window.
bool isModified() const
Returns true if the document the task is editing has been modified.
void windowChanged(WId)
Emitted when a window changes desktop.
void raise()
Raise the task's window.
void activate()
Activate the task's window.
void iconify()
Iconify the task.
void updateThumbnail()
Tells the task to generate a new thumbnail.
void restore()
Restore the main window of the task (if it was iconified).
TQString desktopName(int n) const
Returns the name of the nth desktop.
bool isActive() const
Returns true if the task's window is the active window.
void toCurrentDesktop()
Moves the task's window to the current virtual desktop.
A dynamic interface to a task (main window).
bool isMaximized() const
Returns true if the task's window is maximized.
void lower()
Lower the task's window.