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 QXCBNATIVEINTERFACE_H
5#define QXCBNATIVEINTERFACE_H
6
7#include <qpa/qplatformnativeinterface.h>
8#include <xcb/xcb.h>
9
10#include <QtCore/QRect>
11
12#include <QtGui/qguiapplication.h>
13
14#include "qxcbexport.h"
15#include "qxcbconnection.h"
16
17QT_BEGIN_NAMESPACE
18
19class QXcbScreen;
20class QXcbNativeInterfaceHandler;
21
22class Q_XCB_EXPORT QXcbNativeInterface : public QPlatformNativeInterface
23 , public QNativeInterface::QX11Application
24{
25 Q_OBJECT
26public:
27 enum ResourceType {
28 XDisplay,
29 Connection,
30 Screen,
31 AppTime,
32 AppUserTime,
33 ScreenHintStyle,
34 StartupId,
35 TrayWindow,
36 GetTimestamp,
37 X11Screen,
38 RootWindow,
39 ScreenSubpixelType,
40 ScreenAntialiasingEnabled,
41 AtspiBus,
42 CompositingEnabled,
43 VkSurface,
44 GeneratePeekerId,
45 RemovePeekerId,
46 PeekEventQueue
47 };
48
49 QXcbNativeInterface();
50
51 void *nativeResourceForIntegration(const QByteArray &resource) override;
52 void *nativeResourceForContext(const QByteArray &resourceString, QOpenGLContext *context) override;
53 void *nativeResourceForScreen(const QByteArray &resource, QScreen *screen) override;
54 void *nativeResourceForWindow(const QByteArray &resourceString, QWindow *window) override;
55 void *nativeResourceForBackingStore(const QByteArray &resource, QBackingStore *backingStore) override;
56#ifndef QT_NO_CURSOR
57 void *nativeResourceForCursor(const QByteArray &resource, const QCursor &cursor) override;
58#endif
59
60 NativeResourceForIntegrationFunction nativeResourceFunctionForIntegration(const QByteArray &resource) override;
61 NativeResourceForContextFunction nativeResourceFunctionForContext(const QByteArray &resource) override;
62 NativeResourceForScreenFunction nativeResourceFunctionForScreen(const QByteArray &resource) override;
63 NativeResourceForWindowFunction nativeResourceFunctionForWindow(const QByteArray &resource) override;
64 NativeResourceForBackingStoreFunction nativeResourceFunctionForBackingStore(const QByteArray &resource) override;
65
66 QFunctionPointer platformFunction(const QByteArray &function) const override;
67
68 inline const QByteArray &nativeEventType() const { return m_nativeEventType; }
69
70 void *displayForWindow(QWindow *window);
71 void *connectionForWindow(QWindow *window);
72 void *screenForWindow(QWindow *window);
73 void *appTime(const QXcbScreen *screen);
74 void *appUserTime(const QXcbScreen *screen);
75 void *getTimestamp(const QXcbScreen *screen);
76 void *startupId();
77 void *x11Screen();
78 void *rootWindow();
79
80 Display *display() const override;
81 xcb_connection_t *connection() const override;
82
83 void *atspiBus();
84 static void setStartupId(const char *);
85 static void setAppTime(QScreen *screen, xcb_timestamp_t time);
86 static void setAppUserTime(QScreen *screen, xcb_timestamp_t time);
87
88 static qint32 generatePeekerId();
89 static bool removePeekerId(qint32 peekerId);
90 static bool peekEventQueue(QXcbEventQueue::PeekerCallback peeker, void *peekerData = nullptr,
91 QXcbEventQueue::PeekOptions option = QXcbEventQueue::PeekDefault,
92 qint32 peekerId = -1);
93
94 Q_INVOKABLE QString dumpConnectionNativeWindows(const QXcbConnection *connection, WId root) const;
95 Q_INVOKABLE QString dumpNativeWindows(WId root = 0) const;
96
97 void addHandler(QXcbNativeInterfaceHandler *handler);
98 void removeHandler(QXcbNativeInterfaceHandler *handler);
99signals:
100 void systemTrayWindowChanged(QScreen *screen);
101
102private:
103 const QByteArray m_nativeEventType = QByteArrayLiteral("xcb_generic_event_t");
104
105 static QXcbScreen *qPlatformScreenForWindow(QWindow *window);
106
107 QList<QXcbNativeInterfaceHandler *> m_handlers;
108 NativeResourceForIntegrationFunction handlerNativeResourceFunctionForIntegration(const QByteArray &resource) const;
109 NativeResourceForContextFunction handlerNativeResourceFunctionForContext(const QByteArray &resource) const;
110 NativeResourceForScreenFunction handlerNativeResourceFunctionForScreen(const QByteArray &resource) const;
111 NativeResourceForWindowFunction handlerNativeResourceFunctionForWindow(const QByteArray &resource) const;
112 NativeResourceForBackingStoreFunction handlerNativeResourceFunctionForBackingStore(const QByteArray &resource) const;
113 QFunctionPointer handlerPlatformFunction(const QByteArray &function) const;
114 void *handlerNativeResourceForIntegration(const QByteArray &resource) const;
115 void *handlerNativeResourceForContext(const QByteArray &resource, QOpenGLContext *context) const;
116 void *handlerNativeResourceForScreen(const QByteArray &resource, QScreen *screen) const;
117 void *handlerNativeResourceForWindow(const QByteArray &resource, QWindow *window) const;
118 void *handlerNativeResourceForBackingStore(const QByteArray &resource, QBackingStore *backingStore) const;
119};
120
121QT_END_NAMESPACE
122
123#endif // QXCBNATIVEINTERFACE_H
124

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