Minor tweaks

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2021-03-09 11:32:30 +08:00
parent 21f1f69684
commit 44ed5fcf3d
4 changed files with 40 additions and 72 deletions

View File

@ -58,46 +58,18 @@
#define qAsConst(i) std::as_const(i)
#endif
#ifndef _flh_framelessMode_flag
#define _flh_framelessMode_flag "_FRAMELESSHELPER_FRAMELESS_MODE_ENABLED"
#endif
namespace _flh_global {
#ifndef _flh_borderWidth_flag
#define _flh_borderWidth_flag "_FRAMELESSHELPER_WINDOW_BORDER_WIDTH"
#endif
[[maybe_unused]] const char _flh_framelessMode_flag[] = "_FRAMELESSHELPER_FRAMELESS_MODE_ENABLED";
[[maybe_unused]] const char _flh_borderWidth_flag[] = "_FRAMELESSHELPER_WINDOW_BORDER_WIDTH";
[[maybe_unused]] const char _flh_borderHeight_flag[] = "_FRAMELESSHELPER_WINDOW_BORDER_HEIGHT";
[[maybe_unused]] const char _flh_titleBarHeight_flag[] = "_FRAMELESSHELPER_WINDOW_TITLE_BAR_HEIGHT";
[[maybe_unused]] const char _flh_ignoredObjects_flag[] = "_FRAMELESSHELPER_WINDOW_TITLE_BAR_IGNORED_OBJECTS";
[[maybe_unused]] const char _flh_acrylic_forceOfficialMSWin10Blur_flag[] = "_FRAMELESSHELPER_FORCE_MSWIN10_OFFICIAL_ACRYLIC";
[[maybe_unused]] const char _flh_acrylic_forceDWMBlur_flag[] = "_FRAMELESSHELPER_FORCE_DWM_BLUR";
[[maybe_unused]] const char _flh_acrylic_forceDisableWallpaperBlur_flag[] = "_FRAMELESSHELPER_FORCE_DISABLE_WALLPAPER_BLUR";
[[maybe_unused]] const char _flh_useNativeTitleBar_flag[] = "_FRAMELESSHELPER_USE_NATIVE_TITLE_BAR";
[[maybe_unused]] const char _flh_preserveNativeFrame_flag[] = "_FRAMELESSHELPER_PRESERVE_NATIVE_WINDOW_FRAME";
[[maybe_unused]] const char _flh_forcePreserveNativeFrame_flag[] = "_FRAMELESSHELPER_FORCE_PRESERVE_NATIVE_WINDOW_FRAME";
#ifndef _flh_borderHeight_flag
#define _flh_borderHeight_flag "_FRAMELESSHELPER_WINDOW_BORDER_HEIGHT"
#endif
#ifndef _flh_titleBarHeight_flag
#define _flh_titleBarHeight_flag "_FRAMELESSHELPER_WINDOW_TITLE_BAR_HEIGHT"
#endif
#ifndef _flh_ignoredObjects_flag
#define _flh_ignoredObjects_flag "_FRAMELESSHELPER_WINDOW_TITLE_BAR_IGNORED_OBJECTS"
#endif
#ifndef _flh_acrylic_forceOfficialMSWin10Blur_flag
#define _flh_acrylic_forceOfficialMSWin10Blur_flag "_FRAMELESSHELPER_FORCE_MSWIN10_OFFICIAL_ACRYLIC"
#endif
#ifndef _flh_acrylic_forceDWMBlur_flag
#define _flh_acrylic_forceDWMBlur_flag "_FRAMELESSHELPER_FORCE_DWM_BLUR"
#endif
#ifndef _flh_acrylic_forceDisableWallpaperBlur_flag
#define _flh_acrylic_forceDisableWallpaperBlur_flag "_FRAMELESSHELPER_FORCE_DISABLE_WALLPAPER_BLUR"
#endif
#ifndef _flh_useNativeTitleBar_flag
#define _flh_useNativeTitleBar_flag "_FRAMELESSHELPER_USE_NATIVE_TITLE_BAR"
#endif
#ifndef _flh_preserveNativeFrame_flag
#define _flh_preserveNativeFrame_flag "_FRAMELESSHELPER_PRESERVE_NATIVE_WINDOW_FRAME"
#endif
#ifndef _flh_forcePreserveNativeFrame_flag
#define _flh_forcePreserveNativeFrame_flag "_FRAMELESSHELPER_FORCE_PRESERVE_NATIVE_WINDOW_FRAME"
#endif
}

