Debian Codegraph @

xcb/libqt5xcbqpa-dev/5.12.8/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 NetWmStateHidden = 0x100
38 };
39
40 Q_DECLARE_FLAGS(NetWmStates, NetWmState)
41
42 QXcbWindow(QWindow *window);
43 ~QXcbWindow();
44
45 void setGeometry(const QRect &rect) override;
46
47 QMargins frameMargins() const override;
48
49 void setVisible(bool visible) override;
50 void setWindowFlags(Qt::WindowFlags flags) override;
51 void setWindowState(Qt::WindowStates state) override;
52 WId winId() const override;
53 void setParent(const QPlatformWindow *window) override;
54
55 bool isExposed() const override;
56 bool isEmbedded() const override;
57 QPoint mapToGlobal(const QPoint &pos) const override;
58 QPoint mapFromGlobal(const QPoint &pos) const override;
59
60 void setWindowTitle(const QString &title) override;
61 void setWindowIconText(const QString &title);
62 void setWindowIcon(const QIcon &icon) override;
63 void raise() override;
64 void lower() override;
65 void propagateSizeHints() override;
66
67 void requestActivateWindow() override;
68
69 bool setKeyboardGrabEnabled(bool grab) override;
70 bool setMouseGrabEnabled(bool grab) override;
71
72 QSurfaceFormat format() const override;
73
74 bool windowEvent(QEvent *event) override;
75
76 bool startSystemResize(const QPoint &pos, Qt::Corner corner) override;
77 bool startSystemMove(const QPoint &pos) override;
78
79 void setOpacity(qreal level) override;
80 void setMask(const QRegion &region) override;
81
82 void setAlertState(bool enabled) override;
83 bool isAlertState() const override { return m_alertState; }
84
85 xcb_window_t xcb_window() const { return m_window; }
86 uint depth() const { return m_depth; }
87 QImage::Format imageFormat() const { return m_imageFormat; }
88 bool imageNeedsRgbSwap() const { return m_imageRgbSwap; }
89
90 bool handleNativeEvent(xcb_generic_event_t *event) override;
91
92 void handleExposeEvent(const xcb_expose_event_t *event) override;
93 void handleClientMessageEvent(const xcb_client_message_event_t *event) override;
94 void handleConfigureNotifyEvent(const xcb_configure_notify_event_t *event) override;
95 void handleMapNotifyEvent(const xcb_map_notify_event_t *event) override;
96 void handleUnmapNotifyEvent(const xcb_unmap_notify_event_t *event) override;
97 void handleButtonPressEvent(const xcb_button_press_event_t *event) override;
98 void handleButtonReleaseEvent(const xcb_button_release_event_t *event) override;
99 void handleMotionNotifyEvent(const xcb_motion_notify_event_t *event) override;
100
101 void handleEnterNotifyEvent(const xcb_enter_notify_event_t *event) override;
102 void handleLeaveNotifyEvent(const xcb_leave_notify_event_t *event) override;
103 void handleFocusInEvent(const xcb_focus_in_event_t *event) override;
104 void handleFocusOutEvent(const xcb_focus_out_event_t *event) override;
105 void handlePropertyNotifyEvent(const xcb_property_notify_event_t *event) override;
106 #if QT_CONFIG(xcb_xinput)
107 void handleXIMouseEvent(xcb_ge_event_t *, Qt::MouseEventSource source = Qt::MouseEventNotSynthesized) override;
108 void handleXIEnterLeave(xcb_ge_event_t *) override;
109 #endif
110
111 QXcbWindow *toWindow() override;
112
113 void handleMouseEvent(xcb_timestamp_t time, const QPoint &local, const QPoint &global,
114 Qt::KeyboardModifiers modifiers, QEvent::Type type, Qt::MouseEventSource source);
115
116 void updateNetWmUserTime(xcb_timestamp_t timestamp);
117
118 static void setWmWindowTypeStatic(QWindow *window, QXcbWindowFunctions::WmWindowTypes windowTypes);
119 static void setWmWindowRoleStatic(QWindow *window, const QByteArray &role);
120 static uint visualIdStatic(QWindow *window);
121
122 QXcbWindowFunctions::WmWindowTypes wmWindowTypes() const;
123 void setWmWindowType(QXcbWindowFunctions::WmWindowTypes types, Qt::WindowFlags flags);
124 void setWmWindowRole(const QByteArray &role);
125
126 static void setWindowIconTextStatic(QWindow *window, const QString &text);
127
128 void setParentRelativeBackPixmap();
129 bool requestSystemTrayWindowDock();
130 uint visualId() const;
131
132 bool needsSync() const;
133
134 void postSyncWindowRequest();
135 void clearSyncWindowRequest() { m_pendingSyncRequest = 0; }
136
137 QXcbScreen *xcbScreen() const;
138
139 bool startSystemMoveResize(const QPoint &pos, int corner);
140 void doStartSystemMoveResize(const QPoint &globalPos, int corner);
141
142 static bool isTrayIconWindow(QWindow *window)
143 {
144 return window->objectName() == QLatin1String("QSystemTrayIconSysWindow");
145 }
146
147 virtual void create();
148 virtual void destroy();
149
150 static void setWindowTitle(const QXcbConnection *conn, xcb_window_t window, const QString &title);
151 static QString windowTitle(const QXcbConnection *conn, xcb_window_t window);
152
153 int swapInterval() const { return m_swapInterval; }
154 void setSwapInterval(int swapInterval) { m_swapInterval = swapInterval; }
155
156 public Q_SLOTS:
157 void updateSyncRequestCounter();
158
159 protected:
160 virtual void resolveFormat(const QSurfaceFormat &format) { m_format = format; }
161 virtual const xcb_visualtype_t *createVisual();
162 void setImageFormatForVisual(const xcb_visualtype_t *visual);
163
164 QXcbScreen *parentScreen();
165 QXcbScreen *initialScreen() const;
166
167 void setNetWmState(bool set, xcb_atom_t one, xcb_atom_t two = 0);
168 void setNetWmState(Qt::WindowFlags flags);
169 void setNetWmState(Qt::WindowStates state);
170 void setNetWmStateOnUnmappedWindow();
171 NetWmStates netWmStates();
172
173 void setMotifWmHints(Qt::WindowFlags flags);
174
175 void setTransparentForMouseEvents(bool transparent);
176 void updateDoesNotAcceptFocus(bool doesNotAcceptFocus);
177
178 void sendXEmbedMessage(xcb_window_t window, quint32 message,
179 quint32 detail = 0, quint32 data1 = 0, quint32 data2 = 0);
180 void handleXEmbedMessage(const xcb_client_message_event_t *event);
181
182 void show();
183 void hide();
184
185 bool relayFocusToModalWindow() const;
186 void doFocusIn();
187 void doFocusOut();
188
189 void handleButtonPressEvent(int event_x, int event_y, int root_x, int root_y,
190 int detail, Qt::KeyboardModifiers modifiers, xcb_timestamp_t timestamp,
191 QEvent::Type type, Qt::MouseEventSource source = Qt::MouseEventNotSynthesized);
192
193 void handleButtonReleaseEvent(int event_x, int event_y, int root_x, int root_y,
194 int detail, Qt::KeyboardModifiers modifiers, xcb_timestamp_t timestamp,
195 QEvent::Type type, Qt::MouseEventSource source = Qt::MouseEventNotSynthesized);
196
197 void handleMotionNotifyEvent(int event_x, int event_y, int root_x, int root_y,
198 Qt::KeyboardModifiers modifiers, xcb_timestamp_t timestamp,
199 QEvent::Type type, Qt::MouseEventSource source = Qt::MouseEventNotSynthesized);
200
201 void handleEnterNotifyEvent(int event_x, int event_y, int root_x, int root_y,
202 quint8 mode, quint8 detail, xcb_timestamp_t timestamp);
203
204 void handleLeaveNotifyEvent(int root_x, int root_y,
205 quint8 mode, quint8 detail, xcb_timestamp_t timestamp);
206
207 xcb_window_t m_window = 0;
208 xcb_colormap_t m_cmap = 0;
209
210 uint m_depth = 0;
211 QImage::Format m_imageFormat = QImage::Format_ARGB32_Premultiplied;
212 bool m_imageRgbSwap = false;
213
214 xcb_sync_int64_t m_syncValue;
215 xcb_sync_counter_t m_syncCounter = 0;
216
217 Qt::WindowStates m_windowState = Qt::WindowNoState;
218
219 bool m_mapped = false;
220 bool m_transparent = false;
221 bool m_deferredActivation = false;
222 bool m_embedded = false;
223 bool m_alertState = false;
224 bool m_minimized = false;
225 bool m_trayIconWindow = false;
226 xcb_window_t m_netWmUserTimeWindow = XCB_NONE;
227
228 QSurfaceFormat m_format;
229
230 mutable bool m_dirtyFrameMargins = false;
231 mutable QMargins m_frameMargins;
232
233 QRegion m_exposeRegion;
234 QSize m_oldWindowSize;
235
236 xcb_visualid_t m_visualId = 0;
237 // Last sent state. Initialized to an invalid state, on purpose.
238 Qt::WindowStates m_lastWindowStateEvent = Qt::WindowActive;
239
240 enum SyncState {
241 NoSyncNeeded,
242 SyncReceived,
243 SyncAndConfigureReceived
244 };
245 SyncState m_syncState = NoSyncNeeded;
246
247 QXcbSyncWindowRequest *m_pendingSyncRequest = nullptr;
248 int m_swapInterval = -1;
249 };
250
251 class QXcbForeignWindow : public QXcbWindow
252 {
253 public:
254 QXcbForeignWindow(QWindow *window, WId nativeHandle)
255 : QXcbWindow(window) { m_window = nativeHandle; }
256 ~QXcbForeignWindow();
257 bool isForeignWindow() const override { return true; }
258
259 protected:
260 void create() override {} // No-op
261 };
262
263 QVector<xcb_rectangle_t> qRegionToXcbRectangleList(const QRegion &region);
264
265 QT_END_NAMESPACE
266
267 Q_DECLARE_METATYPE(QXcbWindow*)
268
269 #endif