Debian Codegraph @

xcb/libqt5xcbqpa-dev/5.11.2/qxcbwindow.h

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