QPlatformWindow: Add Window masks.
[profile/ivi/qtbase.git] / src / plugins / platforms / xcb / qxcbwindow.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the plugins of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QXCBWINDOW_H
43 #define QXCBWINDOW_H
44
45 #include <qpa/qplatformwindow.h>
46 #include <QtGui/QSurfaceFormat>
47 #include <QtGui/QImage>
48
49 #include <xcb/xcb.h>
50 #include <xcb/sync.h>
51
52 #include "qxcbobject.h"
53
54 QT_BEGIN_NAMESPACE
55
56 class QXcbScreen;
57 class QXcbEGLSurface;
58 class QIcon;
59
60 class QXcbWindow : public QXcbObject, public QPlatformWindow
61 {
62 public:
63     enum NetWmState {
64         NetWmStateAbove = 0x1,
65         NetWmStateBelow = 0x2,
66         NetWmStateFullScreen = 0x4,
67         NetWmStateMaximizedHorz = 0x8,
68         NetWmStateMaximizedVert = 0x10,
69         NetWmStateModal = 0x20,
70         NetWmStateStaysOnTop = 0x40,
71         NetWmStateDemandsAttention = 0x80
72     };
73
74     Q_DECLARE_FLAGS(NetWmStates, NetWmState)
75
76     QXcbWindow(QWindow *window);
77     ~QXcbWindow();
78
79     void setGeometry(const QRect &rect);
80
81     QMargins frameMargins() const;
82
83     void setVisible(bool visible);
84     Qt::WindowFlags setWindowFlags(Qt::WindowFlags flags);
85     Qt::WindowState setWindowState(Qt::WindowState state);
86     WId winId() const;
87     void setParent(const QPlatformWindow *window);
88
89     bool isExposed() const;
90
91     void setWindowTitle(const QString &title);
92     void setWindowIcon(const QIcon &icon);
93     void raise();
94     void lower();
95     void propagateSizeHints();
96
97     void requestActivateWindow();
98
99 #if XCB_USE_MAEMO_WINDOW_PROPERTIES
100     void handleContentOrientationChange(Qt::ScreenOrientation orientation);
101 #endif
102
103     bool setKeyboardGrabEnabled(bool grab);
104     bool setMouseGrabEnabled(bool grab);
105
106     void setCursor(xcb_cursor_t cursor);
107
108     QSurfaceFormat format() const;
109
110     bool startSystemResize(const QPoint &pos, Qt::Corner corner);
111
112 #if defined(XCB_USE_XLIB) && !defined(QT_NO_SHAPE)
113     void setMask(const QRegion &region);
114 #endif // XCB_USE_XLIB && !QT_NO_SHAPE
115
116     xcb_window_t xcb_window() const { return m_window; }
117     uint depth() const { return m_depth; }
118     QImage::Format imageFormat() const { return m_imageFormat; }
119
120     void handleExposeEvent(const xcb_expose_event_t *event);
121     void handleClientMessageEvent(const xcb_client_message_event_t *event);
122     void handleConfigureNotifyEvent(const xcb_configure_notify_event_t *event);
123     void handleMapNotifyEvent(const xcb_map_notify_event_t *event);
124     void handleUnmapNotifyEvent(const xcb_unmap_notify_event_t *event);
125     void handleButtonPressEvent(const xcb_button_press_event_t *event);
126     void handleButtonReleaseEvent(const xcb_button_release_event_t *event);
127     void handleMotionNotifyEvent(const xcb_motion_notify_event_t *event);
128
129     void handleEnterNotifyEvent(const xcb_enter_notify_event_t *event);
130     void handleLeaveNotifyEvent(const xcb_leave_notify_event_t *event);
131     void handleFocusInEvent(const xcb_focus_in_event_t *event);
132     void handleFocusOutEvent(const xcb_focus_out_event_t *event);
133     void handlePropertyNotifyEvent(const xcb_property_notify_event_t *event);
134
135     void handleMouseEvent(xcb_button_t detail, uint16_t state, xcb_timestamp_t time, const QPoint &local, const QPoint &global, Qt::KeyboardModifiers modifiers);
136
137     void updateSyncRequestCounter();
138     void updateNetWmUserTime(xcb_timestamp_t timestamp);
139     void netWmUserTime() const;
140
141 #if defined(XCB_USE_EGL)
142     QXcbEGLSurface *eglSurface() const;
143 #endif
144
145 private:
146     void changeNetWmState(bool set, xcb_atom_t one, xcb_atom_t two = 0);
147     NetWmStates netWmStates();
148     void setNetWmStates(NetWmStates);
149
150     void setNetWmWindowFlags(Qt::WindowFlags flags);
151     void setMotifWindowFlags(Qt::WindowFlags flags);
152
153     void updateMotifWmHintsBeforeMap();
154     void updateNetWmStateBeforeMap();
155
156     void setTransparentForMouseEvents(bool transparent);
157     void updateDoesNotAcceptFocus(bool doesNotAcceptFocus);
158
159     QRect windowToWmGeometry(QRect r) const;
160
161     void create();
162     void destroy();
163
164     void show();
165     void hide();
166
167     QXcbScreen *m_screen;
168
169     xcb_window_t m_window;
170
171     uint m_depth;
172     QImage::Format m_imageFormat;
173
174     xcb_sync_int64_t m_syncValue;
175     xcb_sync_counter_t m_syncCounter;
176
177     Qt::WindowState m_windowState;
178
179     xcb_gravity_t m_gravity;
180
181     bool m_mapped;
182     bool m_transparent;
183     bool m_deferredActivation;
184     bool m_deferredExpose;
185     bool m_configureNotifyPending;
186     xcb_window_t m_netWmUserTimeWindow;
187
188     QSurfaceFormat m_format;
189
190     mutable bool m_dirtyFrameMargins;
191     mutable QMargins m_frameMargins;
192
193 #if defined(XCB_USE_EGL)
194     mutable QXcbEGLSurface *m_eglSurface;
195 #endif
196
197     QRegion m_exposeRegion;
198
199     xcb_visualid_t m_visualId;
200     int m_lastWindowStateEvent;
201 };
202
203 QT_END_NAMESPACE
204
205 #endif