1
/********************************************************************
2
KWin - the KDE window manager
3
This file is part of the KDE project.
5
Copyright (C) 2009 Martin Gräßlin <kde@martin-graesslin.com>
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or
10
(at your option) any later version.
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with this program. If not, see <http://www.gnu.org/licenses/>.
19
*********************************************************************/
21
#ifndef TABBOXHANDLER_H
22
#define TABBOXHANDLER_H
24
#include "tabboxconfig.h"
26
#include <QModelIndex>
34
* This file contains the classes which hide KWin core from tabbox.
35
* It defines the pure virtual classes TabBoxHandler and TabBoxClient.
36
* The classes have to be implemented in KWin Core.
38
* @author Martin Gräßlin <kde@martin-graesslin.com>
47
* The TabBox is a model based view for displaying a list while switching windows or desktops.
48
* This functionality is mostly referred as Alt+Tab. TabBox itself does not provide support for
49
* switching windows or desktops. This has to be done outside of TabBox inside an independent controller.
51
* The main entrance point to TabBox is the class TabBoxHandler, which has to be subclassed and implemented.
52
* The class TabBoxClient, which represents a window client inside TabBox, has to be implemented as well.
54
* The behavior of the TabBox is defined by the TabBoxConfig and has to be set in the TabBoxHandler.
55
* If the TabBox should be used to switch desktops as well as clients it is sufficient to just provide
56
* different TabBoxConfig objects instead of creating an own handler for each mode.
58
* In order to use the TabBox the TabBoxConfig has to be set. This defines if the model for desktops or for
59
* clients will be used. The model has to be initialized by calling TabBoxHandler::createModel(), as the
60
* model is undefined when the TabBox is not active. The TabBox is activated by TabBoxHandler::show().
61
* Depending on the current set TabBoxConfig it is possible that an additional outline is shown, the
62
* highlight windows effect activated and that the view is not displayed at all. As already mentioned
63
* the TabBox does not handle any updating of the selected item. This has to be done by invoking
64
* TabBoxHandler::setCurrentIndex(). Nevertheless the TabBoxHandler provides methods to query for the
65
* model index or the next or previous item, for a cursor position or for a given item (that is
66
* TabBoxClient or desktop). By invoking TabBoxHandler::hide() the view, the optional outline and the
67
* optional highlight windows effect are removed. The model is invalidated immediately. So if it is
68
* necessary to retrieve the last selected item this has to be done before calling the hide method.
70
* The layout of the TabBox View and the items is completely customizable. Therefore TabBox provides
71
* a widget LayoutConfig which includes a live preview (in kcmkwin/kwintabbox). The layout of items
72
* can be defined by an xml document. That way the user is able to define own custom layouts. The view
73
* itself is made up of two widgets: one to show the complete list and one to show only the selected
74
* item. This way it is possible to have a view which shows for example a list containing only small
75
* icons and nevertheless show the title of the currently selected client.
84
class TabBoxHandlerPrivate;
85
typedef QList< TabBoxClient* > TabBoxClientList;
88
* This class is a wrapper around KWin Workspace. It is used for accessing the
89
* required core methods from inside TabBox and has to be implemented in KWin core.
91
* @author Martin Gräßlin <kde@martin-graesslin.com>
94
class TabBoxHandler : public QObject
99
virtual ~TabBoxHandler();
102
* @return The id of the active screen
104
virtual int activeScreen() const = 0;
106
* @return The current active TabBoxClient or NULL
107
* if there is no active client.
109
virtual TabBoxClient* activeClient() const = 0;
111
* @param client The client which is starting point to find the next client
112
* @return The next TabBoxClient in focus chain
114
virtual TabBoxClient* nextClientFocusChain(TabBoxClient* client) const = 0;
116
* @param client The client whose desktop name should be retrieved
117
* @return The desktop name of the given TabBoxClient. If the client is
118
* on all desktops the name of current desktop will be returned.
120
virtual QString desktopName(TabBoxClient* client) const = 0;
122
* @param desktop The desktop whose name should be retrieved
123
* @return The desktop name of given desktop
125
virtual QString desktopName(int desktop) const = 0;
127
* @return The number of current desktop
129
virtual int currentDesktop() const = 0;
131
* @return The number of virtual desktops
133
virtual int numberOfDesktops() const = 0;
135
* @param desktop The desktop which is the starting point to find the next desktop
136
* @return The next desktop in the current focus chain.
138
virtual int nextDesktopFocusChain(int desktop) const = 0;
141
* Raise a client (w/o activating it)
143
virtual void raiseClient(TabBoxClient* c) const = 0;
146
* @param c The client to be restacked
147
* @param under The client the other one will be placed below
149
virtual void restack(TabBoxClient *c, TabBoxClient *under) = 0;
152
* @return The current stacking order of TabBoxClients
154
virtual TabBoxClientList stackingOrder() const = 0;
156
* Determines if given client will be added to the list:
158
* <LI>Depends on desktop</LI>
159
* <LI>if the client wants to have tab focus.</LI>
160
* <LI>The client won't be added if it has modal dialogs</LI>
161
* <LI>In that case the modal dialog will be returned if it isn't already
163
* <LI>Won't be added if it isn't on active screen when using separate
166
* @param client The client to be checked for inclusion
167
* @param desktop The desktop the client should be on. This is irrelevant if allDesktops is set
168
* @param allDesktops Add clients from all desktops or only from current
169
* @return The client to be included in the list or NULL if it isn't to be included
171
virtual TabBoxClient* clientToAddToList(TabBoxClient* client, int desktop, bool allDesktops) const = 0;
173
* @return The first desktop window in the stacking order.
175
virtual TabBoxClient* desktopClient() const = 0;
178
* @return The currently used TabBoxConfig
180
const TabBoxConfig& config() const;
182
* Call this method when you want to change the currently used TabBoxConfig.
183
* It fires the signal configChanged.
184
* @param config Updates the currently used TabBoxConfig to config
186
void setConfig(const TabBoxConfig& config);
189
* Call this method to show the TabBoxView. Depending on current
190
* configuration this method might not do anything.
191
* If highlight windows effect is to be used it will be activated.
192
* If the outline has to be shown, it will be shown.
193
* Highlight windows and outline are not shown if
194
* TabBoxConfig::TabBoxMode is TabBoxConfig::DesktopTabBox.
195
* @see TabBoxConfig::isShowTabBox
196
* @see TabBoxConfig::isHighlightWindows
197
* @see TabBoxConfig::showOutline
201
* Hides the TabBoxView if shown.
202
* Deactivates highlight windows effect if active.
203
* Removes the outline if active.
206
void hide(bool abort = false);
209
* Sets the current model index in the view and updates
210
* highlight windows and outline if active.
211
* @param index The current Model index
213
void setCurrentIndex(const QModelIndex& index);
216
* Retrieves the next or previous item of the current item.
217
* @param forward next or previous item
218
* @return The next or previous item. If there is no matching item
219
* the current item will be returned.
221
QModelIndex nextPrev(bool forward) const;
224
* Initializes the model based on the current config.
225
* This method has to be invoked before showing the TabBox.
226
* It can also be invoked when clients are added or removed.
227
* In that case partialReset has to be true.
229
* @param partialReset Keep the currently selected item or regenerate everything
231
void createModel(bool partialReset = false);
234
* @param desktop The desktop whose index should be retrieved
235
* @return The model index of given desktop. If TabBoxMode is not
236
* TabBoxConfig::DesktopTabBox an invalid model index will be returned.
238
QModelIndex desktopIndex(int desktop) const;
240
* @return The current list of desktops.
241
* If TabBoxMode is not TabBoxConfig::DesktopTabBox an empty list will
243
* @see DesktopModel::desktopList
245
QList< int > desktopList() const;
247
* @return The desktop for given model index. If the index is not valid
248
* or TabBoxMode is not TabBoxConfig::DesktopTabBox -1 will be returned.
249
* @see DesktopModel::desktopIndex
251
int desktop(const QModelIndex& index) const;
253
* @return The current selected desktop. If there is no selected desktop
254
* or TabBoxMode is not TabBoxConfig::DesktopTabBox -1 will be returned.
256
int currentSelectedDesktop() const;
259
* Handles additional grabbed key events by the TabBox controller.
260
* It is able to handle cursor key presses and to find the item
261
* left/right/above/below of current item.
262
* @param event The key event which has been grabbed
263
* @return Returns the model index of the left, right, above or
264
* below item, if a cursor key has been pressed. If there is no
265
* such item the current item is returned.
267
virtual QModelIndex grabbedKeyEvent(QKeyEvent* event) const;
269
* @param pos The position to be tested in global coordinates
270
* @return True if the view contains the point, otherwise false.
272
bool containsPos(const QPoint& pos) const;
274
* Returns the index at the given position in global coordinates
276
* @param pos The position in global coordinates
277
* @return The model index at given position. If there is no item
278
* at the position or the position is not in the view an invalid
279
* model index will be returned;
281
QModelIndex indexAt(const QPoint& pos) const;
283
* @param client The TabBoxClient whose index should be returned
284
* @return Returns the ModelIndex of given TabBoxClient or an invalid ModelIndex
285
* if the model does not contain the given TabBoxClient.
286
* @see ClientModel::index
288
QModelIndex index(TabBoxClient* client) const;
290
* @return Returns the current list of TabBoxClients.
291
* If TabBoxMode is not TabBoxConfig::ClientTabBox an empty list will
293
* @see ClientModel::clientList
295
TabBoxClientList clientList() const;
297
* @param index The index of the client to be returned
298
* @return Returns the TabBoxClient at given model index. If
299
* the index is invalid, does not point to a Client or the list
300
* is empty, NULL will be returned.
302
TabBoxClient* client(const QModelIndex& index) const;
304
* @return The first model index. That is the model index at position 0, 0.
305
* It is valid, as desktop has at least one desktop and if there are no
306
* clients an empty item is created.
308
QModelIndex first() const;
311
* @return The tabBoxView Widget
313
QWidget* tabBoxView() const;
317
* Show the outline of the current selected window
318
* @param outline The geometry of the window the outline will be shown
321
virtual void showOutline(const QRect &outline) = 0;
324
* Hide previously shown outline
327
virtual void hideOutline() = 0;
330
* Return outline window ids
331
* @return The outline window ids given in the order left, top, right, bottom
334
virtual QVector<Window> outlineWindowIds() const = 0;
338
* This signal is fired when the TabBoxConfig changes
341
void configChanged();
344
friend class TabBoxHandlerPrivate;
345
TabBoxHandlerPrivate* d;
349
* This class is a wrapper around a KWin Client. It is used for accessing the
350
* required client methods from inside TabBox and has to be implemented in KWin core.
352
* @author Martin Gräßlin <kde@martin-graesslin.com>
359
virtual ~TabBoxClient();
362
* @return The caption of the client
364
virtual QString caption() const = 0;
366
* @param size Requested size of the icon
367
* @return The icon of the client
369
virtual QPixmap icon(const QSize& size = QSize(32, 32)) const = 0;
371
* @return The window Id of the client
373
virtual WId window() const = 0;
375
* @return Minimized state of the client
377
virtual bool isMinimized() const = 0;
378
virtual int x() const = 0;
379
virtual int y() const = 0;
380
virtual int width() const = 0;
381
virtual int height() const = 0;
385
* Pointer to the global TabBoxHandler object.
387
extern TabBoxHandler* tabBox;
389
} // namespace TabBox
392
#endif // TABBOXHANDLER_H