1 /*****************************************************************
3 Copyright (c) 2000-2001 Matthias Elter <elter@kde.org>
4 Copyright (c) 2001 Richard Moore <rich@kde.org>
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 ******************************************************************/
29 #include <QtGui/QDrag>
30 #include <QtGui/QPixmap>
31 #include <QtGui/QWidget>
32 #include <QtGui/QIcon>
35 #include <KDE/KSharedPtr>
36 #include <KDE/KWindowSystem>
37 #include <KDE/NETWinInfo>
39 #include <taskmanager/taskmanager.h>
40 #include <taskmanager/taskmanager_export.h>
46 * A dynamic interface to a task (main window).
50 class TASKMANAGER_EXPORT Task
: public QObject
, public KShared
53 Q_PROPERTY( QString visibleName READ visibleName
)
54 Q_PROPERTY( QString name READ name
)
55 Q_PROPERTY( QString className READ className
)
56 Q_PROPERTY( QString visibleNameWithState READ visibleNameWithState
)
57 Q_PROPERTY( QPixmap pixmap READ pixmap
)
58 Q_PROPERTY( bool maximized READ isMaximized
)
59 Q_PROPERTY( bool minimized READ isMinimized
)
61 Q_PROPERTY( bool iconified READ isIconified
)
62 Q_PROPERTY( bool shaded READ isShaded WRITE setShaded
)
63 Q_PROPERTY( bool active READ isActive
)
64 Q_PROPERTY( bool onCurrentDesktop READ isOnCurrentDesktop
)
65 Q_PROPERTY( bool onAllDesktops READ isOnAllDesktops
)
66 Q_PROPERTY( bool alwaysOnTop READ isAlwaysOnTop WRITE setAlwaysOnTop
)
67 Q_PROPERTY( bool modified READ isModified
)
68 Q_PROPERTY( bool demandsAttention READ demandsAttention
)
69 Q_PROPERTY( int desktop READ desktop
)
72 Task(WId win
, QObject
*parent
, const char *name
= 0);
76 KWindowInfo
info() const;
78 QString
visibleName() const;
79 QString
visibleNameWithState() const;
81 QString
className() const;
82 QString
classClass() const;
85 * A list of the window ids of all transient windows (dialogs) associated
88 WindowList
transients() const;
91 * Returns a 16x16 (KIconLoader::Small) icon for the task. This method will
92 * only fall back to a static icon if there is no icon of any size in
95 QPixmap
pixmap() const;
98 * Returns the best icon for any of the KIconLoader::StdSizes. If there is no
99 * icon of the specified size specified in the WM hints, it will try to
100 * get one using KIconLoader.
103 * bool gotStaticIcon;
104 * QPixmap icon = myTask->icon( KIconLoader::SizeMedium, gotStaticIcon );
107 * @param size Any of the constants in KIconLoader::StdSizes.
108 * @param isStaticIcon Set to true if KIconLoader was used, false otherwise.
110 QPixmap
bestIcon( int size
, bool &isStaticIcon
);
113 * Tries to find an icon for the task with the specified size. If there
114 * is no icon that matches then it will either resize the closest available
115 * icon or return a null pixmap depending on the value of allowResize.
117 * Note that the last icon is cached, so a sequence of calls with the same
118 * parameters will only query the NET properties if the icon has changed or
121 QPixmap
icon( int width
, int height
, bool allowResize
= false );
124 * \return a QIcon for the task
129 * Returns true iff the windows with the specified ids should be grouped
130 * together in the task list.
132 static bool idMatch(const QString
&, const QString
&);
137 * Returns true if the task's window is maximized.
139 bool isMaximized() const;
142 * Returns true if the task's window is minimized.
144 bool isMinimized() const;
148 * Returns true if the task's window is minimized(iconified).
150 bool isIconified() const;
153 * Returns true if the task's window is shaded.
155 bool isShaded() const;
158 * Returns true if the task's window is the active window.
160 bool isActive() const;
163 * Returns true if the task's window is the topmost non-iconified,
164 * non-always-on-top window.
166 bool isOnTop() const;
169 * Returns true if the task's window is on the current virtual desktop.
171 bool isOnCurrentDesktop() const;
174 * Returns true if the task's window is on all virtual desktops.
176 bool isOnAllDesktops() const;
179 * Returns true if the task's window will remain at the top of the
182 bool isAlwaysOnTop() const;
185 * Returns true if the task's window will remain at the bottom of the
188 bool isKeptBelowOthers() const;
191 * Returns true if the task's window is in full screen mode
193 bool isFullScreen() const;
196 * Returns true if the document the task is editing has been modified.
197 * This is currently handled heuristically by looking for the string
198 * '[i18n_modified]' in the window title where i18n_modified is the
199 * word 'modified' in the current language.
201 bool isModified() const ;
204 * Returns the desktop on which this task's window resides.
209 * Returns true if the task is not active but demands user's attention.
211 bool demandsAttention() const;
215 * Returns true if the window is on the specified screen of a multihead configuration
217 bool isOnScreen( int screen
) const;
220 * Returns true if the task should be shown in taskbar-like apps
222 bool showInTaskbar() const;
225 * Returns true if the task should be shown in pager-like apps
227 bool showInPager() const;
230 * Returns the geometry for this window
232 QRect
geometry() const;
237 ::TaskManager::TaskChanges
refresh(unsigned int dirty
);
239 void addTransient( WId w
, const NETWinInfo
& info
);
241 void removeTransient( WId w
);
243 bool hasTransient(WId w
) const;
245 void updateDemandsAttentionState( WId w
);
247 void setActive(bool a
);
250 * Adds the identifying information for this task to mime data for drags, copies, etc
252 void addMimeData(QMimeData
*mimeData
) const;
255 * Returns the mimetype used for a Task
257 static QString
mimetype();
260 * Returns the mimetype used for multiple Tasks
262 static QString
groupMimetype();
265 * Given mime data, will return a WId if it can decode one from the data. Otherwise
268 static WId
idFromMimeData(const QMimeData
*mimeData
, bool *ok
= 0);
271 * Given mime data, will return a QList<WId> if it can decode WIds from the data. Otherwise
272 * returns an empty list.
274 static QList
<WId
> idsFromMimeData(const QMimeData
*mimeData
, bool *ok
= 0);
278 * Maximise the main window of this task.
280 void setMaximized(bool);
281 void toggleMaximized();
284 * Restore the main window of the task (if it was iconified).
289 * Move the window of this task.
294 * Resize the window of this task.
301 void setIconified(bool);
302 void toggleIconified();
305 * Close the task's window.
310 * Raise the task's window.
315 * Lower the task's window.
320 * Activate the task's window.
325 * Perform the action that is most appropriate for this task. If it
326 * is not active, activate it. Else if it is not the top window, raise
327 * it. Otherwise, iconify it.
329 void activateRaiseOrIconify();
332 * If true, the task's window will remain at the top of the stacking order.
334 void setAlwaysOnTop(bool);
335 void toggleAlwaysOnTop();
338 * If true, the task's window will remain at the bottom of the stacking order.
340 void setKeptBelowOthers(bool);
341 void toggleKeptBelowOthers();
344 * If true, the task's window will enter full screen mode.
346 void setFullScreen(bool);
347 void toggleFullScreen();
350 * If true then the task's window will be shaded. Most window managers
351 * represent this state by displaying on the window's title bar.
353 void setShaded(bool);
357 * Moves the task's window to the specified virtual desktop.
362 * Moves the task's window to the current virtual desktop.
364 void toCurrentDesktop();
367 * This method informs the window manager of the location at which this
368 * task will be displayed when iconised. It is used, for example by the
369 * KWin inconify animation.
371 void publishIconGeometry(QRect
);
375 * Indicates that this task has changed in some way.
377 void changed(::TaskManager::TaskChanges change
);
380 * Indicates that this task is now the active task.
385 * Indicates that this task is no longer the active task.
390 void findWindowFrameId();
391 void timerEvent(QTimerEvent
*event
);
400 } // TaskManager namespace