Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2022-03-21 13:52:10 +08:00
parent 6676a3c1f9
commit ebd69353a0
5 changed files with 29 additions and 16 deletions

View File

@ -86,9 +86,6 @@ void FramelessHelperWin::addWindow(QWindow *window)
if (!(options & Option::DontTouchQtInternals)) {
Utils::fixupQtInternals(winId);
}
if (!(options & Option::DontTweakDpiAwarenessLevel)) {
Utils::tryToEnableHighestDpiAwarenessLevel(winId);
}
Utils::updateInternalWindowFrameMargins(window, true);
Utils::updateWindowFrameMargins(winId, false);
if (!(options & Option::DontTouchWindowFrameBorderColor)) {

View File

@ -113,6 +113,11 @@ Q_NAMESPACE_EXPORT(FRAMELESSHELPER_CORE_API)
[[maybe_unused]] static constexpr const char kForceHideFrameBorderFlag[] = "FRAMELESSHELPER_FORCE_HIDE_FRAME_BORDER";
[[maybe_unused]] static constexpr const char kForceShowFrameBorderFlag[] = "FRAMELESSHELPER_FORCE_SHOW_FRAME_BORDER";
[[maybe_unused]] static const QString kConfigFileName = QStringLiteral(".framelesshelper.ini");
[[maybe_unused]] static const QString kUsePureQtImplKeyPath = QStringLiteral("Options/UsePureQtImplementation");
[[maybe_unused]] static const QString kForceHideFrameBorderKeyPath = QStringLiteral("Options/ForceHideFrameBorder");
[[maybe_unused]] static const QString kForceShowFrameBorderKeyPath = QStringLiteral("Options/ForceShowFrameBorder");
enum class Option : int
{
Default = 0x00000000, // Default placeholder, have no effect.
@ -131,8 +136,7 @@ enum class Option : int
NoDoubleClickMaximizeToggle = 0x00001000, // Don't toggle the maximize state when double clicks the titlebar.
DisableResizing = 0x00002000, // Disable resizing of the window.
DisableDragging = 0x00004000, // Disable dragging through the titlebar of the window.
DontTouchCursorShape = 0x00008000, // Don't change the cursor shape while the mouse is hovering above the window.
DontTweakDpiAwarenessLevel = 0x00010000 // Windows only, don't tweak the DPI awareness level of the window / process.
DontTouchCursorShape = 0x00008000 // Don't change the cursor shape while the mouse is hovering above the window.
};
Q_DECLARE_FLAGS(Options, Option)
Q_FLAG_NS(Options)

View File

@ -25,6 +25,8 @@
#include "framelesswindowsmanager.h"
#include "framelesswindowsmanager_p.h"
#include <QtCore/qvariant.h>
#include <QtCore/qsettings.h>
#include <QtCore/qcoreapplication.h>
#include <QtGui/qscreen.h>
#include <QtGui/qwindow.h>
#include "framelesshelper_qt.h"
@ -59,7 +61,14 @@ FramelessWindowsManagerPrivate *FramelessWindowsManagerPrivate::get(FramelessWin
bool FramelessWindowsManagerPrivate::usePureQtImplementation() const
{
#ifdef Q_OS_WINDOWS
static const bool result = (qEnvironmentVariableIntValue(kUsePureQtImplFlag) != 0);
static const bool result = []() -> bool {
if (qEnvironmentVariableIntValue(kUsePureQtImplFlag) != 0) {
return true;
}
const QString iniFilePath = QCoreApplication::applicationDirPath() + u'/' + kConfigFileName;
QSettings settings(iniFilePath, QSettings::IniFormat);
return settings.value(kUsePureQtImplKeyPath, false).toBool();
}();
#else
static constexpr const bool result = true;
#endif

View File

@ -113,7 +113,6 @@ FRAMELESSHELPER_CORE_API void fixupQtInternals(const WId winId);
FRAMELESSHELPER_CORE_API void installSystemMenuHook(const WId winId);
FRAMELESSHELPER_CORE_API void uninstallSystemMenuHook(const WId winId);
FRAMELESSHELPER_CORE_API void tryToBeCompatibleWithQtFramelessWindowHint(QWindow *window, const bool enable);
FRAMELESSHELPER_CORE_API void tryToEnableHighestDpiAwarenessLevel(const WId winId);
#endif // Q_OS_WINDOWS
} // namespace Utils

View File

@ -26,6 +26,7 @@
#include <QtCore/qdebug.h>
#include <QtCore/qmutex.h>
#include <QtCore/qhash.h>
#include <QtCore/qsettings.h>
#include <QtGui/qguiapplication.h>
#include <QtCore/private/qsystemlibrary_p.h>
#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))
@ -975,7 +976,18 @@ bool Utils::isWindowFrameBorderVisible()
if (qEnvironmentVariableIntValue(kForceShowFrameBorderFlag) != 0) {
return true;
}
return (isWin10OrGreater() && !qEnvironmentVariableIsSet(kForceHideFrameBorderFlag));
if (qEnvironmentVariableIntValue(kForceHideFrameBorderFlag) != 0) {
return false;
}
const QString iniFilePath = QCoreApplication::applicationDirPath() + u'/' + kConfigFileName;
QSettings settings(iniFilePath, QSettings::IniFormat);
if (settings.value(kForceShowFrameBorderKeyPath, false).toBool()) {
return true;
}
if (settings.value(kForceHideFrameBorderKeyPath, false).toBool()) {
return false;
}
return isWin10OrGreater();
}();
return result;
}
@ -1080,12 +1092,4 @@ void Utils::tryToBeCompatibleWithQtFramelessWindowHint(QWindow *window, const bo
triggerFrameChange(winId);
}
void Utils::tryToEnableHighestDpiAwarenessLevel(const WId winId)
{
Q_ASSERT(winId);
if (!winId) {
return;
}
}
FRAMELESSHELPER_END_NAMESPACE