Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qxcbwindow.h
Go to the documentation of this file.
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// Qt-Security score:significant reason:default
4
5#pragma once
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
20
21class QXcbScreen;
23class QIcon;
24
25class Q_XCB_EXPORT QXcbWindow : public QObject, public QXcbObject, public QXcbWindowEventListener, public QPlatformWindow
26 , public QNativeInterface::Private::QXcbWindow
27{
28 Q_OBJECT
29public:
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 QString windowTitle() const override;
71 void setWindowIconText(const QString &title) override;
72 void setWindowIcon(const QIcon &icon) override;
73 void raise() override;
74 void lower() override;
75 void propagateSizeHints() override;
76
77 void requestActivateWindow() override;
78
79 bool setKeyboardGrabEnabled(bool grab) override;
80 bool setMouseGrabEnabled(bool grab) override;
81
82 QSurfaceFormat format() const override;
83
84 bool windowEvent(QEvent *event) override;
85
86 bool startSystemResize(Qt::Edges edges) override;
87 bool startSystemMove() override;
88
89 void setOpacity(qreal level) override;
90 void setMask(const QRegion &region) override;
91
92 void setAlertState(bool enabled) override;
93 bool isAlertState() const override { return m_alertState; }
94
95 xcb_window_t xcb_window() const { return m_window; }
96 uint depth() const { return m_depth; }
97 QImage::Format imageFormat() const { return m_imageFormat; }
98 bool imageNeedsRgbSwap() const { return m_imageRgbSwap; }
99
100 bool handleNativeEvent(xcb_generic_event_t *event) override;
101
102 void handleExposeEvent(const xcb_expose_event_t *event) override;
103 void handleClientMessageEvent(const xcb_client_message_event_t *event) override;
104 void handleConfigureNotifyEvent(const xcb_configure_notify_event_t *event) override;
105 void handleMapNotifyEvent(const xcb_map_notify_event_t *event) override;
106 void handleUnmapNotifyEvent(const xcb_unmap_notify_event_t *event) override;
107 void handleButtonPressEvent(const xcb_button_press_event_t *event) override;
108 void handleButtonReleaseEvent(const xcb_button_release_event_t *event) override;
109 void handleMotionNotifyEvent(const xcb_motion_notify_event_t *event) override;
110
111 void handleEnterNotifyEvent(const xcb_enter_notify_event_t *event) override;
112 void handleLeaveNotifyEvent(const xcb_leave_notify_event_t *event) override;
113 void handleFocusInEvent(const xcb_focus_in_event_t *event) override;
114 void handleFocusOutEvent(const xcb_focus_out_event_t *event) override;
115 void handlePropertyNotifyEvent(const xcb_property_notify_event_t *event) override;
116 void handleXIMouseEvent(xcb_ge_event_t *, Qt::MouseEventSource source = Qt::MouseEventNotSynthesized) override;
117 void handleXIEnterLeave(xcb_ge_event_t *) override;
118
119 QXcbWindow *toWindow() override;
120
121 void handleMouseEvent(xcb_timestamp_t time, const QPoint &local, const QPoint &global,
122 Qt::KeyboardModifiers modifiers, QEvent::Type type, Qt::MouseEventSource source);
123
124 void updateNetWmUserTime(xcb_timestamp_t timestamp);
125 void updateWmTransientFor();
126 void registerWmTransientForChild(QXcbWindow *);
127
128 WindowTypes wmWindowTypes() const;
129 void setWmWindowType(WindowTypes types, Qt::WindowFlags flags);
130 void setWindowType(WindowTypes windowTypes) override { setWmWindowType(windowTypes, window()->flags()); }
131 void setWindowRole(const QString &role) override;
132
133 void setParentRelativeBackPixmap();
134 bool requestSystemTrayWindowDock();
135 uint visualId() const override;
136
137 bool needsSync() const;
138
139 void postSyncWindowRequest();
140 void clearSyncWindowRequest() { m_pendingSyncRequest = nullptr; }
141
142 QXcbScreen *xcbScreen() const;
143
144 QPoint lastPointerPosition() const { return m_lastPointerPosition; }
145 QPoint lastPointerGlobalPosition() const { return m_lastPointerGlobalPosition; }
146
147 bool startSystemMoveResize(const QPoint &pos, int edges);
148 void doStartSystemMoveResize(const QPoint &globalPos, int edges);
149
150 static bool isTrayIconWindow(QWindow *window)
151 {
152 return window->objectName() == QLatin1StringView("QSystemTrayIconSysWindow");
153 }
154
155 virtual void create();
156 virtual void destroy();
157
158 static void setWindowTitle(const QXcbConnection *conn, xcb_window_t window, const QString &title);
159 static QString windowTitle(const QXcbConnection *conn, xcb_window_t window);
160
161 int swapInterval() const { return m_swapInterval; }
162 void setSwapInterval(int swapInterval) { m_swapInterval = swapInterval; }
163
164public Q_SLOTS:
165 void updateSyncRequestCounter();
166
167protected:
168 virtual void resolveFormat(const QSurfaceFormat &format) { m_format = format; }
169 virtual const xcb_visualtype_t *createVisual();
170 void setImageFormatForVisual(const xcb_visualtype_t *visual);
171
172 QXcbScreen *parentScreen();
173 QXcbScreen *initialScreen() const;
174
175 void setNetWmState(bool set, xcb_atom_t one, xcb_atom_t two = 0);
176 void setNetWmState(Qt::WindowFlags flags);
177 void setNetWmState(Qt::WindowStates state);
178 void setNetWmStateOnUnmappedWindow();
179 NetWmStates netWmStates();
180
181 void setMotifWmHints(Qt::WindowFlags flags);
182
183 void setTransparentForMouseEvents(bool transparent);
184 void updateDoesNotAcceptFocus(bool doesNotAcceptFocus);
185
186 void sendXEmbedMessage(xcb_window_t window, quint32 message,
187 quint32 detail = 0, quint32 data1 = 0, quint32 data2 = 0);
188 void handleXEmbedMessage(const xcb_client_message_event_t *event);
189
190 void show();
191 void hide();
192
193 bool relayFocusToModalWindow() const;
194 void doFocusIn();
195 void doFocusOut();
196
197 void handleButtonPressEvent(int event_x, int event_y, int root_x, int root_y,
198 int detail, Qt::KeyboardModifiers modifiers, xcb_timestamp_t timestamp,
199 QEvent::Type type, Qt::MouseEventSource source = Qt::MouseEventNotSynthesized);
200
201 void handleButtonReleaseEvent(int event_x, int event_y, int root_x, int root_y,
202 int detail, Qt::KeyboardModifiers modifiers, xcb_timestamp_t timestamp,
203 QEvent::Type type, Qt::MouseEventSource source = Qt::MouseEventNotSynthesized);
204
205 void handleMotionNotifyEvent(int event_x, int event_y, int root_x, int root_y,
206 Qt::KeyboardModifiers modifiers, xcb_timestamp_t timestamp,
207 QEvent::Type type, Qt::MouseEventSource source = Qt::MouseEventNotSynthesized);
208
209 void handleEnterNotifyEvent(int event_x, int event_y, int root_x, int root_y,
210 quint8 mode, quint8 detail, xcb_timestamp_t timestamp);
211
212 void handleLeaveNotifyEvent(int root_x, int root_y,
213 quint8 mode, quint8 detail, xcb_timestamp_t timestamp);
214
215 xcb_window_t m_window = 0;
216
217 uint m_depth = 0;
218 QImage::Format m_imageFormat = QImage::Format_ARGB32_Premultiplied;
219 bool m_imageRgbSwap = false;
220
221 xcb_sync_int64_t m_syncValue;
222 xcb_sync_counter_t m_syncCounter = 0;
223
224 Qt::WindowStates m_windowState = Qt::WindowNoState;
225
226 QMutex m_mappedMutex;
227 bool m_mapped = false;
228 bool m_transparent = false;
229 bool m_deferredActivation = false;
230 bool m_embedded = false;
231 bool m_alertState = false;
232 bool m_minimized = false;
233 bool m_trayIconWindow = false;
234 bool m_ignorePressedWindowOnMouseLeave = false;
235 xcb_window_t m_netWmUserTimeWindow = XCB_NONE;
236
237 QSurfaceFormat m_format;
238
239 mutable bool m_dirtyFrameMargins = false;
240 mutable QMargins m_frameMargins;
241
242 QRegion m_exposeRegion;
243 QSize m_oldWindowSize;
244 QPoint m_lastPointerPosition;
245 QPoint m_lastPointerGlobalPosition;
246
247 xcb_visualid_t m_visualId = 0;
248 // Last sent state. Initialized to an invalid state, on purpose.
249 Qt::WindowStates m_lastWindowStateEvent = Qt::WindowActive;
250
251 enum SyncState {
252 NoSyncNeeded,
253 SyncReceived,
254 SyncAndConfigureReceived
255 };
256 SyncState m_syncState = NoSyncNeeded;
257
258 QXcbSyncWindowRequest *m_pendingSyncRequest = nullptr;
259 int m_swapInterval = -1;
260
261 qreal m_sizeHintsScaleFactor = 1.0;
262
263 RecreationReasons m_recreationReasons = RecreationNotNeeded;
264
265 QList<QPointer<QXcbWindow>> m_wmTransientForChildren;
266};
267
269{
270public:
271 QXcbForeignWindow(QWindow *window, WId nativeHandle);
273 bool isForeignWindow() const override { return true; }
274
275protected:
276 void create() override {} // No-op
277};
278
279QList<xcb_rectangle_t> qRegionToXcbRectangleList(const QRegion &region);
280
281QT_END_NAMESPACE
282
283Q_DECLARE_METATYPE(QXcbWindow*)
\inmodule QtSql
bool isForeignWindow() const override
Definition qxcbwindow.h:273
void create() override
Definition qxcbwindow.h:276
QXcbForeignWindow(QWindow *window, WId nativeHandle)
#define Q_XCB_EXPORT
Definition qxcbexport.h:14
QList< xcb_rectangle_t > qRegionToXcbRectangleList(const QRegion &region)