View File

@ -76,7 +76,7 @@
static inline bool shouldUseNativeTitleBar()
{
return qEnvironmentVariableIsSet(_flh_useNativeTitleBar_flag);
return qEnvironmentVariableIsSet(_flh_global::_flh_useNativeTitleBar_flag);
}
static inline bool shouldHaveWindowFrame()
@ -86,8 +86,8 @@ static inline bool shouldHaveWindowFrame()
// want to use the native title bar.
return true;
}
const bool should = qEnvironmentVariableIsSet(_flh_preserveNativeFrame_flag);
const bool force = qEnvironmentVariableIsSet(_flh_forcePreserveNativeFrame_flag);
const bool should = qEnvironmentVariableIsSet(_flh_global::_flh_preserveNativeFrame_flag);
const bool force = qEnvironmentVariableIsSet(_flh_global::_flh_forcePreserveNativeFrame_flag);
if (should || force) {
if (force) {
return true;
@ -121,7 +121,7 @@ static inline void installHelper(QWindow *window, const bool enable)
if (!window) {
return;
}
window->setProperty(_flh_framelessMode_flag, enable);
window->setProperty(_flh_global::_flh_framelessMode_flag, enable);
Utilities::updateQtFrameMargins(window, enable);
Utilities::updateFrameMargins(window, !enable);
Utilities::triggerFrameChange(window);
@ -149,7 +149,7 @@ bool FramelessHelperWin::isWindowFrameless(const QWindow *window)
if (!window) {
return false;
}
return window->property(_flh_framelessMode_flag).toBool();
return window->property(_flh_global::_flh_framelessMode_flag).toBool();
}
void FramelessHelperWin::removeFramelessWindow(QWindow *window)
@ -167,7 +167,7 @@ void FramelessHelperWin::setIgnoredObjects(QWindow *window, const QObjectList &o
if (!window) {
return;
}
window->setProperty(_flh_ignoredObjects_flag, QVariant::fromValue(objects));
window->setProperty(_flh_global::_flh_ignoredObjects_flag, QVariant::fromValue(objects));
}
QObjectList FramelessHelperWin::getIgnoredObjects(const QWindow *window)
@ -176,7 +176,7 @@ QObjectList FramelessHelperWin::getIgnoredObjects(const QWindow *window)
if (!window) {
return {};
}
return qvariant_cast<QObjectList>(window->property(_flh_ignoredObjects_flag));
return qvariant_cast<QObjectList>(window->property(_flh_global::_flh_ignoredObjects_flag));
}
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
@ -211,7 +211,7 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
return false;
}
const QWindow *window = Utilities::findWindow(reinterpret_cast<WId>(msg->hwnd));
if (!window || (window && !window->property(_flh_framelessMode_flag).toBool())) {
if (!window || (window && !window->property(_flh_global::_flh_framelessMode_flag).toBool())) {
return false;
}
switch (msg->message) {
@ -592,11 +592,8 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
const QPointF globalMouse = QCursor::pos(window->screen()) * dpr;
POINT winLocalMouse = {qRound(globalMouse.x()), qRound(globalMouse.y())};
ScreenToClient(msg->hwnd, &winLocalMouse);
const QPointF localMouse = {static_cast<qreal>(winLocalMouse.x),
static_cast<qreal>(winLocalMouse.y)};
const bool isInIgnoreObjects = isInSpecificObjects(globalMouse,
qvariant_cast<QObjectList>(window->property(_flh_ignoredObjects_flag)),
dpr);
const QPointF localMouse = {static_cast<qreal>(winLocalMouse.x), static_cast<qreal>(winLocalMouse.y)};
const bool isInIgnoreObjects = isInSpecificObjects(globalMouse, qvariant_cast<QObjectList>(window->property(_flh_global::_flh_ignoredObjects_flag)), dpr);
const int bh = getSystemMetric(window, Utilities::SystemMetric::BorderHeight, true);
const int tbh = getSystemMetric(window, Utilities::SystemMetric::TitleBarHeight, true);
const bool isTitleBar = (localMouse.y() <= tbh) && !isInIgnoreObjects;
@ -723,7 +720,7 @@ void FramelessHelperWin::setBorderWidth(QWindow *window, const int bw)
if (!window) {
return;
}
window->setProperty(_flh_borderWidth_flag, bw);
window->setProperty(_flh_global::_flh_borderWidth_flag, bw);
}
void FramelessHelperWin::setBorderHeight(QWindow *window, const int bh)
@ -732,7 +729,7 @@ void FramelessHelperWin::setBorderHeight(QWindow *window, const int bh)
if (!window) {
return;
}
window->setProperty(_flh_borderHeight_flag, bh);
window->setProperty(_flh_global::_flh_borderHeight_flag, bh);
}
void FramelessHelperWin::setTitleBarHeight(QWindow *window, const int tbh)
@ -741,5 +738,5 @@ void FramelessHelperWin::setTitleBarHeight(QWindow *window, const int tbh)
if (!window) {
return;
}
window->setProperty(_flh_titleBarHeight_flag, tbh);
window->setProperty(_flh_global::_flh_titleBarHeight_flag, tbh);
}

