d3832484286b81ec3ddee4d4a1f60e4723c96d1b
[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     xcb_window_t xcb_window() const { return m_window; }
113     uint depth() const { return m_depth; }
114     QImage::Format imageFormat() const { return m_imageFormat; }
115
116     void handleExposeEvent(const xcb_expose_event_t *event);
117     void handleClientMessageEvent(const xcb_client_message_event_t *event);
118     void handleConfigureNotifyEvent(const xcb_configure_notify_event_t *event);
119     void handleMapNotifyEvent(const xcb_map_notify_event_t *event);
120     void handleUnmapNotifyEvent(const xcb_unmap_notify_event_t *event);
121     void handleButtonPressEvent(const xcb_button_press_event_t *event);
122     void handleButtonReleaseEvent(const xcb_button_release_event_t *event);
123     void handleMotionNotifyEvent(const xcb_motion_notify_event_t *event);
124
125     void handleEnterNotifyEvent(const xcb_enter_notify_event_t *event);
126     void handleLeaveNotifyEvent(const xcb_leave_notify_event_t *event);
127     void handleFocusInEvent(const xcb_focus_in_event_t *event);
128     void handleFocusOutEvent(const xcb_focus_out_event_t *event);
129     void handlePropertyNotifyEvent(const xcb_property_notify_event_t *event);
130
131     void handleMouseEvent(xcb_button_t detail, uint16_t state, xcb_timestamp_t time, const QPoint &local, const QPoint &global, Qt::KeyboardModifiers modifiers);
132
133     void updateSyncRequestCounter();
134     void updateNetWmUserTime(xcb_timestamp_t timestamp);
135     void netWmUserTime() const;
136
137 #if defined(XCB_USE_EGL)
138     QXcbEGLSurface *eglSurface() const;
139 #endif
140
141 private:
142     void changeNetWmState(bool set, xcb_atom_t one, xcb_atom_t two = 0);
143     NetWmStates netWmStates();
144     void setNetWmStates(NetWmStates);
145
146     void setNetWmWindowFlags(Qt::WindowFlags flags);
147     void setMotifWindowFlags(Qt::WindowFlags flags);
148
149     void updateMotifWmHintsBeforeMap();
150     void updateNetWmStateBeforeMap();
151
152     void setTransparentForMouseEvents(bool transparent);
153     void updateDoesNotAcceptFocus(bool doesNotAcceptFocus);
154
155     QRect windowToWmGeometry(QRect r) const;
156
157     void create();
158     void destroy();
159
160     void show();
161     void hide();
162
163     QXcbScreen *m_screen;
164
165     xcb_window_t m_window;
166
167     uint m_depth;
168     QImage::Format m_imageFormat;
169
170     xcb_sync_int64_t m_syncValue;
171     xcb_sync_counter_t m_syncCounter;
172
173     Qt::WindowState m_windowState;
174
175     xcb_gravity_t m_gravity;
176
177     bool m_mapped;
178     bool m_transparent;
179     bool m_deferredActivation;
180     bool m_deferredExpose;
181     bool m_configureNotifyPending;
182     xcb_window_t m_netWmUserTimeWindow;
183
184     QSurfaceFormat m_format;
185
186     mutable bool m_dirtyFrameMargins;
187     mutable QMargins m_frameMargins;
188
189 #if defined(XCB_USE_EGL)
190     mutable QXcbEGLSurface *m_eglSurface;
191 #endif
192
193     QRegion m_exposeRegion;
194
195     xcb_visualid_t m_visualId;
196     int m_lastWindowStateEvent;
197 };
198
199 QT_END_NAMESPACE
200
201 #endif