~ubuntu-branches/ubuntu/gutsy/kdebase-workspace/gutsy-backports

« back to all changes in this revision

Viewing changes to kwin/toplevel.h

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2007-09-05 20:45:14 UTC
  • Revision ID: james.westby@ubuntu.com-20070905204514-632hhspl0nvrc84i
Tags: upstream-3.93.0
ImportĀ upstreamĀ versionĀ 3.93.0

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) 2006 Lubos Lunak <l.lunak@kde.org>
 
6
 
 
7
You can Freely distribute this program under the GNU General Public
 
8
License. See the file "COPYING" for the exact licensing terms.
 
9
******************************************************************/
 
10
 
 
11
#ifndef KWIN_TOPLEVEL_H
 
12
#define KWIN_TOPLEVEL_H
 
13
 
 
14
#include <config-X11.h>
 
15
 
 
16
#include <assert.h>
 
17
#include <qobject.h>
 
18
#include <kdecoration.h>
 
19
 
 
20
#include "utils.h"
 
21
#include "workspace.h"
 
22
 
 
23
#ifdef HAVE_XDAMAGE
 
24
#include <X11/extensions/Xdamage.h>
 
25
#endif
 
26
 
 
27
class NETWinInfo;
 
28
 
 
29
namespace KWin
 
