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 QXCBNATIVEINTERFACE_H 41 #define QXCBNATIVEINTERFACE_H 42 43 #include <qpa/qplatformnativeinterface.h> 44 #include <xcb/xcb.h> 45 46 #include <QtCore/QRect> 47 48 #include "qxcbexport.h" 49 #include "qxcbconnection.h" 50 51 QT_BEGIN_NAMESPACE 52 53 class QXcbScreen; 54 class QXcbNativeInterfaceHandler; 55 56 class Q_XCB_EXPORT QXcbNativeInterface : public QPlatformNativeInterface 57 { 58 Q_OBJECT 59 public: 60 enum ResourceType { 61 Display, 62 Connection, 63 Screen, 64 AppTime, 65 AppUserTime, 66 ScreenHintStyle, 67 StartupId, 68 TrayWindow, 69 GetTimestamp, 70 X11Screen, 71 RootWindow, 72 ScreenSubpixelType, 73 ScreenAntialiasingEnabled, 74 AtspiBus, 75 CompositingEnabled, 76 VkSurface, 77 GeneratePeekerId, 78 RemovePeekerId, 79 PeekEventQueue 80 }; 81 82 QXcbNativeInterface(); 83 84 void *nativeResourceForIntegration(const QByteArray &resource) override; 85 void *nativeResourceForContext(const QByteArray &resourceString, QOpenGLContext *context) override; 86 void *nativeResourceForScreen(const QByteArray &resource, QScreen *screen) override; 87 void *nativeResourceForWindow(const QByteArray &resourceString, QWindow *window) override; 88 void *nativeResourceForBackingStore(const QByteArray &resource, QBackingStore *backingStore) override; 89 #ifndef QT_NO_CURSOR 90 void *nativeResourceForCursor(const QByteArray &resource, const QCursor &cursor) override; 91 #endif 92 93 NativeResourceForIntegrationFunction nativeResourceFunctionForIntegration(const QByteArray &resource) override; 94 NativeResourceForContextFunction nativeResourceFunctionForContext(const QByteArray &resource) override; 95 NativeResourceForScreenFunction nativeResourceFunctionForScreen(const QByteArray &resource) override; 96 NativeResourceForWindowFunction nativeResourceFunctionForWindow(const QByteArray &resource) override; 97 NativeResourceForBackingStoreFunction nativeResourceFunctionForBackingStore(const QByteArray &resource) override; 98 99 QFunctionPointer platformFunction(const QByteArray &function) const override; 100 nativeEventType()101 inline const QByteArray &nativeEventType() const { return m_nativeEventType; } 102 103 void *displayForWindow(QWindow *window); 104 void *connectionForWindow(QWindow *window); 105 void *screenForWindow(QWindow *window); 106 void *appTime(const QXcbScreen *screen); 107 void *appUserTime(const QXcbScreen *screen); 108 void *getTimestamp(const QXcbScreen *screen); 109 void *startupId(); 110 void *x11Screen(); 111 void *rootWindow(); 112 void *display(); 113 void *atspiBus(); 114 void *connection(); 115 static void setStartupId(const char *); 116 static void setAppTime(QScreen *screen, xcb_timestamp_t time); 117 static void setAppUserTime(QScreen *screen, xcb_timestamp_t time); 118 119 static qint32 generatePeekerId(); 120 static bool removePeekerId(qint32 peekerId); 121 static bool peekEventQueue(QXcbEventQueue::PeekerCallback peeker, void *peekerData = nullptr, 122 QXcbEventQueue::PeekOptions option = QXcbEventQueue::PeekDefault, 123 qint32 peekerId = -1); 124 125 Q_INVOKABLE QString dumpConnectionNativeWindows(const QXcbConnection *connection, WId root) const; 126 Q_INVOKABLE QString dumpNativeWindows(WId root = 0) const; 127 128 void addHandler(QXcbNativeInterfaceHandler *handler); 129 void removeHandler(QXcbNativeInterfaceHandler *handler); 130 signals: 131 void systemTrayWindowChanged(QScreen *screen); 132 133 private: 134 const QByteArray m_nativeEventType = QByteArrayLiteral("xcb_generic_event_t"); 135 136 xcb_atom_t m_sysTraySelectionAtom = XCB_ATOM_NONE; 137 138 static QXcbScreen *qPlatformScreenForWindow(QWindow *window); 139 140 QList<QXcbNativeInterfaceHandler *> m_handlers; 141 NativeResourceForIntegrationFunction handlerNativeResourceFunctionForIntegration(const QByteArray &resource) const; 142 NativeResourceForContextFunction handlerNativeResourceFunctionForContext(const QByteArray &resource) const; 143 NativeResourceForScreenFunction handlerNativeResourceFunctionForScreen(const QByteArray &resource) const; 144 NativeResourceForWindowFunction handlerNativeResourceFunctionForWindow(const QByteArray &resource) const; 145 NativeResourceForBackingStoreFunction handlerNativeResourceFunctionForBackingStore(const QByteArray &resource) const; 146 QFunctionPointer handlerPlatformFunction(const QByteArray &function) const; 147 void *handlerNativeResourceForIntegration(const QByteArray &resource) const; 148 void *handlerNativeResourceForContext(const QByteArray &resource, QOpenGLContext *context) const; 149 void *handlerNativeResourceForScreen(const QByteArray &resource, QScreen *screen) const; 150 void *handlerNativeResourceForWindow(const QByteArray &resource, QWindow *window) const; 151 void *handlerNativeResourceForBackingStore(const QByteArray &resource, QBackingStore *backingStore) const; 152 }; 153 154 QT_END_NAMESPACE 155 156 #endif // QXCBNATIVEINTERFACE_H 157