summaryrefslogtreecommitdiff
path: root/src/window.h
blob: e3f757e097e30d8799788ae2b36e29eb228a40fa (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
/*
 *  Aquamarine the KDE window decorator
 *
 *  Copyright (c) 2006 Dennis Kasprzyk <onestone@beryl-project.org>
 *  Copyright (c) 2006 Volker Krause <vkrause@kde.org>
 *
 *  Uses code of:
 *      Emerald window decorator (www.beryl-project.org)
 *      gtk-window-decorator (www.freedesktop.org/wiki/Software/Compiz)
 *      KWin window manager (www.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.
 *
 */

#ifndef AQUAMARINE_WINDOW_H
#define AQUAMARINE_WINDOW_H

#include <kdecoration_p.h>

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

#include <X11/extensions/Xrender.h>

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

class KDecoration;
class QPopupMenu;
class KProcess;

namespace Aquamarine
{

    class Window:public QWidget, public KDecorationBridge
    {
      Q_OBJECT public:

      public:
        Window (WId wid, WId frame);
        ~Window ();

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

        virtual int currentDesktop () const;
        virtual QWidget *initialParentWidget () const;
        virtual Qt::WFlags initialWFlags () const;
        virtual void helperShowHide (bool);
        virtual void grabXServer (bool grab);

        void setActive (bool active);
        void updateFrame (WId frame);
        void updateWindowGeometry ();

        void updateCursor (QPoint pos);

        WId frameId () const
        {
            return m_frame;
        }
        KDecoration *decoration () const
        {
            return m_deco;
        }

        void moveWindow (QMouseEvent * qme);

        void reloadDecoration ();
		void updateConfig ();

        void updateState ();
        void updateName ();
        void updateIcons ();

        void updateOpacity ()
        {
            m_opacity =
                readWindowPropertyDefault (m_wid, Atoms::opacity, 0xffff);
        }
        void updateBrightness ()
        {
            m_brightness =
                readWindowPropertyDefault (m_wid, Atoms::brightness, 0xffff);
        }
        void updateSaturation ()
        {
            m_saturation =
                readWindowPropertyDefault (m_wid, Atoms::saturation, 0xffff);
        }

 		void setMapping (bool map);

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

	  protected:
        virtual bool eventFilter (QObject * watched, QEvent * event);

      private:
        enum WindowAppearance
        {
            ResetValues,
            ChangeOpacity25,
            ChangeOpacity50,
            ChangeOpacity75,
            ChangeOpacity100,
            ChangeBrightness25,
            ChangeBrightness50,
            ChangeBrightness75,
            ChangeBrightness100,
            ChangeSaturation25,
            ChangeSaturation50,
            ChangeSaturation75,
            ChangeSaturation100
        };

      private:
        void createDecoration ();
        void resizeDecoration ();
        void getWindowProtocols ();
        void performMouseCommand( Options::MouseCommand, QMouseEvent *qme );
		XFixed *createGaussianKernel (int *r_size);
		void setPictureTransform (Picture p, int dx, int dy);
		void renderShadow ();
		void renderShadow (QRegion reg);

      private slots:
		void updateWindow ();
        void updateWindowProperties ();
        void slotPopupActivated (int id);
        void slotPopupAboutToShow ();
        void slotChangeViewport (int id);
        void slotAppearanceChange (int id);
        void slotDesktopGeometryChanged ();
		void handleProcessKillerExited (void);

      private:
        WId m_wid;
        WId m_frame;

        // window properties
        QRect m_geometry;
        bool m_active;
        QString m_name;
        QIconSet m_icons;

        unsigned short m_opacity;
        unsigned short m_brightness;
        unsigned short m_saturation;

        // decoration stuff
        KDecoration *m_deco;
		Pixmap m_currentPixmap;
		bool m_updatePixmap;
		bool m_mapped;
        bool m_fakeMaximized;

        // shape stuff
        bool m_shapeSet;
        QRegion m_shape;
		QRegion m_shapeChange;

        // window handling
        bool m_supportDeleteWindow;
        bool m_supportTakeFocus;
        bool m_supportTakeActivity;
        bool m_supportContextHelp;
        bool m_supportPing;

        // window menu
        QPopupMenu *m_popup;
        QPopupMenu *m_advanced_popup;
        QPopupMenu *m_viewport_menu;
        QPopupMenu *m_appearance_menu;
        QPopupMenu *m_brightness_menu;
        QPopupMenu *m_saturation_menu;
        QPopupMenu *m_opacity_menu;

        unsigned long m_state;

		// shadow
		QRect m_soffset;
		int m_sradius;
		short m_scolor[4];

		KProcess *mProcessKiller;
    };

}

#endif