~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kwin/utils.h

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/********************************************************************
 
2
 KWin - the KDE window manager
 
3
 This file is part of the KDE project.
 
4
 
 
5
Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org>
 
6
Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
 
7
 
 
8
This program is free software; you can redistribute it and/or modify
 
9
it under the terms of the GNU General Public License as published by
 
10
the Free Software Foundation; either version 2 of the License, or
 
11
(at your option) any later version.
 
12
 
 
13
This program is distributed in the hope that it will be useful,
 
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
GNU General Public License for more details.
 
17
 
 
18
You should have received a copy of the GNU General Public License
 
19
along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
*********************************************************************/
 
21
 
 
22
#ifndef KWIN_UTILS_H
 
23
#define KWIN_UTILS_H
 
24
 
 
25
class QLabel;
 
26
 
 
27
#include <config-workspace.h>
 
28
#include <config-X11.h>
 
29
#include <config-kwin.h>
 
30
 
 
31
#include <kwinconfig.h>
 
32
 
 
33
#include <X11/Xlib.h>
 
34
 
 
35
#include <fixx11h.h>
 
36
 
 
37
#include <QWidget>
 
38
#include <kmanagerselection.h>
 
39
#include <netwm_def.h>
 
40
#include <kkeysequencewidget.h>
 
41
#include <limits.h>
 
42
#include <QX11Info>
 
43
#include <kdialog.h>
 
44
 
 
45
#include <kwinglobals.h>
 
46
 
 
47
// needed by the DBUS interface
 
48
Q_DECLARE_METATYPE(QList<int>)
 
49
 
 
50
namespace KWin
 