View File

@ -417,17 +417,17 @@ bool Utilities::isWin10OrGreater(const int subVer)
static inline bool forceEnableDwmBlur()
{
return qEnvironmentVariableIsSet(_flh_acrylic_forceDWMBlur_flag);
return qEnvironmentVariableIsSet(_flh_global::_flh_acrylic_forceDWMBlur_flag);
}
static inline bool forceDisableWallpaperBlur()
{
return qEnvironmentVariableIsSet(_flh_acrylic_forceDisableWallpaperBlur_flag);
return qEnvironmentVariableIsSet(_flh_global::_flh_acrylic_forceDisableWallpaperBlur_flag);
}
static inline bool forceEnableOfficialMSWin10AcrylicBlur()
{
return qEnvironmentVariableIsSet(_flh_acrylic_forceOfficialMSWin10Blur_flag);
return qEnvironmentVariableIsSet(_flh_global::_flh_acrylic_forceOfficialMSWin10Blur_flag);
}
bool Utilities::isMSWin10AcrylicEffectAvailable()
@ -517,12 +517,3 @@ QRect Utilities::getScreenAvailableGeometry()
{
return QGuiApplication::primaryScreen()->availableGeometry();
}
QColor Utilities::getNativeWindowFrameColor(const bool isActive)
{
if (!isActive) {
return Qt::darkGray;
}
// TODO: what about Linux and macOS?
return isWin10OrGreater() ? getColorizationColor() : Qt::black;
}

View File

@ -220,7 +220,7 @@ int Utilities::getSystemMetric(const QWindow *window, const SystemMetric metric,
int ret = 0;
switch (metric) {
case SystemMetric::BorderWidth: {
const int bw = window->property(_flh_borderWidth_flag).toInt();
const int bw = window->property(_flh_global::_flh_borderWidth_flag).toInt();
if ((bw > 0) && !forceSystemValue) {
ret = qRound(bw * dpr);
} else {
@ -233,7 +233,7 @@ int Utilities::getSystemMetric(const QWindow *window, const SystemMetric metric,
}
} break;
case SystemMetric::BorderHeight: {
const int bh = window->property(_flh_borderHeight_flag).toInt();
const int bh = window->property(_flh_global::_flh_borderHeight_flag).toInt();
if ((bh > 0) && !forceSystemValue) {
ret = qRound(bh * dpr);
} else {
@ -246,7 +246,7 @@ int Utilities::getSystemMetric(const QWindow *window, const SystemMetric metric,
}
} break;
case SystemMetric::TitleBarHeight: {
const int tbh = window->property(_flh_titleBarHeight_flag).toInt();
const int tbh = window->property(_flh_global::_flh_titleBarHeight_flag).toInt();
if ((tbh > 0) && !forceSystemValue) {
// Special case: this is the user defined value,
// don't change it and just return it untouched.
@ -531,3 +531,11 @@ QMargins Utilities::getWindowNativeFrameMargins(const QWindow *window)
}
return {qAbs(rect.left), qAbs(rect.top), qAbs(rect.right), qAbs(rect.bottom)};
}
QColor Utilities::getNativeWindowFrameColor(const bool isActive)
{
if (!isActive) {
return Qt::darkGray;
}
return (isWin10OrGreater() && isColorizationEnabled()) ? getColorizationColor() : (isDarkThemeEnabled() ? Qt::white : Qt::black);
}