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