51
{
 
52
 
 
53
#ifndef HAVE_XDAMAGE
 
54
typedef long Damage;
 
55
struct XDamageNotifyEvent {
 
56
};
 
57
#endif
 
58
 
 
59
// window types that are supported as normal windows (i.e. KWin actually manages them)
 
60
const int SUPPORTED_MANAGED_WINDOW_TYPES_MASK = NET::NormalMask | NET::DesktopMask | NET::DockMask
 
61
        | NET::ToolbarMask | NET::MenuMask | NET::DialogMask /*| NET::OverrideMask*/ | NET::TopMenuMask
 
62
        | NET::UtilityMask | NET::SplashMask;
 
63
// window types that are supported as unmanaged (mainly for compositing)
 
64
const int SUPPORTED_UNMANAGED_WINDOW_TYPES_MASK = NET::NormalMask | NET::DesktopMask | NET::DockMask
 
65
        | NET::ToolbarMask | NET::MenuMask | NET::DialogMask /*| NET::OverrideMask*/ | NET::TopMenuMask
 
66
        | NET::UtilityMask | NET::SplashMask | NET::DropdownMenuMask | NET::PopupMenuMask
 
67
        | NET::TooltipMask | NET::NotificationMask | NET::ComboBoxMask | NET::DNDIconMask;
 
68
 
 
69
const long ClientWinMask = KeyPressMask | KeyReleaseMask |
 
70
                           ButtonPressMask | ButtonReleaseMask |
 
71
                           KeymapStateMask |
 
72
                           ButtonMotionMask |
 
73
                           PointerMotionMask | // need this, too!
 
74
                           EnterWindowMask | LeaveWindowMask |
 
75
                           FocusChangeMask |
 
76
                           ExposureMask |
 
77
                           StructureNotifyMask |
 
78
                           SubstructureRedirectMask;
 
79
 
 
80
const QPoint invalidPoint(INT_MIN, INT_MIN);
 
81
 
 
82
class Toplevel;
 
83
class Client;
 
84
class Unmanaged;
 
85
class Deleted;
 
86
class Group;
 
87
class Options;
 
88
 
 
89
typedef QList< Toplevel* > ToplevelList;
 
90
typedef QList< const Toplevel* > ConstToplevelList;
 
91
typedef QList< Client* > ClientList;
 
92
typedef QList< const Client* > ConstClientList;
 
93
typedef QList< Unmanaged* > UnmanagedList;
 
94
typedef QList< const Unmanaged* > ConstUnmanagedList;
 
95
typedef QList< Deleted* > DeletedList;
 
96
typedef QList< const Deleted* > ConstDeletedList;
 
97
 
 
98
typedef QList< Group* > GroupList;
 
99
typedef QList< const Group* > ConstGroupList;
 
100
 
 
101
extern Options* options;
 
102
extern bool initting; // whether kwin is starting up
 
103
 
 
104
enum Layer {
 
105
    UnknownLayer = -1,
 
106
    FirstLayer = 0,
 
107
    DesktopLayer = FirstLayer,
 
108
    BelowLayer,
 
109
    NormalLayer,
 
110
    DockLayer,
 
111
    AboveLayer,
 
112
    ActiveLayer, // active fullscreen, or active dialog
 
113
    NumLayers // number of layers, must be last
 
114
};
 
115
 
 
116
// yes, I know this is not 100% like standard operator++
 
117
inline void operator++(Layer& lay)
 
118
{
 
119
    lay = static_cast< Layer >(lay + 1);
 
120
}
 
121
 
 
122
// for Client::takeActivity()
 
123
enum ActivityFlags {
 
124
    ActivityFocus = 1 << 0, // focus the window
 
125
    ActivityFocusForce = 1 << 1, // focus even if Dock etc.
 
126
    ActivityRaise = 1 << 2 // raise the window
 
127
};
 
128
 
 
129
enum StrutArea {
 
130
    StrutAreaInvalid = 0, // Null
 
131
    StrutAreaTop     = 1 << 0,
 
132
    StrutAreaRight   = 1 << 1,
 
133
    StrutAreaBottom  = 1 << 2,
 
134
    StrutAreaLeft    = 1 << 3,
 
135
    StrutAreaAll     = StrutAreaTop | StrutAreaRight | StrutAreaBottom | StrutAreaLeft
 
136
};
 
137
Q_DECLARE_FLAGS(StrutAreas, StrutArea)
 
138
 
 
139
class StrutRect : public QRect
 
140
{
 
141
public:
 
142
    explicit StrutRect(QRect rect = QRect(), StrutArea area = StrutAreaInvalid);
 
143
    StrutRect(const StrutRect& other);
 
144
    inline StrutArea area() const {
 
145
        return m_area;
 
146
    };
 
147
private:
 
148
    StrutArea m_area;
 
149
};
 
150
typedef QVector<StrutRect> StrutRects;
 
151
 
 
152
// Some KWin classes, mainly Client and Workspace, are very tighly coupled,
 
153
// and some of the methods of one class may be called only from speficic places.
 
154
// Those methods have additional allowed_t argument. If you pass Allowed
 
155
// as an argument to any function, make sure you really know what you're doing.
 
156
enum allowed_t { Allowed };
 
157
 
 
158
// some enums to have more readable code, instead of using bools
 
159
enum ForceGeometry_t { NormalGeometrySet, ForceGeometrySet };
 
160
 
 
161
 
 
162
 
 
163
enum ShadeMode {
 
164
    ShadeNone, // not shaded
 
165
    ShadeNormal, // normally shaded - isShade() is true only here
 
166
    ShadeHover, // "shaded", but visible due to hover unshade
 
167
    ShadeActivated // "shaded", but visible due to alt+tab to the window
 
168
};
 
169
 
 
170
// Whether to keep all windows mapped when compositing (i.e. whether to have
 
171
// actively updated window pixmaps).
 
172
enum HiddenPreviews {
 
173
    // The normal mode with regard to mapped windows. Hidden (minimized, etc.)
 
174
    // and windows on inactive virtual desktops are not mapped, their pixmaps
 
175
    // are only their icons.
 
176
    HiddenPreviewsNever,
 
177
    // Like normal mode, but shown windows (i.e. on inactive virtual desktops)
 
178
    // are kept mapped, only hidden windows are unmapped.
 
179
    HiddenPreviewsShown,
 
180
    // All windows are kept mapped regardless of their state.
 
181
    HiddenPreviewsAlways
 
182
};
 
183
 
 
184
// compile with XShape older than 1.0
 
185
#ifndef ShapeInput
 
186
const int ShapeInput = 2;
 
187
#endif
 
188
 
 
189
class Motif
 
190
{
 
191
public:
 
192
    // Read a window's current settings from its _MOTIF_WM_HINTS
 
193
    // property.  If it explicitly requests that decorations be shown
 
194
    // or hidden, 'got_noborder' is set to true and 'noborder' is set
 
195
    // appropriately.
 
196
    static void readFlags(WId w, bool& got_noborder, bool& noborder,
 
197
                          bool& resize, bool& move, bool& minimize, bool& maximize,
 
198
                          bool& close);
 
199
    struct MwmHints {
 
200
        ulong flags;
 
201
        ulong functions;
 
202
        ulong decorations;
 
203
        long input_mode;
 
204
        ulong status;
 
205
    };
 
206
    enum {
 
207
        MWM_HINTS_FUNCTIONS = (1L << 0),
 
208
        MWM_HINTS_DECORATIONS = (1L << 1),
 
209
 
 
210
        MWM_FUNC_ALL = (1L << 0),
 
211
        MWM_FUNC_RESIZE = (1L << 1),
 
212
        MWM_FUNC_MOVE = (1L << 2),
 
213
        MWM_FUNC_MINIMIZE = (1L << 3),
 
214
        MWM_FUNC_MAXIMIZE = (1L << 4),
 
215
        MWM_FUNC_CLOSE = (1L << 5)
 
216
    };
 
217
};
 
218
 
 
219
class KWinSelectionOwner
 
220
    : public KSelectionOwner
 
221
{
 
222
    Q_OBJECT
 
223
public:
 
224
    KWinSelectionOwner(int screen);
 
225
protected:
 
226
    virtual bool genericReply(Atom target, Atom property, Window requestor);
 
227
    virtual void replyTargets(Atom property, Window requestor);
 
228
    virtual void getAtoms();
 
229
private:
 
230
    Atom make_selection_atom(int screen);
 
231
    static Atom xa_version;
 
232
};
 
233
 
 
234
// Class which saves original value of the variable, assigns the new value
 
235
// to it, and in the destructor restores the value.
 
236
// Used in Client::isMaximizable() and so on.
 
237
// It also casts away contness and generally this looks like a hack.
 
238
template< typename T >
 
239
class TemporaryAssign
 
240
{
 
241
public:
 
242
    TemporaryAssign(const T& var, const T& value)
 
243
        : variable(var), orig(var) {
 
244
        const_cast< T& >(variable) = value;
 
245
    }
 
246
    ~TemporaryAssign() {
 
247
        const_cast< T& >(variable) = orig;
 
248
    }
 
249
private:
 
250
    const T& variable;
 
251
    T orig;
 
252
};
 
253
 
 
254
QByteArray getStringProperty(WId w, Atom prop, char separator = 0);
 
255
void updateXTime();
 
256
void grabXServer();
 
257
void ungrabXServer();
 
258
bool grabbedXServer();
 
259
bool grabXKeyboard(Window w = rootWindow());
 
260
void ungrabXKeyboard();
 
261
 
 
262
class Scene;
 
263
extern Scene* scene;
 
264
inline bool compositing()
 
265
{
 
266
    return scene != NULL;
 
267
}
 
268
 
 
269
// the docs say it's UrgencyHint, but it's often #defined as XUrgencyHint
 
270
#ifndef UrgencyHint
 
271
#define UrgencyHint XUrgencyHint
 
272
#endif
 
273
 
 
274
// for STL-like algo's
 
275
#define KWIN_CHECK_PREDICATE( name, cls, check ) \
 
276
    struct name \
 
277
    { \
 
278
        inline bool operator()( const cls* cl ) { return check; } \
 
279
    }
 
280
 
 
281
#define KWIN_COMPARE_PREDICATE( name, cls, type, check ) \
 
282
    struct name \
 
283
    { \
 
284
        typedef type type_helper; /* in order to work also with type being 'const Client*' etc. */ \
 
285
        inline name( const type_helper& compare_value ) : value( compare_value ) {} \
 
286
        inline bool operator()( const cls* cl ) { return check; } \
 
287
        const type_helper& value; \
 
288
    }
 
289
 
 
290
#define KWIN_PROCEDURE( name, cls, action ) \
 
291
    struct name \
 
292
    { \
 
293
        inline void operator()( cls* cl ) { action; } \
 
294
    }
 
295
 
 
296
KWIN_CHECK_PREDICATE(TruePredicate, Client, cl == cl /*true, avoid warning about 'cl' */);
 
297
 
 
298
template< typename T >
 
299
Client* findClientInList(const ClientList& list, T predicate)
 
300
{
 
301
    for (ClientList::ConstIterator it = list.begin(); it != list.end(); ++it) {
 
302
        if (predicate(const_cast< const Client* >(*it)))
 
303
            return *it;
 
304
    }
 
305
    return NULL;
 
306
}
 
307
 
 
308
template< typename T >
 
309
Unmanaged* findUnmanagedInList(const UnmanagedList& list, T predicate)
 
310
{
 
311
    for (UnmanagedList::ConstIterator it = list.begin(); it != list.end(); ++it) {
 
312
        if (predicate(const_cast< const Unmanaged* >(*it)))
 
313
            return *it;
 
314
    }
 
315
    return NULL;
 
316
}
 
317
 
 
318
inline
 
319
int timestampCompare(Time time1, Time time2)   // like strcmp()
 
320
{
 
321
    return NET::timestampCompare(time1, time2);
 
322
}
 
323
 
 
324
inline
 
325
Time timestampDiff(Time time1, Time time2)   // returns time2 - time1
 
326
{
 
327
    return NET::timestampDiff(time1, time2);
 
328
}
 
329
 
 
330
bool isLocalMachine(const QByteArray& host);
 
331
 
 
332
QPoint cursorPos();
 
333
 
 
334
// converting between X11 mouse/keyboard state mask and Qt button/keyboard states
 
335
int qtToX11Button(Qt::MouseButton button);
 
336
Qt::MouseButton x11ToQtMouseButton(int button);
 
337
int qtToX11State(Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
 
338
Qt::MouseButtons x11ToQtMouseButtons(int state);
 
339
Qt::KeyboardModifiers x11ToQtKeyboardModifiers(int state);
 
340
 
 
341
void checkNonExistentClients();
 
342
 
 
343
#ifndef KCMRULES
 
344
// Qt dialogs emit no signal when closed :(
 
345
class ShortcutDialog
 
346
    : public KDialog
 
347
{
 
348
    Q_OBJECT
 
349
public:
 
350
    ShortcutDialog(const QKeySequence& cut);
 
351
    virtual void accept();
 
352
    QKeySequence shortcut() const;
 
353
public Q_SLOTS:
 
354
    void keySequenceChanged(const QKeySequence &seq);
 
355
signals:
 
356
    void dialogDone(bool ok);
 
357
protected:
 
358
    virtual void done(int r);
 
359
private:
 
360
    KKeySequenceWidget* widget;
 
361
    QKeySequence _shortcut;
 
362
    QLabel *warning;
 
363
};
 
364
 
 
365
#endif //KCMRULES
 
366
 
 
367
} // namespace
 
368
 
 
369
// Must be outside namespace
 
370
Q_DECLARE_OPERATORS_FOR_FLAGS(KWin::StrutAreas)
 
371
 
 
372
#endif