summaryrefslogtreecommitdiff
path: root/kde/window-decorator-kde4/window.h
blob: de7031a7b3282caf8aeda306ece6539684948e36 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
/*
 * Copyright © 2008 Dennis Kasprzyk <onestone@opencompositing.org>
 * Copyright © 2006 Novell, Inc.
 * Copyright © 2006 Volker Krause <vkrause@kde.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301, USA.
 *
 * Author: David Reveman <davidr@novell.com>
 */

#ifndef _WINDOW_H
#define _WINDOW_H

#include <kdecorationbridge.h>
#include <KDE/KActionCollection>

#include <qpixmap.h>
#include <qwidget.h>
#include <qprocess.h>

#include <decoration.h>

#include <X11/extensions/Xdamage.h>

#include "utils.h"
#include "options.h"

class QProcess;
class KDecoration;
class KActionCollection;
class QMenu;

namespace KWD
{
class Window:public QWidget, public KDecorationBridgeUnstable {
    Q_OBJECT public:

	enum Type
	{
	    Normal,
	    Default,
	    DefaultActive,
	    Normal2D
	};

    public:
	Window (WId parentId, WId clientId, WId frame, Type type,
		int x = 0, int y = 0, int w = 1, int h = 1);
	~Window (void);

	// unsable API part
        virtual void repaintShadow ();
        virtual bool compositingActive () const;
        virtual bool shadowsActive () const;
        virtual double opacity () const;

        // stable API part;
	virtual bool isActive (void) const;
	virtual bool isCloseable (void) const;
	virtual bool isMaximizable (void) const;
	virtual MaximizeMode maximizeMode (void) const;
	virtual bool isMinimizable (void) const;
	virtual bool providesContextHelp (void) const;
	virtual int desktop (void) const;
	virtual bool isModal (void) const;
	virtual bool isShadeable (void) const;
	virtual bool isShade (void) const;
	virtual bool isSetShade (void) const;
	virtual bool keepAbove (void) const;
	virtual bool keepBelow (void) const;
	virtual bool isMovable (void) const;
	virtual bool isResizable (void) const;
	virtual NET::WindowType
	    windowType (unsigned long supported_types) const;
	virtual QIcon icon (void) const;
	virtual QString caption (void) const;
	virtual void processMousePressEvent (QMouseEvent *);
	virtual void showWindowMenu (const QRect &);
	virtual void showWindowMenu (const QPoint &);
	virtual void performWindowOperation (WindowOperation);
	virtual void setMask (const QRegion &, int);
	virtual bool isPreview (void) const;
	virtual QRect geometry (void) const;
	virtual QRect iconGeometry (void) const;
	virtual QRegion unobscuredRegion (const QRegion & r) const;
	virtual WId windowId (void) const;
	virtual void closeWindow (void);
	virtual void maximize (MaximizeMode mode);
	virtual void minimize (void);
	virtual void showContextHelp (void);
	virtual void setDesktop (int desktop);
	virtual void titlebarDblClickOperation (void);
	virtual void titlebarMouseWheelOperation (int delta);
	virtual void setShade (bool set);
	virtual void setKeepAbove (bool);
	virtual void setKeepBelow (bool);
	virtual int currentDesktop (void) const;
	virtual QWidget *initialParentWidget (void) const;
	virtual Qt::WFlags initialWFlags (void) const;
	virtual void grabXServer (bool grab);

	void handleActiveChange (void);
	void updateFrame (WId frame);
	void updateWindowGeometry (void);
	void updateCursor (QPoint pos);
	void updateSelected (WId selected);
	WId frameId (void) const
	{
	    return mFrame;
	}
	KDecoration *decoration (void) const
	{
	    return mDecor;
	}
	QWidget *activeChild (void) const
	{
	    return mActiveChild;
	}
	void setActiveChild (QWidget * child)
	{
	    mActiveChild = child;
	}
	QRegion *getShape (void)
	{
	    if (mShapeSet)
		return &mShape;

	    return NULL;
	}
	void getShapeInfo (bool *horz, bool *vert)
	{
	    *horz = mUniqueHorzShape;
	    *vert = mUniqueVertShape;
	}
	void moveWindow (QMouseEvent *qme);
	void reloadDecoration (void);
	void updateState (void);
	void updateName (void);
	void updateIcons (void);
	void updateOpacity (void)
	{
	    mOpacity = readPropertyShort (mClientId, Atoms::netWmWindowOpacity,
					  0xffff);
	}
	Drawable pixmapId (void) const
	{
	    return mPixmap;
	}
	void addDamageRect (int x, int y, int w, int h)
	{
	    mDamage += QRegion (x, y, w, h);
	}
	bool handleMap (void);
	bool handleConfigure (QSize size);
	void processDamage (void);
	decor_context_t *context (void)
	{
	    return &mContext;
	}
	decor_shadow_t *shadow (void)
	{
	    return mShadow;
	}
	decor_extents_t *border (void)
	{
	    return &mBorder;
	}

