diff options
Diffstat (limited to 'src/platformsupport')
75 files changed, 2238 insertions, 807 deletions
diff --git a/src/platformsupport/devicediscovery/qdevicediscovery_p.h b/src/platformsupport/devicediscovery/qdevicediscovery_p.h index e3c22b0b37..f1f50e9708 100644 --- a/src/platformsupport/devicediscovery/qdevicediscovery_p.h +++ b/src/platformsupport/devicediscovery/qdevicediscovery_p.h @@ -86,7 +86,7 @@ public: Q_ENUM(QDeviceType) Q_DECLARE_FLAGS(QDeviceTypes, QDeviceType) - static QDeviceDiscovery *create(QDeviceTypes type, QObject *parent = 0); + static QDeviceDiscovery *create(QDeviceTypes type, QObject *parent = nullptr); virtual QStringList scanConnectedDevices() = 0; @@ -96,7 +96,7 @@ signals: protected: QDeviceDiscovery(QDeviceTypes types, QObject *parent) : QObject(parent), m_types(types) { } - Q_DISABLE_COPY(QDeviceDiscovery) + Q_DISABLE_COPY_MOVE(QDeviceDiscovery) QDeviceTypes m_types; }; diff --git a/src/platformsupport/devicediscovery/qdevicediscovery_udev_p.h b/src/platformsupport/devicediscovery/qdevicediscovery_udev_p.h index 28618d0b21..82b475776d 100644 --- a/src/platformsupport/devicediscovery/qdevicediscovery_udev_p.h +++ b/src/platformsupport/devicediscovery/qdevicediscovery_udev_p.h @@ -61,7 +61,7 @@ class QDeviceDiscoveryUDev : public QDeviceDiscovery Q_OBJECT public: - QDeviceDiscoveryUDev(QDeviceTypes types, struct udev *udev, QObject *parent = 0); + QDeviceDiscoveryUDev(QDeviceTypes types, struct udev *udev, QObject *parent = nullptr); ~QDeviceDiscoveryUDev(); QStringList scanConnectedDevices() override; diff --git a/src/platformsupport/eglconvenience/qeglpbuffer_p.h b/src/platformsupport/eglconvenience/qeglpbuffer_p.h index 0285e067a6..8ad2eb7248 100644 --- a/src/platformsupport/eglconvenience/qeglpbuffer_p.h +++ b/src/platformsupport/eglconvenience/qeglpbuffer_p.h @@ -60,7 +60,7 @@ class QEGLPbuffer : public QPlatformOffscreenSurface { public: QEGLPbuffer(EGLDisplay display, const QSurfaceFormat &format, QOffscreenSurface *offscreenSurface, - QEGLPlatformContext::Flags flags = 0); + QEGLPlatformContext::Flags flags = nullptr); ~QEGLPbuffer(); QSurfaceFormat format() const override { return m_format; } diff --git a/src/platformsupport/eglconvenience/qeglplatformcontext.cpp b/src/platformsupport/eglconvenience/qeglplatformcontext.cpp index e44918823b..94def16748 100644 --- a/src/platformsupport/eglconvenience/qeglplatformcontext.cpp +++ b/src/platformsupport/eglconvenience/qeglplatformcontext.cpp @@ -338,14 +338,6 @@ void QEGLPlatformContext::updateFormatFromGL() QByteArray version = QByteArray(reinterpret_cast<const char *>(s)); int major, minor; if (QPlatformOpenGLContext::parseOpenGLVersion(version, major, minor)) { -#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED) - // Some Android 4.2.2 devices report OpenGL ES 3.0 without the functions being available. - static int apiLevel = QtAndroidPrivate::androidSdkVersion(); - if (apiLevel <= 17 && major >= 3) { - major = 2; - minor = 0; - } -#endif m_format.setMajorVersion(major); m_format.setMinorVersion(minor); } diff --git a/src/platformsupport/eglconvenience/qeglplatformcontext_p.h b/src/platformsupport/eglconvenience/qeglplatformcontext_p.h index d6cbbe4131..ed77c57df5 100644 --- a/src/platformsupport/eglconvenience/qeglplatformcontext_p.h +++ b/src/platformsupport/eglconvenience/qeglplatformcontext_p.h @@ -68,8 +68,8 @@ public: Q_DECLARE_FLAGS(Flags, Flag) QEGLPlatformContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share, EGLDisplay display, - EGLConfig *config = 0, const QVariant &nativeHandle = QVariant(), - Flags flags = 0); + EGLConfig *config = nullptr, const QVariant &nativeHandle = QVariant(), + Flags flags = nullptr); ~QEGLPlatformContext(); void initialize() override; diff --git a/src/platformsupport/eglconvenience/qeglstreamconvenience_p.h b/src/platformsupport/eglconvenience/qeglstreamconvenience_p.h index c3d3070210..31a79dbc6c 100644 --- a/src/platformsupport/eglconvenience/qeglstreamconvenience_p.h +++ b/src/platformsupport/eglconvenience/qeglstreamconvenience_p.h @@ -131,6 +131,12 @@ typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMERRELEASEKHRPROC) (EGLDisplay typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMEROUTPUTEXTPROC) (EGLDisplay dpy, EGLStreamKHR stream, EGLOutputLayerEXT layer); #endif +#ifndef EGL_EXT_stream_acquire_mode +#define EGL_EXT_stream_acquire_mode 1 +#define EGL_CONSUMER_AUTO_ACQUIRE_EXT 0x332B +#define EGL_RESOURCE_BUSY_EXT 0x3353 +#endif + #ifndef EGL_EXT_platform_device #define EGL_PLATFORM_DEVICE_EXT 0x313F #endif @@ -156,6 +162,11 @@ typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMERACQUIREATTRIBNVPROC) (EGLDi typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMERRELEASEATTRIBNVPROC) (EGLDisplay dpy, EGLStreamKHR stream, const EGLAttrib *attrib_list); #endif +#ifndef EGL_NV_output_drm_flip_event +#define EGL_NV_output_drm_flip_event 1 +#define EGL_DRM_FLIP_EVENT_DATA_NV 0x333E +#endif + QT_BEGIN_NAMESPACE class QEGLStreamConvenience diff --git a/src/platformsupport/eventdispatchers/qeventdispatcher_glib_p.h b/src/platformsupport/eventdispatchers/qeventdispatcher_glib_p.h index 085a1c52f3..b9254d3071 100644 --- a/src/platformsupport/eventdispatchers/qeventdispatcher_glib_p.h +++ b/src/platformsupport/eventdispatchers/qeventdispatcher_glib_p.h @@ -64,7 +64,7 @@ class QPAEventDispatcherGlib : public QEventDispatcherGlib Q_DECLARE_PRIVATE(QPAEventDispatcherGlib) public: - explicit QPAEventDispatcherGlib(QObject *parent = 0); + explicit QPAEventDispatcherGlib(QObject *parent = nullptr); ~QPAEventDispatcherGlib(); bool processEvents(QEventLoop::ProcessEventsFlags flags) override; @@ -77,7 +77,7 @@ class QPAEventDispatcherGlibPrivate : public QEventDispatcherGlibPrivate { Q_DECLARE_PUBLIC(QPAEventDispatcherGlib) public: - QPAEventDispatcherGlibPrivate(GMainContext *context = 0); + QPAEventDispatcherGlibPrivate(GMainContext *context = nullptr); GUserEventSource *userEventSource; }; diff --git a/src/platformsupport/eventdispatchers/qunixeventdispatcher_qpa_p.h b/src/platformsupport/eventdispatchers/qunixeventdispatcher_qpa_p.h index 7f775b73ee..8157b8793d 100644 --- a/src/platformsupport/eventdispatchers/qunixeventdispatcher_qpa_p.h +++ b/src/platformsupport/eventdispatchers/qunixeventdispatcher_qpa_p.h @@ -61,7 +61,7 @@ class QUnixEventDispatcherQPA : public QEventDispatcherUNIX Q_OBJECT public: - explicit QUnixEventDispatcherQPA(QObject *parent = 0); + explicit QUnixEventDispatcherQPA(QObject *parent = nullptr); ~QUnixEventDispatcherQPA(); bool processEvents(QEventLoop::ProcessEventsFlags flags); diff --git a/src/platformsupport/fbconvenience/qfbvthandler_p.h b/src/platformsupport/fbconvenience/qfbvthandler_p.h index 17d07317b2..d565ec3632 100644 --- a/src/platformsupport/fbconvenience/qfbvthandler_p.h +++ b/src/platformsupport/fbconvenience/qfbvthandler_p.h @@ -63,7 +63,7 @@ class QFbVtHandler : public QObject Q_OBJECT public: - QFbVtHandler(QObject *parent = 0); + QFbVtHandler(QObject *parent = nullptr); ~QFbVtHandler(); signals: diff --git a/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp b/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp index e545d54ec2..7abf295782 100644 --- a/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp +++ b/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp @@ -721,7 +721,7 @@ QStringList QFontconfigDatabase::fallbacksForFamily(const QString &family, QFont FcValue value; value.type = FcTypeString; - QByteArray cs = family.toUtf8(); + const QByteArray cs = family.toUtf8(); value.u.s = (const FcChar8 *)cs.data(); FcPatternAdd(pattern,FC_FAMILY,value,true); @@ -863,7 +863,7 @@ QString QFontconfigDatabase::resolveFontFamilyAlias(const QString &family) const return family; if (!family.isEmpty()) { - QByteArray cs = family.toUtf8(); + const QByteArray cs = family.toUtf8(); FcPatternAddString(pattern, FC_FAMILY, (const FcChar8 *) cs.constData()); } FcConfigSubstitute(0, pattern, FcMatchPattern); diff --git a/src/platformsupport/fontdatabases/freetype/qfontengine_ft.cpp b/src/platformsupport/fontdatabases/freetype/qfontengine_ft.cpp index 8d6620a55f..8d0a20f7b9 100644 --- a/src/platformsupport/fontdatabases/freetype/qfontengine_ft.cpp +++ b/src/platformsupport/fontdatabases/freetype/qfontengine_ft.cpp @@ -121,13 +121,12 @@ class QtFreetypeData { public: QtFreetypeData() - : library(0), hasPatentFreeLcdRendering(false) + : library(0) { } ~QtFreetypeData(); FT_Library library; QHash<QFontEngine::FaceId, QFreetypeFace *> faces; - bool hasPatentFreeLcdRendering; }; QtFreetypeData::~QtFreetypeData() @@ -153,11 +152,6 @@ QtFreetypeData *qt_getFreetypeData() FT_Bool no_darkening = false; FT_Property_Set(freetypeData->library, "cff", "no-stem-darkening", &no_darkening); #endif - // FreeType has since 2.8.1 a patent free alternative to LCD-filtering. - FT_Int amajor, aminor = 0, apatch = 0; - FT_Library_Version(freetypeData->library, &amajor, &aminor, &apatch); - if (QT_VERSION_CHECK(amajor, aminor, apatch) >= QT_VERSION_CHECK(2, 8, 1)) - freetypeData->hasPatentFreeLcdRendering = true; } return freetypeData; } @@ -260,7 +254,7 @@ QFreetypeFace *QFreetypeFace::getFace(const QFontEngine::FaceId &face_id, } newFreetype->face = face; - newFreetype->ref.store(1); + newFreetype->ref.storeRelaxed(1); newFreetype->xsize = 0; newFreetype->ysize = 0; newFreetype->matrix.xx = 0x10000; @@ -561,26 +555,7 @@ QFontEngineFT::Glyph::~Glyph() delete [] data; } -struct LcdFilterDummy -{ - static inline void filterPixel(uchar &, uchar &, uchar &) - {} -}; - -struct LcdFilterLegacy -{ - static inline void filterPixel(uchar &red, uchar &green, uchar &blue) - { - uint r = red, g = green, b = blue; - // intra-pixel filter used by the legacy filter (adopted from _ft_lcd_filter_legacy) - red = (r * uint(65538 * 9/13) + g * uint(65538 * 1/6) + b * uint(65538 * 1/13)) / 65536; - green = (r * uint(65538 * 3/13) + g * uint(65538 * 4/6) + b * uint(65538 * 3/13)) / 65536; - blue = (r * uint(65538 * 1/13) + g * uint(65538 * 1/6) + b * uint(65538 * 9/13)) / 65536; - } -}; - -template <typename LcdFilter> -static void convertRGBToARGB_helper(const uchar *src, uint *dst, int width, int height, int src_pitch, bool bgr) +static inline void convertRGBToARGB(const uchar *src, uint *dst, int width, int height, int src_pitch, bool bgr) { const int offs = bgr ? -1 : 1; const int w = width * 3; @@ -590,7 +565,6 @@ static void convertRGBToARGB_helper(const uchar *src, uint *dst, int width, int uchar red = src[x + 1 - offs]; uchar green = src[x + 1]; uchar blue = src[x + 1 + offs]; - LcdFilter::filterPixel(red, green, blue); *dd++ = (0xFFU << 24) | (red << 16) | (green << 8) | blue; } dst += width; @@ -598,16 +572,7 @@ static void convertRGBToARGB_helper(const uchar *src, uint *dst, int width, int } } -static inline void convertRGBToARGB(const uchar *src, uint *dst, int width, int height, int src_pitch, bool bgr, bool legacyFilter) -{ - if (!legacyFilter) - convertRGBToARGB_helper<LcdFilterDummy>(src, dst, width, height, src_pitch, bgr); - else - convertRGBToARGB_helper<LcdFilterLegacy>(src, dst, width, height, src_pitch, bgr); -} - -template <typename LcdFilter> -static void convertRGBToARGB_V_helper(const uchar *src, uint *dst, int width, int height, int src_pitch, bool bgr) +static inline void convertRGBToARGB_V(const uchar *src, uint *dst, int width, int height, int src_pitch, bool bgr) { const int offs = bgr ? -src_pitch : src_pitch; while (height--) { @@ -615,54 +580,12 @@ static void convertRGBToARGB_V_helper(const uchar *src, uint *dst, int width, in uchar red = src[x + src_pitch - offs]; uchar green = src[x + src_pitch]; uchar blue = src[x + src_pitch + offs]; - LcdFilter::filterPixel(red, green, blue); *dst++ = (0XFFU << 24) | (red << 16) | (green << 8) | blue; } src += 3*src_pitch; } } -static inline void convertRGBToARGB_V(const uchar *src, uint *dst, int width, int height, int src_pitch, bool bgr, bool legacyFilter) -{ - if (!legacyFilter) - convertRGBToARGB_V_helper<LcdFilterDummy>(src, dst, width, height, src_pitch, bgr); - else - convertRGBToARGB_V_helper<LcdFilterLegacy>(src, dst, width, height, src_pitch, bgr); -} - -static inline void convertGRAYToARGB(const uchar *src, uint *dst, int width, int height, int src_pitch) -{ - while (height--) { - const uchar *p = src; - const uchar * const e = p + width; - while (p < e) { - uchar gray = *p++; - *dst++ = (0xFFU << 24) | (gray << 16) | (gray << 8) | gray; - } - src += src_pitch; - } -} - -static void convoluteBitmap(const uchar *src, uchar *dst, int width, int height, int pitch) -{ - // convolute the bitmap with a triangle filter to get rid of color fringes - // If we take account for a gamma value of 2, we end up with - // weights of 1, 4, 9, 4, 1. We use an approximation of 1, 3, 8, 3, 1 here, - // as this nicely sums up to 16 :) - int h = height; - while (h--) { - dst[0] = dst[1] = 0; - // - for (int x = 2; x < width - 2; ++x) { - uint sum = src[x-2] + 3*src[x-1] + 8*src[x] + 3*src[x+1] + src[x+2]; - dst[x] = (uchar) (sum >> 4); - } - dst[width - 2] = dst[width - 1] = 0; - src += pitch; - dst += pitch; - } -} - static QFontEngine::SubpixelAntialiasingType subpixelAntialiasingTypeHint() { static int type = -1; @@ -1153,196 +1076,97 @@ QFontEngineFT::Glyph *QFontEngineFT::loadGlyph(QGlyphSet *set, uint glyph, int glyph_buffer_size = 0; QScopedArrayPointer<uchar> glyph_buffer; - bool useFreetypeRenderGlyph = false; - if (slot->format == FT_GLYPH_FORMAT_OUTLINE && (hsubpixel || vfactor != 1)) { - err = FT_Library_SetLcdFilter(slot->library, (FT_LcdFilter)lcdFilterType); - // We use FT_Render_Glyph if freetype has support for lcd-filtering - // or is version 2.8.1 or higher and can do without. - if (err == FT_Err_Ok || qt_getFreetypeData()->hasPatentFreeLcdRendering) - useFreetypeRenderGlyph = true; + FT_Render_Mode renderMode = (default_hint_style == HintLight) ? FT_RENDER_MODE_LIGHT : FT_RENDER_MODE_NORMAL; + switch (format) { + case Format_Mono: + renderMode = FT_RENDER_MODE_MONO; + break; + case Format_A32: + Q_ASSERT(hsubpixel || vfactor != 1); + renderMode = hsubpixel ? FT_RENDER_MODE_LCD : FT_RENDER_MODE_LCD_V; + break; + case Format_A8: + case Format_ARGB: + break; + default: + Q_UNREACHABLE(); } - if (useFreetypeRenderGlyph) { - err = FT_Render_Glyph(slot, hsubpixel ? FT_RENDER_MODE_LCD : FT_RENDER_MODE_LCD_V); - - if (err != FT_Err_Ok) - qWarning("render glyph failed err=%x face=%p, glyph=%d", err, face, glyph); - - FT_Library_SetLcdFilter(slot->library, FT_LCD_FILTER_NONE); + FT_Library_SetLcdFilter(slot->library, (FT_LcdFilter)lcdFilterType); - info.height = slot->bitmap.rows / vfactor; - info.width = hsubpixel ? slot->bitmap.width / 3 : slot->bitmap.width; - info.x = slot->bitmap_left; - info.y = slot->bitmap_top; + err = FT_Render_Glyph(slot, renderMode); + if (err != FT_Err_Ok) + qWarning("render glyph failed err=%x face=%p, glyph=%d", err, face, glyph); - glyph_buffer_size = info.width * info.height * 4; - glyph_buffer.reset(new uchar[glyph_buffer_size]); + FT_Library_SetLcdFilter(slot->library, FT_LCD_FILTER_NONE); - if (hsubpixel) - convertRGBToARGB(slot->bitmap.buffer, (uint *)glyph_buffer.data(), info.width, info.height, slot->bitmap.pitch, subpixelType != Subpixel_RGB, false); - else if (vfactor != 1) - convertRGBToARGB_V(slot->bitmap.buffer, (uint *)glyph_buffer.data(), info.width, info.height, slot->bitmap.pitch, subpixelType != Subpixel_VRGB, false); - } else { - int left = slot->metrics.horiBearingX; - int right = slot->metrics.horiBearingX + slot->metrics.width; - int top = slot->metrics.horiBearingY; - int bottom = slot->metrics.horiBearingY - slot->metrics.height; - if (transform && slot->format != FT_GLYPH_FORMAT_BITMAP) - transformBoundingBox(&left, &top, &right, &bottom, &matrix); - left = FLOOR(left); - right = CEIL(right); - bottom = FLOOR(bottom); - top = CEIL(top); - - int hpixels = TRUNC(right - left); - // subpixel position requires one more pixel - if (subPixelPosition > 0 && format != Format_Mono) - hpixels++; - - if (hsubpixel) - hpixels = hpixels*3 + 8; - info.width = hpixels; - info.height = TRUNC(top - bottom); - info.x = TRUNC(left); - info.y = TRUNC(top); - if (hsubpixel) { - info.width /= 3; - info.x -= 1; - } - - // If any of the metrics are too large to fit, don't cache them - if (areMetricsTooLarge(info)) - return 0; + info.height = slot->bitmap.rows; + info.width = slot->bitmap.width; + info.x = slot->bitmap_left; + info.y = slot->bitmap_top; + if (slot->bitmap.pixel_mode == FT_PIXEL_MODE_LCD) + info.width = info.width / 3; + if (slot->bitmap.pixel_mode == FT_PIXEL_MODE_LCD_V) + info.height = info.height / vfactor; int pitch = (format == Format_Mono ? ((info.width + 31) & ~31) >> 3 : (format == Format_A8 ? (info.width + 3) & ~3 : info.width * 4)); - if (glyph_buffer_size < pitch * info.height) { - glyph_buffer_size = pitch * info.height; - glyph_buffer.reset(new uchar[glyph_buffer_size]); - memset(glyph_buffer.data(), 0, glyph_buffer_size); - } - if (slot->format == FT_GLYPH_FORMAT_OUTLINE) { - FT_Bitmap bitmap; - bitmap.rows = info.height*vfactor; - bitmap.width = hpixels; - bitmap.pitch = format == Format_Mono ? (((info.width + 31) & ~31) >> 3) : ((bitmap.width + 3) & ~3); - int bitmap_buffer_size = bitmap.rows * bitmap.pitch; - if (!hsubpixel && vfactor == 1 && format != Format_A32) { - Q_ASSERT(glyph_buffer_size <= bitmap_buffer_size); - bitmap.buffer = glyph_buffer.data(); - } else { - bitmap.buffer = new uchar[bitmap_buffer_size]; - memset(bitmap.buffer, 0, bitmap_buffer_size); - } - bitmap.pixel_mode = format == Format_Mono ? FT_PIXEL_MODE_MONO : FT_PIXEL_MODE_GRAY; - FT_Matrix matrix; - matrix.xx = (hsubpixel ? 3 : 1) << 16; - matrix.yy = vfactor << 16; - matrix.yx = matrix.xy = 0; - - FT_Outline_Transform(&slot->outline, &matrix); - FT_Outline_Translate (&slot->outline, (hsubpixel ? -3*left +(4<<6) : -left), -bottom*vfactor); - FT_Outline_Get_Bitmap(slot->library, &slot->outline, &bitmap); - if (hsubpixel) { - Q_ASSERT (bitmap.pixel_mode == FT_PIXEL_MODE_GRAY); - Q_ASSERT(antialias); - uchar *convoluted = new uchar[bitmap_buffer_size]; - bool useLegacyLcdFilter = false; - useLegacyLcdFilter = (lcdFilterType == FT_LCD_FILTER_LEGACY); - uchar *buffer = bitmap.buffer; - if (!useLegacyLcdFilter) { - convoluteBitmap(bitmap.buffer, convoluted, bitmap.width, info.height, bitmap.pitch); - buffer = convoluted; - } - convertRGBToARGB(buffer + 1, (uint *)glyph_buffer.data(), info.width, info.height, bitmap.pitch, subpixelType != Subpixel_RGB, useLegacyLcdFilter); - delete [] convoluted; - } else if (vfactor != 1) { - convertRGBToARGB_V(bitmap.buffer, (uint *)glyph_buffer.data(), info.width, info.height, bitmap.pitch, subpixelType != Subpixel_VRGB, true); - } else if (format == Format_A32 && bitmap.pixel_mode == FT_PIXEL_MODE_GRAY) { - convertGRAYToARGB(bitmap.buffer, (uint *)glyph_buffer.data(), info.width, info.height, bitmap.pitch); - } + glyph_buffer_size = info.height * pitch; + glyph_buffer.reset(new uchar[glyph_buffer_size]); - if (bitmap.buffer != glyph_buffer.data()) - delete [] bitmap.buffer; - } else if (slot->format == FT_GLYPH_FORMAT_BITMAP) { -#if ((FREETYPE_MAJOR*10000 + FREETYPE_MINOR*100) >= 20500) - Q_ASSERT(slot->bitmap.pixel_mode == FT_PIXEL_MODE_MONO || slot->bitmap.pixel_mode == FT_PIXEL_MODE_BGRA); -#else - Q_ASSERT(slot->bitmap.pixel_mode == FT_PIXEL_MODE_MONO); -#endif + if (slot->bitmap.pixel_mode == FT_PIXEL_MODE_MONO) { + Q_ASSERT(format == Format_Mono); uchar *src = slot->bitmap.buffer; uchar *dst = glyph_buffer.data(); int h = slot->bitmap.rows; - if (format == Format_Mono) { - int bytes = ((info.width + 7) & ~7) >> 3; - while (h--) { - memcpy (dst, src, bytes); - dst += pitch; - src += slot->bitmap.pitch; - } - } else if (slot->bitmap.pixel_mode == FT_PIXEL_MODE_MONO) { - if (hsubpixel) { - while (h--) { - uint *dd = (uint *)dst; - *dd++ = 0; - for (int x = 0; x < static_cast<int>(slot->bitmap.width); x++) { - uint a = ((src[x >> 3] & (0x80 >> (x & 7))) ? 0xffffff : 0x000000); - *dd++ = a; - } - *dd++ = 0; - dst += pitch; - src += slot->bitmap.pitch; - } - } else if (vfactor != 1) { - while (h--) { - uint *dd = (uint *)dst; - for (int x = 0; x < static_cast<int>(slot->bitmap.width); x++) { - uint a = ((src[x >> 3] & (0x80 >> (x & 7))) ? 0xffffff : 0x000000); - *dd++ = a; - } - dst += pitch; - src += slot->bitmap.pitch; - } - } else { - while (h--) { - for (int x = 0; x < static_cast<int>(slot->bitmap.width); x++) { - unsigned char a = ((src[x >> 3] & (0x80 >> (x & 7))) ? 0xff : 0x00); - dst[x] = a; - } - dst += pitch; - src += slot->bitmap.pitch; - } - } + + int bytes = ((info.width + 7) & ~7) >> 3; + while (h--) { + memcpy (dst, src, bytes); + dst += pitch; + src += slot->bitmap.pitch; } -#if ((FREETYPE_MAJOR*10000 + FREETYPE_MINOR*100) >= 20500) - else if (slot->bitmap.pixel_mode == FT_PIXEL_MODE_BGRA) - { - while (h--) { + } else if (slot->bitmap.pixel_mode == 7 /*FT_PIXEL_MODE_BGRA*/) { + Q_ASSERT(format == Format_ARGB); + uchar *src = slot->bitmap.buffer; + uchar *dst = glyph_buffer.data(); + int h = slot->bitmap.rows; + while (h--) { #if Q_BYTE_ORDER == Q_BIG_ENDIAN - const quint32 *srcPixel = (const quint32 *)src; - quint32 *dstPixel = (quint32 *)dst; - for (int x = 0; x < static_cast<int>(slot->bitmap.width); x++, srcPixel++, dstPixel++) { - const quint32 pixel = *srcPixel; - *dstPixel = qbswap(pixel); - } + const quint32 *srcPixel = (const quint32 *)src; + quint32 *dstPixel = (quint32 *)dst; + for (int x = 0; x < static_cast<int>(slot->bitmap.width); x++, srcPixel++, dstPixel++) { + const quint32 pixel = *srcPixel; + *dstPixel = qbswap(pixel); + } #else - memcpy(dst, src, slot->bitmap.width * 4); + memcpy(dst, src, slot->bitmap.width * 4); #endif - dst += slot->bitmap.pitch; - src += slot->bitmap.pitch; - } - info.width = info.linearAdvance = info.xOff = slot->bitmap.width; - info.height = slot->bitmap.rows; - info.x = slot->bitmap_left; - info.y = slot->bitmap_top; + dst += slot->bitmap.pitch; + src += slot->bitmap.pitch; } -#endif + info.linearAdvance = info.xOff = slot->bitmap.width; + } else if (slot->bitmap.pixel_mode == FT_PIXEL_MODE_GRAY) { + Q_ASSERT(format == Format_A8); + uchar *src = slot->bitmap.buffer; + uchar *dst = glyph_buffer.data(); + int h = slot->bitmap.rows; + int bytes = info.width; + while (h--) { + memcpy (dst, src, bytes); + dst += pitch; + src += slot->bitmap.pitch; + } + } else if (slot->bitmap.pixel_mode == FT_PIXEL_MODE_LCD) { + Q_ASSERT(format == Format_A32); + convertRGBToARGB(slot->bitmap.buffer, (uint *)glyph_buffer.data(), info.width, info.height, slot->bitmap.pitch, subpixelType != Subpixel_RGB); + } else if (slot->bitmap.pixel_mode == FT_PIXEL_MODE_LCD_V) { + Q_ASSERT(format == Format_A32); + convertRGBToARGB_V(slot->bitmap.buffer, (uint *)glyph_buffer.data(), info.width, info.height, slot->bitmap.pitch, subpixelType != Subpixel_VRGB); } else { - qWarning("QFontEngine: Glyph neither outline nor bitmap format=%d", slot->format); + qWarning("QFontEngine: Glyph rendered in unknown pixel_mode=%d", slot->bitmap.pixel_mode); return 0; } - } - if (!g) { g = new Glyph; @@ -1556,7 +1380,7 @@ QFontEngineFT::QGlyphSet *QFontEngineFT::loadGlyphSet(const QTransform &matrix) gs = &transformedGlyphSets[0]; gs->clear(); gs->transformationMatrix = m; - gs->outline_drawing = fontDef.pixelSize * fontDef.pixelSize * qAbs(matrix.det()) >= QT_MAX_CACHED_GLYPH_SIZE * QT_MAX_CACHED_GLYPH_SIZE; + gs->outline_drawing = fontDef.pixelSize * fontDef.pixelSize * qAbs(matrix.determinant()) > QT_MAX_CACHED_GLYPH_SIZE * QT_MAX_CACHED_GLYPH_SIZE; } Q_ASSERT(gs != 0); diff --git a/src/platformsupport/fontdatabases/freetype/qfontengine_ft_p.h b/src/platformsupport/fontdatabases/freetype/qfontengine_ft_p.h index d498b0ac8b..2d1d5e6572 100644 --- a/src/platformsupport/fontdatabases/freetype/qfontengine_ft_p.h +++ b/src/platformsupport/fontdatabases/freetype/qfontengine_ft_p.h @@ -268,7 +268,7 @@ private: inline bool isScalableBitmap() const { return freetype->isScalableBitmap(); } inline Glyph *loadGlyph(uint glyph, QFixed subPixelPosition, GlyphFormat format = Format_None, bool fetchMetricsOnly = false, bool disableOutlineDrawing = false) const - { return loadGlyph(cacheEnabled ? &defaultGlyphSet : 0, glyph, subPixelPosition, format, fetchMetricsOnly, disableOutlineDrawing); } + { return loadGlyph(cacheEnabled ? &defaultGlyphSet : nullptr, glyph, subPixelPosition, format, fetchMetricsOnly, disableOutlineDrawing); } Glyph *loadGlyph(QGlyphSet *set, uint glyph, QFixed subPixelPosition, GlyphFormat = Format_None, bool fetchMetricsOnly = false, bool disableOutlineDrawing = false) const; Glyph *loadGlyphFor(glyph_t g, QFixed subPixelPosition, GlyphFormat format, const QTransform &t, bool fetchBoundingBox = false, bool disableOutlineDrawing = false); diff --git a/src/platformsupport/fontdatabases/freetype/qfreetypefontdatabase.cpp b/src/platformsupport/fontdatabases/freetype/qfreetypefontdatabase.cpp index 4baba64de3..25c10fbd3c 100644 --- a/src/platformsupport/fontdatabases/freetype/qfreetypefontdatabase.cpp +++ b/src/platformsupport/fontdatabases/freetype/qfreetypefontdatabase.cpp @@ -127,7 +127,7 @@ QStringList QFreeTypeFontDatabase::addTTFile(const QByteArray &fontData, const Q error = FT_New_Face(library, file.constData(), index, &face); } if (error != FT_Err_Ok) { - qDebug() << "FT_New_Face failed with index" << index << ':' << hex << error; + qDebug() << "FT_New_Face failed with index" << index << ':' << Qt::hex << error; break; } numFaces = face->num_faces; @@ -142,7 +142,6 @@ QStringList QFreeTypeFontDatabase::addTTFile(const QByteArray &fontData, const Q weight = QFont::Bold; bool fixedPitch = (face->face_flags & FT_FACE_FLAG_FIXED_WIDTH); - QSupportedWritingSystems writingSystems; // detect symbol fonts for (int i = 0; i < face->num_charmaps; ++i) { diff --git a/src/platformsupport/fontdatabases/windows/qwindowsfontdatabase.cpp b/src/platformsupport/fontdatabases/windows/qwindowsfontdatabase.cpp index 9e6e5d88c7..79f7eb3d43 100644 --- a/src/platformsupport/fontdatabases/windows/qwindowsfontdatabase.cpp +++ b/src/platformsupport/fontdatabases/windows/qwindowsfontdatabase.cpp @@ -1007,12 +1007,27 @@ static QChar *createFontFile(const QString &faceName) return faceNamePtr; } +namespace { + struct StoreFontPayload { + StoreFontPayload(const QString &family, + QWindowsFontDatabase *fontDatabase) + : populatedFontFamily(family) + , windowsFontDatabase(fontDatabase) + {} + + QString populatedFontFamily; + QSet<QPair<QString,QString> > foundFontAndStyles; + QWindowsFontDatabase *windowsFontDatabase; + }; +} + static bool addFontToDatabase(QString familyName, QString styleName, const LOGFONT &logFont, const TEXTMETRIC *textmetric, const FONTSIGNATURE *signature, - int type) + int type, + StoreFontPayload *sfp) { // the "@family" fonts are just the same as "family". Ignore them. if (familyName.isEmpty() || familyName.at(0) == QLatin1Char('@') || familyName.startsWith(QLatin1String("WST_"))) @@ -1092,6 +1107,16 @@ static bool addFontToDatabase(QString familyName, writingSystems.setSupported(ws); } + // We came here from populating a different font family, so we have + // to ensure the entire typographic family is populated before we + // mark it as such inside registerFont() + if (!subFamilyName.isEmpty() + && familyName != subFamilyName + && sfp->populatedFontFamily != familyName + && !QPlatformFontDatabase::isFamilyPopulated(familyName)) { + sfp->windowsFontDatabase->populateFamily(familyName); + } + QPlatformFontDatabase::registerFont(familyName, styleName, foundryName, weight, style, stretch, antialias, scalable, size, fixed, writingSystems, createFontFile(faceName)); @@ -1128,17 +1153,18 @@ static int QT_WIN_CALLBACK storeFont(const LOGFONT *logFont, const TEXTMETRIC *t // to the documentation is identical to a TEXTMETRIC except for the last four // members, which we don't use anyway const FONTSIGNATURE *signature = nullptr; + StoreFontPayload *sfp = reinterpret_cast<StoreFontPayload *>(lparam); + Q_ASSERT(sfp != nullptr); if (type & TRUETYPE_FONTTYPE) { signature = &reinterpret_cast<const NEWTEXTMETRICEX *>(textmetric)->ntmFontSig; // We get a callback for each script-type supported, but we register them all // at once using the signature, so we only need one call to addFontToDatabase(). - QSet<QPair<QString,QString>> *foundFontAndStyles = reinterpret_cast<QSet<QPair<QString,QString>> *>(lparam); QPair<QString,QString> fontAndStyle(familyName, styleName); - if (foundFontAndStyles->contains(fontAndStyle)) + if (sfp->foundFontAndStyles.contains(fontAndStyle)) return 1; - foundFontAndStyles->insert(fontAndStyle); + sfp->foundFontAndStyles.insert(fontAndStyle); } - addFontToDatabase(familyName, styleName, *logFont, textmetric, signature, type); + addFontToDatabase(familyName, styleName, *logFont, textmetric, signature, type, sfp); // keep on enumerating return 1; @@ -1157,8 +1183,8 @@ void QWindowsFontDatabase::populateFamily(const QString &familyName) familyName.toWCharArray(lf.lfFaceName); lf.lfFaceName[familyName.size()] = 0; lf.lfPitchAndFamily = 0; - QSet<QPair<QString,QString>> foundFontAndStyles; - EnumFontFamiliesEx(dummy, &lf, storeFont, reinterpret_cast<intptr_t>(&foundFontAndStyles), 0); + StoreFontPayload sfp(familyName, this); + EnumFontFamiliesEx(dummy, &lf, storeFont, reinterpret_cast<intptr_t>(&sfp), 0); ReleaseDC(0, dummy); } @@ -1338,11 +1364,11 @@ QT_WARNING_POP if (request.family != fontEngine->fontDef.family) { qWarning("%s: Failed to load font. Got fallback instead: %s", __FUNCTION__, qPrintable(fontEngine->fontDef.family)); - if (fontEngine->ref.load() == 0) + if (fontEngine->ref.loadRelaxed() == 0) delete fontEngine; fontEngine = 0; } else { - Q_ASSERT(fontEngine->ref.load() == 0); + Q_ASSERT(fontEngine->ref.loadRelaxed() == 0); // Override the generated font name switch (fontEngine->type()) { @@ -1514,7 +1540,7 @@ static void getFamiliesAndSignatures(const QByteArray &fontData, if (names.name.isEmpty()) continue; - families->append(qMove(names)); + families->append(std::move(names)); if (values || signatures) getFontTable(data, font, MAKE_TAG('O', 'S', '/', '2'), &table, &length); @@ -1598,8 +1624,9 @@ QStringList QWindowsFontDatabase::addApplicationFont(const QByteArray &fontData, TEXTMETRIC textMetrics; GetTextMetrics(hdc, &textMetrics); + StoreFontPayload sfp(familyName, this); addFontToDatabase(familyName, styleName, lf, &textMetrics, &signatures.at(j), - TRUETYPE_FONTTYPE); + TRUETYPE_FONTTYPE, &sfp); SelectObject(hdc, oldobj); DeleteObject(hfont); @@ -1818,7 +1845,7 @@ LOGFONT QWindowsFontDatabase::fontDefToLOGFONT(const QFontDef &request, const QS QString fam = faceName; if (fam.isEmpty()) - fam = request.family; + fam = request.families.size() > 0 ? request.families.at(0) : request.family; if (Q_UNLIKELY(fam.size() >= LF_FACESIZE)) { qCritical("%s: Family name '%s' is too long.", __FUNCTION__, qPrintable(fam)); fam.truncate(LF_FACESIZE - 1); @@ -1961,13 +1988,13 @@ QFontEngine *QWindowsFontDatabase::createEngine(const QFontDef &request, const Q } else { HGDIOBJ oldFont = SelectObject(data->hdc, hfont); + const QFont::HintingPreference hintingPreference = + static_cast<QFont::HintingPreference>(request.hintingPreference); + bool useDw = useDirectWrite(hintingPreference, fam); + IDWriteFontFace *directWriteFontFace = NULL; HRESULT hr = data->directWriteGdiInterop->CreateFontFaceFromHdc(data->hdc, &directWriteFontFace); - if (FAILED(hr)) { - const QString errorString = qt_error_string(int(hr)); - qWarning().noquote().nospace() << "DirectWrite: CreateFontFaceFromHDC() failed (" - << errorString << ") for " << request << ' ' << lf << " dpi=" << dpi; - } else { + if (SUCCEEDED(hr)) { bool isColorFont = false; #if defined(QT_USE_DIRECTWRITE2) IDWriteFontFace2 *directWriteFontFace2 = nullptr; @@ -1977,9 +2004,7 @@ QFontEngine *QWindowsFontDatabase::createEngine(const QFontDef &request, const Q isColorFont = directWriteFontFace2->GetPaletteEntryCount() > 0; } #endif - const QFont::HintingPreference hintingPreference = - static_cast<QFont::HintingPreference>(request.hintingPreference); - const bool useDw = useDirectWrite(hintingPreference, fam, isColorFont); + useDw = useDw || useDirectWrite(hintingPreference, fam, isColorFont); qCDebug(lcQpaFonts) << __FUNCTION__ << request.family << request.pointSize << "pt" << "hintingPreference=" << hintingPreference << "color=" << isColorFont << dpi << "dpi" << "useDirectWrite=" << useDw; @@ -2001,6 +2026,10 @@ QFontEngine *QWindowsFontDatabase::createEngine(const QFontDef &request, const Q } else { directWriteFontFace->Release(); } + } else if (useDw) { + const QString errorString = qt_error_string(int(hr)); + qWarning().noquote().nospace() << "DirectWrite: CreateFontFaceFromHDC() failed (" + << errorString << ") for " << request << ' ' << lf << " dpi=" << dpi; } SelectObject(data->hdc, oldFont); diff --git a/src/platformsupport/fontdatabases/windows/qwindowsfontdatabase_ft.cpp b/src/platformsupport/fontdatabases/windows/qwindowsfontdatabase_ft.cpp index fdef0f5ff1..a6b7fcf31e 100644 --- a/src/platformsupport/fontdatabases/windows/qwindowsfontdatabase_ft.cpp +++ b/src/platformsupport/fontdatabases/windows/qwindowsfontdatabase_ft.cpp @@ -48,7 +48,11 @@ #include <QtCore/QDir> #include <QtCore/QDirIterator> #include <QtCore/QSettings> +#if QT_CONFIG(regularexpression) #include <QtCore/QRegularExpression> +#else +#include <QtCore/QRegExp> +#endif #include <QtGui/QGuiApplication> #include <QtGui/QFontDatabase> diff --git a/src/platformsupport/fontdatabases/windows/qwindowsfontdatabase_p.h b/src/platformsupport/fontdatabases/windows/qwindowsfontdatabase_p.h index afba86bbe1..a1cab17a87 100644 --- a/src/platformsupport/fontdatabases/windows/qwindowsfontdatabase_p.h +++ b/src/platformsupport/fontdatabases/windows/qwindowsfontdatabase_p.h @@ -67,7 +67,7 @@ Q_DECLARE_LOGGING_CATEGORY(lcQpaFonts) class QWindowsFontEngineData { - Q_DISABLE_COPY(QWindowsFontEngineData) + Q_DISABLE_COPY_MOVE(QWindowsFontEngineData) public: QWindowsFontEngineData(); ~QWindowsFontEngineData(); @@ -85,7 +85,7 @@ public: class QWindowsFontDatabase : public QPlatformFontDatabase { - Q_DISABLE_COPY(QWindowsFontDatabase) + Q_DISABLE_COPY_MOVE(QWindowsFontDatabase) public: enum FontOptions { // Relevant bits from QWindowsIntegration::Options @@ -96,6 +96,8 @@ public: QWindowsFontDatabase(); ~QWindowsFontDatabase() override; + void ensureFamilyPopulated(const QString &familyName); + void populateFontDatabase() override; void populateFamily(const QString &familyName) override; QFontEngine *fontEngine(const QFontDef &fontDef, void *handle) override; diff --git a/src/platformsupport/fontdatabases/windows/qwindowsfontengine_p.h b/src/platformsupport/fontdatabases/windows/qwindowsfontengine_p.h index 2b575a9b45..b1b9d828ac 100644 --- a/src/platformsupport/fontdatabases/windows/qwindowsfontengine_p.h +++ b/src/platformsupport/fontdatabases/windows/qwindowsfontengine_p.h @@ -66,7 +66,7 @@ class QWindowsFontEngineData; class QWindowsFontEngine : public QFontEngine { - Q_DISABLE_COPY(QWindowsFontEngine) + Q_DISABLE_COPY_MOVE(QWindowsFontEngine) public: QWindowsFontEngine(const QString &name, LOGFONT lf, const QSharedPointer<QWindowsFontEngineData> &fontEngineData); diff --git a/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite.cpp b/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite.cpp index 57c41938bc..60a5896e7b 100644 --- a/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite.cpp +++ b/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite.cpp @@ -69,7 +69,7 @@ namespace { class GeometrySink: public IDWriteGeometrySink { - Q_DISABLE_COPY(GeometrySink) + Q_DISABLE_COPY_MOVE(GeometrySink) public: GeometrySink(QPainterPath *path) : m_refCount(0), m_path(path) diff --git a/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite_p.h b/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite_p.h index 9326f5aece..3eaf8cf3d8 100644 --- a/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite_p.h +++ b/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite_p.h @@ -72,7 +72,7 @@ class QWindowsFontEngineData; class QWindowsFontEngineDirectWrite : public QFontEngine { - Q_DISABLE_COPY(QWindowsFontEngineDirectWrite) + Q_DISABLE_COPY_MOVE(QWindowsFontEngineDirectWrite) public: explicit QWindowsFontEngineDirectWrite(IDWriteFontFace *directWriteFontFace, qreal pixelSize, diff --git a/src/platformsupport/fontdatabases/windows/qwindowsnativeimage_p.h b/src/platformsupport/fontdatabases/windows/qwindowsnativeimage_p.h index 6c47a527d2..ed68ac2644 100644 --- a/src/platformsupport/fontdatabases/windows/qwindowsnativeimage_p.h +++ b/src/platformsupport/fontdatabases/windows/qwindowsnativeimage_p.h @@ -59,7 +59,7 @@ QT_BEGIN_NAMESPACE class QWindowsNativeImage { - Q_DISABLE_COPY(QWindowsNativeImage) + Q_DISABLE_COPY_MOVE(QWindowsNativeImage) public: QWindowsNativeImage(int width, int height, QImage::Format format); diff --git a/src/platformsupport/fontdatabases/windows/windows.pri b/src/platformsupport/fontdatabases/windows/windows.pri index 9c529f55ea..7ddfb2c281 100644 --- a/src/platformsupport/fontdatabases/windows/windows.pri +++ b/src/platformsupport/fontdatabases/windows/windows.pri @@ -30,5 +30,5 @@ qtConfig(directwrite):qtConfig(direct2d) { DEFINES *= QT_NO_DIRECTWRITE } -LIBS += -lole32 -lgdi32 -luser32 -ladvapi32 -mingw: LIBS += -luuid +QMAKE_USE_PRIVATE += advapi32 ole32 user32 gdi32 +mingw: QMAKE_USE_PRIVATE += uuid diff --git a/src/platformsupport/fontdatabases/winrt/winrt.pri b/src/platformsupport/fontdatabases/winrt/winrt.pri index 7617df2e7a..1cd417c1fd 100644 --- a/src/platformsupport/fontdatabases/winrt/winrt.pri +++ b/src/platformsupport/fontdatabases/winrt/winrt.pri @@ -8,6 +8,4 @@ HEADERS += \ DEFINES += __WRL_NO_DEFAULT_LIB__ -LIBS += -lws2_32 - -QMAKE_USE_PRIVATE += dwrite_1 +QMAKE_USE_PRIVATE += dwrite_1 ws2_32 diff --git a/src/platformsupport/glxconvenience/glxconvenience.pro b/src/platformsupport/glxconvenience/glxconvenience.pro index 8367dc5e31..1b9cf79080 100644 --- a/src/platformsupport/glxconvenience/glxconvenience.pro +++ b/src/platformsupport/glxconvenience/glxconvenience.pro @@ -6,7 +6,7 @@ CONFIG += static internal_module DEFINES += QT_NO_CAST_FROM_ASCII -QMAKE_USE_PRIVATE += xlib +QMAKE_USE += xlib HEADERS += qglxconvenience_p.h SOURCES += qglxconvenience.cpp diff --git a/src/platformsupport/glxconvenience/qglxconvenience.cpp b/src/platformsupport/glxconvenience/qglxconvenience.cpp index 6bd73de8f3..948b00596f 100644 --- a/src/platformsupport/glxconvenience/qglxconvenience.cpp +++ b/src/platformsupport/glxconvenience/qglxconvenience.cpp @@ -224,13 +224,16 @@ GLXFBConfig qglx_findConfig(Display *display, int screen , QSurfaceFormat format } QXlibPointer<XVisualInfo> visual(glXGetVisualFromFBConfig(display, candidate)); - if (visual.isNull()) - continue; - - const int actualRed = qPopulationCount(visual->red_mask); - const int actualGreen = qPopulationCount(visual->green_mask); - const int actualBlue = qPopulationCount(visual->blue_mask); - const int actualAlpha = visual->depth - actualRed - actualGreen - actualBlue; + int actualRed; + int actualGreen; + int actualBlue; + int actualAlpha; + glXGetFBConfigAttrib(display, candidate, GLX_RED_SIZE, &actualRed); + glXGetFBConfigAttrib(display, candidate, GLX_GREEN_SIZE, &actualGreen); + glXGetFBConfigAttrib(display, candidate, GLX_BLUE_SIZE, &actualBlue); + glXGetFBConfigAttrib(display, candidate, GLX_ALPHA_SIZE, &actualAlpha); + // Sometimes the visuals don't have a depth that includes the alpha channel. + actualAlpha = qMin(actualAlpha, visual->depth - actualRed - actualGreen - actualBlue); if (requestedRed && actualRed < requestedRed) continue; @@ -312,7 +315,7 @@ void qglx_surfaceFormatFromGLXFBConfig(QSurfaceFormat *format, Display *display, glXGetFBConfigAttrib(display, config, GLX_ALPHA_SIZE, &alphaSize); glXGetFBConfigAttrib(display, config, GLX_DEPTH_SIZE, &depthSize); glXGetFBConfigAttrib(display, config, GLX_STENCIL_SIZE, &stencilSize); - glXGetFBConfigAttrib(display, config, GLX_SAMPLES_ARB, &sampleBuffers); + glXGetFBConfigAttrib(display, config, GLX_SAMPLE_BUFFERS_ARB, &sampleBuffers); glXGetFBConfigAttrib(display, config, GLX_STEREO, &stereo); if (flags & QGLX_SUPPORTS_SRGB) glXGetFBConfigAttrib(display, config, GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB, &srgbCapable); @@ -351,7 +354,7 @@ void qglx_surfaceFormatFromVisualInfo(QSurfaceFormat *format, Display *display, glXGetConfig(display, visualInfo, GLX_ALPHA_SIZE, &alphaSize); glXGetConfig(display, visualInfo, GLX_DEPTH_SIZE, &depthSize); glXGetConfig(display, visualInfo, GLX_STENCIL_SIZE, &stencilSize); - glXGetConfig(display, visualInfo, GLX_SAMPLES_ARB, &sampleBuffers); + glXGetConfig(display, visualInfo, GLX_SAMPLE_BUFFERS_ARB, &sampleBuffers); glXGetConfig(display, visualInfo, GLX_STEREO, &stereo); if (flags & QGLX_SUPPORTS_SRGB) glXGetConfig(display, visualInfo, GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB, &srgbCapable); diff --git a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler.cpp b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler.cpp index ad134a825f..bff4a2522c 100644 --- a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler.cpp +++ b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler.cpp @@ -66,7 +66,7 @@ Q_LOGGING_CATEGORY(qLcEvdevKeyMap, "qt.qpa.input.keymap") // simple builtin US keymap #include "qevdevkeyboard_defaultmap_p.h" -void QFdContainer::reset() Q_DECL_NOTHROW +void QFdContainer::reset() noexcept { if (m_fd >= 0) qt_safe_close(m_fd); @@ -98,11 +98,12 @@ QEvdevKeyboardHandler::~QEvdevKeyboardHandler() unloadKeymap(); } -QEvdevKeyboardHandler *QEvdevKeyboardHandler::create(const QString &device, +std::unique_ptr<QEvdevKeyboardHandler> QEvdevKeyboardHandler::create(const QString &device, const QString &specification, const QString &defaultKeymapFile) { - qCDebug(qLcEvdevKey) << "Try to create keyboard handler for" << device << specification; + qCDebug(qLcEvdevKey, "Try to create keyboard handler for \"%ls\" \"%ls\"", + qUtf16Printable(device), qUtf16Printable(specification)); QString keymapFile = defaultKeymapFile; int repeatDelay = 400; @@ -127,7 +128,7 @@ QEvdevKeyboardHandler *QEvdevKeyboardHandler::create(const QString &device, grab = arg.mid(5).toInt(); } - qCDebug(qLcEvdevKey) << "Opening keyboard at" << device; + qCDebug(qLcEvdevKey, "Opening keyboard at %ls", qUtf16Printable(device)); QFdContainer fd(qt_safe_open(device.toLocal8Bit().constData(), O_RDONLY | O_NDELAY, 0)); if (fd.get() >= 0) { @@ -137,16 +138,16 @@ QEvdevKeyboardHandler *QEvdevKeyboardHandler::create(const QString &device, ::ioctl(fd.get(), EVIOCSREP, kbdrep); } - return new QEvdevKeyboardHandler(device, fd, disableZap, enableCompose, keymapFile); + return std::unique_ptr<QEvdevKeyboardHandler>(new QEvdevKeyboardHandler(device, fd, disableZap, enableCompose, keymapFile)); } else { - qWarning("Cannot open keyboard input device '%s': %s", qPrintable(device), strerror(errno)); - return 0; + qErrnoWarning("Cannot open keyboard input device '%ls'", qUtf16Printable(device)); + return nullptr; } } void QEvdevKeyboardHandler::switchLed(int led, bool state) { - qCDebug(qLcEvdevKey) << "switchLed" << led << state; + qCDebug(qLcEvdevKey, "switchLed %d %d", led, int(state)); struct ::input_event led_ie; ::gettimeofday(&led_ie.time, 0); @@ -170,7 +171,7 @@ void QEvdevKeyboardHandler::readKeycode() return; } else if (result < 0) { if (errno != EINTR && errno != EAGAIN) { - qErrnoWarning(errno, "evdevkeyboard: Could not read from input device"); + qErrnoWarning("evdevkeyboard: Could not read from input device"); // If the device got disconnected, stop reading, otherwise we get flooded // by the above error over and over again. if (errno == ENODEV) { @@ -473,7 +474,7 @@ QEvdevKeyboardHandler::KeycodeAction QEvdevKeyboardHandler::processKeycode(quint void QEvdevKeyboardHandler::unloadKeymap() { - qCDebug(qLcEvdevKey) << "Unload current keymap and restore built-in"; + qCDebug(qLcEvdevKey, "Unload current keymap and restore built-in"); if (m_keymap && m_keymap != s_keymap_default) delete [] m_keymap; @@ -517,12 +518,12 @@ void QEvdevKeyboardHandler::unloadKeymap() bool QEvdevKeyboardHandler::loadKeymap(const QString &file) { - qCDebug(qLcEvdevKey) << "Loading keymap" << file; + qCDebug(qLcEvdevKey, "Loading keymap %ls", qUtf16Printable(file)); QFile f(file); if (!f.open(QIODevice::ReadOnly)) { - qWarning("Could not open keymap file '%s'", qPrintable(file)); + qWarning("Could not open keymap file '%ls'", qUtf16Printable(file)); return false; } @@ -541,7 +542,7 @@ bool QEvdevKeyboardHandler::loadKeymap(const QString &file) ds >> qmap_magic >> qmap_version >> qmap_keymap_size >> qmap_keycompose_size; if (ds.status() != QDataStream::Ok || qmap_magic != QEvdevKeyboardMap::FileMagic || qmap_version != 1 || qmap_keymap_size == 0) { - qWarning("'%s' is not a valid .qmap keymap file", qPrintable(file)); + qWarning("'%ls' is not a valid .qmap keymap file", qUtf16Printable(file)); return false; } @@ -557,7 +558,7 @@ bool QEvdevKeyboardHandler::loadKeymap(const QString &file) delete [] qmap_keymap; delete [] qmap_keycompose; - qWarning("Keymap file '%s' can not be loaded.", qPrintable(file)); + qWarning("Keymap file '%ls' cannot be loaded.", qUtf16Printable(file)); return false; } diff --git a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler_p.h b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler_p.h index 5498a3e4f0..f92a2bf704 100644 --- a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler_p.h +++ b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler_p.h @@ -55,6 +55,8 @@ #include <QTimer> #include <QDataStream> +#include <memory> + QT_BEGIN_NAMESPACE class QSocketNotifier; @@ -132,15 +134,15 @@ inline QDataStream &operator<<(QDataStream &ds, const QEvdevKeyboardMap::Composi class QFdContainer { int m_fd; - Q_DISABLE_COPY(QFdContainer); + Q_DISABLE_COPY_MOVE(QFdContainer); public: - explicit QFdContainer(int fd = -1) Q_DECL_NOTHROW : m_fd(fd) {} + explicit QFdContainer(int fd = -1) noexcept : m_fd(fd) {} ~QFdContainer() { reset(); } - int get() const Q_DECL_NOTHROW { return m_fd; } + int get() const noexcept { return m_fd; } - int release() Q_DECL_NOTHROW { int result = m_fd; m_fd = -1; return result; } - void reset() Q_DECL_NOTHROW; + int release() noexcept { int result = m_fd; m_fd = -1; return result; } + void reset() noexcept; }; class QEvdevKeyboardHandler : public QObject @@ -168,7 +170,7 @@ public: SwitchConsoleMask = 0x0000007f }; - static QEvdevKeyboardHandler *create(const QString &device, + static std::unique_ptr<QEvdevKeyboardHandler> create(const QString &device, const QString &specification, const QString &defaultKeymapFile = QString()); diff --git a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardmanager.cpp b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardmanager.cpp index e1659bc0d9..52d9c34b1c 100644 --- a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardmanager.cpp +++ b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardmanager.cpp @@ -39,6 +39,8 @@ #include "qevdevkeyboardmanager_p.h" +#include <QtInputSupport/private/qevdevutil_p.h> + #include <QStringList> #include <QCoreApplication> #include <QLoggingCategory> @@ -61,36 +63,24 @@ QEvdevKeyboardManager::QEvdevKeyboardManager(const QString &key, const QString & if (spec.isEmpty()) spec = specification; - QStringList args = spec.split(QLatin1Char(':')); - QStringList devices; - - foreach (const QString &arg, args) { - if (arg.startsWith(QLatin1String("/dev/"))) { - // if device is specified try to use it - devices.append(arg); - args.removeAll(arg); - } - } - - // build new specification without /dev/ elements - m_spec = args.join(QLatin1Char(':')); + auto parsed = QEvdevUtil::parseSpecification(spec); + m_spec = std::move(parsed.spec); // add all keyboards for devices specified in the argument list - foreach (const QString &device, devices) + for (const QString &device : qAsConst(parsed.devices)) addKeyboard(device); - if (devices.isEmpty()) { - qCDebug(qLcEvdevKey) << "evdevkeyboard: Using device discovery"; - m_deviceDiscovery = QDeviceDiscovery::create(QDeviceDiscovery::Device_Keyboard, this); - if (m_deviceDiscovery) { + if (parsed.devices.isEmpty()) { + qCDebug(qLcEvdevKey, "evdevkeyboard: Using device discovery"); + if (auto deviceDiscovery = QDeviceDiscovery::create(QDeviceDiscovery::Device_Keyboard, this)) { // scan and add already connected keyboards - const QStringList devices = m_deviceDiscovery->scanConnectedDevices(); + const QStringList devices = deviceDiscovery->scanConnectedDevices(); for (const QString &device : devices) addKeyboard(device); - connect(m_deviceDiscovery, &QDeviceDiscovery::deviceDetected, + connect(deviceDiscovery, &QDeviceDiscovery::deviceDetected, this, &QEvdevKeyboardManager::addKeyboard); - connect(m_deviceDiscovery, &QDeviceDiscovery::deviceRemoved, + connect(deviceDiscovery, &QDeviceDiscovery::deviceRemoved, this, &QEvdevKeyboardManager::removeKeyboard); } } @@ -98,36 +88,34 @@ QEvdevKeyboardManager::QEvdevKeyboardManager(const QString &key, const QString & QEvdevKeyboardManager::~QEvdevKeyboardManager() { - qDeleteAll(m_keyboards); - m_keyboards.clear(); } void QEvdevKeyboardManager::addKeyboard(const QString &deviceNode) { - qCDebug(qLcEvdevKey) << "Adding keyboard at" << deviceNode; - QEvdevKeyboardHandler *keyboard; - keyboard = QEvdevKeyboardHandler::create(deviceNode, m_spec, m_defaultKeymapFile); + qCDebug(qLcEvdevKey, "Adding keyboard at %ls", qUtf16Printable(deviceNode)); + auto keyboard = QEvdevKeyboardHandler::create(deviceNode, m_spec, m_defaultKeymapFile); if (keyboard) { - m_keyboards.insert(deviceNode, keyboard); - QInputDeviceManagerPrivate::get(QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount( - QInputDeviceManager::DeviceTypeKeyboard, m_keyboards.count()); + m_keyboards.add(deviceNode, std::move(keyboard)); + updateDeviceCount(); } else { - qWarning("Failed to open keyboard device %s", qPrintable(deviceNode)); + qWarning("Failed to open keyboard device %ls", qUtf16Printable(deviceNode)); } } void QEvdevKeyboardManager::removeKeyboard(const QString &deviceNode) { - if (m_keyboards.contains(deviceNode)) { - qCDebug(qLcEvdevKey) << "Removing keyboard at" << deviceNode; - QEvdevKeyboardHandler *keyboard = m_keyboards.value(deviceNode); - m_keyboards.remove(deviceNode); - QInputDeviceManagerPrivate::get(QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount( - QInputDeviceManager::DeviceTypeKeyboard, m_keyboards.count()); - delete keyboard; + if (m_keyboards.remove(deviceNode)) { + qCDebug(qLcEvdevKey, "Removing keyboard at %ls", qUtf16Printable(deviceNode)); + updateDeviceCount(); } } +void QEvdevKeyboardManager::updateDeviceCount() +{ + QInputDeviceManagerPrivate::get(QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount( + QInputDeviceManager::DeviceTypeKeyboard, m_keyboards.count()); +} + void QEvdevKeyboardManager::loadKeymap(const QString &file) { m_defaultKeymapFile = file; @@ -141,22 +129,22 @@ void QEvdevKeyboardManager::loadKeymap(const QString &file) if (arg.startsWith(QLatin1String("keymap="))) keymapFromSpec = arg.mid(7).toString(); } - foreach (QEvdevKeyboardHandler *handler, m_keyboards) { + for (const auto &keyboard : m_keyboards) { if (keymapFromSpec.isEmpty()) - handler->unloadKeymap(); + keyboard.handler->unloadKeymap(); else - handler->loadKeymap(keymapFromSpec); + keyboard.handler->loadKeymap(keymapFromSpec); } } else { - foreach (QEvdevKeyboardHandler *handler, m_keyboards) - handler->loadKeymap(file); + for (const auto &keyboard : m_keyboards) + keyboard.handler->loadKeymap(file); } } void QEvdevKeyboardManager::switchLang() { - foreach (QEvdevKeyboardHandler *handler, m_keyboards) - handler->switchLang(); + for (const auto &keyboard : m_keyboards) + keyboard.handler->switchLang(); } QT_END_NAMESPACE diff --git a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardmanager_p.h b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardmanager_p.h index 326e438a7c..d91da330c3 100644 --- a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardmanager_p.h +++ b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardmanager_p.h @@ -53,6 +53,7 @@ #include "qevdevkeyboardhandler_p.h" +#include <QtInputSupport/private/devicehandlerlist_p.h> #include <QtDeviceDiscoverySupport/private/qdevicediscovery_p.h> #include <QObject> @@ -64,7 +65,7 @@ QT_BEGIN_NAMESPACE class QEvdevKeyboardManager : public QObject { public: - QEvdevKeyboardManager(const QString &key, const QString &specification, QObject *parent = 0); + QEvdevKeyboardManager(const QString &key, const QString &specification, QObject *parent = nullptr); ~QEvdevKeyboardManager(); void loadKeymap(const QString &file); @@ -74,9 +75,10 @@ public: void removeKeyboard(const QString &deviceNode); private: + void updateDeviceCount(); + QString m_spec; - QHash<QString,QEvdevKeyboardHandler*> m_keyboards; - QDeviceDiscovery *m_deviceDiscovery; + QtInputSupport::DeviceHandlerList<QEvdevKeyboardHandler> m_keyboards; QString m_defaultKeymapFile; }; diff --git a/src/platformsupport/input/evdevmouse/qevdevmousehandler.cpp b/src/platformsupport/input/evdevmouse/qevdevmousehandler.cpp index 86a4cd0076..6a53ad2088 100644 --- a/src/platformsupport/input/evdevmouse/qevdevmousehandler.cpp +++ b/src/platformsupport/input/evdevmouse/qevdevmousehandler.cpp @@ -66,7 +66,7 @@ QT_BEGIN_NAMESPACE Q_LOGGING_CATEGORY(qLcEvdevMouse, "qt.qpa.input") -QEvdevMouseHandler *QEvdevMouseHandler::create(const QString &device, const QString &specification) +std::unique_ptr<QEvdevMouseHandler> QEvdevMouseHandler::create(const QString &device, const QString &specification) { qCDebug(qLcEvdevMouse) << "create mouse handler for" << device << specification; @@ -91,10 +91,10 @@ QEvdevMouseHandler *QEvdevMouseHandler::create(const QString &device, const QStr fd = qt_safe_open(device.toLocal8Bit().constData(), O_RDONLY | O_NDELAY, 0); if (fd >= 0) { ::ioctl(fd, EVIOCGRAB, grab); - return new QEvdevMouseHandler(device, fd, abs, compression, jitterLimit); + return std::unique_ptr<QEvdevMouseHandler>(new QEvdevMouseHandler(device, fd, abs, compression, jitterLimit)); } else { qErrnoWarning(errno, "Cannot open mouse input device %s", qPrintable(device)); - return 0; + return nullptr; } } diff --git a/src/platformsupport/input/evdevmouse/qevdevmousehandler_p.h b/src/platformsupport/input/evdevmouse/qevdevmousehandler_p.h index c7f2b04eb2..727f1a02f9 100644 --- a/src/platformsupport/input/evdevmouse/qevdevmousehandler_p.h +++ b/src/platformsupport/input/evdevmouse/qevdevmousehandler_p.h @@ -56,6 +56,8 @@ #include <QPoint> #include <QEvent> +#include <memory> + QT_BEGIN_NAMESPACE class QSocketNotifier; @@ -64,7 +66,7 @@ class QEvdevMouseHandler : public QObject { Q_OBJECT public: - static QEvdevMouseHandler *create(const QString &device, const QString &specification); + static std::unique_ptr<QEvdevMouseHandler> create(const QString &device, const QString &specification); ~QEvdevMouseHandler(); void readMouseData(); diff --git a/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp b/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp index ae81bca00f..0c19294905 100644 --- a/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp +++ b/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp @@ -39,6 +39,8 @@ #include "qevdevmousemanager_p.h" +#include <QtInputSupport/private/qevdevutil_p.h> + #include <QStringList> #include <QGuiApplication> #include <QScreen> @@ -63,40 +65,32 @@ QEvdevMouseManager::QEvdevMouseManager(const QString &key, const QString &specif if (spec.isEmpty()) spec = specification; - QStringList args = spec.split(QLatin1Char(':')); - QStringList devices; + auto parsed = QEvdevUtil::parseSpecification(spec); + m_spec = std::move(parsed.spec); - foreach (const QString &arg, args) { - if (arg.startsWith(QLatin1String("/dev/"))) { - // if device is specified try to use it - devices.append(arg); - args.removeAll(arg); - } else if (arg.startsWith(QLatin1String("xoffset="))) { + for (const QStringRef &arg : qAsConst(parsed.args)) { + if (arg.startsWith(QLatin1String("xoffset="))) { m_xoffset = arg.mid(8).toInt(); } else if (arg.startsWith(QLatin1String("yoffset="))) { m_yoffset = arg.mid(8).toInt(); } } - // build new specification without /dev/ elements - m_spec = args.join(QLatin1Char(':')); - // add all mice for devices specified in the argument list - foreach (const QString &device, devices) + for (const QString &device : qAsConst(parsed.devices)) addMouse(device); - if (devices.isEmpty()) { - qCDebug(qLcEvdevMouse) << "evdevmouse: Using device discovery"; - m_deviceDiscovery = QDeviceDiscovery::create(QDeviceDiscovery::Device_Mouse | QDeviceDiscovery::Device_Touchpad, this); - if (m_deviceDiscovery) { + if (parsed.devices.isEmpty()) { + qCDebug(qLcEvdevMouse, "evdevmouse: Using device discovery"); + if (auto deviceDiscovery = QDeviceDiscovery::create(QDeviceDiscovery::Device_Mouse | QDeviceDiscovery::Device_Touchpad, this)) { // scan and add already connected keyboards - const QStringList devices = m_deviceDiscovery->scanConnectedDevices(); + const QStringList devices = deviceDiscovery->scanConnectedDevices(); for (const QString &device : devices) addMouse(device); - connect(m_deviceDiscovery, &QDeviceDiscovery::deviceDetected, + connect(deviceDiscovery, &QDeviceDiscovery::deviceDetected, this, &QEvdevMouseManager::addMouse); - connect(m_deviceDiscovery, &QDeviceDiscovery::deviceRemoved, + connect(deviceDiscovery, &QDeviceDiscovery::deviceRemoved, this, &QEvdevMouseManager::removeMouse); } } @@ -111,8 +105,6 @@ QEvdevMouseManager::QEvdevMouseManager(const QString &key, const QString &specif QEvdevMouseManager::~QEvdevMouseManager() { - qDeleteAll(m_mice); - m_mice.clear(); } void QEvdevMouseManager::clampPosition() @@ -159,31 +151,32 @@ void QEvdevMouseManager::handleWheelEvent(QPoint delta) void QEvdevMouseManager::addMouse(const QString &deviceNode) { - qCDebug(qLcEvdevMouse) << "Adding mouse at" << deviceNode; - QEvdevMouseHandler *handler = QEvdevMouseHandler::create(deviceNode, m_spec); + qCDebug(qLcEvdevMouse, "Adding mouse at %ls", qUtf16Printable(deviceNode)); + auto handler = QEvdevMouseHandler::create(deviceNode, m_spec); if (handler) { - connect(handler, &QEvdevMouseHandler::handleMouseEvent, + connect(handler.get(), &QEvdevMouseHandler::handleMouseEvent, this, &QEvdevMouseManager::handleMouseEvent); - connect(handler, &QEvdevMouseHandler::handleWheelEvent, + connect(handler.get(), &QEvdevMouseHandler::handleWheelEvent, this, &QEvdevMouseManager::handleWheelEvent); - m_mice.insert(deviceNode, handler); - QInputDeviceManagerPrivate::get(QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount( - QInputDeviceManager::DeviceTypePointer, m_mice.count()); + m_mice.add(deviceNode, std::move(handler)); + updateDeviceCount(); } else { - qWarning("evdevmouse: Failed to open mouse device %s", qPrintable(deviceNode)); + qWarning("evdevmouse: Failed to open mouse device %ls", qUtf16Printable(deviceNode)); } } void QEvdevMouseManager::removeMouse(const QString &deviceNode) { - if (m_mice.contains(deviceNode)) { - qCDebug(qLcEvdevMouse) << "Removing mouse at" << deviceNode; - QEvdevMouseHandler *handler = m_mice.value(deviceNode); - m_mice.remove(deviceNode); - QInputDeviceManagerPrivate::get(QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount( - QInputDeviceManager::DeviceTypePointer, m_mice.count()); - delete handler; + if (m_mice.remove(deviceNode)) { + qCDebug(qLcEvdevMouse, "Removing mouse at %ls", qUtf16Printable(deviceNode)); + updateDeviceCount(); } } +void QEvdevMouseManager::updateDeviceCount() +{ + QInputDeviceManagerPrivate::get(QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount( + QInputDeviceManager::DeviceTypePointer, m_mice.count()); +} + QT_END_NAMESPACE diff --git a/src/platformsupport/input/evdevmouse/qevdevmousemanager_p.h b/src/platformsupport/input/evdevmouse/qevdevmousemanager_p.h index 13a8e3dec5..f5c32ed8b5 100644 --- a/src/platformsupport/input/evdevmouse/qevdevmousemanager_p.h +++ b/src/platformsupport/input/evdevmouse/qevdevmousemanager_p.h @@ -53,6 +53,8 @@ #include "qevdevmousehandler_p.h" +#include <QtInputSupport/private/devicehandlerlist_p.h> + #include <QObject> #include <QHash> #include <QSocketNotifier> @@ -65,7 +67,7 @@ class QDeviceDiscovery; class QEvdevMouseManager : public QObject { public: - QEvdevMouseManager(const QString &key, const QString &specification, QObject *parent = 0); + QEvdevMouseManager(const QString &key, const QString &specification, QObject *parent = nullptr); ~QEvdevMouseManager(); void handleMouseEvent(int x, int y, bool abs, Qt::MouseButtons buttons, @@ -77,10 +79,10 @@ public: private: void clampPosition(); + void updateDeviceCount(); QString m_spec; - QHash<QString,QEvdevMouseHandler*> m_mice; - QDeviceDiscovery *m_deviceDiscovery; + QtInputSupport::DeviceHandlerList<QEvdevMouseHandler> m_mice; int m_x; int m_y; int m_xoffset; diff --git a/src/platformsupport/input/evdevtablet/qevdevtablethandler.cpp b/src/platformsupport/input/evdevtablet/qevdevtablethandler.cpp index b6051aaf3c..c86840b76c 100644 --- a/src/platformsupport/input/evdevtablet/qevdevtablethandler.cpp +++ b/src/platformsupport/input/evdevtablet/qevdevtablethandler.cpp @@ -172,11 +172,11 @@ QEvdevTabletHandler::QEvdevTabletHandler(const QString &device, const QString &s setObjectName(QLatin1String("Evdev Tablet Handler")); - qCDebug(qLcEvdevTablet, "evdevtablet: using %s", qPrintable(device)); + qCDebug(qLcEvdevTablet, "evdevtablet: using %ls", qUtf16Printable(device)); m_fd = QT_OPEN(device.toLocal8Bit().constData(), O_RDONLY | O_NDELAY, 0); if (m_fd < 0) { - qErrnoWarning(errno, "evdevtablet: Cannot open input device %s", qPrintable(device)); + qErrnoWarning("evdevtablet: Cannot open input device %ls", qUtf16Printable(device)); return; } @@ -184,11 +184,11 @@ QEvdevTabletHandler::QEvdevTabletHandler(const QString &device, const QString &s if (grabSuccess) ioctl(m_fd, EVIOCGRAB, (void *) 0); else - qWarning("evdevtablet: %s: The device is grabbed by another process. No events will be read.", qPrintable(device)); + qWarning("evdevtablet: %ls: The device is grabbed by another process. No events will be read.", qUtf16Printable(device)); d = new QEvdevTabletData(this); if (!queryLimits()) - qWarning("evdevtablet: %s: Unset or invalid ABS limits. Behavior will be unspecified.", qPrintable(device)); + qWarning("evdevtablet: %ls: Unset or invalid ABS limits. Behavior will be unspecified.", qUtf16Printable(device)); m_notifier = new QSocketNotifier(m_fd, QSocketNotifier::Read, this); connect(m_notifier, &QSocketNotifier::activated, this, &QEvdevTabletHandler::readData); @@ -216,32 +216,32 @@ bool QEvdevTabletHandler::queryLimits() if (ok) { d->minValues.x = absInfo.minimum; d->maxValues.x = absInfo.maximum; - qCDebug(qLcEvdevTablet, "evdevtablet: %s: min X: %d max X: %d", qPrintable(m_device), + qCDebug(qLcEvdevTablet, "evdevtablet: %ls: min X: %d max X: %d", qUtf16Printable(m_device), d->minValues.x, d->maxValues.x); } ok &= ioctl(m_fd, EVIOCGABS(ABS_Y), &absInfo) >= 0; if (ok) { d->minValues.y = absInfo.minimum; d->maxValues.y = absInfo.maximum; - qCDebug(qLcEvdevTablet, "evdevtablet: %s: min Y: %d max Y: %d", qPrintable(m_device), + qCDebug(qLcEvdevTablet, "evdevtablet: %ls: min Y: %d max Y: %d", qUtf16Printable(m_device), d->minValues.y, d->maxValues.y); } if (ioctl(m_fd, EVIOCGABS(ABS_PRESSURE), &absInfo) >= 0) { d->minValues.p = absInfo.minimum; d->maxValues.p = absInfo.maximum; - qCDebug(qLcEvdevTablet, "evdevtablet: %s: min pressure: %d max pressure: %d", qPrintable(m_device), + qCDebug(qLcEvdevTablet, "evdevtablet: %ls: min pressure: %d max pressure: %d", qUtf16Printable(m_device), d->minValues.p, d->maxValues.p); } if (ioctl(m_fd, EVIOCGABS(ABS_DISTANCE), &absInfo) >= 0) { d->minValues.d = absInfo.minimum; d->maxValues.d = absInfo.maximum; - qCDebug(qLcEvdevTablet, "evdevtablet: %s: min distance: %d max distance: %d", qPrintable(m_device), + qCDebug(qLcEvdevTablet, "evdevtablet: %ls: min distance: %d max distance: %d", qUtf16Printable(m_device), d->minValues.d, d->maxValues.d); } char name[128]; if (ioctl(m_fd, EVIOCGNAME(sizeof(name) - 1), name) >= 0) { d->devName = QString::fromLocal8Bit(name); - qCDebug(qLcEvdevTablet, "evdevtablet: %s: device name: %s", qPrintable(m_device), name); + qCDebug(qLcEvdevTablet, "evdevtablet: %ls: device name: %s", qUtf16Printable(m_device), name); } return ok; } @@ -253,11 +253,11 @@ void QEvdevTabletHandler::readData() for (; ;) { int result = QT_READ(m_fd, reinterpret_cast<char*>(buffer) + n, sizeof(buffer) - n); if (!result) { - qWarning("evdevtablet: %s: Got EOF from input device", qPrintable(m_device)); + qWarning("evdevtablet: %ls: Got EOF from input device", qUtf16Printable(m_device)); return; } else if (result < 0) { if (errno != EINTR && errno != EAGAIN) { - qErrnoWarning(errno, "evdevtablet: %s: Could not read from input device", qPrintable(m_device)); + qErrnoWarning("evdevtablet: %ls: Could not read from input device", qUtf16Printable(m_device)); if (errno == ENODEV) { // device got disconnected -> stop reading delete m_notifier; m_notifier = 0; diff --git a/src/platformsupport/input/evdevtablet/qevdevtablethandler_p.h b/src/platformsupport/input/evdevtablet/qevdevtablethandler_p.h index 66e821117a..b83bb21258 100644 --- a/src/platformsupport/input/evdevtablet/qevdevtablethandler_p.h +++ b/src/platformsupport/input/evdevtablet/qevdevtablethandler_p.h @@ -64,7 +64,7 @@ class QEvdevTabletData; class QEvdevTabletHandler : public QObject { public: - explicit QEvdevTabletHandler(const QString &device, const QString &spec = QString(), QObject *parent = 0); + explicit QEvdevTabletHandler(const QString &device, const QString &spec = QString(), QObject *parent = nullptr); ~QEvdevTabletHandler(); qint64 deviceId() const; @@ -83,7 +83,7 @@ private: class QEvdevTabletHandlerThread : public QDaemonThread { public: - explicit QEvdevTabletHandlerThread(const QString &device, const QString &spec, QObject *parent = 0); + explicit QEvdevTabletHandlerThread(const QString &device, const QString &spec, QObject *parent = nullptr); ~QEvdevTabletHandlerThread(); void run() override; QEvdevTabletHandler *handler() { return m_handler; } diff --git a/src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp b/src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp index 90949408ac..d9888c5b97 100644 --- a/src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp +++ b/src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp @@ -40,12 +40,15 @@ #include "qevdevtabletmanager_p.h" #include "qevdevtablethandler_p.h" +#include <QtInputSupport/private/qevdevutil_p.h> + #include <QStringList> #include <QGuiApplication> #include <QLoggingCategory> #include <QtDeviceDiscoverySupport/private/qdevicediscovery_p.h> #include <private/qguiapplication_p.h> #include <private/qinputdevicemanager_p_p.h> +#include <private/qmemory_p.h> QT_BEGIN_NAMESPACE @@ -64,34 +67,23 @@ QEvdevTabletManager::QEvdevTabletManager(const QString &key, const QString &spec if (spec.isEmpty()) spec = specification; - QStringList args = spec.split(QLatin1Char(':')); - QStringList devices; - - foreach (const QString &arg, args) { - if (arg.startsWith(QLatin1String("/dev/"))) { - devices.append(arg); - args.removeAll(arg); - } - } - - // build new specification without /dev/ elements - m_spec = args.join(QLatin1Char(':')); + auto parsed = QEvdevUtil::parseSpecification(spec); + m_spec = std::move(parsed.spec); - foreach (const QString &device, devices) + for (const QString &device : qAsConst(parsed.devices)) addDevice(device); // when no devices specified, use device discovery to scan and monitor - if (devices.isEmpty()) { - qCDebug(qLcEvdevTablet) << "evdevtablet: Using device discovery"; - m_deviceDiscovery = QDeviceDiscovery::create(QDeviceDiscovery::Device_Tablet, this); - if (m_deviceDiscovery) { - const QStringList devices = m_deviceDiscovery->scanConnectedDevices(); + if (parsed.devices.isEmpty()) { + qCDebug(qLcEvdevTablet, "evdevtablet: Using device discovery"); + if (auto deviceDiscovery = QDeviceDiscovery::create(QDeviceDiscovery::Device_Tablet, this)) { + const QStringList devices = deviceDiscovery->scanConnectedDevices(); for (const QString &device : devices) addDevice(device); - connect(m_deviceDiscovery, &QDeviceDiscovery::deviceDetected, + connect(deviceDiscovery, &QDeviceDiscovery::deviceDetected, this, &QEvdevTabletManager::addDevice); - connect(m_deviceDiscovery, &QDeviceDiscovery::deviceRemoved, + connect(deviceDiscovery, &QDeviceDiscovery::deviceRemoved, this, &QEvdevTabletManager::removeDevice); } } @@ -99,33 +91,32 @@ QEvdevTabletManager::QEvdevTabletManager(const QString &key, const QString &spec QEvdevTabletManager::~QEvdevTabletManager() { - qDeleteAll(m_activeDevices); } void QEvdevTabletManager::addDevice(const QString &deviceNode) { - qCDebug(qLcEvdevTablet) << "Adding device at" << deviceNode; - QEvdevTabletHandlerThread *handler; - handler = new QEvdevTabletHandlerThread(deviceNode, m_spec); + qCDebug(qLcEvdevTablet, "Adding device at %ls", qUtf16Printable(deviceNode)); + auto handler = qt_make_unique<QEvdevTabletHandlerThread>(deviceNode, m_spec); if (handler) { - m_activeDevices.insert(deviceNode, handler); - QInputDeviceManagerPrivate::get(QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount( - QInputDeviceManager::DeviceTypeTablet, m_activeDevices.count()); + m_activeDevices.add(deviceNode, std::move(handler)); + updateDeviceCount(); } else { - qWarning("evdevtablet: Failed to open tablet device %s", qPrintable(deviceNode)); + qWarning("evdevtablet: Failed to open tablet device %ls", qUtf16Printable(deviceNode)); } } void QEvdevTabletManager::removeDevice(const QString &deviceNode) { - if (m_activeDevices.contains(deviceNode)) { - qCDebug(qLcEvdevTablet) << "Removing device at" << deviceNode; - QEvdevTabletHandlerThread *handler = m_activeDevices.value(deviceNode); - m_activeDevices.remove(deviceNode); - QInputDeviceManagerPrivate::get(QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount( - QInputDeviceManager::DeviceTypeTablet, m_activeDevices.count()); - delete handler; + if (m_activeDevices.remove(deviceNode)) { + qCDebug(qLcEvdevTablet, "Removing device at %ls", qUtf16Printable(deviceNode)); + updateDeviceCount(); } } +void QEvdevTabletManager::updateDeviceCount() +{ + QInputDeviceManagerPrivate::get(QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount( + QInputDeviceManager::DeviceTypeTablet, m_activeDevices.count()); +} + QT_END_NAMESPACE diff --git a/src/platformsupport/input/evdevtablet/qevdevtabletmanager_p.h b/src/platformsupport/input/evdevtablet/qevdevtabletmanager_p.h index cde91c55aa..bb18ffba04 100644 --- a/src/platformsupport/input/evdevtablet/qevdevtabletmanager_p.h +++ b/src/platformsupport/input/evdevtablet/qevdevtabletmanager_p.h @@ -51,6 +51,8 @@ // We mean it. // +#include <QtInputSupport/private/devicehandlerlist_p.h> + #include <QObject> #include <QHash> #include <QSocketNotifier> @@ -63,16 +65,17 @@ class QEvdevTabletHandlerThread; class QEvdevTabletManager : public QObject { public: - QEvdevTabletManager(const QString &key, const QString &spec, QObject *parent = 0); + QEvdevTabletManager(const QString &key, const QString &spec, QObject *parent = nullptr); ~QEvdevTabletManager(); void addDevice(const QString &deviceNode); void removeDevice(const QString &deviceNode); private: + void updateDeviceCount(); + QString m_spec; - QDeviceDiscovery *m_deviceDiscovery; - QHash<QString, QEvdevTabletHandlerThread *> m_activeDevices; + QtInputSupport::DeviceHandlerList<QEvdevTabletHandlerThread> m_activeDevices; }; QT_END_NAMESPACE diff --git a/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp b/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp index f3cc160b3e..737d85d5c3 100644 --- a/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp +++ b/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp @@ -49,6 +49,9 @@ #include <QtCore/private/qcore_unix_p.h> #include <QtGui/private/qhighdpiscaling_p.h> #include <QtGui/private/qguiapplication_p.h> + +#include <mutex> + #ifdef Q_OS_FREEBSD #include <dev/evdev/input.h> #else @@ -225,7 +228,7 @@ QEvdevTouchScreenHandler::QEvdevTouchScreenHandler(const QString &device, const } } - qCDebug(qLcEvdevTouch, "evdevtouch: Using device %s", qPrintable(device)); + qCDebug(qLcEvdevTouch, "evdevtouch: Using device %ls", qUtf16Printable(device)); m_fd = QT_OPEN(device.toLocal8Bit().constData(), O_RDONLY | O_NDELAY, 0); @@ -233,7 +236,7 @@ QEvdevTouchScreenHandler::QEvdevTouchScreenHandler(const QString &device, const m_notify = new QSocketNotifier(m_fd, QSocketNotifier::Read, this); connect(m_notify, &QSocketNotifier::activated, this, &QEvdevTouchScreenHandler::readData); } else { - qErrnoWarning(errno, "evdevtouch: Cannot open input device %s", qPrintable(device)); + qErrnoWarning("evdevtouch: Cannot open input device %ls", qUtf16Printable(device)); return; } @@ -263,8 +266,8 @@ QEvdevTouchScreenHandler::QEvdevTouchScreenHandler(const QString &device, const d->deviceNode = device; qCDebug(qLcEvdevTouch, - "evdevtouch: %s: Protocol type %c %s (%s), filtered=%s", - qPrintable(d->deviceNode), + "evdevtouch: %ls: Protocol type %c %s (%s), filtered=%s", + qUtf16Printable(d->deviceNode), d->m_typeB ? 'B' : 'A', mtdevStr, d->m_singleTouch ? "single" : "multi", d->m_filtered ? "yes" : "no"); @@ -276,7 +279,7 @@ QEvdevTouchScreenHandler::QEvdevTouchScreenHandler(const QString &device, const bool has_x_range = false, has_y_range = false; if (ioctl(m_fd, EVIOCGABS((d->m_singleTouch ? ABS_X : ABS_MT_POSITION_X)), &absInfo) >= 0) { - qCDebug(qLcEvdevTouch, "evdevtouch: %s: min X: %d max X: %d", qPrintable(device), + qCDebug(qLcEvdevTouch, "evdevtouch: %ls: min X: %d max X: %d", qUtf16Printable(device), absInfo.minimum, absInfo.maximum); d->hw_range_x_min = absInfo.minimum; d->hw_range_x_max = absInfo.maximum; @@ -284,7 +287,7 @@ QEvdevTouchScreenHandler::QEvdevTouchScreenHandler(const QString &device, const } if (ioctl(m_fd, EVIOCGABS((d->m_singleTouch ? ABS_Y : ABS_MT_POSITION_Y)), &absInfo) >= 0) { - qCDebug(qLcEvdevTouch, "evdevtouch: %s: min Y: %d max Y: %d", qPrintable(device), + qCDebug(qLcEvdevTouch, "evdevtouch: %ls: min Y: %d max Y: %d", qUtf16Printable(device), absInfo.minimum, absInfo.maximum); d->hw_range_y_min = absInfo.minimum; d->hw_range_y_max = absInfo.maximum; @@ -292,10 +295,10 @@ QEvdevTouchScreenHandler::QEvdevTouchScreenHandler(const QString &device, const } if (!has_x_range || !has_y_range) - qWarning("evdevtouch: %s: Invalid ABS limits, behavior unspecified", qPrintable(device)); + qWarning("evdevtouch: %ls: Invalid ABS limits, behavior unspecified", qUtf16Printable(device)); if (ioctl(m_fd, EVIOCGABS(ABS_PRESSURE), &absInfo) >= 0) { - qCDebug(qLcEvdevTouch, "evdevtouch: %s: min pressure: %d max pressure: %d", qPrintable(device), + qCDebug(qLcEvdevTouch, "evdevtouch: %ls: min pressure: %d max pressure: %d", qUtf16Printable(device), absInfo.minimum, absInfo.maximum); if (absInfo.maximum > absInfo.minimum) { d->hw_pressure_min = absInfo.minimum; @@ -306,7 +309,7 @@ QEvdevTouchScreenHandler::QEvdevTouchScreenHandler(const QString &device, const char name[1024]; if (ioctl(m_fd, EVIOCGNAME(sizeof(name) - 1), name) >= 0) { d->hw_name = QString::fromLocal8Bit(name); - qCDebug(qLcEvdevTouch, "evdevtouch: %s: device name: %s", qPrintable(device), name); + qCDebug(qLcEvdevTouch, "evdevtouch: %ls: device name: %s", qUtf16Printable(device), name); } // Fix up the coordinate ranges for am335x in case the kernel driver does not have them fixed. @@ -342,8 +345,8 @@ QEvdevTouchScreenHandler::QEvdevTouchScreenHandler(const QString &device, const if (mapping.load()) { d->m_screenName = mapping.screenNameForDeviceNode(d->deviceNode); if (!d->m_screenName.isEmpty()) - qCDebug(qLcEvdevTouch, "evdevtouch: Mapping device %s to screen %s", - qPrintable(d->deviceNode), qPrintable(d->m_screenName)); + qCDebug(qLcEvdevTouch, "evdevtouch: Mapping device %ls to screen %ls", + qUtf16Printable(d->deviceNode), qUtf16Printable(d->m_screenName)); } registerTouchDevice(); @@ -424,7 +427,7 @@ err: return; } else if (events < 0) { if (errno != EINTR && errno != EAGAIN) { - qErrnoWarning(errno, "evdevtouch: Could not read from input device"); + qErrnoWarning("evdevtouch: Could not read from input device"); if (errno == ENODEV) { // device got disconnected -> stop reading delete m_notify; m_notify = nullptr; @@ -560,8 +563,9 @@ void QEvdevTouchScreenData::processInputEvent(input_event *data) if (!m_contacts.isEmpty() && m_contacts.constBegin().value().trackingId == -1) assignIds(); + std::unique_lock<QMutex> locker; if (m_filtered) - m_mutex.lock(); + locker = std::unique_lock<QMutex>{m_mutex}; // update timestamps m_lastTimeStamp = m_timeStamp; @@ -571,9 +575,9 @@ void QEvdevTouchScreenData::processInputEvent(input_event *data) m_touchPoints.clear(); Qt::TouchPointStates combinedStates; - QMutableHashIterator<int, Contact> it(m_contacts); - while (it.hasNext()) { - it.next(); + for (auto i = m_contacts.begin(), end = m_contacts.end(); i != end; /*erasing*/) { + auto it = i++; + Contact &contact(it.value()); if (!contact.state) @@ -596,7 +600,7 @@ void QEvdevTouchScreenData::processInputEvent(input_event *data) // Avoid reporting a contact in released state more than once. if (!m_typeB && contact.state == Qt::TouchPointReleased && !m_lastContacts.contains(key)) { - it.remove(); + m_contacts.erase(it); continue; } @@ -604,9 +608,7 @@ void QEvdevTouchScreenData::processInputEvent(input_event *data) } // Now look for contacts that have disappeared since the last sync. - it = m_lastContacts; - while (it.hasNext()) { - it.next(); + for (auto it = m_lastContacts.begin(), end = m_lastContacts.end(); it != end; ++it) { Contact &contact(it.value()); int key = m_typeB ? it.key() : contact.trackingId; if (m_typeB) { @@ -623,9 +625,9 @@ void QEvdevTouchScreenData::processInputEvent(input_event *data) } // Remove contacts that have just been reported as released. - it = m_contacts; - while (it.hasNext()) { - it.next(); + for (auto i = m_contacts.begin(), end = m_contacts.end(); i != end; /*erasing*/) { + auto it = i++; + Contact &contact(it.value()); if (!contact.state) @@ -635,7 +637,7 @@ void QEvdevTouchScreenData::processInputEvent(input_event *data) if (m_typeB) contact.state = static_cast<Qt::TouchPointState>(0); else - it.remove(); + m_contacts.erase(it); } else { contact.state = Qt::TouchPointStationary; } @@ -648,9 +650,6 @@ void QEvdevTouchScreenData::processInputEvent(input_event *data) if (!m_touchPoints.isEmpty() && combinedStates != Qt::TouchPointStationary) reportPoints(); - - if (m_filtered) - m_mutex.unlock(); } m_lastEventType = data->type; diff --git a/src/platformsupport/input/evdevtouch/qevdevtouchmanager.cpp b/src/platformsupport/input/evdevtouch/qevdevtouchmanager.cpp index 4cacbf03e5..b280f27fac 100644 --- a/src/platformsupport/input/evdevtouch/qevdevtouchmanager.cpp +++ b/src/platformsupport/input/evdevtouch/qevdevtouchmanager.cpp @@ -40,12 +40,15 @@ #include "qevdevtouchmanager_p.h" #include "qevdevtouchhandler_p.h" +#include <QtInputSupport/private/qevdevutil_p.h> + #include <QStringList> #include <QGuiApplication> #include <QLoggingCategory> #include <QtDeviceDiscoverySupport/private/qdevicediscovery_p.h> #include <private/qguiapplication_p.h> #include <private/qinputdevicemanager_p_p.h> +#include <private/qmemory_p.h> QT_BEGIN_NAMESPACE @@ -64,34 +67,23 @@ QEvdevTouchManager::QEvdevTouchManager(const QString &key, const QString &specif if (spec.isEmpty()) spec = specification; - QStringList args = spec.split(QLatin1Char(':')); - QStringList devices; - - foreach (const QString &arg, args) { - if (arg.startsWith(QLatin1String("/dev/"))) { - devices.append(arg); - args.removeAll(arg); - } - } - - // build new specification without /dev/ elements - m_spec = args.join(QLatin1Char(':')); + auto parsed = QEvdevUtil::parseSpecification(spec); + m_spec = std::move(parsed.spec); - foreach (const QString &device, devices) + for (const QString &device : qAsConst(parsed.devices)) addDevice(device); // when no devices specified, use device discovery to scan and monitor - if (devices.isEmpty()) { - qCDebug(qLcEvdevTouch) << "evdevtouch: Using device discovery"; - m_deviceDiscovery = QDeviceDiscovery::create(QDeviceDiscovery::Device_Touchpad | QDeviceDiscovery::Device_Touchscreen, this); - if (m_deviceDiscovery) { - const QStringList devices = m_deviceDiscovery->scanConnectedDevices(); + if (parsed.devices.isEmpty()) { + qCDebug(qLcEvdevTouch, "evdevtouch: Using device discovery"); + if (auto deviceDiscovery = QDeviceDiscovery::create(QDeviceDiscovery::Device_Touchpad | QDeviceDiscovery::Device_Touchscreen, this)) { + const QStringList devices = deviceDiscovery->scanConnectedDevices(); for (const QString &device : devices) addDevice(device); - connect(m_deviceDiscovery, &QDeviceDiscovery::deviceDetected, + connect(deviceDiscovery, &QDeviceDiscovery::deviceDetected, this, &QEvdevTouchManager::addDevice); - connect(m_deviceDiscovery, &QDeviceDiscovery::deviceRemoved, + connect(deviceDiscovery, &QDeviceDiscovery::deviceRemoved, this, &QEvdevTouchManager::removeDevice); } } @@ -99,30 +91,24 @@ QEvdevTouchManager::QEvdevTouchManager(const QString &key, const QString &specif QEvdevTouchManager::~QEvdevTouchManager() { - qDeleteAll(m_activeDevices); } void QEvdevTouchManager::addDevice(const QString &deviceNode) { - qCDebug(qLcEvdevTouch) << "evdevtouch: Adding device at" << deviceNode; - QEvdevTouchScreenHandlerThread *handler; - handler = new QEvdevTouchScreenHandlerThread(deviceNode, m_spec); + qCDebug(qLcEvdevTouch, "evdevtouch: Adding device at %ls", qUtf16Printable(deviceNode)); + auto handler = qt_make_unique<QEvdevTouchScreenHandlerThread>(deviceNode, m_spec); if (handler) { - m_activeDevices.insert(deviceNode, handler); - connect(handler, &QEvdevTouchScreenHandlerThread::touchDeviceRegistered, this, &QEvdevTouchManager::updateInputDeviceCount); + m_activeDevices.add(deviceNode, std::move(handler)); + connect(handler.get(), &QEvdevTouchScreenHandlerThread::touchDeviceRegistered, this, &QEvdevTouchManager::updateInputDeviceCount); } else { - qWarning("evdevtouch: Failed to open touch device %s", qPrintable(deviceNode)); + qWarning("evdevtouch: Failed to open touch device %ls", qUtf16Printable(deviceNode)); } } void QEvdevTouchManager::removeDevice(const QString &deviceNode) { - if (m_activeDevices.contains(deviceNode)) { - qCDebug(qLcEvdevTouch) << "evdevtouch: Removing device at" << deviceNode; - QEvdevTouchScreenHandlerThread *handler = m_activeDevices.value(deviceNode); - m_activeDevices.remove(deviceNode); - delete handler; - + if (m_activeDevices.remove(deviceNode)) { + qCDebug(qLcEvdevTouch, "evdevtouch: Removing device at %ls", qUtf16Printable(deviceNode)); updateInputDeviceCount(); } } @@ -130,13 +116,13 @@ void QEvdevTouchManager::removeDevice(const QString &deviceNode) void QEvdevTouchManager::updateInputDeviceCount() { int registeredTouchDevices = 0; - Q_FOREACH (QEvdevTouchScreenHandlerThread *handler, m_activeDevices) { - if (handler->isTouchDeviceRegistered()) + for (const auto &device : m_activeDevices) { + if (device.handler->isTouchDeviceRegistered()) ++registeredTouchDevices; } - qCDebug(qLcEvdevTouch) << "evdevtouch: Updating QInputDeviceManager device count:" << registeredTouchDevices << " touch devices," - << m_activeDevices.count() - registeredTouchDevices << "pending handler(s)" ; + qCDebug(qLcEvdevTouch, "evdevtouch: Updating QInputDeviceManager device count: %d touch devices, %d pending handler(s)", + registeredTouchDevices, m_activeDevices.count() - registeredTouchDevices); QInputDeviceManagerPrivate::get(QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount( QInputDeviceManager::DeviceTypeTouch, registeredTouchDevices); diff --git a/src/platformsupport/input/evdevtouch/qevdevtouchmanager_p.h b/src/platformsupport/input/evdevtouch/qevdevtouchmanager_p.h index e524c516f1..94ee05d900 100644 --- a/src/platformsupport/input/evdevtouch/qevdevtouchmanager_p.h +++ b/src/platformsupport/input/evdevtouch/qevdevtouchmanager_p.h @@ -51,6 +51,8 @@ // We mean it. // +#include <QtInputSupport/private/devicehandlerlist_p.h> + #include <QObject> #include <QHash> #include <QSocketNotifier> @@ -63,7 +65,7 @@ class QEvdevTouchScreenHandlerThread; class QEvdevTouchManager : public QObject { public: - QEvdevTouchManager(const QString &key, const QString &spec, QObject *parent = 0); + QEvdevTouchManager(const QString &key, const QString &spec, QObject *parent = nullptr); ~QEvdevTouchManager(); void addDevice(const QString &deviceNode); @@ -73,8 +75,7 @@ public: private: QString m_spec; - QDeviceDiscovery *m_deviceDiscovery; - QHash<QString, QEvdevTouchScreenHandlerThread *> m_activeDevices; + QtInputSupport::DeviceHandlerList<QEvdevTouchScreenHandlerThread> m_activeDevices; }; QT_END_NAMESPACE diff --git a/src/platformsupport/input/input-support.pro b/src/platformsupport/input/input-support.pro new file mode 100644 index 0000000000..3d39210b9e --- /dev/null +++ b/src/platformsupport/input/input-support.pro @@ -0,0 +1,35 @@ +TARGET = QtInputSupport +MODULE = input_support + +QT = core-private gui-private devicediscovery_support-private +CONFIG += static internal_module + +DEFINES += QT_NO_CAST_FROM_ASCII +PRECOMPILED_HEADER = ../../corelib/global/qt_pch.h + +qtConfig(evdev) { + include($$PWD/evdevmouse/evdevmouse.pri) + include($$PWD/evdevkeyboard/evdevkeyboard.pri) + include($$PWD/evdevtouch/evdevtouch.pri) + qtConfig(tabletevent) { + include($$PWD/evdevtablet/evdevtablet.pri) + } +} + +qtConfig(tslib) { + include($$PWD/tslib/tslib.pri) +} + +qtConfig(libinput) { + include($$PWD/libinput/libinput.pri) +} + +qtConfig(evdev)|qtConfig(libinput) { + include($$PWD/shared/shared.pri) +} + +qtConfig(integrityhid) { + include($$PWD/integrityhid/integrityhid.pri) +} + +load(qt_module) diff --git a/src/platformsupport/input/input.pro b/src/platformsupport/input/input.pro index 3d39210b9e..138c04dea3 100644 --- a/src/platformsupport/input/input.pro +++ b/src/platformsupport/input/input.pro @@ -1,35 +1,8 @@ -TARGET = QtInputSupport -MODULE = input_support +TEMPLATE = subdirs +QT_FOR_CONFIG += gui-private -QT = core-private gui-private devicediscovery_support-private -CONFIG += static internal_module +qtConfig(xkbcommon): SUBDIRS += xkbcommon -DEFINES += QT_NO_CAST_FROM_ASCII -PRECOMPILED_HEADER = ../../corelib/global/qt_pch.h +SUBDIRS += input-support.pro ### FIXME - QTBUG-52657 -qtConfig(evdev) { - include($$PWD/evdevmouse/evdevmouse.pri) - include($$PWD/evdevkeyboard/evdevkeyboard.pri) - include($$PWD/evdevtouch/evdevtouch.pri) - qtConfig(tabletevent) { - include($$PWD/evdevtablet/evdevtablet.pri) - } -} - -qtConfig(tslib) { - include($$PWD/tslib/tslib.pri) -} - -qtConfig(libinput) { - include($$PWD/libinput/libinput.pri) -} - -qtConfig(evdev)|qtConfig(libinput) { - include($$PWD/shared/shared.pri) -} - -qtConfig(integrityhid) { - include($$PWD/integrityhid/integrityhid.pri) -} - -load(qt_module) +CONFIG += ordered diff --git a/src/platformsupport/input/libinput/libinput.pri b/src/platformsupport/input/libinput/libinput.pri index 476f20c1b8..f80b5f41d9 100644 --- a/src/platformsupport/input/libinput/libinput.pri +++ b/src/platformsupport/input/libinput/libinput.pri @@ -14,4 +14,7 @@ QMAKE_USE_PRIVATE += libudev libinput INCLUDEPATH += $$PWD/../shared -qtConfig(xkbcommon): QMAKE_USE_PRIVATE += xkbcommon +qtConfig(xkbcommon): { + QMAKE_USE_PRIVATE += xkbcommon + QT += xkbcommon_support-private +} diff --git a/src/platformsupport/input/libinput/qlibinputhandler.cpp b/src/platformsupport/input/libinput/qlibinputhandler.cpp index 52eaa18f4b..bb81890a67 100644 --- a/src/platformsupport/input/libinput/qlibinputhandler.cpp +++ b/src/platformsupport/input/libinput/qlibinputhandler.cpp @@ -205,6 +205,9 @@ void QLibInputHandler::processEvent(libinput_event *ev) case LIBINPUT_EVENT_POINTER_MOTION: m_pointer->processMotion(libinput_event_get_pointer_event(ev)); break; + case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE: + m_pointer->processAbsMotion(libinput_event_get_pointer_event(ev)); + break; case LIBINPUT_EVENT_POINTER_AXIS: m_pointer->processAxis(libinput_event_get_pointer_event(ev)); break; diff --git a/src/platformsupport/input/libinput/qlibinputkeyboard.cpp b/src/platformsupport/input/libinput/qlibinputkeyboard.cpp index baef769bc9..6586b084f1 100644 --- a/src/platformsupport/input/libinput/qlibinputkeyboard.cpp +++ b/src/platformsupport/input/libinput/qlibinputkeyboard.cpp @@ -47,6 +47,7 @@ #if QT_CONFIG(xkbcommon) #include <xkbcommon/xkbcommon-keysyms.h> #include <xkbcommon/xkbcommon-names.h> +#include <QtXkbCommonSupport/private/qxkbcommon_p.h> #endif QT_BEGIN_NAMESPACE @@ -56,88 +57,7 @@ Q_DECLARE_LOGGING_CATEGORY(qLcLibInput) const int REPEAT_DELAY = 500; const int REPEAT_RATE = 100; -#if QT_CONFIG(xkbcommon) -struct KeyTabEntry { - int xkbkey; - int qtkey; -}; - -static inline bool operator==(const KeyTabEntry &a, const KeyTabEntry &b) -{ - return a.xkbkey == b.xkbkey; -} - -static const KeyTabEntry keyTab[] = { - { XKB_KEY_Escape, Qt::Key_Escape }, - { XKB_KEY_Tab, Qt::Key_Tab }, - { XKB_KEY_ISO_Left_Tab, Qt::Key_Backtab }, - { XKB_KEY_BackSpace, Qt::Key_Backspace }, - { XKB_KEY_Return, Qt::Key_Return }, - { XKB_KEY_Insert, Qt::Key_Insert }, - { XKB_KEY_Delete, Qt::Key_Delete }, - { XKB_KEY_Clear, Qt::Key_Delete }, - { XKB_KEY_Pause, Qt::Key_Pause }, - { XKB_KEY_Print, Qt::Key_Print }, - - { XKB_KEY_Home, Qt::Key_Home }, - { XKB_KEY_End, Qt::Key_End }, - { XKB_KEY_Left, Qt::Key_Left }, - { XKB_KEY_Up, Qt::Key_Up }, - { XKB_KEY_Right, Qt::Key_Right }, - { XKB_KEY_Down, Qt::Key_Down }, - { XKB_KEY_Prior, Qt::Key_PageUp }, - { XKB_KEY_Next, Qt::Key_PageDown }, - - { XKB_KEY_Shift_L, Qt::Key_Shift }, - { XKB_KEY_Shift_R, Qt::Key_Shift }, - { XKB_KEY_Shift_Lock, Qt::Key_Shift }, - { XKB_KEY_Control_L, Qt::Key_Control }, - { XKB_KEY_Control_R, Qt::Key_Control }, - { XKB_KEY_Meta_L, Qt::Key_Meta }, - { XKB_KEY_Meta_R, Qt::Key_Meta }, - { XKB_KEY_Alt_L, Qt::Key_Alt }, - { XKB_KEY_Alt_R, Qt::Key_Alt }, - { XKB_KEY_Caps_Lock, Qt::Key_CapsLock }, - { XKB_KEY_Num_Lock, Qt::Key_NumLock }, - { XKB_KEY_Scroll_Lock, Qt::Key_ScrollLock }, - { XKB_KEY_Super_L, Qt::Key_Super_L }, - { XKB_KEY_Super_R, Qt::Key_Super_R }, - { XKB_KEY_Menu, Qt::Key_Menu }, - { XKB_KEY_Hyper_L, Qt::Key_Hyper_L }, - { XKB_KEY_Hyper_R, Qt::Key_Hyper_R }, - { XKB_KEY_Help, Qt::Key_Help }, - - { XKB_KEY_KP_Space, Qt::Key_Space }, - { XKB_KEY_KP_Tab, Qt::Key_Tab }, - { XKB_KEY_KP_Enter, Qt::Key_Enter }, - { XKB_KEY_KP_Home, Qt::Key_Home }, - { XKB_KEY_KP_Left, Qt::Key_Left }, - { XKB_KEY_KP_Up, Qt::Key_Up }, - { XKB_KEY_KP_Right, Qt::Key_Right }, - { XKB_KEY_KP_Down, Qt::Key_Down }, - { XKB_KEY_KP_Prior, Qt::Key_PageUp }, - { XKB_KEY_KP_Next, Qt::Key_PageDown }, - { XKB_KEY_KP_End, Qt::Key_End }, - { XKB_KEY_KP_Begin, Qt::Key_Clear }, - { XKB_KEY_KP_Insert, Qt::Key_Insert }, - { XKB_KEY_KP_Delete, Qt::Key_Delete }, - { XKB_KEY_KP_Equal, Qt::Key_Equal }, - { XKB_KEY_KP_Multiply, Qt::Key_Asterisk }, - { XKB_KEY_KP_Add, Qt::Key_Plus }, - { XKB_KEY_KP_Separator, Qt::Key_Comma }, - { XKB_KEY_KP_Subtract, Qt::Key_Minus }, - { XKB_KEY_KP_Decimal, Qt::Key_Period }, - { XKB_KEY_KP_Divide, Qt::Key_Slash }, -}; -#endif - QLibInputKeyboard::QLibInputKeyboard() -#if QT_CONFIG(xkbcommon) - : m_ctx(0), - m_keymap(0), - m_state(0), - m_mods(Qt::NoModifier) -#endif { #if QT_CONFIG(xkbcommon) qCDebug(qLcLibInput) << "Using xkbcommon for key mapping"; @@ -148,18 +68,14 @@ QLibInputKeyboard::QLibInputKeyboard() } m_keymap = xkb_keymap_new_from_names(m_ctx, nullptr, XKB_KEYMAP_COMPILE_NO_FLAGS); if (!m_keymap) { - qWarning("Failed to compile keymap"); + qCWarning(qLcLibInput, "Failed to compile keymap"); return; } m_state = xkb_state_new(m_keymap); if (!m_state) { - qWarning("Failed to create xkb state"); + qCWarning(qLcLibInput, "Failed to create xkb state"); return; } - m_modindex[0] = xkb_keymap_mod_get_index(m_keymap, XKB_MOD_NAME_CTRL); - m_modindex[1] = xkb_keymap_mod_get_index(m_keymap, XKB_MOD_NAME_ALT); - m_modindex[2] = xkb_keymap_mod_get_index(m_keymap, XKB_MOD_NAME_SHIFT); - m_modindex[3] = xkb_keymap_mod_get_index(m_keymap, XKB_MOD_NAME_LOGO); m_repeatTimer.setSingleShot(true); connect(&m_repeatTimer, &QTimer::timeout, this, &QLibInputKeyboard::handleRepeat); @@ -186,52 +102,33 @@ void QLibInputKeyboard::processKey(libinput_event_keyboard *e) if (!m_ctx || !m_keymap || !m_state) return; - const uint32_t k = libinput_event_keyboard_get_key(e) + 8; + const uint32_t keycode = libinput_event_keyboard_get_key(e) + 8; + const xkb_keysym_t sym = xkb_state_key_get_one_sym(m_state, keycode); const bool pressed = libinput_event_keyboard_get_key_state(e) == LIBINPUT_KEY_STATE_PRESSED; - QVarLengthArray<char, 32> chars(32); - const int size = xkb_state_key_get_utf8(m_state, k, chars.data(), chars.size()); - if (Q_UNLIKELY(size + 1 > chars.size())) { // +1 for NUL - chars.resize(size + 1); - xkb_state_key_get_utf8(m_state, k, chars.data(), chars.size()); - } - const QString text = QString::fromUtf8(chars.constData(), size); - - const xkb_keysym_t sym = xkb_state_key_get_one_sym(m_state, k); + // Modifiers here is the modifier state before the event, i.e. not + // including the current key in case it is a modifier. See the XOR + // logic in QKeyEvent::modifiers(). ### QTBUG-73826 + Qt::KeyboardModifiers modifiers = QXkbCommon::modifiers(m_state); - // mods here is the modifier state before the event, i.e. not - // including the current key in case it is a modifier. - Qt::KeyboardModifiers mods = Qt::NoModifier; - const int qtkey = keysymToQtKey(sym, &mods, text); + const QString text = QXkbCommon::lookupString(m_state, keycode); + const int qtkey = QXkbCommon::keysymToQtKey(sym, modifiers, m_state, keycode); - if (qtkey == Qt::Key_Control) - mods |= Qt::ControlModifier; - if (qtkey == Qt::Key_Alt) - mods |= Qt::AltModifier; - if (qtkey == Qt::Key_Shift) - mods |= Qt::ShiftModifier; - if (qtkey == Qt::Key_Meta) - mods |= Qt::MetaModifier; - xkb_state_update_key(m_state, k, pressed ? XKB_KEY_DOWN : XKB_KEY_UP); + xkb_state_update_key(m_state, keycode, pressed ? XKB_KEY_DOWN : XKB_KEY_UP); - if (mods != Qt::NoModifier) { - if (pressed) - m_mods |= mods; - else - m_mods &= ~mods; + Qt::KeyboardModifiers modifiersAfterStateChange = QXkbCommon::modifiers(m_state); + QGuiApplicationPrivate::inputDeviceManager()->setKeyboardModifiers(modifiersAfterStateChange); - QGuiApplicationPrivate::inputDeviceManager()->setKeyboardModifiers(m_mods); - } QWindowSystemInterface::handleExtendedKeyEvent(nullptr, pressed ? QEvent::KeyPress : QEvent::KeyRelease, - qtkey, m_mods, k, sym, m_mods, text); + qtkey, modifiers, keycode, sym, modifiers, text); - if (pressed && xkb_keymap_key_repeats(m_keymap, k)) { + if (pressed && xkb_keymap_key_repeats(m_keymap, keycode)) { m_repeatData.qtkey = qtkey; - m_repeatData.mods = mods; - m_repeatData.nativeScanCode = k; + m_repeatData.mods = modifiers; + m_repeatData.nativeScanCode = keycode; m_repeatData.virtualKey = sym; - m_repeatData.nativeMods = mods; + m_repeatData.nativeMods = modifiers; m_repeatData.unicodeText = text; m_repeatData.repeatCount = 1; m_repeatTimer.setInterval(REPEAT_DELAY); @@ -256,50 +153,6 @@ void QLibInputKeyboard::handleRepeat() m_repeatTimer.setInterval(REPEAT_RATE); m_repeatTimer.start(); } - -int QLibInputKeyboard::keysymToQtKey(xkb_keysym_t key) const -{ - const size_t elemCount = sizeof(keyTab) / sizeof(KeyTabEntry); - KeyTabEntry e; - e.xkbkey = key; - const KeyTabEntry *result = std::find(keyTab, keyTab + elemCount, e); - return result != keyTab + elemCount ? result->qtkey : 0; -} - -int QLibInputKeyboard::keysymToQtKey(xkb_keysym_t keysym, Qt::KeyboardModifiers *modifiers, const QString &text) const -{ - int code = 0; -#if QT_CONFIG(textcodec) - QTextCodec *systemCodec = QTextCodec::codecForLocale(); -#endif - if (keysym < 128 || (keysym < 256 -#if QT_CONFIG(textcodec) - && systemCodec->mibEnum() == 4 -#endif - )) { - // upper-case key, if known - code = isprint((int)keysym) ? toupper((int)keysym) : 0; - } else if (keysym >= XKB_KEY_F1 && keysym <= XKB_KEY_F35) { - // function keys - code = Qt::Key_F1 + ((int)keysym - XKB_KEY_F1); - } else if (keysym >= XKB_KEY_KP_Space && keysym <= XKB_KEY_KP_9) { - if (keysym >= XKB_KEY_KP_0) { - // numeric keypad keys - code = Qt::Key_0 + ((int)keysym - XKB_KEY_KP_0); - } else { - code = keysymToQtKey(keysym); - } - *modifiers |= Qt::KeypadModifier; - } else if (text.length() == 1 && text.unicode()->unicode() > 0x1f - && text.unicode()->unicode() != 0x7f - && !(keysym >= XKB_KEY_dead_grave && keysym <= XKB_KEY_dead_longsolidusoverlay)) { - code = text.unicode()->toUpper().unicode(); - } else { - // any other keys - code = keysymToQtKey(keysym); - } - return code; -} #endif QT_END_NAMESPACE diff --git a/src/platformsupport/input/libinput/qlibinputkeyboard_p.h b/src/platformsupport/input/libinput/qlibinputkeyboard_p.h index 14ae71b545..7521902e02 100644 --- a/src/platformsupport/input/libinput/qlibinputkeyboard_p.h +++ b/src/platformsupport/input/libinput/qlibinputkeyboard_p.h @@ -79,10 +79,9 @@ private: int keysymToQtKey(xkb_keysym_t key) const; int keysymToQtKey(xkb_keysym_t keysym, Qt::KeyboardModifiers *modifiers, const QString &text) const; - xkb_context *m_ctx; - xkb_keymap *m_keymap; - xkb_state *m_state; - xkb_mod_index_t m_modindex[4]; + xkb_context *m_ctx = nullptr; + xkb_keymap *m_keymap = nullptr; + xkb_state *m_state = nullptr; QTimer m_repeatTimer; @@ -95,7 +94,6 @@ private: QString unicodeText; int repeatCount; } m_repeatData; - Qt::KeyboardModifiers m_mods; #endif }; diff --git a/src/platformsupport/input/libinput/qlibinputpointer.cpp b/src/platformsupport/input/libinput/qlibinputpointer.cpp index c54b61fc66..db9e81b5df 100644 --- a/src/platformsupport/input/libinput/qlibinputpointer.cpp +++ b/src/platformsupport/input/libinput/qlibinputpointer.cpp @@ -103,6 +103,24 @@ void QLibInputPointer::processMotion(libinput_event_pointer *e) Qt::NoButton, QEvent::MouseMove, mods); } +void QLibInputPointer::processAbsMotion(libinput_event_pointer *e) +{ + QScreen * const primaryScreen = QGuiApplication::primaryScreen(); + const QRect g = QHighDpi::toNativePixels(primaryScreen->virtualGeometry(), primaryScreen); + + const double x = libinput_event_pointer_get_absolute_x_transformed(e, g.width()); + const double y = libinput_event_pointer_get_absolute_y_transformed(e, g.height()); + + m_pos.setX(qBound(g.left(), qRound(g.left() + x), g.right())); + m_pos.setY(qBound(g.top(), qRound(g.top() + y), g.bottom())); + + Qt::KeyboardModifiers mods = QGuiApplicationPrivate::inputDeviceManager()->keyboardModifiers(); + + QWindowSystemInterface::handleMouseEvent(nullptr, m_pos, m_pos, m_buttons, + Qt::NoButton, QEvent::MouseMove, mods); + +} + void QLibInputPointer::processAxis(libinput_event_pointer *e) { double value; // default axis value is 15 degrees per wheel click diff --git a/src/platformsupport/input/libinput/qlibinputpointer_p.h b/src/platformsupport/input/libinput/qlibinputpointer_p.h index a7a66337f1..55d4a5f919 100644 --- a/src/platformsupport/input/libinput/qlibinputpointer_p.h +++ b/src/platformsupport/input/libinput/qlibinputpointer_p.h @@ -64,6 +64,7 @@ public: void processButton(libinput_event_pointer *e); void processMotion(libinput_event_pointer *e); + void processAbsMotion(libinput_event_pointer *e); void processAxis(libinput_event_pointer *e); void setPos(const QPoint &pos); diff --git a/src/platformsupport/input/libinput/qlibinputtouch_p.h b/src/platformsupport/input/libinput/qlibinputtouch_p.h index 6f88001d19..51304e6a21 100644 --- a/src/platformsupport/input/libinput/qlibinputtouch_p.h +++ b/src/platformsupport/input/libinput/qlibinputtouch_p.h @@ -73,7 +73,7 @@ public: private: struct DeviceState { - DeviceState() : m_touchDevice(0) { } + DeviceState() : m_touchDevice(nullptr) { } QWindowSystemInterface::TouchPoint *point(int32_t slot); QList<QWindowSystemInterface::TouchPoint> m_points; QTouchDevice *m_touchDevice; diff --git a/src/platformsupport/input/shared/devicehandlerlist_p.h b/src/platformsupport/input/shared/devicehandlerlist_p.h new file mode 100644 index 0000000000..97794d4d7d --- /dev/null +++ b/src/platformsupport/input/shared/devicehandlerlist_p.h @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz <marc.mutz@kdab.com> +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QTINPUTSUPPORT_DEVICEHANDLERLIST_P_H +#define QTINPUTSUPPORT_DEVICEHANDLERLIST_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QString> + +#include <vector> +#include <memory> + +namespace QtInputSupport { + +template <typename Handler> +class DeviceHandlerList { +public: + struct Device { + QString deviceNode; + std::unique_ptr<Handler> handler; + }; + + void add(const QString &deviceNode, std::unique_ptr<Handler> handler) + { + v.push_back({deviceNode, std::move(handler)}); + } + + bool remove(const QString &deviceNode) + { + const auto deviceNodeMatches = [&] (const Device &d) { return d.deviceNode == deviceNode; }; + const auto it = std::find_if(v.cbegin(), v.cend(), deviceNodeMatches); + if (it == v.cend()) + return false; + v.erase(it); + return true; + } + + int count() const noexcept { return static_cast<int>(v.size()); } + + typename std::vector<Device>::const_iterator begin() const noexcept { return v.begin(); } + typename std::vector<Device>::const_iterator end() const noexcept { return v.end(); } + +private: + std::vector<Device> v; +}; + +} // QtInputSupport + +#endif // QTINPUTSUPPORT_DEVICEHANDLERLIST_P_H diff --git a/src/platformsupport/input/shared/qevdevutil.cpp b/src/platformsupport/input/shared/qevdevutil.cpp new file mode 100644 index 0000000000..74f8bcdc2b --- /dev/null +++ b/src/platformsupport/input/shared/qevdevutil.cpp @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz <marc.mutz@kdab.com> +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the plugins module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qevdevutil_p.h" + +QT_BEGIN_NAMESPACE + +namespace QEvdevUtil { + +ParsedSpecification parseSpecification(const QString &specification) +{ + ParsedSpecification result; + + result.args = specification.splitRef(QLatin1Char(':')); + + for (const QStringRef &arg : qAsConst(result.args)) { + if (arg.startsWith(QLatin1String("/dev/"))) { + // if device is specified try to use it + result.devices.append(arg.toString()); + } else { + // build new specification without /dev/ elements + result.spec += arg + QLatin1Char(':'); + } + } + + if (!result.spec.isEmpty()) + result.spec.chop(1); // remove trailing ':' + + return result; +} + +} // namespace QEvdevUtil + +QT_END_NAMESPACE diff --git a/src/platformsupport/input/shared/qevdevutil_p.h b/src/platformsupport/input/shared/qevdevutil_p.h new file mode 100644 index 0000000000..7d0a5af130 --- /dev/null +++ b/src/platformsupport/input/shared/qevdevutil_p.h @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz <marc.mutz@kdab.com> +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the plugins module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QEVDEVUTIL_P_H +#define QEVDEVUTIL_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QString> +#include <QStringList> +#include <QVector> +#include <QStringRef> + +QT_BEGIN_NAMESPACE + +namespace QEvdevUtil { + +struct ParsedSpecification +{ + QString spec; + QStringList devices; + QVector<QStringRef> args; +}; + +ParsedSpecification parseSpecification(const QString &specification); + +} + +QT_END_NAMESPACE + +#endif // QEVDEVUTIL_P_H diff --git a/src/platformsupport/input/shared/shared.pri b/src/platformsupport/input/shared/shared.pri index 1443235244..c29d11e7d6 100644 --- a/src/platformsupport/input/shared/shared.pri +++ b/src/platformsupport/input/shared/shared.pri @@ -1,5 +1,8 @@ HEADERS += \ + $$PWD/devicehandlerlist_p.h \ + $$PWD/qevdevutil_p.h \ $$PWD/qtouchoutputmapping_p.h SOURCES += \ + $$PWD/qevdevutil.cpp \ $$PWD/qtouchoutputmapping.cpp diff --git a/src/platformsupport/input/tslib/qtslib.cpp b/src/platformsupport/input/tslib/qtslib.cpp index 7609416fea..df57147af6 100644 --- a/src/platformsupport/input/tslib/qtslib.cpp +++ b/src/platformsupport/input/tslib/qtslib.cpp @@ -57,38 +57,20 @@ QTsLibMouseHandler::QTsLibMouseHandler(const QString &key, const QString &specification, QObject *parent) : QObject(parent), - m_notify(0), m_x(0), m_y(0), m_pressed(0), m_rawMode(false) + m_rawMode(!key.compare(QLatin1String("TslibRaw"), Qt::CaseInsensitive)) { qCDebug(qLcTsLib) << "Initializing tslib plugin" << key << specification; setObjectName(QLatin1String("TSLib Mouse Handler")); - QByteArray device = qgetenv("TSLIB_TSDEVICE"); - - if (specification.startsWith(QLatin1String("/dev/"))) - device = specification.toLocal8Bit(); - - if (device.isEmpty()) - device = QByteArrayLiteral("/dev/input/event1"); - - m_dev = ts_open(device.constData(), 1); + m_dev = ts_setup(nullptr, 1); if (!m_dev) { - qErrnoWarning(errno, "ts_open() failed"); + qErrnoWarning(errno, "ts_setup() failed"); return; } - if (ts_config(m_dev)) - qErrnoWarning(errno, "ts_config() failed"); - - m_rawMode = !key.compare(QLatin1String("TslibRaw"), Qt::CaseInsensitive); - - int fd = ts_fd(m_dev); - if (fd >= 0) { - qCDebug(qLcTsLib) << "tslib device is" << device; - m_notify = new QSocketNotifier(fd, QSocketNotifier::Read, this); - connect(m_notify, &QSocketNotifier::activated, this, &QTsLibMouseHandler::readMouseData); - } else { - qErrnoWarning(errno, "tslib: Cannot open input device %s", device.constData()); - } + qCDebug(qLcTsLib) << "tslib device is" << ts_get_eventpath(m_dev); + m_notify = new QSocketNotifier(ts_fd(m_dev), QSocketNotifier::Read, this); + connect(m_notify, &QSocketNotifier::activated, this, &QTsLibMouseHandler::readMouseData); } QTsLibMouseHandler::~QTsLibMouseHandler() diff --git a/src/platformsupport/input/tslib/qtslib_p.h b/src/platformsupport/input/tslib/qtslib_p.h index 0c08fb6a3d..ffd60cd0e3 100644 --- a/src/platformsupport/input/tslib/qtslib_p.h +++ b/src/platformsupport/input/tslib/qtslib_p.h @@ -71,11 +71,12 @@ private slots: void readMouseData(); private: - QSocketNotifier * m_notify; + QSocketNotifier * m_notify = nullptr; tsdev *m_dev; - int m_x, m_y; - bool m_pressed; - bool m_rawMode; + int m_x = 0; + int m_y = 0; + bool m_pressed = false; + const bool m_rawMode; }; QT_END_NAMESPACE diff --git a/src/platformsupport/input/xkbcommon/qxkbcommon.cpp b/src/platformsupport/input/xkbcommon/qxkbcommon.cpp new file mode 100644 index 0000000000..877c5d848f --- /dev/null +++ b/src/platformsupport/input/xkbcommon/qxkbcommon.cpp @@ -0,0 +1,828 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qxkbcommon_p.h" + +#include <private/qmakearray_p.h> + +#include <QtCore/QMetaMethod> +#include <QtGui/QKeyEvent> +#include <QtGui/private/qguiapplication_p.h> + +#include <qpa/qplatforminputcontext.h> +#include <qpa/qplatformintegration.h> + +QT_BEGIN_NAMESPACE + +Q_LOGGING_CATEGORY(lcXkbcommon, "qt.xkbcommon") + +static int keysymToQtKey_internal(xkb_keysym_t keysym, Qt::KeyboardModifiers modifiers, + xkb_state *state, xkb_keycode_t code, + bool superAsMeta, bool hyperAsMeta); + +typedef struct xkb2qt +{ + unsigned int xkb; + unsigned int qt; + + constexpr bool operator <=(const xkb2qt &that) const noexcept + { + return xkb <= that.xkb; + } + + constexpr bool operator <(const xkb2qt &that) const noexcept + { + return xkb < that.xkb; + } +} xkb2qt_t; + +template<std::size_t Xkb, std::size_t Qt> +struct Xkb2Qt +{ + using Type = xkb2qt_t; + static constexpr Type data() noexcept { return Type{Xkb, Qt}; } +}; + +static constexpr const auto KeyTbl = qMakeArray( + QSortedData< + // misc keys + + Xkb2Qt<XKB_KEY_Escape, Qt::Key_Escape>, + Xkb2Qt<XKB_KEY_Tab, Qt::Key_Tab>, + Xkb2Qt<XKB_KEY_ISO_Left_Tab, Qt::Key_Backtab>, + Xkb2Qt<XKB_KEY_BackSpace, Qt::Key_Backspace>, + Xkb2Qt<XKB_KEY_Return, Qt::Key_Return>, + Xkb2Qt<XKB_KEY_Insert, Qt::Key_Insert>, + Xkb2Qt<XKB_KEY_Delete, Qt::Key_Delete>, + Xkb2Qt<XKB_KEY_Clear, Qt::Key_Delete>, + Xkb2Qt<XKB_KEY_Pause, Qt::Key_Pause>, + Xkb2Qt<XKB_KEY_Print, Qt::Key_Print>, + Xkb2Qt<0x1005FF60, Qt::Key_SysReq>, // hardcoded Sun SysReq + Xkb2Qt<0x1007ff00, Qt::Key_SysReq>, // hardcoded X386 SysReq + + // cursor movement + + Xkb2Qt<XKB_KEY_Home, Qt::Key_Home>, + Xkb2Qt<XKB_KEY_End, Qt::Key_End>, + Xkb2Qt<XKB_KEY_Left, Qt::Key_Left>, + Xkb2Qt<XKB_KEY_Up, Qt::Key_Up>, + Xkb2Qt<XKB_KEY_Right, Qt::Key_Right>, + Xkb2Qt<XKB_KEY_Down, Qt::Key_Down>, + Xkb2Qt<XKB_KEY_Prior, Qt::Key_PageUp>, + Xkb2Qt<XKB_KEY_Next, Qt::Key_PageDown>, + + // modifiers + + Xkb2Qt<XKB_KEY_Shift_L, Qt::Key_Shift>, + Xkb2Qt<XKB_KEY_Shift_R, Qt::Key_Shift>, + Xkb2Qt<XKB_KEY_Shift_Lock, Qt::Key_Shift>, + Xkb2Qt<XKB_KEY_Control_L, Qt::Key_Control>, + Xkb2Qt<XKB_KEY_Control_R, Qt::Key_Control>, + Xkb2Qt<XKB_KEY_Meta_L, Qt::Key_Meta>, + Xkb2Qt<XKB_KEY_Meta_R, Qt::Key_Meta>, + Xkb2Qt<XKB_KEY_Alt_L, Qt::Key_Alt>, + Xkb2Qt<XKB_KEY_Alt_R, Qt::Key_Alt>, + Xkb2Qt<XKB_KEY_Caps_Lock, Qt::Key_CapsLock>, + Xkb2Qt<XKB_KEY_Num_Lock, Qt::Key_NumLock>, + Xkb2Qt<XKB_KEY_Scroll_Lock, Qt::Key_ScrollLock>, + Xkb2Qt<XKB_KEY_Super_L, Qt::Key_Super_L>, + Xkb2Qt<XKB_KEY_Super_R, Qt::Key_Super_R>, + Xkb2Qt<XKB_KEY_Menu, Qt::Key_Menu>, + Xkb2Qt<XKB_KEY_Hyper_L, Qt::Key_Hyper_L>, + Xkb2Qt<XKB_KEY_Hyper_R, Qt::Key_Hyper_R>, + Xkb2Qt<XKB_KEY_Help, Qt::Key_Help>, + Xkb2Qt<0x1000FF74, Qt::Key_Backtab>, // hardcoded HP backtab + Xkb2Qt<0x1005FF10, Qt::Key_F11>, // hardcoded Sun F36 (labeled F11) + Xkb2Qt<0x1005FF11, Qt::Key_F12>, // hardcoded Sun F37 (labeled F12) + + // numeric and function keypad keys + + Xkb2Qt<XKB_KEY_KP_Space, Qt::Key_Space>, + Xkb2Qt<XKB_KEY_KP_Tab, Qt::Key_Tab>, + Xkb2Qt<XKB_KEY_KP_Enter, Qt::Key_Enter>, + Xkb2Qt<XKB_KEY_KP_Home, Qt::Key_Home>, + Xkb2Qt<XKB_KEY_KP_Left, Qt::Key_Left>, + Xkb2Qt<XKB_KEY_KP_Up, Qt::Key_Up>, + Xkb2Qt<XKB_KEY_KP_Right, Qt::Key_Right>, + Xkb2Qt<XKB_KEY_KP_Down, Qt::Key_Down>, + Xkb2Qt<XKB_KEY_KP_Prior, Qt::Key_PageUp>, + Xkb2Qt<XKB_KEY_KP_Next, Qt::Key_PageDown>, + Xkb2Qt<XKB_KEY_KP_End, Qt::Key_End>, + Xkb2Qt<XKB_KEY_KP_Begin, Qt::Key_Clear>, + Xkb2Qt<XKB_KEY_KP_Insert, Qt::Key_Insert>, + Xkb2Qt<XKB_KEY_KP_Delete, Qt::Key_Delete>, + Xkb2Qt<XKB_KEY_KP_Equal, Qt::Key_Equal>, + Xkb2Qt<XKB_KEY_KP_Multiply, Qt::Key_Asterisk>, + Xkb2Qt<XKB_KEY_KP_Add, Qt::Key_Plus>, + Xkb2Qt<XKB_KEY_KP_Separator, Qt::Key_Comma>, + Xkb2Qt<XKB_KEY_KP_Subtract, Qt::Key_Minus>, + Xkb2Qt<XKB_KEY_KP_Decimal, Qt::Key_Period>, + Xkb2Qt<XKB_KEY_KP_Divide, Qt::Key_Slash>, + + // special non-XF86 function keys + + Xkb2Qt<XKB_KEY_Undo, Qt::Key_Undo>, + Xkb2Qt<XKB_KEY_Redo, Qt::Key_Redo>, + Xkb2Qt<XKB_KEY_Find, Qt::Key_Find>, + Xkb2Qt<XKB_KEY_Cancel, Qt::Key_Cancel>, + + // International input method support keys + + // International & multi-key character composition + Xkb2Qt<XKB_KEY_ISO_Level3_Shift, Qt::Key_AltGr>, + Xkb2Qt<XKB_KEY_Multi_key, Qt::Key_Multi_key>, + Xkb2Qt<XKB_KEY_Codeinput, Qt::Key_Codeinput>, + Xkb2Qt<XKB_KEY_SingleCandidate, Qt::Key_SingleCandidate>, + Xkb2Qt<XKB_KEY_MultipleCandidate, Qt::Key_MultipleCandidate>, + Xkb2Qt<XKB_KEY_PreviousCandidate, Qt::Key_PreviousCandidate>, + + // Misc Functions + Xkb2Qt<XKB_KEY_Mode_switch, Qt::Key_Mode_switch>, + Xkb2Qt<XKB_KEY_script_switch, Qt::Key_Mode_switch>, + + // Japanese keyboard support + Xkb2Qt<XKB_KEY_Kanji, Qt::Key_Kanji>, + Xkb2Qt<XKB_KEY_Muhenkan, Qt::Key_Muhenkan>, + //Xkb2Qt<XKB_KEY_Henkan_Mode, Qt::Key_Henkan_Mode>, + Xkb2Qt<XKB_KEY_Henkan_Mode, Qt::Key_Henkan>, + Xkb2Qt<XKB_KEY_Henkan, Qt::Key_Henkan>, + Xkb2Qt<XKB_KEY_Romaji, Qt::Key_Romaji>, + Xkb2Qt<XKB_KEY_Hiragana, Qt::Key_Hiragana>, + Xkb2Qt<XKB_KEY_Katakana, Qt::Key_Katakana>, + Xkb2Qt<XKB_KEY_Hiragana_Katakana, Qt::Key_Hiragana_Katakana>, + Xkb2Qt<XKB_KEY_Zenkaku, Qt::Key_Zenkaku>, + Xkb2Qt<XKB_KEY_Hankaku, Qt::Key_Hankaku>, + Xkb2Qt<XKB_KEY_Zenkaku_Hankaku, Qt::Key_Zenkaku_Hankaku>, + Xkb2Qt<XKB_KEY_Touroku, Qt::Key_Touroku>, + Xkb2Qt<XKB_KEY_Massyo, Qt::Key_Massyo>, + Xkb2Qt<XKB_KEY_Kana_Lock, Qt::Key_Kana_Lock>, + Xkb2Qt<XKB_KEY_Kana_Shift, Qt::Key_Kana_Shift>, + Xkb2Qt<XKB_KEY_Eisu_Shift, Qt::Key_Eisu_Shift>, + Xkb2Qt<XKB_KEY_Eisu_toggle, Qt::Key_Eisu_toggle>, + //Xkb2Qt<XKB_KEY_Kanji_Bangou, Qt::Key_Kanji_Bangou>, + //Xkb2Qt<XKB_KEY_Zen_Koho, Qt::Key_Zen_Koho>, + //Xkb2Qt<XKB_KEY_Mae_Koho, Qt::Key_Mae_Koho>, + Xkb2Qt<XKB_KEY_Kanji_Bangou, Qt::Key_Codeinput>, + Xkb2Qt<XKB_KEY_Zen_Koho, Qt::Key_MultipleCandidate>, + Xkb2Qt<XKB_KEY_Mae_Koho, Qt::Key_PreviousCandidate>, + + // Korean keyboard support + Xkb2Qt<XKB_KEY_Hangul, Qt::Key_Hangul>, + Xkb2Qt<XKB_KEY_Hangul_Start, Qt::Key_Hangul_Start>, + Xkb2Qt<XKB_KEY_Hangul_End, Qt::Key_Hangul_End>, + Xkb2Qt<XKB_KEY_Hangul_Hanja, Qt::Key_Hangul_Hanja>, + Xkb2Qt<XKB_KEY_Hangul_Jamo, Qt::Key_Hangul_Jamo>, + Xkb2Qt<XKB_KEY_Hangul_Romaja, Qt::Key_Hangul_Romaja>, + //Xkb2Qt<XKB_KEY_Hangul_Codeinput, Qt::Key_Hangul_Codeinput>, + Xkb2Qt<XKB_KEY_Hangul_Codeinput, Qt::Key_Codeinput>, + Xkb2Qt<XKB_KEY_Hangul_Jeonja, Qt::Key_Hangul_Jeonja>, + Xkb2Qt<XKB_KEY_Hangul_Banja, Qt::Key_Hangul_Banja>, + Xkb2Qt<XKB_KEY_Hangul_PreHanja, Qt::Key_Hangul_PreHanja>, + Xkb2Qt<XKB_KEY_Hangul_PostHanja, Qt::Key_Hangul_PostHanja>, + //Xkb2Qt<XKB_KEY_Hangul_SingleCandidate,Qt::Key_Hangul_SingleCandidate>, + //Xkb2Qt<XKB_KEY_Hangul_MultipleCandidate,Qt::Key_Hangul_MultipleCandidate>, + //Xkb2Qt<XKB_KEY_Hangul_PreviousCandidate,Qt::Key_Hangul_PreviousCandidate>, + Xkb2Qt<XKB_KEY_Hangul_SingleCandidate, Qt::Key_SingleCandidate>, + Xkb2Qt<XKB_KEY_Hangul_MultipleCandidate,Qt::Key_MultipleCandidate>, + Xkb2Qt<XKB_KEY_Hangul_PreviousCandidate,Qt::Key_PreviousCandidate>, + Xkb2Qt<XKB_KEY_Hangul_Special, Qt::Key_Hangul_Special>, + //Xkb2Qt<XKB_KEY_Hangul_switch, Qt::Key_Hangul_switch>, + Xkb2Qt<XKB_KEY_Hangul_switch, Qt::Key_Mode_switch>, + + // dead keys + Xkb2Qt<XKB_KEY_dead_grave, Qt::Key_Dead_Grave>, + Xkb2Qt<XKB_KEY_dead_acute, Qt::Key_Dead_Acute>, + Xkb2Qt<XKB_KEY_dead_circumflex, Qt::Key_Dead_Circumflex>, + Xkb2Qt<XKB_KEY_dead_tilde, Qt::Key_Dead_Tilde>, + Xkb2Qt<XKB_KEY_dead_macron, Qt::Key_Dead_Macron>, + Xkb2Qt<XKB_KEY_dead_breve, Qt::Key_Dead_Breve>, + Xkb2Qt<XKB_KEY_dead_abovedot, Qt::Key_Dead_Abovedot>, + Xkb2Qt<XKB_KEY_dead_diaeresis, Qt::Key_Dead_Diaeresis>, + Xkb2Qt<XKB_KEY_dead_abovering, Qt::Key_Dead_Abovering>, + Xkb2Qt<XKB_KEY_dead_doubleacute, Qt::Key_Dead_Doubleacute>, + Xkb2Qt<XKB_KEY_dead_caron, Qt::Key_Dead_Caron>, + Xkb2Qt<XKB_KEY_dead_cedilla, Qt::Key_Dead_Cedilla>, + Xkb2Qt<XKB_KEY_dead_ogonek, Qt::Key_Dead_Ogonek>, + Xkb2Qt<XKB_KEY_dead_iota, Qt::Key_Dead_Iota>, + Xkb2Qt<XKB_KEY_dead_voiced_sound, Qt::Key_Dead_Voiced_Sound>, + Xkb2Qt<XKB_KEY_dead_semivoiced_sound, Qt::Key_Dead_Semivoiced_Sound>, + Xkb2Qt<XKB_KEY_dead_belowdot, Qt::Key_Dead_Belowdot>, + Xkb2Qt<XKB_KEY_dead_hook, Qt::Key_Dead_Hook>, + Xkb2Qt<XKB_KEY_dead_horn, Qt::Key_Dead_Horn>, + Xkb2Qt<XKB_KEY_dead_stroke, Qt::Key_Dead_Stroke>, + Xkb2Qt<XKB_KEY_dead_abovecomma, Qt::Key_Dead_Abovecomma>, + Xkb2Qt<XKB_KEY_dead_abovereversedcomma, Qt::Key_Dead_Abovereversedcomma>, + Xkb2Qt<XKB_KEY_dead_doublegrave, Qt::Key_Dead_Doublegrave>, + Xkb2Qt<XKB_KEY_dead_belowring, Qt::Key_Dead_Belowring>, + Xkb2Qt<XKB_KEY_dead_belowmacron, Qt::Key_Dead_Belowmacron>, + Xkb2Qt<XKB_KEY_dead_belowcircumflex, Qt::Key_Dead_Belowcircumflex>, + Xkb2Qt<XKB_KEY_dead_belowtilde, Qt::Key_Dead_Belowtilde>, + Xkb2Qt<XKB_KEY_dead_belowbreve, Qt::Key_Dead_Belowbreve>, + Xkb2Qt<XKB_KEY_dead_belowdiaeresis, Qt::Key_Dead_Belowdiaeresis>, + Xkb2Qt<XKB_KEY_dead_invertedbreve, Qt::Key_Dead_Invertedbreve>, + Xkb2Qt<XKB_KEY_dead_belowcomma, Qt::Key_Dead_Belowcomma>, + Xkb2Qt<XKB_KEY_dead_currency, Qt::Key_Dead_Currency>, + Xkb2Qt<XKB_KEY_dead_a, Qt::Key_Dead_a>, + Xkb2Qt<XKB_KEY_dead_A, Qt::Key_Dead_A>, + Xkb2Qt<XKB_KEY_dead_e, Qt::Key_Dead_e>, + Xkb2Qt<XKB_KEY_dead_E, Qt::Key_Dead_E>, + Xkb2Qt<XKB_KEY_dead_i, Qt::Key_Dead_i>, + Xkb2Qt<XKB_KEY_dead_I, Qt::Key_Dead_I>, + Xkb2Qt<XKB_KEY_dead_o, Qt::Key_Dead_o>, + Xkb2Qt<XKB_KEY_dead_O, Qt::Key_Dead_O>, + Xkb2Qt<XKB_KEY_dead_u, Qt::Key_Dead_u>, + Xkb2Qt<XKB_KEY_dead_U, Qt::Key_Dead_U>, + Xkb2Qt<XKB_KEY_dead_small_schwa, Qt::Key_Dead_Small_Schwa>, + Xkb2Qt<XKB_KEY_dead_capital_schwa, Qt::Key_Dead_Capital_Schwa>, + Xkb2Qt<XKB_KEY_dead_greek, Qt::Key_Dead_Greek>, + Xkb2Qt<XKB_KEY_dead_lowline, Qt::Key_Dead_Lowline>, + Xkb2Qt<XKB_KEY_dead_aboveverticalline, Qt::Key_Dead_Aboveverticalline>, + Xkb2Qt<XKB_KEY_dead_belowverticalline, Qt::Key_Dead_Belowverticalline>, + Xkb2Qt<XKB_KEY_dead_longsolidusoverlay, Qt::Key_Dead_Longsolidusoverlay>, + + // Special keys from X.org - This include multimedia keys, + // wireless/bluetooth/uwb keys, special launcher keys, etc. + Xkb2Qt<XKB_KEY_XF86Back, Qt::Key_Back>, + Xkb2Qt<XKB_KEY_XF86Forward, Qt::Key_Forward>, + Xkb2Qt<XKB_KEY_XF86Stop, Qt::Key_Stop>, + Xkb2Qt<XKB_KEY_XF86Refresh, Qt::Key_Refresh>, + Xkb2Qt<XKB_KEY_XF86Favorites, Qt::Key_Favorites>, + Xkb2Qt<XKB_KEY_XF86AudioMedia, Qt::Key_LaunchMedia>, + Xkb2Qt<XKB_KEY_XF86OpenURL, Qt::Key_OpenUrl>, + Xkb2Qt<XKB_KEY_XF86HomePage, Qt::Key_HomePage>, + Xkb2Qt<XKB_KEY_XF86Search, Qt::Key_Search>, + Xkb2Qt<XKB_KEY_XF86AudioLowerVolume, Qt::Key_VolumeDown>, + Xkb2Qt<XKB_KEY_XF86AudioMute, Qt::Key_VolumeMute>, + Xkb2Qt<XKB_KEY_XF86AudioRaiseVolume, Qt::Key_VolumeUp>, + Xkb2Qt<XKB_KEY_XF86AudioPlay, Qt::Key_MediaPlay>, + Xkb2Qt<XKB_KEY_XF86AudioStop, Qt::Key_MediaStop>, + Xkb2Qt<XKB_KEY_XF86AudioPrev, Qt::Key_MediaPrevious>, + Xkb2Qt<XKB_KEY_XF86AudioNext, Qt::Key_MediaNext>, + Xkb2Qt<XKB_KEY_XF86AudioRecord, Qt::Key_MediaRecord>, + Xkb2Qt<XKB_KEY_XF86AudioPause, Qt::Key_MediaPause>, + Xkb2Qt<XKB_KEY_XF86Mail, Qt::Key_LaunchMail>, + Xkb2Qt<XKB_KEY_XF86MyComputer, Qt::Key_Launch0>, // ### Qt 6: remap properly + Xkb2Qt<XKB_KEY_XF86Calculator, Qt::Key_Launch1>, + Xkb2Qt<XKB_KEY_XF86Memo, Qt::Key_Memo>, + Xkb2Qt<XKB_KEY_XF86ToDoList, Qt::Key_ToDoList>, + Xkb2Qt<XKB_KEY_XF86Calendar, Qt::Key_Calendar>, + Xkb2Qt<XKB_KEY_XF86PowerDown, Qt::Key_PowerDown>, + Xkb2Qt<XKB_KEY_XF86ContrastAdjust, Qt::Key_ContrastAdjust>, + Xkb2Qt<XKB_KEY_XF86Standby, Qt::Key_Standby>, + Xkb2Qt<XKB_KEY_XF86MonBrightnessUp, Qt::Key_MonBrightnessUp>, + Xkb2Qt<XKB_KEY_XF86MonBrightnessDown, Qt::Key_MonBrightnessDown>, + Xkb2Qt<XKB_KEY_XF86KbdLightOnOff, Qt::Key_KeyboardLightOnOff>, + Xkb2Qt<XKB_KEY_XF86KbdBrightnessUp, Qt::Key_KeyboardBrightnessUp>, + Xkb2Qt<XKB_KEY_XF86KbdBrightnessDown, Qt::Key_KeyboardBrightnessDown>, + Xkb2Qt<XKB_KEY_XF86PowerOff, Qt::Key_PowerOff>, + Xkb2Qt<XKB_KEY_XF86WakeUp, Qt::Key_WakeUp>, + Xkb2Qt<XKB_KEY_XF86Eject, Qt::Key_Eject>, + Xkb2Qt<XKB_KEY_XF86ScreenSaver, Qt::Key_ScreenSaver>, + Xkb2Qt<XKB_KEY_XF86WWW, Qt::Key_WWW>, + Xkb2Qt<XKB_KEY_XF86Sleep, Qt::Key_Sleep>, + Xkb2Qt<XKB_KEY_XF86LightBulb, Qt::Key_LightBulb>, + Xkb2Qt<XKB_KEY_XF86Shop, Qt::Key_Shop>, + Xkb2Qt<XKB_KEY_XF86History, Qt::Key_History>, + Xkb2Qt<XKB_KEY_XF86AddFavorite, Qt::Key_AddFavorite>, + Xkb2Qt<XKB_KEY_XF86HotLinks, Qt::Key_HotLinks>, + Xkb2Qt<XKB_KEY_XF86BrightnessAdjust, Qt::Key_BrightnessAdjust>, + Xkb2Qt<XKB_KEY_XF86Finance, Qt::Key_Finance>, + Xkb2Qt<XKB_KEY_XF86Community, Qt::Key_Community>, + Xkb2Qt<XKB_KEY_XF86AudioRewind, Qt::Key_AudioRewind>, + Xkb2Qt<XKB_KEY_XF86BackForward, Qt::Key_BackForward>, + Xkb2Qt<XKB_KEY_XF86ApplicationLeft, Qt::Key_ApplicationLeft>, + Xkb2Qt<XKB_KEY_XF86ApplicationRight, Qt::Key_ApplicationRight>, + Xkb2Qt<XKB_KEY_XF86Book, Qt::Key_Book>, + Xkb2Qt<XKB_KEY_XF86CD, Qt::Key_CD>, + Xkb2Qt<XKB_KEY_XF86Calculater, Qt::Key_Calculator>, + Xkb2Qt<XKB_KEY_XF86Clear, Qt::Key_Clear>, + Xkb2Qt<XKB_KEY_XF86ClearGrab, Qt::Key_ClearGrab>, + Xkb2Qt<XKB_KEY_XF86Close, Qt::Key_Close>, + Xkb2Qt<XKB_KEY_XF86Copy, Qt::Key_Copy>, + Xkb2Qt<XKB_KEY_XF86Cut, Qt::Key_Cut>, + Xkb2Qt<XKB_KEY_XF86Display, Qt::Key_Display>, + Xkb2Qt<XKB_KEY_XF86DOS, Qt::Key_DOS>, + Xkb2Qt<XKB_KEY_XF86Documents, Qt::Key_Documents>, + Xkb2Qt<XKB_KEY_XF86Excel, Qt::Key_Excel>, + Xkb2Qt<XKB_KEY_XF86Explorer, Qt::Key_Explorer>, + Xkb2Qt<XKB_KEY_XF86Game, Qt::Key_Game>, + Xkb2Qt<XKB_KEY_XF86Go, Qt::Key_Go>, + Xkb2Qt<XKB_KEY_XF86iTouch, Qt::Key_iTouch>, + Xkb2Qt<XKB_KEY_XF86LogOff, Qt::Key_LogOff>, + Xkb2Qt<XKB_KEY_XF86Market, Qt::Key_Market>, + Xkb2Qt<XKB_KEY_XF86Meeting, Qt::Key_Meeting>, + Xkb2Qt<XKB_KEY_XF86MenuKB, Qt::Key_MenuKB>, + Xkb2Qt<XKB_KEY_XF86MenuPB, Qt::Key_MenuPB>, + Xkb2Qt<XKB_KEY_XF86MySites, Qt::Key_MySites>, + Xkb2Qt<XKB_KEY_XF86New, Qt::Key_New>, + Xkb2Qt<XKB_KEY_XF86News, Qt::Key_News>, + Xkb2Qt<XKB_KEY_XF86OfficeHome, Qt::Key_OfficeHome>, + Xkb2Qt<XKB_KEY_XF86Open, Qt::Key_Open>, + Xkb2Qt<XKB_KEY_XF86Option, Qt::Key_Option>, + Xkb2Qt<XKB_KEY_XF86Paste, Qt::Key_Paste>, + Xkb2Qt<XKB_KEY_XF86Phone, Qt::Key_Phone>, + Xkb2Qt<XKB_KEY_XF86Reply, Qt::Key_Reply>, + Xkb2Qt<XKB_KEY_XF86Reload, Qt::Key_Reload>, + Xkb2Qt<XKB_KEY_XF86RotateWindows, Qt::Key_RotateWindows>, + Xkb2Qt<XKB_KEY_XF86RotationPB, Qt::Key_RotationPB>, + Xkb2Qt<XKB_KEY_XF86RotationKB, Qt::Key_RotationKB>, + Xkb2Qt<XKB_KEY_XF86Save, Qt::Key_Save>, + Xkb2Qt<XKB_KEY_XF86Send, Qt::Key_Send>, + Xkb2Qt<XKB_KEY_XF86Spell, Qt::Key_Spell>, + Xkb2Qt<XKB_KEY_XF86SplitScreen, Qt::Key_SplitScreen>, + Xkb2Qt<XKB_KEY_XF86Support, Qt::Key_Support>, + Xkb2Qt<XKB_KEY_XF86TaskPane, Qt::Key_TaskPane>, + Xkb2Qt<XKB_KEY_XF86Terminal, Qt::Key_Terminal>, + Xkb2Qt<XKB_KEY_XF86Tools, Qt::Key_Tools>, + Xkb2Qt<XKB_KEY_XF86Travel, Qt::Key_Travel>, + Xkb2Qt<XKB_KEY_XF86Video, Qt::Key_Video>, + Xkb2Qt<XKB_KEY_XF86Word, Qt::Key_Word>, + Xkb2Qt<XKB_KEY_XF86Xfer, Qt::Key_Xfer>, + Xkb2Qt<XKB_KEY_XF86ZoomIn, Qt::Key_ZoomIn>, + Xkb2Qt<XKB_KEY_XF86ZoomOut, Qt::Key_ZoomOut>, + Xkb2Qt<XKB_KEY_XF86Away, Qt::Key_Away>, + Xkb2Qt<XKB_KEY_XF86Messenger, Qt::Key_Messenger>, + Xkb2Qt<XKB_KEY_XF86WebCam, Qt::Key_WebCam>, + Xkb2Qt<XKB_KEY_XF86MailForward, Qt::Key_MailForward>, + Xkb2Qt<XKB_KEY_XF86Pictures, Qt::Key_Pictures>, + Xkb2Qt<XKB_KEY_XF86Music, Qt::Key_Music>, + Xkb2Qt<XKB_KEY_XF86Battery, Qt::Key_Battery>, + Xkb2Qt<XKB_KEY_XF86Bluetooth, Qt::Key_Bluetooth>, + Xkb2Qt<XKB_KEY_XF86WLAN, Qt::Key_WLAN>, + Xkb2Qt<XKB_KEY_XF86UWB, Qt::Key_UWB>, + Xkb2Qt<XKB_KEY_XF86AudioForward, Qt::Key_AudioForward>, + Xkb2Qt<XKB_KEY_XF86AudioRepeat, Qt::Key_AudioRepeat>, + Xkb2Qt<XKB_KEY_XF86AudioRandomPlay, Qt::Key_AudioRandomPlay>, + Xkb2Qt<XKB_KEY_XF86Subtitle, Qt::Key_Subtitle>, + Xkb2Qt<XKB_KEY_XF86AudioCycleTrack, Qt::Key_AudioCycleTrack>, + Xkb2Qt<XKB_KEY_XF86Time, Qt::Key_Time>, + Xkb2Qt<XKB_KEY_XF86Select, Qt::Key_Select>, + Xkb2Qt<XKB_KEY_XF86View, Qt::Key_View>, + Xkb2Qt<XKB_KEY_XF86TopMenu, Qt::Key_TopMenu>, + Xkb2Qt<XKB_KEY_XF86Red, Qt::Key_Red>, + Xkb2Qt<XKB_KEY_XF86Green, Qt::Key_Green>, + Xkb2Qt<XKB_KEY_XF86Yellow, Qt::Key_Yellow>, + Xkb2Qt<XKB_KEY_XF86Blue, Qt::Key_Blue>, + Xkb2Qt<XKB_KEY_XF86Bluetooth, Qt::Key_Bluetooth>, + Xkb2Qt<XKB_KEY_XF86Suspend, Qt::Key_Suspend>, + Xkb2Qt<XKB_KEY_XF86Hibernate, Qt::Key_Hibernate>, + Xkb2Qt<XKB_KEY_XF86TouchpadToggle, Qt::Key_TouchpadToggle>, + Xkb2Qt<XKB_KEY_XF86TouchpadOn, Qt::Key_TouchpadOn>, + Xkb2Qt<XKB_KEY_XF86TouchpadOff, Qt::Key_TouchpadOff>, + Xkb2Qt<XKB_KEY_XF86AudioMicMute, Qt::Key_MicMute>, + Xkb2Qt<XKB_KEY_XF86Launch0, Qt::Key_Launch2>, // ### Qt 6: remap properly + Xkb2Qt<XKB_KEY_XF86Launch1, Qt::Key_Launch3>, + Xkb2Qt<XKB_KEY_XF86Launch2, Qt::Key_Launch4>, + Xkb2Qt<XKB_KEY_XF86Launch3, Qt::Key_Launch5>, + Xkb2Qt<XKB_KEY_XF86Launch4, Qt::Key_Launch6>, + Xkb2Qt<XKB_KEY_XF86Launch5, Qt::Key_Launch7>, + Xkb2Qt<XKB_KEY_XF86Launch6, Qt::Key_Launch8>, + Xkb2Qt<XKB_KEY_XF86Launch7, Qt::Key_Launch9>, + Xkb2Qt<XKB_KEY_XF86Launch8, Qt::Key_LaunchA>, + Xkb2Qt<XKB_KEY_XF86Launch9, Qt::Key_LaunchB>, + Xkb2Qt<XKB_KEY_XF86LaunchA, Qt::Key_LaunchC>, + Xkb2Qt<XKB_KEY_XF86LaunchB, Qt::Key_LaunchD>, + Xkb2Qt<XKB_KEY_XF86LaunchC, Qt::Key_LaunchE>, + Xkb2Qt<XKB_KEY_XF86LaunchD, Qt::Key_LaunchF>, + Xkb2Qt<XKB_KEY_XF86LaunchE, Qt::Key_LaunchG>, + Xkb2Qt<XKB_KEY_XF86LaunchF, Qt::Key_LaunchH> + >::Data{} +); + +xkb_keysym_t QXkbCommon::qxkbcommon_xkb_keysym_to_upper(xkb_keysym_t ks) +{ + xkb_keysym_t lower, upper; + + xkbcommon_XConvertCase(ks, &lower, &upper); + + return upper; +} + +QString QXkbCommon::lookupString(struct xkb_state *state, xkb_keycode_t code) +{ + QVarLengthArray<char, 32> chars(32); + const int size = xkb_state_key_get_utf8(state, code, chars.data(), chars.size()); + if (Q_UNLIKELY(size + 1 > chars.size())) { // +1 for NUL + chars.resize(size + 1); + xkb_state_key_get_utf8(state, code, chars.data(), chars.size()); + } + return QString::fromUtf8(chars.constData(), size); +} + +QString QXkbCommon::lookupStringNoKeysymTransformations(xkb_keysym_t keysym) +{ + QVarLengthArray<char, 32> chars(32); + const int size = xkb_keysym_to_utf8(keysym, chars.data(), chars.size()); + if (size == 0) + return QString(); // the keysym does not have a Unicode representation + + if (Q_UNLIKELY(size > chars.size())) { + chars.resize(size); + xkb_keysym_to_utf8(keysym, chars.data(), chars.size()); + } + return QString::fromUtf8(chars.constData(), size - 1); +} + +QVector<xkb_keysym_t> QXkbCommon::toKeysym(QKeyEvent *event) +{ + QVector<xkb_keysym_t> keysyms; + int qtKey = event->key(); + + if (qtKey >= Qt::Key_F1 && qtKey <= Qt::Key_F35) { + keysyms.append(XKB_KEY_F1 + (qtKey - Qt::Key_F1)); + } else if (event->modifiers() & Qt::KeypadModifier) { + if (qtKey >= Qt::Key_0 && qtKey <= Qt::Key_9) + keysyms.append(XKB_KEY_KP_0 + (qtKey - Qt::Key_0)); + } else if (isLatin(qtKey) && event->text().isUpper()) { + keysyms.append(qtKey); + } + + if (!keysyms.isEmpty()) + return keysyms; + + // check if we have a direct mapping + auto it = std::find_if(KeyTbl.cbegin(), KeyTbl.cend(), [&qtKey](xkb2qt_t elem) { + return elem.qt == static_cast<uint>(qtKey); + }); + if (it != KeyTbl.end()) { + keysyms.append(it->xkb); + return keysyms; + } + + QVector<uint> ucs4; + if (event->text().isEmpty()) + ucs4.append(qtKey); + else + ucs4 = event->text().toUcs4(); + + // From libxkbcommon keysym-utf.c: + // "We allow to represent any UCS character in the range U-00000000 to + // U-00FFFFFF by a keysym value in the range 0x01000000 to 0x01ffffff." + for (uint utf32 : qAsConst(ucs4)) + keysyms.append(utf32 | 0x01000000); + + return keysyms; +} + +int QXkbCommon::keysymToQtKey(xkb_keysym_t keysym, Qt::KeyboardModifiers modifiers) +{ + return keysymToQtKey(keysym, modifiers, nullptr, 0); +} + +int QXkbCommon::keysymToQtKey(xkb_keysym_t keysym, Qt::KeyboardModifiers modifiers, + xkb_state *state, xkb_keycode_t code, + bool superAsMeta, bool hyperAsMeta) +{ + // Note 1: All standard key sequences on linux (as defined in platform theme) + // that use a latin character also contain a control modifier, which is why + // checking for Qt::ControlModifier is sufficient here. It is possible to + // override QPlatformTheme::keyBindings() and provide custom sequences for + // QKeySequence::StandardKey. Custom sequences probably should respect this + // convention (alternatively, we could test against other modifiers here). + // Note 2: The possibleKeys() shorcut mechanism is not affected by this value + // adjustment and does its own thing. + if (modifiers & Qt::ControlModifier) { + // With standard shortcuts we should prefer a latin character, this is + // for checks like "some qkeyevent == QKeySequence::Copy" to work even + // when using for example 'russian' keyboard layout. + if (!QXkbCommon::isLatin(keysym)) { + xkb_keysym_t latinKeysym = QXkbCommon::lookupLatinKeysym(state, code); + if (latinKeysym != XKB_KEY_NoSymbol) + keysym = latinKeysym; + } + } + + return keysymToQtKey_internal(keysym, modifiers, state, code, superAsMeta, hyperAsMeta); +} + +static int keysymToQtKey_internal(xkb_keysym_t keysym, Qt::KeyboardModifiers modifiers, + xkb_state *state, xkb_keycode_t code, + bool superAsMeta, bool hyperAsMeta) +{ + int qtKey = 0; + + // lookup from direct mapping + if (keysym >= XKB_KEY_F1 && keysym <= XKB_KEY_F35) { + // function keys + qtKey = Qt::Key_F1 + (keysym - XKB_KEY_F1); + } else if (keysym >= XKB_KEY_KP_0 && keysym <= XKB_KEY_KP_9) { + // numeric keypad keys + qtKey = Qt::Key_0 + (keysym - XKB_KEY_KP_0); + } else if (QXkbCommon::isLatin(keysym)) { + qtKey = QXkbCommon::qxkbcommon_xkb_keysym_to_upper(keysym); + } else { + // check if we have a direct mapping + xkb2qt_t searchKey{keysym, 0}; + auto it = std::lower_bound(KeyTbl.cbegin(), KeyTbl.cend(), searchKey); + if (it != KeyTbl.end() && !(searchKey < *it)) + qtKey = it->qt; + } + + if (qtKey) + return qtKey; + + // lookup from unicode + QString text; + if (!state || modifiers & Qt::ControlModifier) { + // Control modifier changes the text to ASCII control character, therefore we + // can't use this text to map keysym to a qt key. We can use the same keysym + // (it is not affectd by transformation) to obtain untransformed text. For details + // see "Appendix A. Default Symbol Transformations" in the XKB specification. + text = QXkbCommon::lookupStringNoKeysymTransformations(keysym); + } else { + text = QXkbCommon::lookupString(state, code); + } + if (!text.isEmpty()) { + if (text.unicode()->isDigit()) { + // Ensures that also non-latin digits are mapped to corresponding qt keys, + // e.g CTRL + ۲ (arabic two), is mapped to CTRL + Qt::Key_2. + qtKey = Qt::Key_0 + text.unicode()->digitValue(); + } else { + qtKey = text.unicode()->toUpper().unicode(); + } + } + + // translate Super/Hyper keys to Meta if we're using them as the MetaModifier + if (superAsMeta && (qtKey == Qt::Key_Super_L || qtKey == Qt::Key_Super_R)) + qtKey = Qt::Key_Meta; + if (hyperAsMeta && (qtKey == Qt::Key_Hyper_L || qtKey == Qt::Key_Hyper_R)) + qtKey = Qt::Key_Meta; + + return qtKey; +} + +Qt::KeyboardModifiers QXkbCommon::modifiers(struct xkb_state *state) +{ + Qt::KeyboardModifiers modifiers = Qt::NoModifier; + + if (xkb_state_mod_name_is_active(state, XKB_MOD_NAME_CTRL, XKB_STATE_MODS_EFFECTIVE) > 0) + modifiers |= Qt::ControlModifier; + if (xkb_state_mod_name_is_active(state, XKB_MOD_NAME_ALT, XKB_STATE_MODS_EFFECTIVE) > 0) + modifiers |= Qt::AltModifier; + if (xkb_state_mod_name_is_active(state, XKB_MOD_NAME_SHIFT, XKB_STATE_MODS_EFFECTIVE) > 0) + modifiers |= Qt::ShiftModifier; + if (xkb_state_mod_name_is_active(state, XKB_MOD_NAME_LOGO, XKB_STATE_MODS_EFFECTIVE) > 0) + modifiers |= Qt::MetaModifier; + + return modifiers; +} + +// Possible modifier states. +static const Qt::KeyboardModifiers ModsTbl[] = { + Qt::NoModifier, // 0 + Qt::ShiftModifier, // 1 + Qt::ControlModifier, // 2 + Qt::ControlModifier | Qt::ShiftModifier, // 3 + Qt::AltModifier, // 4 + Qt::AltModifier | Qt::ShiftModifier, // 5 + Qt::AltModifier | Qt::ControlModifier, // 6 + Qt::AltModifier | Qt::ShiftModifier | Qt::ControlModifier, // 7 + Qt::NoModifier // Fall-back to raw Key_*, for non-latin1 kb layouts +}; + +QList<int> QXkbCommon::possibleKeys(xkb_state *state, const QKeyEvent *event, + bool superAsMeta, bool hyperAsMeta) +{ + QList<int> result; + quint32 keycode = event->nativeScanCode(); + Qt::KeyboardModifiers modifiers = event->modifiers(); + xkb_keymap *keymap = xkb_state_get_keymap(state); + // turn off the modifier bits which doesn't participate in shortcuts + Qt::KeyboardModifiers notNeeded = Qt::KeypadModifier | Qt::GroupSwitchModifier; + modifiers &= ~notNeeded; + // create a fresh kb state and test against the relevant modifier combinations + ScopedXKBState scopedXkbQueryState(xkb_state_new(keymap)); + xkb_state *queryState = scopedXkbQueryState.get(); + if (!queryState) { + qCWarning(lcXkbcommon) << Q_FUNC_INFO << "failed to compile xkb keymap"; + return result; + } + // get kb state from the master state and update the temporary state + xkb_layout_index_t lockedLayout = xkb_state_serialize_layout(state, XKB_STATE_LAYOUT_LOCKED); + xkb_mod_mask_t latchedMods = xkb_state_serialize_mods(state, XKB_STATE_MODS_LATCHED); + xkb_mod_mask_t lockedMods = xkb_state_serialize_mods(state, XKB_STATE_MODS_LOCKED); + xkb_mod_mask_t depressedMods = xkb_state_serialize_mods(state, XKB_STATE_MODS_DEPRESSED); + xkb_state_update_mask(queryState, depressedMods, latchedMods, lockedMods, 0, 0, lockedLayout); + // handle shortcuts for level three and above + xkb_layout_index_t layoutIndex = xkb_state_key_get_layout(queryState, keycode); + xkb_level_index_t levelIndex = 0; + if (layoutIndex != XKB_LAYOUT_INVALID) { + levelIndex = xkb_state_key_get_level(queryState, keycode, layoutIndex); + if (levelIndex == XKB_LEVEL_INVALID) + levelIndex = 0; + } + if (levelIndex <= 1) + xkb_state_update_mask(queryState, 0, latchedMods, lockedMods, 0, 0, lockedLayout); + + xkb_keysym_t sym = xkb_state_key_get_one_sym(queryState, keycode); + if (sym == XKB_KEY_NoSymbol) + return result; + + int baseQtKey = keysymToQtKey_internal(sym, modifiers, queryState, keycode, superAsMeta, hyperAsMeta); + if (baseQtKey) + result += (baseQtKey + modifiers); + + xkb_mod_index_t shiftMod = xkb_keymap_mod_get_index(keymap, "Shift"); + xkb_mod_index_t altMod = xkb_keymap_mod_get_index(keymap, "Alt"); + xkb_mod_index_t controlMod = xkb_keymap_mod_get_index(keymap, "Control"); + xkb_mod_index_t metaMod = xkb_keymap_mod_get_index(keymap, "Meta"); + + Q_ASSERT(shiftMod < 32); + Q_ASSERT(altMod < 32); + Q_ASSERT(controlMod < 32); + + xkb_mod_mask_t depressed; + int qtKey = 0; + // obtain a list of possible shortcuts for the given key event + for (uint i = 1; i < sizeof(ModsTbl) / sizeof(*ModsTbl) ; ++i) { + Qt::KeyboardModifiers neededMods = ModsTbl[i]; + if ((modifiers & neededMods) == neededMods) { + if (i == 8) { + if (isLatin(baseQtKey)) + continue; + // add a latin key as a fall back key + sym = lookupLatinKeysym(state, keycode); + } else { + depressed = 0; + if (neededMods & Qt::AltModifier) + depressed |= (1 << altMod); + if (neededMods & Qt::ShiftModifier) + depressed |= (1 << shiftMod); + if (neededMods & Qt::ControlModifier) + depressed |= (1 << controlMod); + if (metaMod < 32 && neededMods & Qt::MetaModifier) + depressed |= (1 << metaMod); + xkb_state_update_mask(queryState, depressed, latchedMods, lockedMods, 0, 0, lockedLayout); + sym = xkb_state_key_get_one_sym(queryState, keycode); + } + if (sym == XKB_KEY_NoSymbol) + continue; + + Qt::KeyboardModifiers mods = modifiers & ~neededMods; + qtKey = keysymToQtKey_internal(sym, mods, queryState, keycode, superAsMeta, hyperAsMeta); + if (!qtKey || qtKey == baseQtKey) + continue; + + // catch only more specific shortcuts, i.e. Ctrl+Shift+= also generates Ctrl++ and +, + // but Ctrl++ is more specific than +, so we should skip the last one + bool ambiguous = false; + for (int shortcut : qAsConst(result)) { + if (int(shortcut & ~Qt::KeyboardModifierMask) == qtKey && (shortcut & mods) == mods) { + ambiguous = true; + break; + } + } + if (ambiguous) + continue; + + result += (qtKey + mods); + } + } + + return result; +} + +void QXkbCommon::verifyHasLatinLayout(xkb_keymap *keymap) +{ + const xkb_layout_index_t layoutCount = xkb_keymap_num_layouts(keymap); + const xkb_keycode_t minKeycode = xkb_keymap_min_keycode(keymap); + const xkb_keycode_t maxKeycode = xkb_keymap_max_keycode(keymap); + + const xkb_keysym_t *keysyms = nullptr; + int nrLatinKeys = 0; + for (xkb_layout_index_t layout = 0; layout < layoutCount; ++layout) { + for (xkb_keycode_t code = minKeycode; code < maxKeycode; ++code) { + xkb_keymap_key_get_syms_by_level(keymap, code, layout, 0, &keysyms); + if (keysyms && isLatin(keysyms[0])) + nrLatinKeys++; + if (nrLatinKeys > 10) // arbitrarily chosen threshold + return; + } + } + // This means that lookupLatinKeysym() will not find anything and latin + // key shortcuts might not work. This is a bug in the affected desktop + // environment. Usually can be solved via system settings by adding e.g. 'us' + // layout to the list of seleced layouts, or by using command line, "setxkbmap + // -layout rus,en". The position of latin key based layout in the list of the + // selected layouts is irrelevant. Properly functioning desktop environments + // handle this behind the scenes, even if no latin key based layout has been + // explicitly listed in the selected layouts. + qCDebug(lcXkbcommon, "no keyboard layouts with latin keys present"); +} + +xkb_keysym_t QXkbCommon::lookupLatinKeysym(xkb_state *state, xkb_keycode_t keycode) +{ + xkb_layout_index_t layout; + xkb_keysym_t sym = XKB_KEY_NoSymbol; + xkb_keymap *keymap = xkb_state_get_keymap(state); + const xkb_layout_index_t layoutCount = xkb_keymap_num_layouts_for_key(keymap, keycode); + const xkb_layout_index_t currentLayout = xkb_state_key_get_layout(state, keycode); + // Look at user layouts in the order in which they are defined in system + // settings to find a latin keysym. + for (layout = 0; layout < layoutCount; ++layout) { + if (layout == currentLayout) + continue; + const xkb_keysym_t *syms = nullptr; + xkb_level_index_t level = xkb_state_key_get_level(state, keycode, layout); + if (xkb_keymap_key_get_syms_by_level(keymap, keycode, layout, level, &syms) != 1) + continue; + if (isLatin(syms[0])) { + sym = syms[0]; + break; + } + } + + if (sym == XKB_KEY_NoSymbol) + return sym; + + xkb_mod_mask_t latchedMods = xkb_state_serialize_mods(state, XKB_STATE_MODS_LATCHED); + xkb_mod_mask_t lockedMods = xkb_state_serialize_mods(state, XKB_STATE_MODS_LOCKED); + + // Check for uniqueness, consider the following setup: + // setxkbmap -layout us,ru,us -variant dvorak,, -option 'grp:ctrl_alt_toggle' (set 'ru' as active). + // In this setup, the user would expect to trigger a ctrl+q shortcut by pressing ctrl+<physical x key>, + // because "US dvorak" is higher up in the layout settings list. This check verifies that an obtained + // 'sym' can not be acquired by any other layout higher up in the user's layout list. If it can be acquired + // then the obtained key is not unique. This prevents ctrl+<physical q key> from generating a ctrl+q + // shortcut in the above described setup. We don't want ctrl+<physical x key> and ctrl+<physical q key> to + // generate the same shortcut event in this case. + const xkb_keycode_t minKeycode = xkb_keymap_min_keycode(keymap); + const xkb_keycode_t maxKeycode = xkb_keymap_max_keycode(keymap); + ScopedXKBState queryState(xkb_state_new(keymap)); + for (xkb_layout_index_t prevLayout = 0; prevLayout < layout; ++prevLayout) { + xkb_state_update_mask(queryState.get(), 0, latchedMods, lockedMods, 0, 0, prevLayout); + for (xkb_keycode_t code = minKeycode; code < maxKeycode; ++code) { + xkb_keysym_t prevSym = xkb_state_key_get_one_sym(queryState.get(), code); + if (prevSym == sym) { + sym = XKB_KEY_NoSymbol; + break; + } + } + } + + return sym; +} + +void QXkbCommon::setXkbContext(QPlatformInputContext *inputContext, struct xkb_context *context) +{ + if (!inputContext || !context) + return; + + const char *const inputContextClassName = "QComposeInputContext"; + const char *const normalizedSignature = "setXkbContext(xkb_context*)"; + + if (inputContext->objectName() != QLatin1String(inputContextClassName)) + return; + + static const QMetaMethod setXkbContext = [&]() { + int methodIndex = inputContext->metaObject()->indexOfMethod(normalizedSignature); + QMetaMethod method = inputContext->metaObject()->method(methodIndex); + Q_ASSERT(method.isValid()); + if (!method.isValid()) + qCWarning(lcXkbcommon) << normalizedSignature << "not found on" << inputContextClassName; + return method; + }(); + + if (!setXkbContext.isValid()) + return; + + setXkbContext.invoke(inputContext, Qt::DirectConnection, Q_ARG(struct xkb_context*, context)); +} + +QT_END_NAMESPACE diff --git a/src/platformsupport/input/xkbcommon/qxkbcommon_3rdparty.cpp b/src/platformsupport/input/xkbcommon/qxkbcommon_3rdparty.cpp new file mode 100644 index 0000000000..08f43b3b72 --- /dev/null +++ b/src/platformsupport/input/xkbcommon/qxkbcommon_3rdparty.cpp @@ -0,0 +1,219 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/* Copyright 1985, 1987, 1990, 1998 The Open Group + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + Except as contained in this notice, the names of the authors or their + institutions shall not be used in advertising or otherwise to promote the + sale, use or other dealings in this Software without prior written + authorization from the authors. + + + + Copyright © 2009 Dan Nicholson + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice (including the next + paragraph) shall be included in all copies or substantial portions of the + Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +/* + XConvertCase was copied from src/3rdparty/xkbcommon/src/keysym.c + The following code modifications were applied: + + XConvertCase() was renamed to xkbcommon_XConvertCase(), to not confuse it + with Xlib's XConvertCase(). + + UCSConvertCase() was renamed to qt_UCSConvertCase() and function's body was + replaced to use Qt APIs for doing case conversion, which should give us better + results instead of using the less complete version from keysym.c +*/ + +#include "qxkbcommon_p.h" + +#include <QtCore/QChar> + +static void qt_UCSConvertCase(uint32_t code, xkb_keysym_t *lower, xkb_keysym_t *upper) +{ + *lower = QChar::toLower(code); + *upper = QChar::toUpper(code); +} + +void QXkbCommon::xkbcommon_XConvertCase(xkb_keysym_t sym, xkb_keysym_t *lower, xkb_keysym_t *upper) +{ + /* Latin 1 keysym */ + if (sym < 0x100) { + qt_UCSConvertCase(sym, lower, upper); + return; + } + + /* Unicode keysym */ + if ((sym & 0xff000000) == 0x01000000) { + qt_UCSConvertCase((sym & 0x00ffffff), lower, upper); + *upper |= 0x01000000; + *lower |= 0x01000000; + return; + } + + /* Legacy keysym */ + + *lower = sym; + *upper = sym; + + switch (sym >> 8) { + case 1: /* Latin 2 */ + /* Assume the KeySym is a legal value (ignore discontinuities) */ + if (sym == XKB_KEY_Aogonek) + *lower = XKB_KEY_aogonek; + else if (sym >= XKB_KEY_Lstroke && sym <= XKB_KEY_Sacute) + *lower += (XKB_KEY_lstroke - XKB_KEY_Lstroke); + else if (sym >= XKB_KEY_Scaron && sym <= XKB_KEY_Zacute) + *lower += (XKB_KEY_scaron - XKB_KEY_Scaron); + else if (sym >= XKB_KEY_Zcaron && sym <= XKB_KEY_Zabovedot) + *lower += (XKB_KEY_zcaron - XKB_KEY_Zcaron); + else if (sym == XKB_KEY_aogonek) + *upper = XKB_KEY_Aogonek; + else if (sym >= XKB_KEY_lstroke && sym <= XKB_KEY_sacute) + *upper -= (XKB_KEY_lstroke - XKB_KEY_Lstroke); + else if (sym >= XKB_KEY_scaron && sym <= XKB_KEY_zacute) + *upper -= (XKB_KEY_scaron - XKB_KEY_Scaron); + else if (sym >= XKB_KEY_zcaron && sym <= XKB_KEY_zabovedot) + *upper -= (XKB_KEY_zcaron - XKB_KEY_Zcaron); + else if (sym >= XKB_KEY_Racute && sym <= XKB_KEY_Tcedilla) + *lower += (XKB_KEY_racute - XKB_KEY_Racute); + else if (sym >= XKB_KEY_racute && sym <= XKB_KEY_tcedilla) + *upper -= (XKB_KEY_racute - XKB_KEY_Racute); + break; + case 2: /* Latin 3 */ + /* Assume the KeySym is a legal value (ignore discontinuities) */ + if (sym >= XKB_KEY_Hstroke && sym <= XKB_KEY_Hcircumflex) + *lower += (XKB_KEY_hstroke - XKB_KEY_Hstroke); + else if (sym >= XKB_KEY_Gbreve && sym <= XKB_KEY_Jcircumflex) + *lower += (XKB_KEY_gbreve - XKB_KEY_Gbreve); + else if (sym >= XKB_KEY_hstroke && sym <= XKB_KEY_hcircumflex) + *upper -= (XKB_KEY_hstroke - XKB_KEY_Hstroke); + else if (sym >= XKB_KEY_gbreve && sym <= XKB_KEY_jcircumflex) + *upper -= (XKB_KEY_gbreve - XKB_KEY_Gbreve); + else if (sym >= XKB_KEY_Cabovedot && sym <= XKB_KEY_Scircumflex) + *lower += (XKB_KEY_cabovedot - XKB_KEY_Cabovedot); + else if (sym >= XKB_KEY_cabovedot && sym <= XKB_KEY_scircumflex) + *upper -= (XKB_KEY_cabovedot - XKB_KEY_Cabovedot); + break; + case 3: /* Latin 4 */ + /* Assume the KeySym is a legal value (ignore discontinuities) */ + if (sym >= XKB_KEY_Rcedilla && sym <= XKB_KEY_Tslash) + *lower += (XKB_KEY_rcedilla - XKB_KEY_Rcedilla); + else if (sym >= XKB_KEY_rcedilla && sym <= XKB_KEY_tslash) + *upper -= (XKB_KEY_rcedilla - XKB_KEY_Rcedilla); + else if (sym == XKB_KEY_ENG) + *lower = XKB_KEY_eng; + else if (sym == XKB_KEY_eng) + *upper = XKB_KEY_ENG; + else if (sym >= XKB_KEY_Amacron && sym <= XKB_KEY_Umacron) + *lower += (XKB_KEY_amacron - XKB_KEY_Amacron); + else if (sym >= XKB_KEY_amacron && sym <= XKB_KEY_umacron) + *upper -= (XKB_KEY_amacron - XKB_KEY_Amacron); + break; + case 6: /* Cyrillic */ + /* Assume the KeySym is a legal value (ignore discontinuities) */ + if (sym >= XKB_KEY_Serbian_DJE && sym <= XKB_KEY_Serbian_DZE) + *lower -= (XKB_KEY_Serbian_DJE - XKB_KEY_Serbian_dje); + else if (sym >= XKB_KEY_Serbian_dje && sym <= XKB_KEY_Serbian_dze) + *upper += (XKB_KEY_Serbian_DJE - XKB_KEY_Serbian_dje); + else if (sym >= XKB_KEY_Cyrillic_YU && sym <= XKB_KEY_Cyrillic_HARDSIGN) + *lower -= (XKB_KEY_Cyrillic_YU - XKB_KEY_Cyrillic_yu); + else if (sym >= XKB_KEY_Cyrillic_yu && sym <= XKB_KEY_Cyrillic_hardsign) + *upper += (XKB_KEY_Cyrillic_YU - XKB_KEY_Cyrillic_yu); + break; + case 7: /* Greek */ + /* Assume the KeySym is a legal value (ignore discontinuities) */ + if (sym >= XKB_KEY_Greek_ALPHAaccent && sym <= XKB_KEY_Greek_OMEGAaccent) + *lower += (XKB_KEY_Greek_alphaaccent - XKB_KEY_Greek_ALPHAaccent); + else if (sym >= XKB_KEY_Greek_alphaaccent && sym <= XKB_KEY_Greek_omegaaccent && + sym != XKB_KEY_Greek_iotaaccentdieresis && + sym != XKB_KEY_Greek_upsilonaccentdieresis) + *upper -= (XKB_KEY_Greek_alphaaccent - XKB_KEY_Greek_ALPHAaccent); + else if (sym >= XKB_KEY_Greek_ALPHA && sym <= XKB_KEY_Greek_OMEGA) + *lower += (XKB_KEY_Greek_alpha - XKB_KEY_Greek_ALPHA); + else if (sym >= XKB_KEY_Greek_alpha && sym <= XKB_KEY_Greek_omega && + sym != XKB_KEY_Greek_finalsmallsigma) + *upper -= (XKB_KEY_Greek_alpha - XKB_KEY_Greek_ALPHA); + break; + case 0x13: /* Latin 9 */ + if (sym == XKB_KEY_OE) + *lower = XKB_KEY_oe; + else if (sym == XKB_KEY_oe) + *upper = XKB_KEY_OE; + else if (sym == XKB_KEY_Ydiaeresis) + *lower = XKB_KEY_ydiaeresis; + break; + } +} diff --git a/src/platformsupport/input/xkbcommon/qxkbcommon_p.h b/src/platformsupport/input/xkbcommon/qxkbcommon_p.h new file mode 100644 index 0000000000..561eae03db --- /dev/null +++ b/src/platformsupport/input/xkbcommon/qxkbcommon_p.h @@ -0,0 +1,122 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QXKBCOMMON_P_H +#define QXKBCOMMON_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QtCore/QString> +#include <QtCore/QVector> +#include <QtCore/QLoggingCategory> +#include <QtCore/QList> + +#include <xkbcommon/xkbcommon.h> + +#include <memory> + +QT_BEGIN_NAMESPACE + +Q_DECLARE_LOGGING_CATEGORY(lcXkbcommon) + +class QEvent; +class QKeyEvent; +class QPlatformInputContext; + +class QXkbCommon +{ +public: + static QString lookupString(struct xkb_state *state, xkb_keycode_t code); + static QString lookupStringNoKeysymTransformations(xkb_keysym_t keysym); + + static QVector<xkb_keysym_t> toKeysym(QKeyEvent *event); + + static int keysymToQtKey(xkb_keysym_t keysym, Qt::KeyboardModifiers modifiers); + static int keysymToQtKey(xkb_keysym_t keysym, Qt::KeyboardModifiers modifiers, + xkb_state *state, xkb_keycode_t code, + bool superAsMeta = false, bool hyperAsMeta = false); + + // xkbcommon_* API is part of libxkbcommon internals, with modifications as + // desribed in the header of the implementation file. + static void xkbcommon_XConvertCase(xkb_keysym_t sym, xkb_keysym_t *lower, xkb_keysym_t *upper); + static xkb_keysym_t qxkbcommon_xkb_keysym_to_upper(xkb_keysym_t ks); + + static Qt::KeyboardModifiers modifiers(struct xkb_state *state); + + static QList<int> possibleKeys(xkb_state *state, const QKeyEvent *event, + bool superAsMeta = false, bool hyperAsMeta = false); + + static void verifyHasLatinLayout(xkb_keymap *keymap); + static xkb_keysym_t lookupLatinKeysym(xkb_state *state, xkb_keycode_t keycode); + + static bool isLatin(xkb_keysym_t sym) { + return ((sym >= 'a' && sym <= 'z') || (sym >= 'A' && sym <= 'Z')); + } + static bool isKeypad(xkb_keysym_t sym) { + return sym >= XKB_KEY_KP_Space && sym <= XKB_KEY_KP_9; + } + + static void setXkbContext(QPlatformInputContext *inputContext, struct xkb_context *context); + + struct XKBStateDeleter { + void operator()(struct xkb_state *state) const { return xkb_state_unref(state); } + }; + struct XKBKeymapDeleter { + void operator()(struct xkb_keymap *keymap) const { return xkb_keymap_unref(keymap); } + }; + struct XKBContextDeleter { + void operator()(struct xkb_context *context) const { return xkb_context_unref(context); } + }; + using ScopedXKBState = std::unique_ptr<struct xkb_state, XKBStateDeleter>; + using ScopedXKBKeymap = std::unique_ptr<struct xkb_keymap, XKBKeymapDeleter>; + using ScopedXKBContext = std::unique_ptr<struct xkb_context, XKBContextDeleter>; +}; + +QT_END_NAMESPACE + +#endif // QXKBCOMMON_P_H diff --git a/src/platformsupport/input/xkbcommon/xkbcommon.pro b/src/platformsupport/input/xkbcommon/xkbcommon.pro new file mode 100644 index 0000000000..22b16ae44a --- /dev/null +++ b/src/platformsupport/input/xkbcommon/xkbcommon.pro @@ -0,0 +1,23 @@ +TARGET = QtXkbCommonSupport +MODULE = xkbcommon_support + +QT = core-private gui-private +CONFIG += static internal_module + +DEFINES += QT_NO_CAST_FROM_ASCII +PRECOMPILED_HEADER = ../../../corelib/global/qt_pch.h + +QMAKE_USE += xkbcommon + +HEADERS += \ + qxkbcommon_p.h + +SOURCES += \ + qxkbcommon.cpp \ + qxkbcommon_3rdparty.cpp + +# qxkbcommon.cpp::KeyTbl has more than 256 levels of expansion and older +# Clang uses that as a limit (it's 1024 in current versions). +clang:!intel_icc: QMAKE_CXXFLAGS += -ftemplate-depth=1024 + +load(qt_module) diff --git a/src/platformsupport/kmsconvenience/qkmsdevice.cpp b/src/platformsupport/kmsconvenience/qkmsdevice.cpp index 7e3a870421..8cc7a539b5 100644 --- a/src/platformsupport/kmsconvenience/qkmsdevice.cpp +++ b/src/platformsupport/kmsconvenience/qkmsdevice.cpp @@ -791,9 +791,7 @@ void QKmsDevice::discoverPlanes() for (int i = 0; i < countFormats; ++i) { uint32_t f = drmplane->formats[i]; plane.supportedFormats.append(f); - QString s; - s.sprintf("%c%c%c%c ", f, f >> 8, f >> 16, f >> 24); - formatStr += s; + formatStr += QString::asprintf("%c%c%c%c ", f, f >> 8, f >> 16, f >> 24); } qCDebug(qLcKmsDebug, "plane %d: id = %u countFormats = %d possibleCrtcs = 0x%x supported formats = %s", diff --git a/src/platformsupport/linuxaccessibility/atspiadaptor.cpp b/src/platformsupport/linuxaccessibility/atspiadaptor.cpp index 580cf0e31d..8a825f8284 100644 --- a/src/platformsupport/linuxaccessibility/atspiadaptor.cpp +++ b/src/platformsupport/linuxaccessibility/atspiadaptor.cpp @@ -2050,8 +2050,8 @@ QVariantList AtSpiAdaptor::getAttributes(QAccessibleInterface *interface, int of int endOffset; QString joined = interface->textInterface()->attributes(offset, &startOffset, &endOffset); - QStringList attributes = joined.split (QLatin1Char(';'), QString::SkipEmptyParts, Qt::CaseSensitive); - foreach (const QString &attr, attributes) { + const QStringList attributes = joined.split (QLatin1Char(';'), QString::SkipEmptyParts, Qt::CaseSensitive); + for (const QString &attr : attributes) { QStringList items; items = attr.split(QLatin1Char(':'), QString::SkipEmptyParts, Qt::CaseSensitive); AtSpiAttribute attribute = atspiTextAttribute(items[0], items[1]); @@ -2069,14 +2069,13 @@ QVariantList AtSpiAdaptor::getAttributeValue(QAccessibleInterface *interface, in { QString mapped; QString joined; - QStringList attributes; QSpiAttributeSet map; int startOffset; int endOffset; joined = interface->textInterface()->attributes(offset, &startOffset, &endOffset); - attributes = joined.split (QLatin1Char(';'), QString::SkipEmptyParts, Qt::CaseSensitive); - foreach (const QString& attr, attributes) { + const QStringList attributes = joined.split (QLatin1Char(';'), QString::SkipEmptyParts, Qt::CaseSensitive); + for (const QString& attr : attributes) { QStringList items; items = attr.split(QLatin1Char(':'), QString::SkipEmptyParts, Qt::CaseSensitive); AtSpiAttribute attribute = atspiTextAttribute(items[0], items[1]); diff --git a/src/platformsupport/linuxaccessibility/atspiadaptor_p.h b/src/platformsupport/linuxaccessibility/atspiadaptor_p.h index b5704f53ad..0b624389a3 100644 --- a/src/platformsupport/linuxaccessibility/atspiadaptor_p.h +++ b/src/platformsupport/linuxaccessibility/atspiadaptor_p.h @@ -76,7 +76,7 @@ class AtSpiAdaptor :public QDBusVirtualObject Q_OBJECT public: - explicit AtSpiAdaptor(DBusConnection *connection, QObject *parent = 0); + explicit AtSpiAdaptor(DBusConnection *connection, QObject *parent = nullptr); ~AtSpiAdaptor(); void registerApplication(); diff --git a/src/platformsupport/linuxaccessibility/cache_p.h b/src/platformsupport/linuxaccessibility/cache_p.h index e8529b779b..cc55acc6f8 100644 --- a/src/platformsupport/linuxaccessibility/cache_p.h +++ b/src/platformsupport/linuxaccessibility/cache_p.h @@ -65,7 +65,7 @@ class QSpiDBusCache : public QObject Q_OBJECT public: - explicit QSpiDBusCache(QDBusConnection c, QObject* parent = 0); + explicit QSpiDBusCache(QDBusConnection c, QObject* parent = nullptr); void emitAddAccessible(const QSpiAccessibleCacheItem& item); void emitRemoveAccessible(const QSpiObjectReference& item); diff --git a/src/platformsupport/linuxaccessibility/dbusconnection_p.h b/src/platformsupport/linuxaccessibility/dbusconnection_p.h index 4030fabc22..860c18ca05 100644 --- a/src/platformsupport/linuxaccessibility/dbusconnection_p.h +++ b/src/platformsupport/linuxaccessibility/dbusconnection_p.h @@ -65,7 +65,7 @@ class DBusConnection : public QObject Q_OBJECT public: - DBusConnection(QObject *parent = 0); + DBusConnection(QObject *parent = nullptr); QDBusConnection connection() const; bool isEnabled() const { return m_enabled; } diff --git a/src/platformsupport/themes/genericunix/dbusmenu/qdbusmenuconnection_p.h b/src/platformsupport/themes/genericunix/dbusmenu/qdbusmenuconnection_p.h index 7959f0c28a..f484795fbb 100644 --- a/src/platformsupport/themes/genericunix/dbusmenu/qdbusmenuconnection_p.h +++ b/src/platformsupport/themes/genericunix/dbusmenu/qdbusmenuconnection_p.h @@ -69,7 +69,7 @@ class QDBusMenuConnection : public QObject Q_OBJECT public: - QDBusMenuConnection(QObject *parent = 0, const QString &serviceName = QString()); + QDBusMenuConnection(QObject *parent = nullptr, const QString &serviceName = QString()); QDBusConnection connection() const { return m_connection; } QDBusServiceWatcher *dbusWatcher() const { return m_dbusWatcher; } bool isStatusNotifierHostRegistered() const { return m_statusNotifierHostRegistered; } diff --git a/src/platformsupport/themes/genericunix/dbustray/qdbustrayicon.cpp b/src/platformsupport/themes/genericunix/dbustray/qdbustrayicon.cpp index e81d272d4f..ca740f967e 100644 --- a/src/platformsupport/themes/genericunix/dbustray/qdbustrayicon.cpp +++ b/src/platformsupport/themes/genericunix/dbustray/qdbustrayicon.cpp @@ -52,6 +52,9 @@ #include <qdebug.h> #include <qrect.h> #include <qloggingcategory.h> +#include <qstandardpaths.h> +#include <qdir.h> +#include <qmetaobject.h> #include <qpa/qplatformintegration.h> #include <qpa/qplatformservices.h> #include <qdbusconnectioninterface.h> diff --git a/src/platformsupport/themes/genericunix/dbustray/qstatusnotifieritemadaptor.cpp b/src/platformsupport/themes/genericunix/dbustray/qstatusnotifieritemadaptor.cpp index d3c5454f01..ef2d330959 100644 --- a/src/platformsupport/themes/genericunix/dbustray/qstatusnotifieritemadaptor.cpp +++ b/src/platformsupport/themes/genericunix/dbustray/qstatusnotifieritemadaptor.cpp @@ -52,6 +52,9 @@ #ifndef QT_NO_SYSTEMTRAYICON +#include <QtCore/QLoggingCategory> +#include <QtCore/QCoreApplication> + #include "qdbustrayicon_p.h" QT_BEGIN_NAMESPACE diff --git a/src/platformsupport/themes/genericunix/dbustray/qxdgnotificationproxy_p.h b/src/platformsupport/themes/genericunix/dbustray/qxdgnotificationproxy_p.h index 03899723ab..ab99ea65dd 100644 --- a/src/platformsupport/themes/genericunix/dbustray/qxdgnotificationproxy_p.h +++ b/src/platformsupport/themes/genericunix/dbustray/qxdgnotificationproxy_p.h @@ -65,6 +65,7 @@ #include <QtCore/QObject> #include <QtCore/QByteArray> #include <QtCore/QList> +#include <QtCore/QLoggingCategory> #include <QtCore/QMap> #include <QtCore/QString> #include <QtCore/QStringList> @@ -87,7 +88,7 @@ public: public: QXdgNotificationInterface(const QString &service, const QString &path, - const QDBusConnection &connection, QObject *parent = 0); + const QDBusConnection &connection, QObject *parent = nullptr); ~QXdgNotificationInterface(); diff --git a/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp b/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp index 6db25a90da..70d5616075 100644 --- a/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp +++ b/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp @@ -175,15 +175,9 @@ QStringList QGenericUnixTheme::xdgIconThemePaths() if (homeIconDir.isDir()) paths.prepend(homeIconDir.absoluteFilePath()); - QString xdgDirString = QFile::decodeName(qgetenv("XDG_DATA_DIRS")); - if (xdgDirString.isEmpty()) - xdgDirString = QLatin1String("/usr/local/share/:/usr/share/"); - const auto xdgDirs = xdgDirString.splitRef(QLatin1Char(':')); - for (const QStringRef &xdgDir : xdgDirs) { - const QFileInfo xdgIconsDir(xdgDir + QLatin1String("/icons")); - if (xdgIconsDir.isDir()) - paths.append(xdgIconsDir.absoluteFilePath()); - } + paths.append(QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, + QStringLiteral("icons"), + QStandardPaths::LocateDirectory)); return paths; } diff --git a/src/platformsupport/themes/genericunix/qgenericunixthemes_p.h b/src/platformsupport/themes/genericunix/qgenericunixthemes_p.h index a5963b79ea..c0da9d8370 100644 --- a/src/platformsupport/themes/genericunix/qgenericunixthemes_p.h +++ b/src/platformsupport/themes/genericunix/qgenericunixthemes_p.h @@ -109,7 +109,7 @@ public: QVariant themeHint(ThemeHint hint) const override; QIcon fileIcon(const QFileInfo &fileInfo, - QPlatformTheme::IconOptions iconOptions = 0) const override; + QPlatformTheme::IconOptions iconOptions = nullptr) const override; const QPalette *palette(Palette type = SystemPalette) const override; @@ -134,7 +134,7 @@ public: QGnomeTheme(); QVariant themeHint(ThemeHint hint) const override; QIcon fileIcon(const QFileInfo &fileInfo, - QPlatformTheme::IconOptions = 0) const override; + QPlatformTheme::IconOptions = nullptr) const override; const QFont *font(Font type) const override; QString standardButtonText(int button) const override; diff --git a/src/platformsupport/themes/qabstractfileiconengine.cpp b/src/platformsupport/themes/qabstractfileiconengine.cpp index 192ed00510..c5800d9119 100644 --- a/src/platformsupport/themes/qabstractfileiconengine.cpp +++ b/src/platformsupport/themes/qabstractfileiconengine.cpp @@ -76,7 +76,7 @@ QPixmap QAbstractFileIconEngine::pixmap(const QSize &size, QIcon::Mode mode, key += QLatin1Char('_') + QString::number(size.width()); QPixmap result; - if (!QPixmapCache::find(key, result)) { + if (!QPixmapCache::find(key, &result)) { result = filePixmap(size, mode, state); if (!result.isNull()) QPixmapCache::insert(key, result); diff --git a/src/platformsupport/vkconvenience/qbasicvulkanplatforminstance.cpp b/src/platformsupport/vkconvenience/qbasicvulkanplatforminstance.cpp index b9c5669b3f..68340a3173 100644 --- a/src/platformsupport/vkconvenience/qbasicvulkanplatforminstance.cpp +++ b/src/platformsupport/vkconvenience/qbasicvulkanplatforminstance.cpp @@ -330,6 +330,11 @@ bool QBasicPlatformVulkanInstance::supportsPresent(VkPhysicalDevice physicalDevi return supported; } +void QBasicPlatformVulkanInstance::setDebugFilters(const QVector<QVulkanInstance::DebugFilter> &filters) +{ + m_debugFilters = filters; +} + void QBasicPlatformVulkanInstance::destroySurface(VkSurfaceKHR surface) const { if (m_destroySurface && surface) @@ -345,11 +350,11 @@ static VKAPI_ATTR VkBool32 VKAPI_CALL defaultDebugCallbackFunc(VkDebugReportFlag const char *pMessage, void *pUserData) { - Q_UNUSED(flags); - Q_UNUSED(objectType); - Q_UNUSED(object); - Q_UNUSED(location); - Q_UNUSED(pUserData); + QBasicPlatformVulkanInstance *self = static_cast<QBasicPlatformVulkanInstance *>(pUserData); + for (QVulkanInstance::DebugFilter filter : *self->debugFilters()) { + if (filter(flags, objectType, object, location, messageCode, pLayerPrefix, pMessage)) + return VK_FALSE; + } // not categorized, just route to plain old qDebug qDebug("vkDebug: %s: %d: %s", pLayerPrefix, messageCode, pMessage); @@ -374,6 +379,7 @@ void QBasicPlatformVulkanInstance::setupDebugOutput() | VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT; dbgCallbackInfo.pfnCallback = defaultDebugCallbackFunc; + dbgCallbackInfo.pUserData = this; VkResult err = createDebugReportCallback(m_vkInst, &dbgCallbackInfo, nullptr, &m_debugCallback); if (err != VK_SUCCESS) diff --git a/src/platformsupport/vkconvenience/qbasicvulkanplatforminstance_p.h b/src/platformsupport/vkconvenience/qbasicvulkanplatforminstance_p.h index 566140b032..e59d9219fb 100644 --- a/src/platformsupport/vkconvenience/qbasicvulkanplatforminstance_p.h +++ b/src/platformsupport/vkconvenience/qbasicvulkanplatforminstance_p.h @@ -73,7 +73,10 @@ public: QByteArrayList enabledExtensions() const override; PFN_vkVoidFunction getInstanceProcAddr(const char *name) override; bool supportsPresent(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, QWindow *window) override; + void setDebugFilters(const QVector<QVulkanInstance::DebugFilter> &filters) override; + void destroySurface(VkSurfaceKHR surface) const; + const QVector<QVulkanInstance::DebugFilter> *debugFilters() const { return &m_debugFilters; } protected: void loadVulkanLibrary(const QString &defaultLibraryName); @@ -105,6 +108,7 @@ private: VkDebugReportCallbackEXT m_debugCallback; PFN_vkDestroyDebugReportCallbackEXT m_vkDestroyDebugReportCallbackEXT; + QVector<QVulkanInstance::DebugFilter> m_debugFilters; }; QT_END_NAMESPACE diff --git a/src/platformsupport/vkconvenience/qvkconvenience.cpp b/src/platformsupport/vkconvenience/qvkconvenience.cpp new file mode 100644 index 0000000000..acde1d1bda --- /dev/null +++ b/src/platformsupport/vkconvenience/qvkconvenience.cpp @@ -0,0 +1,217 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qvkconvenience_p.h" + +#include <QOpenGLTexture> + +QT_BEGIN_NAMESPACE + +/*! + \class QVkConvenience + \brief A collection of static helper functions for Vulkan support + \since 5.14 + \internal + \ingroup qpa + */ + +#if QT_CONFIG(opengl) +VkFormat QVkConvenience::vkFormatFromGlFormat(uint glFormat) +{ + using GlFormat = QOpenGLTexture::TextureFormat; + switch (glFormat) { + case GlFormat::NoFormat: return VK_FORMAT_UNDEFINED; // GL_NONE + + // Unsigned normalized formats + case GlFormat::R8_UNorm: return VK_FORMAT_R8_UNORM; // GL_R8 + case GlFormat::RG8_UNorm: return VK_FORMAT_R8G8_UNORM; // GL_RG8 + case GlFormat::RGB8_UNorm: return VK_FORMAT_R8G8B8_UNORM; // GL_RGB8 + case GlFormat::RGBA8_UNorm: return VK_FORMAT_R8G8B8A8_UNORM; // GL_RGBA8 + + case GlFormat::R16_UNorm: return VK_FORMAT_R16_UNORM; // GL_R16 + case GlFormat::RG16_UNorm: return VK_FORMAT_R16G16_UNORM; // GL_RG16 + case GlFormat::RGB16_UNorm: return VK_FORMAT_R16G16B16_UNORM; // GL_RGB16 + case GlFormat::RGBA16_UNorm: return VK_FORMAT_R16G16B16A16_UNORM; // GL_RGBA16 + + // Signed normalized formats + case GlFormat::R8_SNorm: return VK_FORMAT_R8_SNORM; // GL_R8_SNORM + case GlFormat::RG8_SNorm: return VK_FORMAT_R8G8_SNORM; // GL_RG8_SNORM + case GlFormat::RGB8_SNorm: return VK_FORMAT_R8G8B8_SNORM; // GL_RGB8_SNORM + case GlFormat::RGBA8_SNorm: return VK_FORMAT_R8G8B8A8_SNORM; // GL_RGBA8_SNORM + + case GlFormat::R16_SNorm: return VK_FORMAT_R16_SNORM; // GL_R16_SNORM + case GlFormat::RG16_SNorm: return VK_FORMAT_R16G16_SNORM; // GL_RG16_SNORM + case GlFormat::RGB16_SNorm: return VK_FORMAT_R16G16B16_SNORM; // GL_RGB16_SNORM + case GlFormat::RGBA16_SNorm: return VK_FORMAT_R16G16B16A16_SNORM; // GL_RGBA16_SNORM + + // Unsigned integer formats + case GlFormat::R8U: return VK_FORMAT_R8_UINT; // GL_R8UI + case GlFormat::RG8U: return VK_FORMAT_R8G8_UINT; // GL_RG8UI + case GlFormat::RGB8U: return VK_FORMAT_R8G8B8_UINT; // GL_RGB8UI + case GlFormat::RGBA8U: return VK_FORMAT_R8G8B8A8_UINT; // GL_RGBA8UI + + case GlFormat::R16U: return VK_FORMAT_R16_UINT; // GL_R16UI + case GlFormat::RG16U: return VK_FORMAT_R16G16_UINT; // GL_RG16UI + case GlFormat::RGB16U: return VK_FORMAT_R16G16B16_UINT; // GL_RGB16UI + case GlFormat::RGBA16U: return VK_FORMAT_R16G16B16A16_UINT; // GL_RGBA16UI + + case GlFormat::R32U: return VK_FORMAT_R32_UINT; // GL_R32UI + case GlFormat::RG32U: return VK_FORMAT_R32G32_UINT; // GL_RG32UI + case GlFormat::RGB32U: return VK_FORMAT_R32G32B32_UINT; // GL_RGB32UI + case GlFormat::RGBA32U: return VK_FORMAT_R32G32B32A32_UINT; // GL_RGBA32UI + + // Signed integer formats + case GlFormat::R8I: return VK_FORMAT_R8_SINT; // GL_R8I + case GlFormat::RG8I: return VK_FORMAT_R8G8_SINT; // GL_RG8I + case GlFormat::RGB8I: return VK_FORMAT_R8G8B8_SINT; // GL_RGB8I + case GlFormat::RGBA8I: return VK_FORMAT_R8G8B8A8_SINT; // GL_RGBA8I + + case GlFormat::R16I: return VK_FORMAT_R16_SINT; // GL_R16I + case GlFormat::RG16I: return VK_FORMAT_R16G16_SINT; // GL_RG16I + case GlFormat::RGB16I: return VK_FORMAT_R16G16B16_SINT; // GL_RGB16I + case GlFormat::RGBA16I: return VK_FORMAT_R16G16B16A16_SINT; // GL_RGBA16I + + case GlFormat::R32I: return VK_FORMAT_R32_SINT; // GL_R32I + case GlFormat::RG32I: return VK_FORMAT_R32G32_SINT; // GL_RG32I + case GlFormat::RGB32I: return VK_FORMAT_R32G32B32_SINT; // GL_RGB32I + case GlFormat::RGBA32I: return VK_FORMAT_R32G32B32A32_SINT; // GL_RGBA32I + + // Floating point formats + case GlFormat::R16F: return VK_FORMAT_R16_SFLOAT; // GL_R16F + case GlFormat::RG16F: return VK_FORMAT_R16G16_SFLOAT; // GL_RG16F + case GlFormat::RGB16F: return VK_FORMAT_R16G16B16_SFLOAT; // GL_RGB16F + case GlFormat::RGBA16F: return VK_FORMAT_R16G16B16A16_SFLOAT; // GL_RGBA16F + + case GlFormat::R32F: return VK_FORMAT_R32_SFLOAT; // GL_R32F + case GlFormat::RG32F: return VK_FORMAT_R32G32_SFLOAT; // GL_RG32F + case GlFormat::RGB32F: return VK_FORMAT_R32G32B32_SFLOAT; // GL_RGB32F + case GlFormat::RGBA32F: return VK_FORMAT_R32G32B32A32_SFLOAT; // GL_RGBA32F + + // Packed formats + case GlFormat::RGB9E5: return VK_FORMAT_E5B9G9R9_UFLOAT_PACK32; // GL_RGB9_E5 + case GlFormat::RG11B10F: return VK_FORMAT_B10G11R11_UFLOAT_PACK32; // GL_R11F_G11F_B10F +// case GlFormat::RG3B2: return VK_FORMAT_R3_G3_B2; // GL_R3_G3_B2 + case GlFormat::R5G6B5: return VK_FORMAT_R5G6B5_UNORM_PACK16; // GL_RGB565 + case GlFormat::RGB5A1: return VK_FORMAT_R5G5B5A1_UNORM_PACK16; // GL_RGB5_A1 + case GlFormat::RGBA4: return VK_FORMAT_R4G4B4A4_UNORM_PACK16; // GL_RGBA4 + case GlFormat::RGB10A2: return VK_FORMAT_A2R10G10B10_UINT_PACK32; // GL_RGB10_A2UI + + // Depth formats +// case Format::D16: return VK_FORMAT_DEPTH_COMPONENT16; // GL_DEPTH_COMPONENT16 +// case Format::D24: return VK_FORMAT_DEPTH_COMPONENT24; // GL_DEPTH_COMPONENT24 +// case Format::D24S8: return VK_FORMAT_DEPTH24_STENCIL8; // GL_DEPTH24_STENCIL8 +// case Format::D32: return VK_FORMAT_DEPTH_COMPONENT32; // GL_DEPTH_COMPONENT32 +// case Format::D32F: return VK_FORMAT_DEPTH_COMPONENT32F; // GL_DEPTH_COMPONENT32F +// case Format::D32FS8X24: return VK_FORMAT_DEPTH32F_STENCIL8; // GL_DEPTH32F_STENCIL8 +// case Format::S8: return VK_FORMAT_STENCIL_INDEX8; // GL_STENCIL_INDEX8 + + // Compressed formats + case GlFormat::RGB_DXT1: return VK_FORMAT_BC1_RGB_UNORM_BLOCK; // GL_COMPRESSED_RGB_S3TC_DXT1_EXT + case GlFormat::RGBA_DXT1: return VK_FORMAT_BC1_RGBA_UNORM_BLOCK; // GL_COMPRESSED_RGBA_S3TC_DXT1_EXT + case GlFormat::RGBA_DXT3: return VK_FORMAT_BC2_UNORM_BLOCK; // GL_COMPRESSED_RGBA_S3TC_DXT3_EXT + case GlFormat::RGBA_DXT5: return VK_FORMAT_BC3_UNORM_BLOCK; // GL_COMPRESSED_RGBA_S3TC_DXT5_EXT + case GlFormat::R_ATI1N_UNorm: return VK_FORMAT_BC4_UNORM_BLOCK; // GL_COMPRESSED_RED_RGTC1 + case GlFormat::R_ATI1N_SNorm: return VK_FORMAT_BC4_SNORM_BLOCK; // GL_COMPRESSED_SIGNED_RED_RGTC1 + case GlFormat::RG_ATI2N_UNorm: return VK_FORMAT_BC5_UNORM_BLOCK; // GL_COMPRESSED_RG_RGTC2 + case GlFormat::RG_ATI2N_SNorm: return VK_FORMAT_BC5_SNORM_BLOCK; // GL_COMPRESSED_SIGNED_RG_RGTC2 + case GlFormat::RGB_BP_UNSIGNED_FLOAT: return VK_FORMAT_BC6H_UFLOAT_BLOCK; // GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB + case GlFormat::RGB_BP_SIGNED_FLOAT: return VK_FORMAT_BC6H_SFLOAT_BLOCK; // GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB + case GlFormat::RGB_BP_UNorm: return VK_FORMAT_BC7_UNORM_BLOCK; // GL_COMPRESSED_RGBA_BPTC_UNORM_ARB + case GlFormat::R11_EAC_UNorm: return VK_FORMAT_EAC_R11_UNORM_BLOCK; // GL_COMPRESSED_R11_EAC + case GlFormat::R11_EAC_SNorm: return VK_FORMAT_EAC_R11_SNORM_BLOCK; // GL_COMPRESSED_SIGNED_R11_EAC + case GlFormat::RG11_EAC_UNorm: return VK_FORMAT_EAC_R11G11_UNORM_BLOCK; // GL_COMPRESSED_RG11_EAC + case GlFormat::RG11_EAC_SNorm: return VK_FORMAT_EAC_R11G11_SNORM_BLOCK; // GL_COMPRESSED_SIGNED_RG11_EAC + case GlFormat::RGB8_ETC2: return VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK; // GL_COMPRESSED_RGB8_ETC2 + case GlFormat::SRGB8_ETC2: return VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK; // GL_COMPRESSED_SRGB8_ETC2 + case GlFormat::RGB8_PunchThrough_Alpha1_ETC2: return VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK; // GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 + case GlFormat::SRGB8_PunchThrough_Alpha1_ETC2: return VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK; // GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 + case GlFormat::RGBA8_ETC2_EAC: return VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK; // GL_COMPRESSED_RGBA8_ETC2_EAC + case GlFormat::SRGB8_Alpha8_ETC2_EAC: return VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK; // GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC +// case GlFormat::RGB8_ETC1: return VK_FORMAT_ETC1_RGB8_OES; // GL_ETC1_RGB8_OES + case GlFormat::RGBA_ASTC_4x4: return VK_FORMAT_ASTC_4x4_UNORM_BLOCK; // GL_COMPRESSED_RGBA_ASTC_4x4_KHR + case GlFormat::RGBA_ASTC_5x4: return VK_FORMAT_ASTC_5x4_UNORM_BLOCK; // GL_COMPRESSED_RGBA_ASTC_5x4_KHR + case GlFormat::RGBA_ASTC_5x5: return VK_FORMAT_ASTC_5x5_UNORM_BLOCK; // GL_COMPRESSED_RGBA_ASTC_5x5_KHR + case GlFormat::RGBA_ASTC_6x5: return VK_FORMAT_ASTC_6x5_UNORM_BLOCK; // GL_COMPRESSED_RGBA_ASTC_6x5_KHR + case GlFormat::RGBA_ASTC_6x6: return VK_FORMAT_ASTC_6x6_UNORM_BLOCK; // GL_COMPRESSED_RGBA_ASTC_6x6_KHR + case GlFormat::RGBA_ASTC_8x5: return VK_FORMAT_ASTC_8x5_UNORM_BLOCK; // GL_COMPRESSED_RGBA_ASTC_8x5_KHR + case GlFormat::RGBA_ASTC_8x6: return VK_FORMAT_ASTC_8x6_UNORM_BLOCK; // GL_COMPRESSED_RGBA_ASTC_8x6_KHR + case GlFormat::RGBA_ASTC_8x8: return VK_FORMAT_ASTC_8x8_UNORM_BLOCK; // GL_COMPRESSED_RGBA_ASTC_8x8_KHR + case GlFormat::RGBA_ASTC_10x5: return VK_FORMAT_ASTC_10x5_UNORM_BLOCK; // GL_COMPRESSED_RGBA_ASTC_10x5_KHR + case GlFormat::RGBA_ASTC_10x6: return VK_FORMAT_ASTC_10x6_UNORM_BLOCK; // GL_COMPRESSED_RGBA_ASTC_10x6_KHR + case GlFormat::RGBA_ASTC_10x8: return VK_FORMAT_ASTC_10x8_UNORM_BLOCK; // GL_COMPRESSED_RGBA_ASTC_10x8_KHR + case GlFormat::RGBA_ASTC_10x10: return VK_FORMAT_ASTC_10x10_UNORM_BLOCK; // GL_COMPRESSED_RGBA_ASTC_10x10_KHR + case GlFormat::RGBA_ASTC_12x10: return VK_FORMAT_ASTC_12x10_UNORM_BLOCK; // GL_COMPRESSED_RGBA_ASTC_12x10_KHR + case GlFormat::RGBA_ASTC_12x12: return VK_FORMAT_ASTC_12x12_UNORM_BLOCK; // GL_COMPRESSED_RGBA_ASTC_12x12_KHR + case GlFormat::SRGB8_Alpha8_ASTC_4x4: return VK_FORMAT_ASTC_4x4_SRGB_BLOCK; // GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR + case GlFormat::SRGB8_Alpha8_ASTC_5x4: return VK_FORMAT_ASTC_5x4_SRGB_BLOCK; // GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR + case GlFormat::SRGB8_Alpha8_ASTC_5x5: return VK_FORMAT_ASTC_5x5_SRGB_BLOCK; // GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR + case GlFormat::SRGB8_Alpha8_ASTC_6x5: return VK_FORMAT_ASTC_6x5_SRGB_BLOCK; // GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR + case GlFormat::SRGB8_Alpha8_ASTC_6x6: return VK_FORMAT_ASTC_6x6_SRGB_BLOCK; // GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR + case GlFormat::SRGB8_Alpha8_ASTC_8x5: return VK_FORMAT_ASTC_8x5_SRGB_BLOCK; // GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR + case GlFormat::SRGB8_Alpha8_ASTC_8x6: return VK_FORMAT_ASTC_8x6_SRGB_BLOCK; // GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR + case GlFormat::SRGB8_Alpha8_ASTC_8x8: return VK_FORMAT_ASTC_8x8_SRGB_BLOCK; // GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR + case GlFormat::SRGB8_Alpha8_ASTC_10x5: return VK_FORMAT_ASTC_10x5_SRGB_BLOCK; // GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR + case GlFormat::SRGB8_Alpha8_ASTC_10x6: return VK_FORMAT_ASTC_10x6_SRGB_BLOCK; // GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR + case GlFormat::SRGB8_Alpha8_ASTC_10x8: return VK_FORMAT_ASTC_10x8_SRGB_BLOCK; // GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR + case GlFormat::SRGB8_Alpha8_ASTC_10x10: return VK_FORMAT_ASTC_10x10_SRGB_BLOCK; // GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR + case GlFormat::SRGB8_Alpha8_ASTC_12x10: return VK_FORMAT_ASTC_12x10_SRGB_BLOCK; // GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR + case GlFormat::SRGB8_Alpha8_ASTC_12x12: return VK_FORMAT_ASTC_12x12_SRGB_BLOCK; // GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR + + // sRGB formats + case GlFormat::SRGB8: return VK_FORMAT_R8G8B8_SRGB; // GL_SRGB8 + case GlFormat::SRGB8_Alpha8: return VK_FORMAT_R8G8B8A8_SRGB; // GL_SRGB8_ALPHA8 + case GlFormat::SRGB_DXT1: return VK_FORMAT_BC1_RGB_SRGB_BLOCK; // GL_COMPRESSED_SRGB_S3TC_DXT1_EXT + case GlFormat::SRGB_Alpha_DXT1: return VK_FORMAT_BC1_RGBA_SRGB_BLOCK; // GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT + case GlFormat::SRGB_Alpha_DXT3: return VK_FORMAT_BC2_SRGB_BLOCK; // GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT + case GlFormat::SRGB_Alpha_DXT5: return VK_FORMAT_BC3_SRGB_BLOCK; // GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT + case GlFormat::SRGB_BP_UNorm: return VK_FORMAT_BC7_SRGB_BLOCK; // GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB + + // ES 2 formats +// case GlFormat::DepthFormat: return VK_FORMAT_DEPTH_COMPONENT; // GL_DEPTH_COMPONENT +// case GlFormat::AlphaFormat: return VK_FORMAT_ALPHA; // GL_ALPHA +// case GlFormat::RGBFormat: return VK_FORMAT_RGB; // GL_RGB +// case GlFormat::RGBAFormat: return VK_FORMAT_RGBA; // GL_RGBA +// case GlFormat::LuminanceFormat: return VK_FORMAT_LUMINANCE; // GL_LUMINANCE +// case GlFormat::LuminanceAlphaFormat: return VK_FORMAT; + default: return VK_FORMAT_UNDEFINED; + } +} +#endif + +QT_END_NAMESPACE diff --git a/src/platformsupport/vkconvenience/qvkconvenience_p.h b/src/platformsupport/vkconvenience/qvkconvenience_p.h new file mode 100644 index 0000000000..580271b593 --- /dev/null +++ b/src/platformsupport/vkconvenience/qvkconvenience_p.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QVKCONVENIENCE_P_H +#define QVKCONVENIENCE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QtCore/qglobal.h> +#include <qvulkaninstance.h> + +QT_BEGIN_NAMESPACE + +class QVkConvenience +{ +public: +#if QT_CONFIG(opengl) + static VkFormat vkFormatFromGlFormat(uint glFormat); +#endif +}; + +QT_END_NAMESPACE + +#endif // QVKCONVENIENCE_P_H diff --git a/src/platformsupport/vkconvenience/vkconvenience.pro b/src/platformsupport/vkconvenience/vkconvenience.pro index 7a4cdb041d..ee540024cf 100644 --- a/src/platformsupport/vkconvenience/vkconvenience.pro +++ b/src/platformsupport/vkconvenience/vkconvenience.pro @@ -8,9 +8,11 @@ DEFINES += QT_NO_CAST_FROM_ASCII PRECOMPILED_HEADER = ../../corelib/global/qt_pch.h SOURCES += \ + qvkconvenience.cpp \ qbasicvulkanplatforminstance.cpp HEADERS += \ + qvkconvenience_p.h \ qbasicvulkanplatforminstance_p.h load(qt_module) |