Qt 6.x
The Qt SDK
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
qxcbwindow.h
Go to the documentation of this file.
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#ifndef QXCBWINDOW_H
5#define QXCBWINDOW_H
6
7#include <qpa/qplatformwindow.h>
8#include <qpa/qplatformwindow_p.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
18
19class QXcbScreen;
21class QIcon;
22
24 , public QNativeInterface::Private::QXcbWindow
25{
26public:
28 NetWmStateAbove = 0x1,
29 NetWmStateBelow = 0x2,
30 NetWmStateFullScreen = 0x4,
31 NetWmStateMaximizedHorz = 0x8,
32 NetWmStateMaximizedVert = 0x10,
33 NetWmStateModal = 0x20,
34 NetWmStateStaysOnTop = 0x40,
35 NetWmStateDemandsAttention = 0x80,
36 NetWmStateHidden = 0x100
37 };
38
39 Q_DECLARE_FLAGS(NetWmStates, NetWmState)
40
42 RecreationNotNeeded = 0,
43 WindowStaysOnTopHintChanged = 0x1,
44 WindowStaysOnBottomHintChanged = 0x2
45 };
46 Q_DECLARE_FLAGS(RecreationReasons, RecreationReason)
47
50
51 void setGeometry(const QRect &rect) override;
52
53 QMargins frameMargins() const override;
54
55 void setVisible(bool visible) override;
56 void setWindowFlags(Qt::WindowFlags flags) override;
57 void setWindowState(Qt::WindowStates state) override;
58 WId winId() const override;
59 void setParent(const QPlatformWindow *window) override;
60
61 bool isExposed() const override;
62 bool isEmbedded() const override;
63 QPoint mapToGlobal(const QPoint &pos) const override;
64 QPoint mapFromGlobal(const QPoint &pos) const override;
65
66 void setWindowTitle(const QString &title) override;
67 void setWindowIconText(const QString &title) override;
68 void setWindowIcon(const QIcon &icon) override;
69 void raise() override;
70 void lower() override;
71 void propagateSizeHints() override;
72
73 void requestActivateWindow() override;
74
75 bool setKeyboardGrabEnabled(bool grab) override;
76 bool setMouseGrabEnabled(bool grab) override;
77
78 QSurfaceFormat format() const override;
79
80 bool windowEvent(QEvent *event) override;
81
82 bool startSystemResize(Qt::Edges edges) override;
83 bool startSystemMove() override;
84
85 void setOpacity(qreal level) override;
86 void setMask(const QRegion &region) override;
87
88 void setAlertState(bool enabled) override;
89 bool isAlertState() const override { return m_alertState; }
90
91 xcb_window_t xcb_window() const { return m_window; }
92 uint depth() const { return m_depth; }
93 QImage::Format imageFormat() const { return m_imageFormat; }
94 bool imageNeedsRgbSwap() const { return m_imageRgbSwap; }
95
96 bool handleNativeEvent(xcb_generic_event_t *event) override;
97
98 void handleExposeEvent(const xcb_expose_event_t *event) override;
99 void handleClientMessageEvent(const xcb_client_message_event_t *event) override;
100 void handleConfigureNotifyEvent(const xcb_configure_notify_event_t *event) override;
101 void handleMapNotifyEvent(const xcb_map_notify_event_t *event) override;
102 void handleUnmapNotifyEvent(const xcb_unmap_notify_event_t *event) override;
103 void handleButtonPressEvent(const xcb_button_press_event_t *event) override;
104 void handleButtonReleaseEvent(const xcb_button_release_event_t *event) override;
105 void handleMotionNotifyEvent(const xcb_motion_notify_event_t *event) override;
106
107 void handleEnterNotifyEvent(const xcb_enter_notify_event_t *event) override;
108 void handleLeaveNotifyEvent(const xcb_leave_notify_event_t *event) override;
109 void handleFocusInEvent(const xcb_focus_in_event_t *event) override;
110 void handleFocusOutEvent(const xcb_focus_out_event_t *event) override;
111 void handlePropertyNotifyEvent(const xcb_property_notify_event_t *event) override;
113 void handleXIEnterLeave(xcb_ge_event_t *) override;
114
115 QXcbWindow *toWindow() override;
116
117 void handleMouseEvent(xcb_timestamp_t time, const QPoint &local, const QPoint &global,
118 Qt::KeyboardModifiers modifiers, QEvent::Type type, Qt::MouseEventSource source);
119
120 void updateNetWmUserTime(xcb_timestamp_t timestamp);
121
122 WindowTypes wmWindowTypes() const;
123 void setWmWindowType(WindowTypes types, Qt::WindowFlags flags);
124 void setWindowType(WindowTypes windowTypes) override { setWmWindowType(windowTypes, window()->flags()); }
125 void setWindowRole(const QString &role) override;
126
127 void setParentRelativeBackPixmap();
128 bool requestSystemTrayWindowDock();
129 uint visualId() const override;
130
131 bool needsSync() const;
132
133 void postSyncWindowRequest();
134 void clearSyncWindowRequest() { m_pendingSyncRequest = nullptr; }
135
136 QXcbScreen *xcbScreen() const;
137
138 QPoint lastPointerPosition() const { return m_lastPointerPosition; }
139 QPoint lastPointerGlobalPosition() const { return m_lastPointerGlobalPosition; }
140
141 bool startSystemMoveResize(const QPoint &pos, int edges);
142 void doStartSystemMoveResize(const QPoint &globalPos, int edges);
143
145 {
146 return window->objectName() == QLatin1StringView("QSystemTrayIconSysWindow");
147 }
148
149 virtual void create();
150 virtual void destroy();
151
152 static void setWindowTitle(const QXcbConnection *conn, xcb_window_t window, const QString &title);
153 static QString windowTitle(const QXcbConnection *conn, xcb_window_t window);
154
155 int swapInterval() const { return m_swapInterval; }
156 void setSwapInterval(int swapInterval) { m_swapInterval = swapInterval; }
157
158public Q_SLOTS:
159 void updateSyncRequestCounter();
160
161protected:
162 virtual void resolveFormat(const QSurfaceFormat &format) { m_format = format; }
163 virtual const xcb_visualtype_t *createVisual();
164 void setImageFormatForVisual(const xcb_visualtype_t *visual);
165
166 QXcbScreen *parentScreen();
167 QXcbScreen *initialScreen() const;
168
169 void setNetWmState(bool set, xcb_atom_t one, xcb_atom_t two = 0);
170 void setNetWmState(Qt::WindowFlags flags);
171 void setNetWmState(Qt::WindowStates state);
172 void setNetWmStateOnUnmappedWindow();
173 NetWmStates netWmStates();
174
175 void setMotifWmHints(Qt::WindowFlags flags);
176
177 void setTransparentForMouseEvents(bool transparent);
178 void updateDoesNotAcceptFocus(bool doesNotAcceptFocus);
179
180 void sendXEmbedMessage(xcb_window_t window, quint32 message,
181 quint32 detail = 0, quint32 data1 = 0, quint32 data2 = 0);
182 void handleXEmbedMessage(const xcb_client_message_event_t *event);
183
184 void show();
185 void hide();
186
187 bool relayFocusToModalWindow() const;
188 void doFocusIn();
189 void doFocusOut();
190
191 void handleButtonPressEvent(int event_x, int event_y, int root_x, int root_y,
192 int detail, Qt::KeyboardModifiers modifiers, xcb_timestamp_t timestamp,
194
195 void handleButtonReleaseEvent(int event_x, int event_y, int root_x, int root_y,
196 int detail, Qt::KeyboardModifiers modifiers, xcb_timestamp_t timestamp,
198
199 void handleMotionNotifyEvent(int event_x, int event_y, int root_x, int root_y,
200 Qt::KeyboardModifiers modifiers, xcb_timestamp_t timestamp,
202
203 void handleEnterNotifyEvent(int event_x, int event_y, int root_x, int root_y,
204 quint8 mode, quint8 detail, xcb_timestamp_t timestamp);
205
206 void handleLeaveNotifyEvent(int root_x, int root_y,
207 quint8 mode, quint8 detail, xcb_timestamp_t timestamp);
208
209 xcb_window_t m_window = 0;
210
211 uint m_depth = 0;
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 bool m_mapped = false;
221 bool m_transparent = false;
222 bool m_deferredActivation = false;
223 bool m_embedded = false;
224 bool m_alertState = false;
225 bool m_minimized = false;
226 bool m_trayIconWindow = false;
227 xcb_window_t m_netWmUserTimeWindow = XCB_NONE;
228
230
231 mutable bool m_dirtyFrameMargins = false;
233
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
246 SyncAndConfigureReceived
247 };
248 SyncState m_syncState = NoSyncNeeded;
249
250 QXcbSyncWindowRequest *m_pendingSyncRequest = nullptr;
251 int m_swapInterval = -1;
252
253 qreal m_sizeHintsScaleFactor = 1.0;
254
255 RecreationReasons m_recreationReasons = RecreationNotNeeded;
256};
257
259{
260public:
261 QXcbForeignWindow(QWindow *window, WId nativeHandle)
262 : QXcbWindow(window) { m_window = nativeHandle; }
264 bool isForeignWindow() const override { return true; }
265
266protected:
267 void create() override {} // No-op
268};
269
271
273
275
276#endif
\inmodule QtCore
Definition qcoreevent.h:45
Type
This enum type defines the valid event types in Qt.
Definition qcoreevent.h:51
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
Format
The following image formats are available in Qt.
Definition qimage.h:41
@ Format_ARGB32_Premultiplied
Definition qimage.h:48
Definition qlist.h:74
\inmodule QtCore
Definition qmargins.h:23
The QPlatformWindow class provides an abstraction for top-level windows.
virtual bool startSystemMove()
Reimplement this method to start a system move operation if the system supports it and return true to...
virtual bool isExposed() const
Returns if this window is exposed in the windowing system.
virtual void setWindowFlags(Qt::WindowFlags flags)
Requests setting the window flags of this surface to flags.
virtual QPoint mapFromGlobal(const QPoint &pos) const
Translates the global screen coordinate pos to window coordinates using native methods.
virtual void setVisible(bool visible)
Reimplemented in subclasses to show the surface if visible is true, and hide it if visible is false.
virtual void setWindowTitle(const QString &title)
Reimplement to set the window title to title.
QWindow * window() const
Returns the window which belongs to the QPlatformWindow.
virtual bool windowEvent(QEvent *event)
Reimplement this method to be able to do any platform specific event handling.
virtual void setGeometry(const QRect &rect)
This function is called by Qt whenever a window is moved or resized using the QWindow API.
virtual void setMask(const QRegion &region)
Reimplement to be able to let Qt set the mask of a window.
virtual void requestActivateWindow()
Reimplement to let Qt be able to request activation/focus for a window.
virtual void setOpacity(qreal level)
Reimplement to be able to let Qt set the opacity level of a window.
virtual void raise()
Reimplement to be able to let Qt raise windows to the top of the desktop.
virtual void propagateSizeHints()
Reimplement to propagate the size hints of the QWindow.
virtual void setAlertState(bool enabled)
Reimplement this method to set whether the window demands attention (for example, by flashing the tas...
virtual WId winId() const
Reimplement in subclasses to return a handle to the native window.
virtual QMargins frameMargins() const
virtual QPoint mapToGlobal(const QPoint &pos) const
Translates the window coordinate pos to global screen coordinates using native methods.
virtual bool startSystemResize(Qt::Edges edges)
Reimplement this method to start a system resize operation if the system supports it and return true ...
virtual bool setKeyboardGrabEnabled(bool grab)
virtual void lower()
Reimplement to be able to let Qt lower windows to the bottom of the desktop.
virtual bool setMouseGrabEnabled(bool grab)
virtual void setWindowIcon(const QIcon &icon)
Reimplement to set the window icon to icon.
\inmodule QtCore\reentrant
Definition qpoint.h:23
\inmodule QtCore\reentrant
Definition qrect.h:30
The QRegion class specifies a clip region for a painter.
Definition qregion.h:27
\inmodule QtCore
Definition qsize.h:25
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
The QSurfaceFormat class represents the format of a QSurface. \inmodule QtGui.
\inmodule QtGui
Definition qwindow.h:63
bool isForeignWindow() const override
Definition qxcbwindow.h:264
void create() override
Definition qxcbwindow.h:267
QXcbForeignWindow(QWindow *window, WId nativeHandle)
Definition qxcbwindow.h:261
virtual void handleConfigureNotifyEvent(const xcb_configure_notify_event_t *)
virtual void handleUnmapNotifyEvent(const xcb_unmap_notify_event_t *)
virtual void handleXIMouseEvent(xcb_ge_event_t *, Qt::MouseEventSource=Qt::MouseEventNotSynthesized)
virtual void handleButtonPressEvent(const xcb_button_press_event_t *)
virtual void handleEnterNotifyEvent(const xcb_enter_notify_event_t *)
virtual void handleMapNotifyEvent(const xcb_map_notify_event_t *)
virtual void handleClientMessageEvent(const xcb_client_message_event_t *)
virtual void handleXIEnterLeave(xcb_ge_event_t *)
virtual void handleMotionNotifyEvent(const xcb_motion_notify_event_t *)
virtual void handleLeaveNotifyEvent(const xcb_leave_notify_event_t *)
virtual void handleButtonReleaseEvent(const xcb_button_release_event_t *)
virtual void handleExposeEvent(const xcb_expose_event_t *)
virtual void handleFocusOutEvent(const xcb_focus_out_event_t *)
virtual void handleFocusInEvent(const xcb_focus_in_event_t *)
virtual void handlePropertyNotifyEvent(const xcb_property_notify_event_t *)
virtual bool handleNativeEvent(xcb_generic_event_t *)
virtual QXcbWindow * toWindow()
xcb_window_t xcb_window() const
Definition qxcbwindow.h:91
xcb_window_t m_window
Definition qxcbwindow.h:209
QPoint lastPointerPosition() const
Definition qxcbwindow.h:138
void clearSyncWindowRequest()
Definition qxcbwindow.h:134
void setWindowType(WindowTypes windowTypes) override
Definition qxcbwindow.h:124
QMargins m_frameMargins
Definition qxcbwindow.h:232
QRegion m_exposeRegion
Definition qxcbwindow.h:234
QImage::Format imageFormat() const
Definition qxcbwindow.h:93
void setSwapInterval(int swapInterval)
Definition qxcbwindow.h:156
uint depth() const
Definition qxcbwindow.h:92
QSurfaceFormat m_format
Definition qxcbwindow.h:229
xcb_sync_int64_t m_syncValue
Definition qxcbwindow.h:215
bool imageNeedsRgbSwap() const
Definition qxcbwindow.h:94
QPoint m_lastPointerPosition
Definition qxcbwindow.h:236
QPoint m_lastPointerGlobalPosition
Definition qxcbwindow.h:237
static bool isTrayIconWindow(QWindow *window)
Definition qxcbwindow.h:144
int swapInterval() const
Definition qxcbwindow.h:155
QSize m_oldWindowSize
Definition qxcbwindow.h:235
bool isAlertState() const override
Reimplement this method return whether the window is in an alert state.
Definition qxcbwindow.h:89
QPoint lastPointerGlobalPosition() const
Definition qxcbwindow.h:139
virtual void resolveFormat(const QSurfaceFormat &format)
Definition qxcbwindow.h:162
EGLImageKHR int int EGLuint64KHR * modifiers
rect
[4]
else opt state
[0]
Combined button and popup list for selecting options.
@ WindowNoState
Definition qnamespace.h:251
@ WindowActive
Definition qnamespace.h:255
MouseEventSource
@ MouseEventNotSynthesized
#define Q_DECLARE_FLAGS(Flags, Enum)
Definition qflags.h:174
#define Q_DECLARE_METATYPE(TYPE)
Definition qmetatype.h:1504
GLenum mode
GLenum GLuint GLint level
GLsizei GLenum GLenum * types
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLenum type
GLbitfield flags
GLuint GLsizei const GLchar * message
GLint GLsizei GLsizei GLenum format
GLsizei GLsizei GLchar * source
struct _cl_event * event
#define Q_SLOTS
unsigned int quint32
Definition qtypes.h:45
unsigned int uint
Definition qtypes.h:29
double qreal
Definition qtypes.h:92
unsigned char quint8
Definition qtypes.h:41
static bool isEmbedded(const QWindow *w)
Definition qwidget.cpp:6637
static QT_BEGIN_NAMESPACE QString windowTitle(HWND hwnd)
#define Q_XCB_EXPORT
Definition qxcbexport.h:14
QList< xcb_rectangle_t > qRegionToXcbRectangleList(const QRegion &region)
view show()
[18] //! [19]
QFuture< QSet< QChar > > set
[10]
QString title
[35]
edit hide()
w setWindowState(w->windowState() ^ Qt::WindowFullScreen)
[0]
aWidget window() -> setWindowTitle("New Window Title")
[2]
file setParent(multiPart)
view create()
QJSValue global