30
{
 
31
 
 
32
class Workspace;
 
33
class EffectWindowImpl;
 
34
 
 
35
class Toplevel
 
36
    : public QObject, public KDecorationDefines
 
37
    {
 
38
    Q_OBJECT
 
39
    public:
 
40
        Toplevel( Workspace *ws );
 
41
        Window frameId() const;
 
42
        Window window() const;
 
43
        Workspace* workspace() const;
 
44
        QRect geometry() const;
 
45
        QSize size() const;
 
46
        QPoint pos() const;
 
47
        QRect rect() const;
 
48
        int x() const;
 
49
        int y() const;
 
50
        int width() const;
 
51
        int height() const;
 
52
        virtual QPoint clientPos() const = 0; // inside of geometry()
 
53
        virtual QSize clientSize() const = 0;
 
54
 
 
55
    // prefer isXXX() instead
 
56
        NET::WindowType windowType( bool direct = false, int supported_types = SUPPORTED_WINDOW_TYPES_MASK ) const;
 
57
        bool hasNETSupport() const;
 
58
        bool isDesktop() const;
 
59
        bool isDock() const;
 
60
        bool isToolbar() const;
 
61
        bool isTopMenu() const;
 
62
        bool isMenu() const;
 
63
        bool isNormalWindow() const; // normal as in 'NET::Normal or NET::Unknown non-transient'
 
64
        bool isDialog() const;
 
65
        bool isSplash() const;
 
66
        bool isUtility() const;
 
67
        bool isDropdownMenu() const;
 
68
        bool isPopupMenu() const; // a context popup, not dropdown, not torn-off
 
69
        bool isTooltip() const;
 
70
        bool isNotification() const;
 
71
        bool isComboBox() const;
 
72
        bool isDNDIcon() const;
 
73
 
 
74
        virtual int desktop() const = 0;
 
75
        bool isOnDesktop( int d ) const;
 
76
        bool isOnCurrentDesktop() const;
 
77
        bool isOnAllDesktops() const;
 
78
 
 
79
        QByteArray windowRole() const;
 
80
        QByteArray sessionId();
 
81
        QByteArray resourceName() const;
 
82
        QByteArray resourceClass() const;
 
83
        QByteArray wmCommand();
 
84
        QByteArray wmClientMachine( bool use_localhost ) const;
 
85
        Window wmClientLeader() const;
 
86
        pid_t pid() const;
 
87
        static bool resourceMatch( const Toplevel* c1, const Toplevel* c2 );
 
88
 
 
89
        Pixmap windowPixmap( bool allow_create = true ); // may return None (e.g. at a bad moment while resizing)
 
90
        bool readyForPainting() const; // true if the window has been already painted its contents
 
91
        Visual* visual() const;
 
92
        bool shape() const;
 
93
        void setOpacity( float opacity );
 
94
        float opacity() const;
 
95
        int depth() const;
 
96
        bool hasAlpha() const;
 
97
        void setupCompositing();
 
98
        void finishCompositing();
 
99
        void addRepaint( const QRect& r );
 
100
        void addRepaint( int x, int y, int w, int h );
 
101
        void addRepaintFull();
 
102
        // these call workspace->addRepaint(), but first transform the damage if needed
 
103
        void addWorkspaceRepaint( const QRect& r );
 
104
        void addWorkspaceRepaint( int x, int y, int w, int h );
 
105
        QRegion repaints() const;
 
106
        void resetRepaints( const QRect& r );
 
107
        QRegion damage() const;
 
108
        void resetDamage( const QRect& r );
 
109
        EffectWindowImpl* effectWindow();
 
110
 
 
111
    protected:
 
112
        virtual ~Toplevel();
 
113
        void setWindowHandles( Window client, Window frame );
 
114
        void detectShape( Window id );
 
115
        virtual void propertyNotifyEvent( XPropertyEvent* e );
 
116
#ifdef HAVE_XDAMAGE
 
117
        virtual void damageNotifyEvent( XDamageNotifyEvent* e );
 
118
#endif
 
119
        Pixmap createWindowPixmap();
 
120
        void discardWindowPixmap();
 
121
        void addDamage( const QRect& r );
 
122
        void addDamage( int x, int y, int w, int h );
 
123
        void addDamageFull();
 
124
        void getWmClientLeader();
 
125
        void getWmClientMachine();
 
126
        void getResourceClass();
 
127
        void getWindowRole();
 
128
        virtual void debug( kdbgstream& stream ) const = 0;
 
129
        void copyToDeleted( Toplevel* c );
 
130
        void disownDataPassedToDeleted();
 
131
        friend kdbgstream& operator<<( kdbgstream& stream, const Toplevel* );
 
132
        QRect geom;
 
133
        Visual* vis;
 
134
        int bit_depth;
 
135
        NETWinInfo* info;
 
136
        bool ready_for_painting;
 
137
    private:
 
138
        static QByteArray staticWindowRole(WId);
 
139
        static QByteArray staticSessionId(WId);
 
140
        static QByteArray staticWmCommand(WId);
 
141
        static QByteArray staticWmClientMachine(WId);
 
142
        static Window staticWmClientLeader(WId);
 
143
        // when adding new data members, check also copyToDeleted()
 
144
        Window client;
 
145
        Window frame;
 
146
        Workspace* wspace;
 
147
        Pixmap window_pix;
 
148
#ifdef HAVE_XDAMAGE
 
149
        Damage damage_handle;
 
150
#endif
 
151
        QRegion damage_region; // damage is really damaged window (XDamage) and texture needs
 
152
        QRegion repaints_region; // updating, repaint just requires repaint of that area
 
153
        bool is_shape;
 
154
        EffectWindowImpl* effect_window;
 
155
        QByteArray resource_name;
 
156
        QByteArray resource_class;
 
157
        QByteArray client_machine;
 
158
        WId wmClientLeaderWin;
 
159
        QByteArray window_role;
 
160
        // when adding new data members, check also copyToDeleted()
 
161
    };
 
162
 
 
163
inline Window Toplevel::window() const
 
164
    {
 
165
    return client;
 
166
    }
 
167
 
 
168
inline Window Toplevel::frameId() const
 
169
    {
 
170
    return frame;
 
171
    }
 
172
 
 
173
inline void Toplevel::setWindowHandles( Window w, Window f )
 
174
    {
 
175
    assert( client == None && w != None );
 
176
    client = w;
 
177
    assert( frame == None && f != None );
 
178
    frame = f;
 
179
    }
 
180
 
 
181
inline Workspace* Toplevel::workspace() const
 
182
    {
 
183
    return wspace;
 
184
    }
 
185
 
 
186
inline QRect Toplevel::geometry() const
 
187
    {
 
188
    return geom;
 
189
    }
 
190
 
 
191
inline QSize Toplevel::size() const
 
192
    {
 
193
    return geom.size();
 
194
    }
 
195
 
 
196
inline QPoint Toplevel::pos() const
 
197
    {
 
198
    return geom.topLeft();
 
199
    }
 
200
 
 
201
inline int Toplevel::x() const
 
202
    {
 
203
    return geom.x();
 
204
    }
 
205
 
 
206
inline int Toplevel::y() const
 
207
    {
 
208
    return geom.y();
 
209
    }
 
210
 
 
211
inline int Toplevel::width() const
 
212
    {
 
213
    return geom.width();
 
214
    }
 
215
 
 
216
inline int Toplevel::height() const
 
217
    {
 
218
    return geom.height();
 
219
    }
 
220
 
 
221
inline QRect Toplevel::rect() const
 
222
    {
 
223
    return QRect( 0, 0, width(), height());
 
224
    }
 
225
 
 
226
inline bool Toplevel::readyForPainting() const
 
227
    {
 
228
    return ready_for_painting;
 
229
    }
 
230
 
 
231
inline Visual* Toplevel::visual() const
 
232
    {
 
233
    return vis;
 
234
    }
 
235
 
 
236
inline bool Toplevel::isDesktop() const
 
237
    {
 
238
    return windowType() == NET::Desktop;
 
239
    }
 
240
 
 
241
inline bool Toplevel::isDock() const
 
242
    {
 
243
    return windowType() == NET::Dock;
 
244
    }
 
245
 
 
246
inline bool Toplevel::isTopMenu() const
 
247
    {
 
248
    return windowType() == NET::TopMenu;
 
249
    }
 
250
 
 
251
inline bool Toplevel::isMenu() const
 
252
    {
 
253
    return windowType() == NET::Menu && !isTopMenu(); // because of backwards comp.
 
254
    }
 
255
 
 
256
inline bool Toplevel::isToolbar() const
 
257
    {
 
258
    return windowType() == NET::Toolbar;
 
259
    }
 
260
 
 
261
inline bool Toplevel::isSplash() const
 
262
    {
 
263
    return windowType() == NET::Splash;
 
264
    }
 
265
 
 
266
inline bool Toplevel::isUtility() const
 
267
    {
 
268
    return windowType() == NET::Utility;
 
269
    }
 
270
 
 
271
inline bool Toplevel::isDialog() const
 
272
    {
 
273
    return windowType() == NET::Dialog;
 
274
    }
 
275
 
 
276
inline bool Toplevel::isNormalWindow() const
 
277
    {
 
278
    return windowType() == NET::Normal;
 
279
    }
 
280
 
 
281
inline bool Toplevel::isDropdownMenu() const
 
282
    {
 
283
    return windowType() == NET::DropdownMenu;
 
284
    }
 
285
 
 
286
inline bool Toplevel::isPopupMenu() const
 
287
    {
 
288
    return windowType() == NET::PopupMenu;
 
289
    }
 
290
 
 
291
inline bool Toplevel::isTooltip() const
 
292
    {
 
293
    return windowType() == NET::Tooltip;
 
294
    }
 
295
 
 
296
inline bool Toplevel::isNotification() const
 
297
    {
 
298
    return windowType() == NET::Notification;
 
299
    }
 
300
 
 
301
inline bool Toplevel::isComboBox() const
 
302
    {
 
303
    return windowType() == NET::ComboBox;
 
304
    }
 
305
 
 
306
inline bool Toplevel::isDNDIcon() const
 
307
    {
 
308
    return windowType() == NET::DNDIcon;
 
309
    }
 
310
 
 
311
inline Pixmap Toplevel::windowPixmap( bool allow_create )
 
312
    {
 
313
    if( window_pix == None && allow_create )
 
314
        window_pix = createWindowPixmap();
 
315
    return window_pix;
 
316
    }
 
317
 
 
318
inline QRegion Toplevel::damage() const
 
319
    {
 
320
    return damage_region;
 
321
    }
 
322
 
 
323
inline QRegion Toplevel::repaints() const
 
324
    {
 
325
    return repaints_region;
 
326
    }
 
327
 
 
328
inline bool Toplevel::shape() const
 
329
    {
 
330
    return is_shape;
 
331
    }
 
332
 
 
333
inline int Toplevel::depth() const
 
334
    {
 
335
    return bit_depth;
 
336
    }
 
337
 
 
338
inline bool Toplevel::hasAlpha() const
 
339
    {
 
340
    return depth() == 32;
 
341
    }
 
342
 
 
343
inline
 
344
EffectWindowImpl* Toplevel::effectWindow()
 
345
    {
 
346
    return effect_window;
 
347
    }
 
348
 
 
349
inline bool Toplevel::isOnAllDesktops() const
 
350
    {
 
351
    return desktop() == NET::OnAllDesktops;
 
352
    }
 
353
 
 
354
inline bool Toplevel::isOnDesktop( int d ) const
 
355
    {
 
356
    return desktop() == d || /*desk == 0 ||*/ isOnAllDesktops();
 
357
    }
 
358
 
 
359
inline bool Toplevel::isOnCurrentDesktop() const
 
360
    {
 
361
    return isOnDesktop( workspace()->currentDesktop());
 
362
    }
 
363
 
 
364
inline QByteArray Toplevel::resourceName() const
 
365
    {
 
366
    return resource_name; // it is always lowercase
 
367
    }
 
368
 
 
369
inline QByteArray Toplevel::resourceClass() const
 
370
    {
 
371
    return resource_class; // it is always lowercase
 
372
    }
 
373
 
 
374
inline QByteArray Toplevel::windowRole() const
 
375
    {
 
376
    return window_role;
 
377
    }
 
378
 
 
379
inline pid_t Toplevel::pid() const
 
380
    {
 
381
    return info->pid();
 
382
    }
 
383
 
 
384
#ifdef NDEBUG
 
385
inline
 
386
kndbgstream& operator<<( kndbgstream& stream, const Toplevel* ) { return stream; }
 
387
inline
 
388
kndbgstream& operator<<( kndbgstream& stream, const ToplevelList& ) { return stream; }
 
389
inline
 
390
kndbgstream& operator<<( kndbgstream& stream, const ConstToplevelList& ) { return stream; }
 
391
#else
 
392
kdbgstream& operator<<( kdbgstream& stream, const Toplevel* );
 
393
kdbgstream& operator<<( kdbgstream& stream, const ToplevelList& );
 
394
kdbgstream& operator<<( kdbgstream& stream, const ConstToplevelList& );
 
395
#endif
 
396
 
 
397
KWIN_COMPARE_PREDICATE( WindowMatchPredicate, Toplevel, Window, cl->window() == value );
 
398
KWIN_COMPARE_PREDICATE( FrameIdMatchPredicate, Toplevel, Window, cl->frameId() == value );
 
399
 
 
400
} // namespace
 
401
 
 
402
#endif