Debian Codegraph @

xcb/libqt6xcbqpa-dev/6.2.4/qxcbwindow.h

raw
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the plugins of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39
40 #ifndef QXCBWINDOW_H
41 #define QXCBWINDOW_H
42
43 #include <qpa/qplatformwindow.h>
44 #include <qpa/qplatformwindow_p.h>
45 #include <QtGui/QSurfaceFormat>
46 #include <QtGui/QImage>
47
48 #include <xcb/xcb.h>
49 #include <xcb/sync.h>
50
51 #include "qxcbobject.h"
52
53 QT_BEGIN_NAMESPACE
54
55 class QXcbScreen;
56 class QXcbSyncWindowRequest;
57 class QIcon;
58
59 class Q_XCB_EXPORT QXcbWindow : public QXcbObject, public QXcbWindowEventListener, public QPlatformWindow
60 , public QNativeInterface::Private::QXcbWindow
61 {
62 public:
63 enum NetWmState {
64 NetWmStateAbove = 0x1,
65 NetWmStateBelow = 0x2,
66 NetWmStateFullScreen = 0x4,
67 NetWmStateMaximizedHorz = 0x8,
68 NetWmStateMaximizedVert = 0x10,
69 NetWmStateModal = 0x20,
70 NetWmStateStaysOnTop = 0x40,
71 NetWmStateDemandsAttention = 0x80,
72 NetWmStateHidden = 0x100
73 };
74
75 Q_DECLARE_FLAGS(NetWmStates, NetWmState)
76
77 enum Task {
78 Map,
79 Unmap,
80 SetGeometry,
81 SetWindowFlags,
82 SetWindowState
83 };
84
85 QXcbWindow(QWindow *window);
86 ~QXcbWindow();
87
88 void setGeometry(const QRect &rect) override;
89
90 QMargins frameMargins() const override;
91
92 void setVisible(bool visible) override;
93 void setWindowFlags(Qt::WindowFlags flags) override;
94 void setWindowState(Qt::WindowStates state) override;
95 WId winId() const override;
96 void setParent(const QPlatformWindow *window) override;
97
98 bool isExposed() const override;
99 bool isEmbedded() const override;
100 QPoint mapToGlobal(const QPoint &pos) const override;
101 QPoint mapFromGlobal(const QPoint &pos) const override;
102
103 void setWindowTitle(const QString &title) override;
104 void setWindowIconText(const QString &title) override;
105 void setWindowIcon(const QIcon &icon) override;
106 void raise() override;
107 void lower() override;
108 void propagateSizeHints() override;
109
110 void requestActivateWindow() override;
111
112 bool setKeyboardGrabEnabled(bool grab) override;
113 bool setMouseGrabEnabled(bool grab) override;
114
115 QSurfaceFormat format() const override;
116
117 bool windowEvent(QEvent *event) override;
118
119 bool startSystemResize(Qt::Edges edges) override;
120 bool startSystemMove() override;
121
122 void setOpacity(qreal level) override;
123 void setMask(const QRegion &region) override;
124
125 void setAlertState(bool enabled) override;
126 bool isAlertState() const override { return m_alertState; }
127
128 xcb_window_t xcb_window() const { return m_window; }
129 uint depth() const { return m_depth; }
130 QImage::Format imageFormat() const { return m_imageFormat; }
131 bool imageNeedsRgbSwap() const { return m_imageRgbSwap; }
132
133 bool handleNativeEvent(xcb_generic_event_t *event) override;
134
135 void handleExposeEvent(const xcb_expose_event_t *event) override;
136 void handleClientMessageEvent(const xcb_client_message_event_t *event) override;
137 void handleConfigureNotifyEvent(const xcb_configure_notify_event_t *event) override;
138 void handleMapNotifyEvent(const xcb_map_notify_event_t *event) override;
139 void handleUnmapNotifyEvent(const xcb_unmap_notify_event_t *event) override;
140 void handleButtonPressEvent(const xcb_button_press_event_t *event) override;
141 void handleButtonReleaseEvent(const xcb_button_release_event_t *event) override;
142 void handleMotionNotifyEvent(const xcb_motion_notify_event_t *event) override;
143
144 void handleEnterNotifyEvent(const xcb_enter_notify_event_t *event) override;
145 void handleLeaveNotifyEvent(const xcb_leave_notify_event_t *event) override;
146 void handleFocusInEvent(const xcb_focus_in_event_t *event) override;
147 void handleFocusOutEvent(const xcb_focus_out_event_t *event) override;
148 void handlePropertyNotifyEvent(const xcb_property_notify_event_t *event) override;
149 void handleXIMouseEvent(xcb_ge_event_t *, Qt::MouseEventSource source = Qt::MouseEventNotSynthesized) override;
150 void handleXIEnterLeave(xcb_ge_event_t *) override;
151
152 QXcbWindow *toWindow() override;
153
154 bool shouldDeferTask(Task task);
155 void handleDeferredTasks();
156
157 void handleMouseEvent(xcb_timestamp_t time, const QPoint &local, const QPoint &global,
158 Qt::KeyboardModifiers modifiers, QEvent::Type type, Qt::MouseEventSource source);
159
160 void updateNetWmUserTime(xcb_timestamp_t timestamp);
161
162 WindowTypes wmWindowTypes() const;
163 void setWmWindowType(WindowTypes types, Qt::WindowFlags flags);
164 void setWindowType(WindowTypes windowTypes) override { setWmWindowType(windowTypes, window()->flags()); }
165 void setWindowRole(const QString &role) override;
166
167 void setParentRelativeBackPixmap();
168 bool requestSystemTrayWindowDock();
169 uint visualId() const override;
170
171 bool needsSync() const;
172
173 void postSyncWindowRequest();
174 void clearSyncWindowRequest() { m_pendingSyncRequest = nullptr; }
175
176 QXcbScreen *xcbScreen() const;
177
178 bool startSystemMoveResize(const QPoint &pos, int edges);
179 void doStartSystemMoveResize(const QPoint &globalPos, int edges);
180
181 static bool isTrayIconWindow(QWindow *window)
182 {
183 return window->objectName() == QLatin1String("QSystemTrayIconSysWindow");
184 }
185
186 virtual void create();
187 virtual void destroy();
188
189 static void setWindowTitle(const QXcbConnection *conn, xcb_window_t window, const QString &title);
190 static QString windowTitle(const QXcbConnection *conn, xcb_window_t window);
191
192 int swapInterval() const { return m_swapInterval; }
193 void setSwapInterval(int swapInterval) { m_swapInterval = swapInterval; }
194
195 public Q_SLOTS:
196 void updateSyncRequestCounter();
197
198 protected:
199 virtual void resolveFormat(const QSurfaceFormat &format) { m_format = format; }
200 virtual const xcb_visualtype_t *createVisual();
201 void setImageFormatForVisual(const xcb_visualtype_t *visual);
202
203 QXcbScreen *parentScreen();
204 QXcbScreen *initialScreen() const;
205
206 void setNetWmState(bool set, xcb_atom_t one, xcb_atom_t two = 0);
207 void setNetWmState(Qt::WindowFlags flags);
208 void setNetWmState(Qt::WindowStates state);
209 void setNetWmStateOnUnmappedWindow();
210 NetWmStates netWmStates();
211
212 void setMotifWmHints(Qt::WindowFlags flags);
213
214 void setTransparentForMouseEvents(bool transparent);
215 void updateDoesNotAcceptFocus(bool doesNotAcceptFocus);
216
217 void sendXEmbedMessage(xcb_window_t window, quint32 message,
218 quint32 detail = 0, quint32 data1 = 0, quint32 data2 = 0);
219 void handleXEmbedMessage(const xcb_client_message_event_t *event);
220
221 void show();
222 void hide();
223
224 bool relayFocusToModalWindow() const;
225 void doFocusIn();
226 void doFocusOut();
227
228 void handleButtonPressEvent(int event_x, int event_y, int root_x, int root_y,
229 int detail, Qt::KeyboardModifiers modifiers, xcb_timestamp_t timestamp,
230 QEvent::Type type, Qt::MouseEventSource source = Qt::MouseEventNotSynthesized);
231
232 void handleButtonReleaseEvent(int event_x, int event_y, int root_x, int root_y,
233 int detail, Qt::KeyboardModifiers modifiers, xcb_timestamp_t timestamp,
234 QEvent::Type type, Qt::MouseEventSource source = Qt::MouseEventNotSynthesized);
235
236 void handleMotionNotifyEvent(int event_x, int event_y, int root_x, int root_y,
237 Qt::KeyboardModifiers modifiers, xcb_timestamp_t timestamp,
238 QEvent::Type type, Qt::MouseEventSource source = Qt::MouseEventNotSynthesized);
239
240 void handleEnterNotifyEvent(int event_x, int event_y, int root_x, int root_y,
241 quint8 mode, quint8 detail, xcb_timestamp_t timestamp);
242
243 void handleLeaveNotifyEvent(int root_x, int root_y,
244 quint8 mode, quint8 detail, xcb_timestamp_t timestamp);
245
246 xcb_window_t m_window = 0;
247
248 uint m_depth = 0;
249 QImage::Format m_imageFormat = QImage::Format_ARGB32_Premultiplied;
250 bool m_imageRgbSwap = false;
251
252 xcb_sync_int64_t m_syncValue;
253 xcb_sync_counter_t m_syncCounter = 0;
254
255 Qt::WindowStates m_windowState = Qt::WindowNoState;
256
257 bool m_mapped = false;
258 bool m_transparent = false;
259 bool m_deferredActivation = false;
260 bool m_embedded = false;
261 bool m_alertState = false;
262 bool m_minimized = false;
263 bool m_trayIconWindow = false;
264 xcb_window_t m_netWmUserTimeWindow = XCB_NONE;
265
266 QSurfaceFormat m_format;
267
268 mutable bool m_dirtyFrameMargins = false;
269 mutable QMargins m_frameMargins;
270
271 QRegion m_exposeRegion;
272 QSize m_oldWindowSize;
273 QPoint m_lastPointerPosition;
274
275 xcb_visualid_t m_visualId = 0;
276 // Last sent state. Initialized to an invalid state, on purpose.
277 Qt::WindowStates m_lastWindowStateEvent = Qt::WindowActive;
278
279 enum SyncState {
280 NoSyncNeeded,
281 SyncReceived,
282 SyncAndConfigureReceived
283 };
284 SyncState m_syncState = NoSyncNeeded;
285
286 QXcbSyncWindowRequest *m_pendingSyncRequest = nullptr;
287 int m_swapInterval = -1;
288
289 qreal m_sizeHintsScaleFactor = 1.0;
290
291 bool m_wmStateValid = true;
292 QVector<Task> m_deferredTasks;
293 bool m_isWmManagedWindow = true;
294 QRect m_deferredGeometry;
295 };
296
297 class QXcbForeignWindow : public QXcbWindow
298 {
299 public:
300 QXcbForeignWindow(QWindow *window, WId nativeHandle)
301 : QXcbWindow(window) { m_window = nativeHandle; }
302 ~QXcbForeignWindow();
303 bool isForeignWindow() const override { return true; }
304
305 protected:
306 void create() override {} // No-op
307 };
308
309 QList<xcb_rectangle_t> qRegionToXcbRectangleList(const QRegion &region);
310
311 QT_END_NAMESPACE
312
313 Q_DECLARE_METATYPE(QXcbWindow*)
314
315 #endif