linux: minor improvements

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2022-04-20 15:26:25 +08:00
parent b5eebada2c
commit f2faf5dac3
5 changed files with 37 additions and 18 deletions

View File

@ -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()

View File

@ -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,

View File

@ -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 <QtCore/qdebug.h>
#include <QtGui/qscreen.h>
#include <QtGui/qwindow.h>
#include <QtGui/qguiapplication.h>
#include <QtGui/qpa/qplatformnativeinterface.h>
#include <QtGui/qpa/qplatformwindow.h>
#include <QtGui/qpa/qplatformscreen_p.h>
#include <QtGui/qpa/qplatformscreen.h>
#include <xcb/xcb.h>
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
# include <QtGui/qpa/qplatformscreen_p.h>
# include <QtGui/qpa/qplatformscreen.h>
#else
# include <QtPlatformHeaders/qxcbscreenfunctions.h>
#endif
QT_BEGIN_NAMESPACE
[[nodiscard]] static inline QScreen *findScreenForVirtualDesktop(const int virtualDesktopNumber)
{
if (virtualDesktopNumber == -1) {
return QGuiApplication::primaryScreen();
}
const QList<QScreen *> 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<QNativeInterface::Private::QXcbScreen *>(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))

View File

@ -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 <QtGui/private/qtx11extras_p.h>
#else // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
#include <QtCore/private/qglobal_p.h>
#include <QtGui/qtguiglobal.h>
struct xcb_connection_t;
struct xcb_generic_event_t;
struct _XDisplay;
#else // (QT_VERSION >= QT_VERSION_CHECK(6, 2, 0))
#include <xcb/xcb.h>
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))

View File

@ -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); };