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

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of qtbase/src/plugins/platforms/xcb/qxcbwindow.h