	QRect clientGeometry (void);
	void showKillProcessDialog (Time timestamp);
	void hideKillProcessDialog (void);

	void setFakeRelease (bool fakeRelease)
	{
	    mFakeRelease = fakeRelease;
	}

	bool getFakeRelease ()
	{
	    return mFakeRelease;
	}

	WId winId ()
	{
	    if (mType == Normal2D && mDecor)
		return mDecor->widget ()->winId ();
	    return QWidget::winId ();
	}

	QWidget *childAt (int x, int y)
	{
	    QWidget *rv;
	    if (mType == Normal2D && mDecor)
	    {
		rv = mDecor->widget ()->childAt (x, y);
		if (!rv)
		    rv = mDecor->widget ();
		return rv;
	    }
	    return QWidget::childAt (x, y);
	}

	virtual bool eventFilter (QObject *o, QEvent *e);

    private:
	bool resizeDecoration (bool force = false);
	void updateBlurProperty (int topOffset,
				 int bottomOffset,
				 int leftOffset,
				 int rightOffset);
	void updateProperty (void);
	void getWindowProtocols (void);
	void performMouseCommand (KWD::Options::MouseCommand command,
				  QMouseEvent		     *qme);
	NET::Direction positionToDirection (int pos);
	Cursor positionToCursor (QPoint pos);
	void rebindPixmap (void);


    private slots:
	void createDecoration (void);
	void updateShadow (void);
	void handlePopupActivated (QAction *action);
	void handleOpacityPopupActivated (QAction *action);
	void handleDesktopPopupActivated (QAction *action);
	void handlePopupAboutToShow (void);

    private:
	Type mType;
	WId mParentId;
	WId mFrame;
	WId mClientId;
	WId mSelectedId;
	QRect mGeometry;
	QString mName;
	QPixmap mIcon;
	QPixmap mMiniIcon;
	decor_extents_t mBorder;
	unsigned short mOpacity;
	KDecoration *mDecor;
	Pixmap mTexturePixmap;
	Pixmap mTexturePixmapBuffer;
	QSize mTexturePixmapSize;
	Pixmap mPixmap;
	QRegion mDamage;
	WId mDamageId;
	decor_layout_t mLayout;
	decor_context_t mContext;
	decor_shadow_t *mShadow;
	Picture mPicture;
	Picture mTexturePicture;
	Picture mDecorationPicture;
	bool mUpdateProperty;
	bool mShapeSet;
	bool mUniqueHorzShape;
	bool mUniqueVertShape;
	QRegion mShape;
	QWidget *mActiveChild;
	bool mSupportTakeFocus;
	bool mSupportContextHelp;
	QMenu *mPopup;
	QMenu *mAdvancedMenu;
	QMenu *mOpacityMenu;
	QMenu *mDesktopMenu;
	unsigned long mState;
	bool mMapped;
	int mPendingMap;
	int mPendingConfigure;
	QSize mSize;
	QProcess mProcessKiller;
	KActionCollection mKeys;
	bool mFakeRelease;

	QAction *mResizeOpAction;
        QAction *mMoveOpAction;
        QAction *mMaximizeOpAction;
        QAction *mShadeOpAction;
        QAction *mKeepAboveOpAction;
        QAction *mKeepBelowOpAction;
        QAction *mFullScreenOpAction;
        QAction *mNoBorderOpAction;
        QAction *mMinimizeOpAction;
        QAction *mCloseOpAction;
	QAction *mDesktopOpAction;
    };
}

#endif