From f2faf5dac32f44a25b092c6660f2aa1ba511c3cd Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <2546789017@qq.com> Date: Wed, 20 Apr 2022 15:26:25 +0800 Subject: [PATCH] linux: minor improvements Signed-off-by: Yuhang Zhao <2546789017@qq.com> --- src/core/CMakeLists.txt | 7 ++++--- src/core/framelesswindowsmanager.cpp | 2 +- src/core/qtx11extras.cpp | 26 +++++++++++++++++++++----- src/core/qtx11extras_p.h | 18 +++++++++--------- src/widgets/framelesswidgetshelper.cpp | 2 ++ 5 files changed, 37 insertions(+), 18 deletions(-) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 1be7be6..e686593 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -23,8 +23,9 @@ ]] if(UNIX AND NOT APPLE) - find_package(GTK3 REQUIRED) + find_package(PkgConfig REQUIRED) find_package(X11 REQUIRED) + pkg_search_module(GTK3 REQUIRED gtk+-3.0) endif() set(SUB_PROJ_NAME FramelessHelperCore) @@ -117,11 +118,11 @@ if(UNIX AND NOT APPLE) GDK_VERSION_MIN_REQUIRED=GDK_VERSION_3_6 ) target_link_libraries(${SUB_PROJ_NAME} PRIVATE - PkgConfig::GTK3 + ${GTK3_LIBRARIES} X11::X11 ) target_include_directories(${SUB_PROJ_NAME} PRIVATE - "/usr/include/harfbuzz" # GCC complains about can't find "hb.h". Why do we need this? + ${GTK3_INCLUDE_DIRS} ) endif() diff --git a/src/core/framelesswindowsmanager.cpp b/src/core/framelesswindowsmanager.cpp index e8ed451..bc4d852 100644 --- a/src/core/framelesswindowsmanager.cpp +++ b/src/core/framelesswindowsmanager.cpp @@ -275,12 +275,12 @@ void FramelessHelper::Core::initialize(const Options options) // and resize by yourself. Utils::tryToEnableHighestDpiAwarenessLevel(); } -#endif if (!(options & Option::DontEnsureNonNativeWidgetSiblings)) { // This attribute is known to be __NOT__ compatible with QGLWidget. // Please consider migrating to the recommended QOpenGLWidget instead. QCoreApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings); } +#endif #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) if (!(options & Option::DontTouchHighDpiScalingPolicy)) { // Enable high DPI scaling by default, but only for Qt5 applications, diff --git a/src/core/qtx11extras.cpp b/src/core/qtx11extras.cpp index 9ec4e7e..696d666 100644 --- a/src/core/qtx11extras.cpp +++ b/src/core/qtx11extras.cpp @@ -40,30 +40,42 @@ ****************************************************************************/ #include "qtx11extras_p.h" -#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) +#if (QT_VERSION < QT_VERSION_CHECK(6, 2, 0)) #include #include #include #include #include #include -#include -#include -#include +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) +# include +# include +#else +# include +#endif QT_BEGIN_NAMESPACE [[nodiscard]] static inline QScreen *findScreenForVirtualDesktop(const int virtualDesktopNumber) { + if (virtualDesktopNumber == -1) { + return QGuiApplication::primaryScreen(); + } const QList screens = QGuiApplication::screens(); if (screens.isEmpty()) { return nullptr; } for (auto &&screen : qAsConst(screens)) { +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) const auto qxcbScreen = dynamic_cast(screen->handle()); if (qxcbScreen && (qxcbScreen->virtualDesktopNumber() == virtualDesktopNumber)) { return screen; } +#else + if (QXcbScreenFunctions::virtualDesktopNumber(screen) == virtualDesktopNumber) { + return screen; + } +#endif } return nullptr; } @@ -169,7 +181,11 @@ int QX11Info::appDpiY(const int screen) multiscreen), there is only one X screen. Use QDesktopWidget to query for information about Xinerama screens. */ +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) +unsigned long QX11Info::appRootWindow(const int screen) +#else quint32 QX11Info::appRootWindow(const int screen) +#endif { if (!qApp) return 0; @@ -556,4 +572,4 @@ bool QX11Info::peekEventQueue(PeekerCallback peeker, void *peekerData, QT_END_NAMESPACE -#endif // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) +#endif // (QT_VERSION < QT_VERSION_CHECK(6, 2, 0)) diff --git a/src/core/qtx11extras_p.h b/src/core/qtx11extras_p.h index c595f59..79d9060 100644 --- a/src/core/qtx11extras_p.h +++ b/src/core/qtx11extras_p.h @@ -51,15 +51,10 @@ // #include "framelesshelpercore_global.h" -#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) +#if (QT_VERSION >= QT_VERSION_CHECK(6, 2, 0)) #include -#else // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) -#include -#include - -struct xcb_connection_t; -struct xcb_generic_event_t; -struct _XDisplay; +#else // (QT_VERSION >= QT_VERSION_CHECK(6, 2, 0)) +#include using Display = struct _XDisplay; @@ -67,6 +62,7 @@ QT_BEGIN_NAMESPACE class FRAMELESSHELPER_CORE_API QX11Info { + Q_GADGET Q_DISABLE_COPY_MOVE(QX11Info) public: @@ -84,7 +80,11 @@ public: [[nodiscard]] static int appDpiX(const int screen = -1); [[nodiscard]] static int appDpiY(const int screen = -1); +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) + [[nodiscard]] static unsigned long appRootWindow(const int screen = -1); +#else [[nodiscard]] static quint32 appRootWindow(const int screen = -1); +#endif [[nodiscard]] static int appScreen(); [[nodiscard]] static quint32 appTime(); @@ -119,4 +119,4 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(QX11Info::PeekOptions) QT_END_NAMESPACE -#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) +#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 2, 0)) diff --git a/src/widgets/framelesswidgetshelper.cpp b/src/widgets/framelesswidgetshelper.cpp index a9cb01a..442cedb 100644 --- a/src/widgets/framelesswidgetshelper.cpp +++ b/src/widgets/framelesswidgetshelper.cpp @@ -352,6 +352,7 @@ void FramelessWidgetsHelper::initialize() m_initialized = true; // Let the user be able to get the helper class instance from outside. q->setProperty(FRAMELESSHELPER_PROP_NAME, QVariant::fromValue(this)); +#ifdef Q_OS_WINDOWS // Without this flag, Qt will always create an invisible native parent window // for any native widgets which will intercept some win32 messages and confuse // our own native event filter, so to prevent some weired bugs from happening, @@ -360,6 +361,7 @@ void FramelessWidgetsHelper::initialize() // Force the widget become a native window now so that we can deal with its // win32 events as soon as possible. q->setAttribute(Qt::WA_NativeWindow); +#endif m_params.getWindowId = [this]() -> WId { return q->winId(); }; m_params.getWindowFlags = [this]() -> Qt::WindowFlags { return q->windowFlags(); }; m_params.setWindowFlags = [this](const Qt::WindowFlags flags) -> void { q->setWindowFlags(flags); };