Debian Codegraph @

xcb/libqt5xcbqpa-dev/5.15.5/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(Qt::Edges edges) override;
77 bool startSystemMove() 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 void handleXIMouseEvent(xcb_ge_event_t *, Qt::MouseEventSource source = Qt::MouseEventNotSynthesized) override;
107 void handleXIEnterLeave(xcb_ge_event_t *) override;
108
109 QXcbWindow *toWindow() override;
110
111 void handleMouseEvent(xcb_timestamp_t time, const QPoint &local, const QPoint &global,
112 Qt::KeyboardModifiers modifiers, QEvent::Type type, Qt::MouseEventSource source);
113
114 void updateNetWmUserTime(xcb_timestamp_t timestamp);
115
116 static void setWmWindowTypeStatic(QWindow *window, QXcbWindowFunctions::WmWindowTypes windowTypes);
117 static void setWmWindowRoleStatic(QWindow *window, const QByteArray &role);
118 static uint visualIdStatic(QWindow *window);
119
120 QXcbWindowFunctions::WmWindowTypes wmWindowTypes() const;
121 void setWmWindowType(QXcbWindowFunctions::WmWindowTypes types, Qt::WindowFlags flags);
122 void setWmWindowRole(const QByteArray &role);
123
124 static void setWindowIconTextStatic(QWindow *window, const QString &text);
125
126 void setParentRelativeBackPixmap();
127 bool requestSystemTrayWindowDock();
128 uint visualId() const;
129
130 bool needsSync() const;
131
132 void postSyncWindowRequest();
133 void clearSyncWindowRequest() { m_pendingSyncRequest = nullptr; }
134
135 QXcbScreen *xcbScreen() const;
136
137 bool startSystemMoveResize(const QPoint &pos, int edges);
138 void doStartSystemMoveResize(const QPoint &globalPos, int edges);
139
140 static bool isTrayIconWindow(QWindow *window)
141 {
142 return window->objectName() == QLatin1String("QSystemTrayIconSysWindow");
143 }
144
145 virtual void create();
146 virtual void destroy();
147
148 static void setWindowTitle(const QXcbConnection *conn, xcb_window_t window, const QString &title);
149 static QString windowTitle(const QXcbConnection *conn, xcb_window_t window);
150
151 int swapInterval() const { return m_swapInterval; }
152 void setSwapInterval(int swapInterval) { m_swapInterval = swapInterval; }
153
154 public Q_SLOTS:
155 void updateSyncRequestCounter();
156
157 protected:
158 virtual void resolveFormat(const QSurfaceFormat &format) { m_format = format; }
159 virtual const xcb_visualtype_t *createVisual();
160 void setImageFormatForVisual(const xcb_visualtype_t *visual);
161
162 QXcbScreen *parentScreen();
163 QXcbScreen *initialScreen() const;
164
165 void setNetWmState(bool set, xcb_atom_t one, xcb_atom_t two = 0);
166 void setNetWmState(Qt::WindowFlags flags);
167 void setNetWmState(Qt::WindowStates state);
168 void setNetWmStateOnUnmappedWindow();
169 NetWmStates netWmStates();
170
171 void setMotifWmHints(Qt::WindowFlags flags);
172
173 void setTransparentForMouseEvents(bool transparent);
174 void updateDoesNotAcceptFocus(bool doesNotAcceptFocus);
175
176 void sendXEmbedMessage(xcb_window_t window, quint32 message,
177 quint32 detail = 0, quint32 data1 = 0, quint32 data2 = 0);
178 void handleXEmbedMessage(const xcb_client_message_event_t *event);
179
180 void show();
181 void hide();
182
183 bool relayFocusToModalWindow() const;
184 void doFocusIn();
185 void doFocusOut();
186
187 void handleButtonPressEvent(int event_x, int event_y, int root_x, int root_y,
188 int detail, Qt::KeyboardModifiers modifiers, xcb_timestamp_t timestamp,
189 QEvent::Type type, Qt::MouseEventSource source = Qt::MouseEventNotSynthesized);
190
191 void handleButtonReleaseEvent(int event_x, int event_y, int root_x, int root_y,
192 int detail, Qt::KeyboardModifiers modifiers, xcb_timestamp_t timestamp,
193 QEvent::Type type, Qt::MouseEventSource source = Qt::MouseEventNotSynthesized);
194
195 void handleMotionNotifyEvent(int event_x, int event_y, int root_x, int root_y,
196 Qt::KeyboardModifiers modifiers, xcb_timestamp_t timestamp,
197 QEvent::Type type, Qt::MouseEventSource source = Qt::MouseEventNotSynthesized);
198
199 void handleEnterNotifyEvent(int event_x, int event_y, int root_x, int root_y,
200 quint8 mode, quint8 detail, xcb_timestamp_t timestamp);
201
202 void handleLeaveNotifyEvent(int root_x, int root_y,
203 quint8 mode, quint8 detail, xcb_timestamp_t timestamp);
204
205 xcb_window_t m_window = 0;
206
207 uint m_depth = 0;
208 QImage::Format m_imageFormat = QImage::Format_ARGB32_Premultiplied;
209 bool m_imageRgbSwap = false;
210
211 xcb_sync_int64_t m_syncValue;
212 xcb_sync_counter_t m_syncCounter = 0;
213
214 Qt::WindowStates m_windowState = Qt::WindowNoState;
215
216 bool m_mapped = false;
217 bool m_transparent = false;
218 bool m_deferredActivation = false;
219 bool m_embedded = false;
220 bool m_alertState = false;
221 bool m_minimized = false;
222 bool m_trayIconWindow = false;
223 xcb_window_t m_netWmUserTimeWindow = XCB_NONE;
224
225 QSurfaceFormat m_format;
226
227 mutable bool m_dirtyFrameMargins = false;
228 mutable QMargins m_frameMargins;
229
230 QRegion m_exposeRegion;
231 QSize m_oldWindowSize;
232 QPoint m_lastPointerPosition;
233
234 xcb_visualid_t m_visualId = 0;
235 // Last sent state. Initialized to an invalid state, on purpose.
236 Qt::WindowStates m_lastWindowStateEvent = Qt::WindowActive;
237
238 enum SyncState {
239 NoSyncNeeded,
240 SyncReceived,
241 SyncAndConfigureReceived
242 };
243 SyncState m_syncState = NoSyncNeeded;
244
245 QXcbSyncWindowRequest *m_pendingSyncRequest = nullptr;
246 int m_swapInterval = -1;
247
248 qreal m_sizeHintsScaleFactor = 1.0;
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