1 | // Copyright (C) 2016 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QXCBWINDOW_H |
5 | #define QXCBWINDOW_H |
6 | |
7 | #include <qpa/qplatformwindow.h> |
8 | #include <qpa/qplatformwindow_p.h> |
9 | #include <QtCore/QObject> |
10 | #include <QtCore/QPointer> |
11 | #include <QtGui/QSurfaceFormat> |
12 | #include <QtGui/QImage> |
13 | |
14 | #include <xcb/xcb.h> |
15 | #include <xcb/sync.h> |
16 | |
17 | #include "qxcbobject.h" |
18 | |
19 | QT_BEGIN_NAMESPACE |
20 | |
21 | class QXcbScreen; |
22 | class QXcbSyncWindowRequest; |
23 | class QIcon; |
24 | |
25 | class Q_XCB_EXPORT QXcbWindow : public QObject, public QXcbObject, public QXcbWindowEventListener, public QPlatformWindow |
26 | , public QNativeInterface::Private::QXcbWindow |
27 | { |
28 | Q_OBJECT |
29 | public: |
30 | enum NetWmState { |
31 | NetWmStateAbove = 0x1, |
32 | NetWmStateBelow = 0x2, |
33 | NetWmStateFullScreen = 0x4, |
34 | NetWmStateMaximizedHorz = 0x8, |
35 | NetWmStateMaximizedVert = 0x10, |
36 | NetWmStateModal = 0x20, |
37 | NetWmStateStaysOnTop = 0x40, |
38 | NetWmStateDemandsAttention = 0x80, |
39 | NetWmStateHidden = 0x100 |
40 | }; |
41 | |
42 | Q_DECLARE_FLAGS(NetWmStates, NetWmState) |
43 | |
44 | enum RecreationReason { |
45 | RecreationNotNeeded = 0, |
46 | WindowStaysOnTopHintChanged = 0x1, |
47 | WindowStaysOnBottomHintChanged = 0x2 |
48 | }; |
49 | Q_DECLARE_FLAGS(RecreationReasons, RecreationReason) |
50 | |
51 | QXcbWindow(QWindow *window); |
52 | ~QXcbWindow(); |
53 | |
54 | void setGeometry(const QRect &rect) override; |
55 | |
56 | QMargins frameMargins() const override; |
57 | |
58 | void setVisible(bool visible) override; |
59 | void setWindowFlags(Qt::WindowFlags flags) override; |
60 | void setWindowState(Qt::WindowStates state) override; |
61 | WId winId() const override; |
62 | void setParent(const QPlatformWindow *window) override; |
63 | |
64 | bool isExposed() const override; |
65 | bool isEmbedded() const override; |
66 | QPoint mapToGlobal(const QPoint &pos) const override; |
67 | QPoint mapFromGlobal(const QPoint &pos) const override; |
68 | |
69 | void setWindowTitle(const QString &title) override; |
70 | void setWindowIconText(const QString &title) override; |
71 | void setWindowIcon(const QIcon &icon) override; |
72 | void raise() override; |
73 | void lower() override; |
74 | void propagateSizeHints() override; |
75 | |
76 | void requestActivateWindow() override; |
77 | |
78 | bool setKeyboardGrabEnabled(bool grab) override; |
79 | bool setMouseGrabEnabled(bool grab) override; |
80 | |
81 | QSurfaceFormat format() const override; |
82 | |
83 | bool windowEvent(QEvent *event) override; |
84 | |
85 | bool startSystemResize(Qt::Edges edges) override; |
86 | bool startSystemMove() override; |
87 | |
88 | void setOpacity(qreal level) override; |
89 | void setMask(const QRegion ®ion) override; |
90 | |
91 | void setAlertState(bool enabled) override; |
92 | bool isAlertState() const override { return m_alertState; } |
93 | |
94 | xcb_window_t xcb_window() const { return m_window; } |
95 | uint depth() const { return m_depth; } |
96 | QImage::Format imageFormat() const { return m_imageFormat; } |
97 | bool imageNeedsRgbSwap() const { return m_imageRgbSwap; } |
98 | |
99 | bool handleNativeEvent(xcb_generic_event_t *event) override; |
100 | |
101 | void handleExposeEvent(const xcb_expose_event_t *event) override; |
102 | void handleClientMessageEvent(const xcb_client_message_event_t *event) override; |
103 | void handleConfigureNotifyEvent(const xcb_configure_notify_event_t *event) override; |
104 | void handleMapNotifyEvent(const xcb_map_notify_event_t *event) override; |
105 | void handleUnmapNotifyEvent(const xcb_unmap_notify_event_t *event) override; |
106 | void handleButtonPressEvent(const xcb_button_press_event_t *event) override; |
107 | void handleButtonReleaseEvent(const xcb_button_release_event_t *event) override; |
108 | void handleMotionNotifyEvent(const xcb_motion_notify_event_t *event) override; |
109 | |
110 | void handleEnterNotifyEvent(const xcb_enter_notify_event_t *event) override; |
111 | void handleLeaveNotifyEvent(const xcb_leave_notify_event_t *event) override; |
112 | void handleFocusInEvent(const xcb_focus_in_event_t *event) override; |
113 | void handleFocusOutEvent(const xcb_focus_out_event_t *event) override; |
114 | void handlePropertyNotifyEvent(const xcb_property_notify_event_t *event) override; |
115 | void handleXIMouseEvent(xcb_ge_event_t *, Qt::MouseEventSource source = Qt::MouseEventNotSynthesized) override; |
116 | void handleXIEnterLeave(xcb_ge_event_t *) override; |
117 | |
118 | QXcbWindow *toWindow() override; |
119 | |
120 | void handleMouseEvent(xcb_timestamp_t time, const QPoint &local, const QPoint &global, |
121 | Qt::KeyboardModifiers modifiers, QEvent::Type type, Qt::MouseEventSource source); |
122 | |
123 | void updateNetWmUserTime(xcb_timestamp_t timestamp); |
124 | void updateWmTransientFor(); |
125 | void registerWmTransientForChild(QXcbWindow *); |
126 | |
127 | WindowTypes wmWindowTypes() const; |
128 | void setWmWindowType(WindowTypes types, Qt::WindowFlags flags); |
129 | void setWindowType(WindowTypes windowTypes) override { setWmWindowType(types: windowTypes, flags: window()->flags()); } |
130 | void setWindowRole(const QString &role) override; |
131 | |
132 | void setParentRelativeBackPixmap(); |
133 | bool requestSystemTrayWindowDock(); |
134 | uint visualId() const override; |
135 | |
136 | bool needsSync() const; |
137 | |
138 | void postSyncWindowRequest(); |
139 | void clearSyncWindowRequest() { m_pendingSyncRequest = nullptr; } |
140 | |
141 | QXcbScreen *xcbScreen() const; |
142 | |
143 | QPoint lastPointerPosition() const { return m_lastPointerPosition; } |
144 | QPoint lastPointerGlobalPosition() const { return m_lastPointerGlobalPosition; } |
145 | |
146 | bool startSystemMoveResize(const QPoint &pos, int edges); |
147 | void doStartSystemMoveResize(const QPoint &globalPos, int edges); |
148 | |
149 | static bool isTrayIconWindow(QWindow *window) |
150 | { |
151 | return window->objectName() == QLatin1StringView("QSystemTrayIconSysWindow"); |
152 | } |
153 | |
154 | virtual void create(); |
155 | virtual void destroy(); |
156 | |
157 | static void setWindowTitle(const QXcbConnection *conn, xcb_window_t window, const QString &title); |
158 | static QString windowTitle(const QXcbConnection *conn, xcb_window_t window); |
159 | |
160 | int swapInterval() const { return m_swapInterval; } |
161 | void setSwapInterval(int swapInterval) { m_swapInterval = swapInterval; } |
162 | |
163 | public Q_SLOTS: |
164 | void updateSyncRequestCounter(); |
165 | |
166 | protected: |
167 | virtual void resolveFormat(const QSurfaceFormat &format) { m_format = format; } |
168 | virtual const xcb_visualtype_t *createVisual(); |
169 | void setImageFormatForVisual(const xcb_visualtype_t *visual); |
170 | |
171 | QXcbScreen *parentScreen(); |
172 | QXcbScreen *initialScreen() const; |
173 | |
174 | void setNetWmState(bool set, xcb_atom_t one, xcb_atom_t two = 0); |
175 | void setNetWmState(Qt::WindowFlags flags); |
176 | void setNetWmState(Qt::WindowStates state); |
177 | void setNetWmStateOnUnmappedWindow(); |
178 | NetWmStates netWmStates(); |
179 | |
180 | void setMotifWmHints(Qt::WindowFlags flags); |
181 | |
182 | void setTransparentForMouseEvents(bool transparent); |
183 | void updateDoesNotAcceptFocus(bool doesNotAcceptFocus); |
184 | |
185 | void sendXEmbedMessage(xcb_window_t window, quint32 message, |
186 | quint32 detail = 0, quint32 data1 = 0, quint32 data2 = 0); |
187 | void handleXEmbedMessage(const xcb_client_message_event_t *event); |
188 | |
189 | void show(); |
190 | void hide(); |
191 | |
192 | bool relayFocusToModalWindow() const; |
193 | void doFocusIn(); |
194 | void doFocusOut(); |
195 | |
196 | void handleButtonPressEvent(int event_x, int event_y, int root_x, int root_y, |
197 | int detail, Qt::KeyboardModifiers modifiers, xcb_timestamp_t timestamp, |
198 | QEvent::Type type, Qt::MouseEventSource source = Qt::MouseEventNotSynthesized); |
199 | |
200 | void handleButtonReleaseEvent(int event_x, int event_y, int root_x, int root_y, |
201 | int detail, Qt::KeyboardModifiers modifiers, xcb_timestamp_t timestamp, |
202 | QEvent::Type type, Qt::MouseEventSource source = Qt::MouseEventNotSynthesized); |
203 | |
204 | void handleMotionNotifyEvent(int event_x, int event_y, int root_x, int root_y, |
205 | Qt::KeyboardModifiers modifiers, xcb_timestamp_t timestamp, |
206 | QEvent::Type type, Qt::MouseEventSource source = Qt::MouseEventNotSynthesized); |
207 | |
208 | void handleEnterNotifyEvent(int event_x, int event_y, int root_x, int root_y, |
209 | quint8 mode, quint8 detail, xcb_timestamp_t timestamp); |
210 | |
211 | void handleLeaveNotifyEvent(int root_x, int root_y, |
212 | quint8 mode, quint8 detail, xcb_timestamp_t timestamp); |
213 | |
214 | xcb_window_t m_window = 0; |
215 | |
216 | uint m_depth = 0; |
217 | QImage::Format m_imageFormat = QImage::Format_ARGB32_Premultiplied; |
218 | bool m_imageRgbSwap = false; |
219 | |
220 | xcb_sync_int64_t m_syncValue; |
221 | xcb_sync_counter_t m_syncCounter = 0; |
222 | |
223 | Qt::WindowStates m_windowState = Qt::WindowNoState; |
224 | |
225 | QMutex m_mappedMutex; |
226 | bool m_mapped = false; |
227 | bool m_transparent = false; |
228 | bool m_deferredActivation = false; |
229 | bool m_embedded = false; |
230 | bool m_alertState = false; |
231 | bool m_minimized = false; |
232 | bool m_trayIconWindow = false; |
233 | bool m_ignorePressedWindowOnMouseLeave = false; |
234 | xcb_window_t m_netWmUserTimeWindow = XCB_NONE; |
235 | |
236 | QSurfaceFormat m_format; |
237 | |
238 | mutable bool m_dirtyFrameMargins = false; |
239 | mutable QMargins m_frameMargins; |
240 | |
241 | QRegion m_exposeRegion; |
242 | QSize m_oldWindowSize; |
243 | QPoint m_lastPointerPosition; |
244 | QPoint m_lastPointerGlobalPosition; |
245 | |
246 | xcb_visualid_t m_visualId = 0; |
247 | // Last sent state. Initialized to an invalid state, on purpose. |
248 | Qt::WindowStates m_lastWindowStateEvent = Qt::WindowActive; |
249 | |
250 | enum SyncState { |
251 | NoSyncNeeded, |
252 | SyncReceived, |
253 | SyncAndConfigureReceived |
254 | }; |
255 | SyncState m_syncState = NoSyncNeeded; |
256 | |
257 | QXcbSyncWindowRequest *m_pendingSyncRequest = nullptr; |
258 | int m_swapInterval = -1; |
259 | |
260 | qreal m_sizeHintsScaleFactor = 1.0; |
261 | |
262 | RecreationReasons m_recreationReasons = RecreationNotNeeded; |
263 | |
264 | QList<QPointer<QXcbWindow>> m_wmTransientForChildren; |
265 | }; |
266 | |
267 | class QXcbForeignWindow : public QXcbWindow |
268 | { |
269 | public: |
270 | QXcbForeignWindow(QWindow *window, WId nativeHandle); |
271 | ~QXcbForeignWindow(); |
272 | bool isForeignWindow() const override { return true; } |
273 | |
274 | protected: |
275 | void create() override {} // No-op |
276 | }; |
277 | |
278 | QList<xcb_rectangle_t> qRegionToXcbRectangleList(const QRegion ®ion); |
279 | |
280 | QT_END_NAMESPACE |
281 | |
282 | Q_DECLARE_METATYPE(QXcbWindow*) |
283 | |
284 | #endif |
285 |
Definitions
Learn Advanced QML with KDAB
Find out more