28#include <kiconloader.h>
29#include <twinmodule.h>
38#include "taskmanager.h"
39#include "taskmanager.moc"
41template class TQPtrList<Task>;
49KWinModule* twin_module = 0;
51TaskManager::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);
77TaskManager::~TaskManager()
81void 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)
115void 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)
166void 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))
225void TaskManager::activeWindowChanged(WId w )
232 _active->setActive(
false);
241 _active->setActive(
false);
244 _active->setActive(
true);
250void TaskManager::currentDesktopChanged(
int desktop)
255void TaskManager::gotNewStartup(
const TDEStartupInfoId&
id,
const TDEStartupInfoData& data )
263void TaskManager::gotStartupChange(
const TDEStartupInfoId&
id,
const TDEStartupInfoData& data )
265 for(
Startup* s = _startups.first(); s != 0; s = _startups.next()) {
266 if ( s->id() ==
id ) {
273void TaskManager::gotRemoveStartup(
const TDEStartupInfoId&
id )
278void TaskManager::killStartup(
const TDEStartupInfoId&
id )
281 for(s = _startups.first(); s != 0; s = _startups.next()) {
287 _startups.removeRef(s);
292void 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() ) {
331Task::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");
360void 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);
389void 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 );
475TQString Task::iconName()
const
477 NETWinInfo ni( tqt_xdisplay(), _win, tqt_xrootwin(), NET::WMIconName);
478 return TQString::fromUtf8(ni.iconName());
480TQString Task::visibleIconName()
const
482 NETWinInfo ni( tqt_xdisplay(), _win, tqt_xrootwin(), NET::WMVisibleIconName);
483 return TQString::fromUtf8(ni.visibleIconName());
486TQString 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 );
498TQString 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 );
510TQPixmap
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 );
732void 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 );
746void 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 = 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() ) );
786void 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 );
805Startup::Startup(
const TDEStartupInfoId&
id,
const TDEStartupInfoData& data,
806 TQObject * parent,
const char *name)
807 : TQObject(parent, name), _id( id ), _data( data )
816void Startup::update(
const TDEStartupInfoData& data )
818 _data.update( data );
824 return twin_module->currentDesktop();
Represents a task which is in the process of starting.
void changed()
Indicates that this startup has changed in some way.
A generic API for task managers.
int numberOfDesktops() const
Returns the number of virtual desktops.
void windowChanged(WId)
Emitted when a window changes desktop.
Task * findTask(WId w)
Returns the task for a given WId, or 0 if there is no such task.
void activeTaskChanged(Task *)
Emitted when the active window changed.
TQString desktopName(int n) const
Returns the name of the nth desktop.
int currentDesktop() const
Returns the number of the current desktop.
bool isOnTop(const Task *)
Returns true if the specified task is on top.
void startupAdded(Startup *)
Emitted when a new task is expected.
void desktopChanged(int desktop)
Emitted when the current desktop changes.
void startupRemoved(Startup *)
Emitted when a startup item should be removed.
void taskAdded(Task *)
Emitted when a new task has started.
void taskRemoved(Task *)
Emitted when a task has terminated.
A dynamic interface to a task (main window).
void raise()
Raise the task's window.
bool isActive() const
Returns true if the task's window is the active window.
void maximize()
Maximise the main window of this task.
void publishIconGeometry(TQRect)
This method informs the window manager of the location at which this task will be displayed when icon...
bool isOnAllDesktops() const
Returns true if the task's window is on all virtual desktops.
bool isShaded() const
Returns true if the task's window is shaded.
TQPixmap pixmap() const
Returns a 16x16 (TDEIcon::Small) icon for the task.
void activate()
Activate the task's window.
bool isModified() const
Returns true if the document the task is editing has been modified.
void lower()
Lower the task's window.
void iconChanged()
Indicates that the icon for this task has changed.
bool isIconified() const
Returns true if the task's window is iconified.
void toDesktop(int)
Moves the task's window to the specified virtual desktop.
bool isAlwaysOnTop() const
Returns true if the task's window will remain at the top of the stacking order.
bool isOnCurrentDesktop() const
Returns true if the task's window is on the current virtual desktop.
void thumbnailChanged()
Indicates that the thumbnail for this task has changed.
void toCurrentDesktop()
Moves the task's window to the current virtual desktop.
void activated()
Indicates that this task is now the active task.
void activateRaiseOrIconify()
Perform the action that is most appropriate for this task.
void changed()
Indicates that this task has changed in some way.
void restore()
Restore the main window of the task (if it was iconified).
TQPixmap bestIcon(int size, bool &isStaticIcon)
Returns the best icon for any of the TDEIcon::StdSizes.
void iconify()
Iconify the task.
TQPixmap icon(int width, int height, bool allowResize=false)
Tries to find an icon for the task with the specified size.
bool isOnTop() const
Returns true if the task's window is the topmost non-iconified, non-always-on-top window.
void setAlwaysOnTop(bool)
If true, the task's window will remain at the top of the stacking order.
void close()
Activate the task's window.
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 setShaded(bool)
If true then the task's window will be shaded.
void updateThumbnail()
Tells the task to generate a new thumbnail.
bool isMaximized() const
Returns true if the task's window is maximized.
void deactivated()
Indicates that this task is no longer the active task.