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 TWinModule* twin_module = 0;
51 TaskManager::TaskManager(TQObject *parent,
const char *name)
52 : TQObject(parent, name), _active(0), _startup_info( NULL )
55 twin_module =
new TWinModule();
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))
109 void TaskManager::windowAdded(WId w )
111 NETWinInfo info(tqt_xdisplay(), w, tqt_xrootwin(),
112 NET::WMWindowType | NET::WMPid | NET::WMState );
113 NET::WindowType windowType = info.windowType(NET::AllTypesMask);
115 if (windowType != NET::Normal && windowType != NET::Override
116 && windowType != NET::Unknown && windowType != NET::Dialog)
119 if ((info.state() & NET::SkipTaskbar) != 0)
121 _skiptaskbar_windows.push_front( w );
125 Window transient_for_tmp;
126 if (XGetTransientForHint(tqt_xdisplay(), (Window) w, &transient_for_tmp))
128 WId transient_for = (WId) transient_for_tmp;
131 if (_skiptaskbar_windows.contains(transient_for))
135 if (transient_for != tqt_xrootwin() && transient_for != 0 )
140 if (t->window() != w)
156 void TaskManager::windowRemoved(WId w )
158 _skiptaskbar_windows.remove( w );
163 if (t->window() == w) {
168 if(t == _active) _active = 0;
173 t->removeTransient( w );
180 if( dirty & NET::WMState ) {
181 NETWinInfo info ( tqt_xdisplay(), w, tqt_xrootwin(), NET::WMState );
182 if ( (info.state() & NET::SkipTaskbar) != 0 ) {
184 _skiptaskbar_windows.push_front( w );
188 _skiptaskbar_windows.remove( w );
195 if(!(dirty & (NET::WMVisibleName|NET::WMName|NET::WMState|NET::WMIcon|NET::XAWMState|NET::WMDesktop)) )
206 if (dirty & NET::WMIcon)
211 if(dirty & (NET::WMDesktop|NET::WMState|NET::XAWMState))
215 void TaskManager::activeWindowChanged(WId w )
222 _active->setActive(
false);
231 _active->setActive(
false);
234 _active->setActive(
true);
240 void TaskManager::currentDesktopChanged(
int desktop)
245 void TaskManager::gotNewStartup(
const TDEStartupInfoId&
id,
const TDEStartupInfoData& data )
253 void TaskManager::gotStartupChange(
const TDEStartupInfoId&
id,
const TDEStartupInfoData& data )
255 for(
Startup* s = _startups.first(); s != 0; s = _startups.next()) {
256 if ( s->id() ==
id ) {
263 void TaskManager::gotRemoveStartup(
const TDEStartupInfoId&
id )
268 void TaskManager::killStartup(
const TDEStartupInfoId&
id )
271 for(s = _startups.first(); s != 0; s = _startups.next()) {
277 _startups.removeRef(s);
282 void TaskManager::killStartup(
Startup* s)
286 _startups.removeRef(s);
293 return twin_module->desktopName(desk);
298 return twin_module->numberOfDesktops();
303 if(!task)
return false;
305 for (TQValueList<WId>::ConstIterator it = twin_module->stackingOrder().fromLast();
306 it != twin_module->stackingOrder().end(); --it ) {
307 for (
Task* t = _tasks.first(); t != 0; t = _tasks.next() ) {
308 if ( (*it) == t->window() ) {
321 Task::Task(WId win,
TaskManager * parent,
const char *name) :
322 TQObject(parent, name),
323 _active(false), _win(win),
324 _lastWidth(0), _lastHeight(0), _lastResize(false), _lastIcon(),
325 _thumbSize(0.2), _thumb(), _grab()
327 _info = KWin::windowInfo(_win, 0, 0);
329 _pixmap = KWin::icon(_win, 16, 16,
true);
333 TDEGlobal::instance()->iconLoader()->loadIcon(className().lower(),
334 TDEIcon::Small,TDEIcon::Small,
335 TDEIcon::DefaultState, 0,
true);
338 if (_pixmap.isNull())
339 _pixmap = SmallIcon(
"kcmx");
346 void Task::refresh(
bool icon)
348 _info = KWin::windowInfo(_win, 0, 0);
352 _pixmap = KWin::icon(_win, 16, 16,
true);
357 TDEGlobal::instance()->iconLoader()->loadIcon(className().
lower(),
358 TDEIcon::Small, TDEIcon::Small, TDEIcon::DefaultState, 0,
true);
362 if (_pixmap.isNull())
363 _pixmap = SmallIcon(
"kcmx");
365 _lastIcon.resize(0,0);
371 void Task::setActive(
bool a)
383 return(_info.state() & NET::Max);
388 return (_info.mappingState() == NET::Iconic);
393 return (_info.state() & NET::StaysOnTop);
398 return (_info.state() & NET::Shaded);
403 return (_info.onAllDesktops() || _info.desktop() == twin_module->currentDesktop());
408 return _info.onAllDesktops();
418 return taskManager()->
isOnTop(
this );
423 static TQString modStr = TQString::fromUtf8(
"[") + i18n(
"modified") + TQString::fromUtf8(
"]");
424 int modStrPos = _info.visibleName().find(modStr);
426 return ( modStrPos != -1 );
429 TQString Task::iconName()
const
431 NETWinInfo ni( tqt_xdisplay(), _win, tqt_xrootwin(), NET::WMIconName);
432 return TQString::fromUtf8(ni.iconName());
434 TQString Task::visibleIconName()
const
436 NETWinInfo ni( tqt_xdisplay(), _win, tqt_xrootwin(), NET::WMVisibleIconName);
437 return TQString::fromUtf8(ni.visibleIconName());
440 TQString Task::className()
443 if(XGetClassHint(tqt_xdisplay(), _win, &hint)) {
444 TQString nh( hint.res_name );
445 XFree( hint.res_name );
446 XFree( hint.res_class );
452 TQString Task::classClass()
455 if(XGetClassHint(tqt_xdisplay(), _win, &hint)) {
456 TQString ch( hint.res_class );
457 XFree( hint.res_name );
458 XFree( hint.res_class );
464 TQPixmap
Task::icon(
int width,
int height,
bool allowResize )
466 if ( (width == _lastWidth)
467 && (height == _lastHeight)
468 && (allowResize == _lastResize )
469 && (!_lastIcon.isNull()) )
472 TQPixmap newIcon = KWin::icon( _win, width, height, allowResize );
473 if ( !newIcon.isNull() ) {
476 _lastHeight = height;
477 _lastResize = allowResize;
486 isStaticIcon =
false;
489 case TDEIcon::SizeSmall:
495 pixmap = TDEGlobal::iconLoader()->loadIcon(
"go",
497 TDEIcon::SizeSmall );
502 case TDEIcon::SizeMedium:
510 if ( (
pixmap.width() != 34 ) || (
pixmap.height() != 34 ) ) {
511 if ( (
pixmap.width() != 32 ) || (
pixmap.height() != 32 ) ) {
518 pixmap = TDEGlobal::iconLoader()->loadIcon(
"go",
520 TDEIcon::SizeMedium );
525 case TDEIcon::SizeLarge:
532 pixmap = TDEGlobal::iconLoader()->loadIcon( className(),
535 TDEIcon::DefaultState,
544 isStaticIcon =
false;
549 pixmap = TDEGlobal::iconLoader()->loadIcon(
"go",
562 if ( id1.isEmpty() || id2.isEmpty() )
565 if ( id1.contains( id2 ) > 0 )
568 if ( id2.contains( id1 ) > 0 )
577 NETWinInfo ni( tqt_xdisplay(), _win, tqt_xrootwin(), NET::WMState);
578 ni.setState( NET::Max, NET::Max );
580 if (_info.mappingState() == NET::Iconic)
586 NETWinInfo ni( tqt_xdisplay(), _win, tqt_xrootwin(), NET::WMState);
587 ni.setState( 0, NET::Max );
588 if (_info.mappingState() == NET::Iconic)
594 XIconifyWindow( tqt_xdisplay(), _win, tqt_xscreen() );
599 NETRootInfo ri( tqt_xdisplay(), NET::CloseWindow );
600 ri.closeWindowRequest( _win );
606 XRaiseWindow( tqt_xdisplay(), _win );
612 XLowerWindow( tqt_xdisplay(), _win );
618 NETRootInfo ri( tqt_xdisplay(), 0 );
619 ri.setActiveWindow( _win );
635 NETWinInfo ni(tqt_xdisplay(), _win, tqt_xrootwin(), NET::WMDesktop);
638 if (_info.onAllDesktops())
640 ni.setDesktop(twin_module->currentDesktop());
641 KWin::forceActiveWindow(_win);
644 ni.setDesktop(NETWinInfo::OnAllDesktops);
648 if (desk == twin_module->currentDesktop())
649 KWin::forceActiveWindow(_win);
654 toDesktop(twin_module->currentDesktop());
659 NETWinInfo ni( tqt_xdisplay(), _win, tqt_xrootwin(), NET::WMState);
661 ni.setState( NET::StaysOnTop, NET::StaysOnTop );
663 ni.setState( 0, NET::StaysOnTop );
666 void Task::toggleAlwaysOnTop()
673 NETWinInfo ni( tqt_xdisplay(), _win, tqt_xrootwin(), NET::WMState);
675 ni.setState( NET::Shaded, NET::Shaded );
677 ni.setState( 0, NET::Shaded );
680 void Task::toggleShaded()
687 NETWinInfo ni( tqt_xdisplay(), _win, tqt_xrootwin(), NET::WMIconGeometry);
691 r.size.width = rect.width();
692 r.size.height = rect.height();
693 ni.setIconGeometry(r);
702 if ( !_grab.isNull() )
710 TQWidget *rootWin = tqApp->desktop();
711 TQRect geom = _info.geometry();
712 _grab = TQPixmap::grabWindow( rootWin->winId(),
714 geom.width(), geom.height() );
716 if ( !_grab.isNull() )
717 TQTimer::singleShot( 200,
this, TQ_SLOT( generateThumbnail() ) );
720 void Task::generateThumbnail()
722 if ( _grab.isNull() )
725 TQImage img = _grab.convertToImage();
727 double width = img.width();
728 double height = img.height();
729 width = width * _thumbSize;
730 height = height * _thumbSize;
732 img = img.smoothScale( (
int) width, (
int) height );
734 _grab.resize( 0, 0 );
739 Startup::Startup(
const TDEStartupInfoId&
id,
const TDEStartupInfoData& data,
740 TQObject * parent,
const char *name)
741 : TQObject(parent, name), _id( id ), _data( data )
750 void Startup::update(
const TDEStartupInfoData& data )
752 _data.update( data );
758 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.