forked from github_mirror/framelesshelper
Minor tweaks.
Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
parent
f597b64f46
commit
c783bc1fe2
|
@ -66,7 +66,7 @@ WinNativeEventFilter::addFramelessWindow(&widget, &data);
|
|||
// Or
|
||||
WinNativeEventFilter::setWindowData(&widget, &data);
|
||||
// Or modify the window data of a specific window directly:
|
||||
const auto data = WinNativeEventFilter::windowData(&widget);
|
||||
const auto data = WinNativeEventFilter::getWindowData(&widget);
|
||||
if (data) {
|
||||
data->borderWidth = 5;
|
||||
data->borderHeight = 5;
|
||||
|
|
|
@ -313,18 +313,18 @@ bool Widget::shouldDrawBorder(const bool ignoreWindowState) const
|
|||
|
||||
bool Widget::shouldDrawThemedBorder(const bool ignoreWindowState) const
|
||||
{
|
||||
return (shouldDrawBorder(ignoreWindowState) && WinNativeEventFilter::colorizationEnabled());
|
||||
return (shouldDrawBorder(ignoreWindowState) && WinNativeEventFilter::isColorizationEnabled());
|
||||
}
|
||||
|
||||
bool Widget::shouldDrawThemedTitleBar() const
|
||||
{
|
||||
return m_bIsWin10OrGreater && WinNativeEventFilter::colorizationEnabled();
|
||||
return m_bIsWin10OrGreater && WinNativeEventFilter::isColorizationEnabled();
|
||||
}
|
||||
|
||||
QColor Widget::activeBorderColor()
|
||||
{
|
||||
return WinNativeEventFilter::colorizationEnabled() ? g_cColorizationColor
|
||||
: g_cDefaultActiveBorderColor;
|
||||
return WinNativeEventFilter::isColorizationEnabled() ? g_cColorizationColor
|
||||
: g_cDefaultActiveBorderColor;
|
||||
}
|
||||
|
||||
QColor Widget::inactiveBorderColor()
|
||||
|
@ -583,7 +583,7 @@ void Widget::setupConnections()
|
|||
}
|
||||
WinNativeEventFilter::setBlurEffectEnabled(rawHandle(), enable, color);
|
||||
updateWindow();
|
||||
if (useAcrylicEffect && enable && WinNativeEventFilter::transparencyEffectEnabled()) {
|
||||
if (useAcrylicEffect && enable && WinNativeEventFilter::isTransparencyEffectEnabled()) {
|
||||
QMessageBox::warning(this,
|
||||
tr("BUG Warning!"),
|
||||
tr("You have enabled the transparency effect in the personalize "
|
||||
|
@ -630,7 +630,7 @@ void Widget::initializeVariables()
|
|||
m_bIsWin10OrGreater = isWin10OrGreater();
|
||||
if (m_bIsWin10OrGreater) {
|
||||
m_bCanAcrylicBeEnabled = isWin10OrGreater(g_vAcrylicEffectVersion);
|
||||
g_cColorizationColor = WinNativeEventFilter::colorizationColor();
|
||||
g_cColorizationColor = WinNativeEventFilter::getColorizationColor();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -111,37 +111,37 @@ bool FramelessQuickHelper::canHaveWindowFrame() const
|
|||
|
||||
bool FramelessQuickHelper::colorizationEnabled() const
|
||||
{
|
||||
return WinNativeEventFilter::colorizationEnabled();
|
||||
return WinNativeEventFilter::isColorizationEnabled();
|
||||
}
|
||||
|
||||
QColor FramelessQuickHelper::colorizationColor() const
|
||||
{
|
||||
return WinNativeEventFilter::colorizationColor();
|
||||
return WinNativeEventFilter::getColorizationColor();
|
||||
}
|
||||
|
||||
bool FramelessQuickHelper::lightThemeEnabled() const
|
||||
{
|
||||
return WinNativeEventFilter::lightThemeEnabled();
|
||||
return WinNativeEventFilter::isLightThemeEnabled();
|
||||
}
|
||||
|
||||
bool FramelessQuickHelper::darkThemeEnabled() const
|
||||
{
|
||||
return WinNativeEventFilter::darkThemeEnabled();
|
||||
return WinNativeEventFilter::isDarkThemeEnabled();
|
||||
}
|
||||
|
||||
bool FramelessQuickHelper::highContrastModeEnabled() const
|
||||
{
|
||||
return WinNativeEventFilter::highContrastModeEnabled();
|
||||
return WinNativeEventFilter::isHighContrastModeEnabled();
|
||||
}
|
||||
|
||||
bool FramelessQuickHelper::darkFrameEnabled() const
|
||||
{
|
||||
return WinNativeEventFilter::darkFrameEnabled(rawHandle());
|
||||
return WinNativeEventFilter::isDarkFrameEnabled(rawHandle());
|
||||
}
|
||||
|
||||
bool FramelessQuickHelper::transparencyEffectEnabled() const
|
||||
{
|
||||
return WinNativeEventFilter::transparencyEffectEnabled();
|
||||
return WinNativeEventFilter::isTransparencyEffectEnabled();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -201,7 +201,7 @@ void FramelessWindowsManager::addIgnoreArea(QObject *window, const QRect &area)
|
|||
{
|
||||
Q_ASSERT(window);
|
||||
#ifdef Q_OS_WINDOWS
|
||||
const auto data = WinNativeEventFilter::windowData(window);
|
||||
const auto data = WinNativeEventFilter::getWindowData(window);
|
||||
if (data) {
|
||||
data->ignoreAreas.append(area);
|
||||
}
|
||||
|
@ -214,7 +214,7 @@ void FramelessWindowsManager::addDraggableArea(QObject *window, const QRect &are
|
|||
{
|
||||
Q_ASSERT(window);
|
||||
#ifdef Q_OS_WINDOWS
|
||||
const auto data = WinNativeEventFilter::windowData(window);
|
||||
const auto data = WinNativeEventFilter::getWindowData(window);
|
||||
if (data) {
|
||||
data->draggableAreas.append(area);
|
||||
}
|
||||
|
@ -227,7 +227,7 @@ void FramelessWindowsManager::addIgnoreObject(QObject *window, QObject *object)
|
|||
{
|
||||
Q_ASSERT(window);
|
||||
#ifdef Q_OS_WINDOWS
|
||||
const auto data = WinNativeEventFilter::windowData(window);
|
||||
const auto data = WinNativeEventFilter::getWindowData(window);
|
||||
if (data) {
|
||||
data->ignoreObjects.append(object);
|
||||
}
|
||||
|
@ -240,7 +240,7 @@ void FramelessWindowsManager::addDraggableObject(QObject *window, QObject *objec
|
|||
{
|
||||
Q_ASSERT(window);
|
||||
#ifdef Q_OS_WINDOWS
|
||||
const auto data = WinNativeEventFilter::windowData(window);
|
||||
const auto data = WinNativeEventFilter::getWindowData(window);
|
||||
if (data) {
|
||||
data->draggableObjects.append(object);
|
||||
}
|
||||
|
@ -265,7 +265,7 @@ void FramelessWindowsManager::setBorderWidth(QObject *window, const int value)
|
|||
{
|
||||
#ifdef Q_OS_WINDOWS
|
||||
Q_ASSERT(window);
|
||||
const auto data = WinNativeEventFilter::windowData(window);
|
||||
const auto data = WinNativeEventFilter::getWindowData(window);
|
||||
if (data) {
|
||||
data->borderWidth = value;
|
||||
}
|
||||
|
@ -291,7 +291,7 @@ void FramelessWindowsManager::setBorderHeight(QObject *window, const int value)
|
|||
{
|
||||
#ifdef Q_OS_WINDOWS
|
||||
Q_ASSERT(window);
|
||||
const auto data = WinNativeEventFilter::windowData(window);
|
||||
const auto data = WinNativeEventFilter::getWindowData(window);
|
||||
if (data) {
|
||||
data->borderHeight = value;
|
||||
}
|
||||
|
@ -317,7 +317,7 @@ void FramelessWindowsManager::setTitleBarHeight(QObject *window, const int value
|
|||
{
|
||||
#ifdef Q_OS_WINDOWS
|
||||
Q_ASSERT(window);
|
||||
const auto data = WinNativeEventFilter::windowData(window);
|
||||
const auto data = WinNativeEventFilter::getWindowData(window);
|
||||
if (data) {
|
||||
data->titleBarHeight = value;
|
||||
}
|
||||
|
@ -331,7 +331,7 @@ bool FramelessWindowsManager::getResizable(QObject *window)
|
|||
{
|
||||
Q_ASSERT(window);
|
||||
#ifdef Q_OS_WINDOWS
|
||||
const auto data = WinNativeEventFilter::windowData(window);
|
||||
const auto data = WinNativeEventFilter::getWindowData(window);
|
||||
return data ? !data->fixedSize : true;
|
||||
#else
|
||||
return coreData()->framelessHelper.getResizable(window);
|
||||
|
@ -352,7 +352,7 @@ QSize FramelessWindowsManager::getMinimumSize(QObject *window)
|
|||
{
|
||||
Q_ASSERT(window);
|
||||
#ifdef Q_OS_WINDOWS
|
||||
const auto data = WinNativeEventFilter::windowData(window);
|
||||
const auto data = WinNativeEventFilter::getWindowData(window);
|
||||
return data ? data->minimumSize : QSize();
|
||||
#else
|
||||
if (window->isWindowType()) {
|
||||
|
@ -374,7 +374,7 @@ void FramelessWindowsManager::setMinimumSize(QObject *window, const QSize &value
|
|||
{
|
||||
Q_ASSERT(window);
|
||||
#ifdef Q_OS_WINDOWS
|
||||
const auto data = WinNativeEventFilter::windowData(window);
|
||||
const auto data = WinNativeEventFilter::getWindowData(window);
|
||||
if (data) {
|
||||
data->minimumSize = value;
|
||||
}
|
||||
|
@ -397,7 +397,7 @@ QSize FramelessWindowsManager::getMaximumSize(QObject *window)
|
|||
{
|
||||
Q_ASSERT(window);
|
||||
#ifdef Q_OS_WINDOWS
|
||||
const auto data = WinNativeEventFilter::windowData(window);
|
||||
const auto data = WinNativeEventFilter::getWindowData(window);
|
||||
return data ? data->maximumSize : QSize();
|
||||
#else
|
||||
if (window->isWindowType()) {
|
||||
|
@ -419,7 +419,7 @@ void FramelessWindowsManager::setMaximumSize(QObject *window, const QSize &value
|
|||
{
|
||||
Q_ASSERT(window);
|
||||
#ifdef Q_OS_WINDOWS
|
||||
const auto data = WinNativeEventFilter::windowData(window);
|
||||
const auto data = WinNativeEventFilter::getWindowData(window);
|
||||
if (data) {
|
||||
data->maximumSize = value;
|
||||
}
|
||||
|
@ -442,7 +442,7 @@ bool FramelessWindowsManager::getTitleBarEnabled(QObject *window)
|
|||
{
|
||||
Q_ASSERT(window);
|
||||
#ifdef Q_OS_WINDOWS
|
||||
const auto data = WinNativeEventFilter::windowData(window);
|
||||
const auto data = WinNativeEventFilter::getWindowData(window);
|
||||
return data ? !data->disableTitleBar : true;
|
||||
#else
|
||||
return coreData()->framelessHelper.getTitleBarEnabled(window);
|
||||
|
@ -453,7 +453,7 @@ void FramelessWindowsManager::setTitleBarEnabled(QObject *window, const bool val
|
|||
{
|
||||
Q_ASSERT(window);
|
||||
#ifdef Q_OS_WINDOWS
|
||||
const auto data = WinNativeEventFilter::windowData(window);
|
||||
const auto data = WinNativeEventFilter::getWindowData(window);
|
||||
if (data) {
|
||||
data->disableTitleBar = !value;
|
||||
}
|
||||
|
|
|
@ -698,7 +698,6 @@ using WNEF_CORE_DATA = struct _WNEF_CORE_DATA
|
|||
|
||||
int m_borderWidth = -1, m_borderHeight = -1, m_titleBarHeight = -1;
|
||||
QScopedPointer<WinNativeEventFilter> m_instance;
|
||||
QList<HWND> m_framelessWindows = {};
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
@ -1226,9 +1225,6 @@ void install()
|
|||
qApp->removeNativeEventFilter(coreData()->m_instance.data());
|
||||
coreData()->m_instance.reset();
|
||||
}
|
||||
if (!coreData()->m_framelessWindows.isEmpty()) {
|
||||
coreData()->m_framelessWindows.clear();
|
||||
}
|
||||
}
|
||||
|
||||
// The standard values of border width, border height and title bar height
|
||||
|
@ -1261,10 +1257,18 @@ void WinNativeEventFilter::addFramelessWindow(void *window,
|
|||
Q_ASSERT(window);
|
||||
qCoreAppFixup();
|
||||
const auto hwnd = reinterpret_cast<HWND>(window);
|
||||
if (WNEF_EXECUTE_WINAPI_RETURN(IsWindow, FALSE, hwnd)
|
||||
&& !coreData()->m_framelessWindows.contains(hwnd)) {
|
||||
coreData()->m_framelessWindows.append(hwnd);
|
||||
createUserData(hwnd, data);
|
||||
if (WNEF_EXECUTE_WINAPI_RETURN(IsWindow, FALSE, hwnd)) {
|
||||
createUserData(hwnd);
|
||||
const auto oldData = getWindowData(window);
|
||||
if (oldData && oldData->framelessModeEnabled) {
|
||||
return;
|
||||
}
|
||||
const auto newData = new WINDOWDATA;
|
||||
if (data) {
|
||||
*newData = *data;
|
||||
}
|
||||
newData->framelessModeEnabled = true;
|
||||
createUserData(hwnd, newData);
|
||||
install();
|
||||
updateQtFrame_internal(hwnd);
|
||||
if ((x > 0) && (y > 0) && (width > 0) && (height > 0)) {
|
||||
|
@ -1291,9 +1295,10 @@ void WinNativeEventFilter::addFramelessWindow(QObject *window,
|
|||
void WinNativeEventFilter::removeFramelessWindow(void *window)
|
||||
{
|
||||
Q_ASSERT(window);
|
||||
const auto hwnd = reinterpret_cast<HWND>(window);
|
||||
if (coreData()->m_framelessWindows.contains(hwnd)) {
|
||||
coreData()->m_framelessWindows.removeAll(hwnd);
|
||||
createUserData(reinterpret_cast<HWND>(window));
|
||||
const auto data = getWindowData(window);
|
||||
if (data) {
|
||||
data->framelessModeEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1303,13 +1308,6 @@ void WinNativeEventFilter::removeFramelessWindow(QObject *window)
|
|||
removeFramelessWindow(getHWNDFromQObject(window));
|
||||
}
|
||||
|
||||
void WinNativeEventFilter::clearFramelessWindows()
|
||||
{
|
||||
if (!coreData()->m_framelessWindows.isEmpty()) {
|
||||
coreData()->m_framelessWindows.clear();
|
||||
}
|
||||
}
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
|
||||
void *message,
|
||||
|
@ -1343,14 +1341,6 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
|
|||
// Anyway, we should skip it in this case.
|
||||
return false;
|
||||
}
|
||||
if (coreData()->m_framelessWindows.isEmpty()) {
|
||||
// Only top level windows can be frameless.
|
||||
if (!IsTopLevel(msg->hwnd)) {
|
||||
return false;
|
||||
}
|
||||
} else if (!coreData()->m_framelessWindows.contains(msg->hwnd)) {
|
||||
return false;
|
||||
}
|
||||
const auto data = reinterpret_cast<WINDOWDATA *>(
|
||||
WNEF_EXECUTE_WINAPI_RETURN(GetWindowLongPtrW, 0, msg->hwnd, GWLP_USERDATA));
|
||||
if (!data) {
|
||||
|
@ -1379,6 +1369,9 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
|
|||
msg->lParam);
|
||||
return false;
|
||||
}
|
||||
if (!data->framelessModeEnabled) {
|
||||
return false;
|
||||
}
|
||||
if (!data->initialized) {
|
||||
// Avoid initializing a same window twice.
|
||||
data->initialized = true;
|
||||
|
@ -1803,99 +1796,89 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
|
|||
return true;
|
||||
}
|
||||
const auto isInSpecificAreas =
|
||||
[](const int x, const int y, const QList<QRect> &areas, const qreal dpr) -> bool {
|
||||
if (!areas.isEmpty()) {
|
||||
for (auto &&area : qAsConst(areas)) {
|
||||
if (!area.isValid()) {
|
||||
continue;
|
||||
}
|
||||
if (QRectF(area.x() * dpr,
|
||||
area.y() * dpr,
|
||||
area.width() * dpr,
|
||||
area.height() * dpr)
|
||||
.contains(x, y)) {
|
||||
return true;
|
||||
}
|
||||
[](const QPointF &mousePos, const QList<QRect> &areas, const qreal dpr) -> bool {
|
||||
if (areas.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
for (auto &&area : qAsConst(areas)) {
|
||||
if (!area.isValid()) {
|
||||
continue;
|
||||
}
|
||||
if (QRectF(area.x() * dpr,
|
||||
area.y() * dpr,
|
||||
area.width() * dpr,
|
||||
area.height() * dpr)
|
||||
.contains(mousePos)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
#if defined(QT_WIDGETS_LIB) || defined(QT_QUICK_LIB)
|
||||
const auto isInSpecificObjects = [](const int x,
|
||||
const int y,
|
||||
const auto isInSpecificObjects = [](const QPointF &mousePos,
|
||||
const QList<QObject *> &objects,
|
||||
const qreal dpr) -> bool {
|
||||
if (!objects.isEmpty()) {
|
||||
for (auto &&object : qAsConst(objects)) {
|
||||
if (!object) {
|
||||
continue;
|
||||
}
|
||||
if (objects.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
for (auto &&object : qAsConst(objects)) {
|
||||
if (!object) {
|
||||
continue;
|
||||
}
|
||||
#ifdef QT_WIDGETS_LIB
|
||||
const auto widget = qobject_cast<QWidget *>(object);
|
||||
if (widget) {
|
||||
const auto widget = qobject_cast<QWidget *>(object);
|
||||
if (widget) {
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
const QPointF pos = widget->mapToGlobal(QPointF{0, 0});
|
||||
const QPointF pos = widget->mapToGlobal(QPointF{0, 0});
|
||||
#else
|
||||
const QPoint pos = widget->mapToGlobal(QPoint{0, 0});
|
||||
const QPoint pos = widget->mapToGlobal(QPoint{0, 0});
|
||||
#endif
|
||||
if (QRectF(pos.x() * dpr,
|
||||
pos.y() * dpr,
|
||||
widget->width() * dpr,
|
||||
widget->height() * dpr)
|
||||
.contains(x, y)) {
|
||||
return true;
|
||||
}
|
||||
if (QRectF(pos.x() * dpr,
|
||||
pos.y() * dpr,
|
||||
widget->width() * dpr,
|
||||
widget->height() * dpr)
|
||||
.contains(mousePos)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef QT_QUICK_LIB
|
||||
const auto quickItem = qobject_cast<QQuickItem *>(object);
|
||||
if (quickItem) {
|
||||
const QPointF pos = quickItem->mapToGlobal(QPointF{0, 0});
|
||||
if (QRectF(pos.x() * dpr,
|
||||
pos.y() * dpr,
|
||||
quickItem->width() * dpr,
|
||||
quickItem->height() * dpr)
|
||||
.contains(x, y)) {
|
||||
return true;
|
||||
}
|
||||
const auto quickItem = qobject_cast<QQuickItem *>(object);
|
||||
if (quickItem) {
|
||||
const QPointF pos = quickItem->mapToGlobal(QPointF{0, 0});
|
||||
if (QRectF(pos.x() * dpr,
|
||||
pos.y() * dpr,
|
||||
quickItem->width() * dpr,
|
||||
quickItem->height() * dpr)
|
||||
.contains(mousePos)) {
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return false;
|
||||
};
|
||||
#endif
|
||||
// Don't use HIWORD(lParam) and LOWORD(lParam) to get cursor
|
||||
// coordinates because their results are unsigned numbers,
|
||||
// however the cursor position may be negative due to in a
|
||||
// different monitor.
|
||||
const POINT globalMouse{GET_X_LPARAM(msg->lParam), GET_Y_LPARAM(msg->lParam)};
|
||||
POINT localMouse = globalMouse;
|
||||
WNEF_EXECUTE_WINAPI(ScreenToClient, msg->hwnd, &localMouse)
|
||||
const qreal dpr = GetDevicePixelRatioForWindow(msg->hwnd);
|
||||
const bool isInIgnoreAreas = isInSpecificAreas(localMouse.x,
|
||||
localMouse.y,
|
||||
data->ignoreAreas,
|
||||
dpr);
|
||||
const QPointF globalMouse = QCursor::pos() * dpr;
|
||||
POINT winLocalMouse = {qRound(globalMouse.x()), qRound(globalMouse.y())};
|
||||
WNEF_EXECUTE_WINAPI(ScreenToClient, msg->hwnd, &winLocalMouse)
|
||||
const QPointF localMouse = {static_cast<qreal>(winLocalMouse.x),
|
||||
static_cast<qreal>(winLocalMouse.y)};
|
||||
const bool isInIgnoreAreas = isInSpecificAreas(localMouse, data->ignoreAreas, dpr);
|
||||
const bool customDragAreas = !data->draggableAreas.isEmpty();
|
||||
const bool isInDraggableAreas = customDragAreas
|
||||
? isInSpecificAreas(localMouse.x,
|
||||
localMouse.y,
|
||||
? isInSpecificAreas(localMouse,
|
||||
data->draggableAreas,
|
||||
dpr)
|
||||
: true;
|
||||
#if defined(QT_WIDGETS_LIB) || defined(QT_QUICK_LIB)
|
||||
// For this purpose, QCursor give more accurate position
|
||||
// than windows when using several monitors.
|
||||
const auto qtGlobalMousePos = QCursor::pos() * dpr;
|
||||
const bool isInIgnoreObjects = isInSpecificObjects(qtGlobalMousePos.x(),
|
||||
qtGlobalMousePos.y(),
|
||||
const bool isInIgnoreObjects = isInSpecificObjects(globalMouse,
|
||||
data->ignoreObjects,
|
||||
dpr);
|
||||
const bool customDragObjects = !data->draggableObjects.isEmpty();
|
||||
const bool isInDraggableObjects = customDragObjects
|
||||
? isInSpecificObjects(qtGlobalMousePos.x(),
|
||||
qtGlobalMousePos.y(),
|
||||
? isInSpecificObjects(globalMouse,
|
||||
data->draggableObjects,
|
||||
dpr)
|
||||
: true;
|
||||
|
@ -1909,12 +1892,12 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
|
|||
#endif
|
||||
const bool customDrag = customDragAreas || customDragObjects;
|
||||
const bool isResizePermitted = !isInIgnoreAreas && !isInIgnoreObjects;
|
||||
const LONG bh = getSystemMetric(msg->hwnd, SystemMetric::BorderHeight, true);
|
||||
const LONG tbh = getSystemMetric(msg->hwnd, SystemMetric::TitleBarHeight, true);
|
||||
const int bh = getSystemMetric(msg->hwnd, SystemMetric::BorderHeight, true);
|
||||
const int tbh = getSystemMetric(msg->hwnd, SystemMetric::TitleBarHeight, true);
|
||||
const bool isTitleBar = (customDrag ? (isInDraggableAreas && isInDraggableObjects)
|
||||
: (localMouse.y <= (tbh + bh)))
|
||||
: (localMouse.y() <= (tbh + bh)))
|
||||
&& isResizePermitted && !data->disableTitleBar;
|
||||
const bool isTop = (localMouse.y <= bh) && isResizePermitted;
|
||||
const bool isTop = (localMouse.y() <= bh) && isResizePermitted;
|
||||
if (shouldHaveWindowFrame()) {
|
||||
// This will handle the left, right and bottom parts of the frame
|
||||
// because we didn't change them.
|
||||
|
@ -1944,28 +1927,26 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
|
|||
*result = HTCLIENT;
|
||||
return true;
|
||||
} else {
|
||||
const auto getHTResult =
|
||||
[isTitleBar, localMouse, bh, isTop](const HWND _hWnd,
|
||||
const WINDOWDATA &_data) -> LRESULT {
|
||||
Q_ASSERT(_hWnd);
|
||||
const auto getHitTestResult =
|
||||
[msg, isTitleBar, &localMouse, bh, isTop, data]() -> LRESULT {
|
||||
RECT clientRect = {0, 0, 0, 0};
|
||||
WNEF_EXECUTE_WINAPI(GetClientRect, _hWnd, &clientRect)
|
||||
WNEF_EXECUTE_WINAPI(GetClientRect, msg->hwnd, &clientRect)
|
||||
const LONG ww = clientRect.right;
|
||||
const LONG wh = clientRect.bottom;
|
||||
const LONG bw = getSystemMetric(_hWnd, SystemMetric::BorderWidth, true);
|
||||
if (IsMaximized(_hWnd)) {
|
||||
const int bw = getSystemMetric(msg->hwnd, SystemMetric::BorderWidth, true);
|
||||
if (IsMaximized(msg->hwnd)) {
|
||||
if (isTitleBar) {
|
||||
return HTCAPTION;
|
||||
}
|
||||
return HTCLIENT;
|
||||
}
|
||||
const bool isBottom = (localMouse.y >= (wh - bh));
|
||||
const bool isBottom = (localMouse.y() >= (wh - bh));
|
||||
// Make the border a little wider to let the user easy to resize
|
||||
// on corners.
|
||||
const int factor = (isTop || isBottom) ? 2 : 1;
|
||||
const bool isLeft = (localMouse.x <= (bw * factor));
|
||||
const bool isRight = (localMouse.x >= (ww - (bw * factor)));
|
||||
const bool fixedSize = _data.fixedSize;
|
||||
const bool isLeft = (localMouse.x() <= (bw * factor));
|
||||
const bool isRight = (localMouse.x() >= (ww - (bw * factor)));
|
||||
const bool fixedSize = data->fixedSize;
|
||||
const auto getBorderValue = [fixedSize](int value) -> int {
|
||||
// HTBORDER: non-resizeable window border.
|
||||
return fixedSize ? HTBORDER : value;
|
||||
|
@ -1999,7 +1980,7 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
|
|||
}
|
||||
return HTCLIENT;
|
||||
};
|
||||
*result = getHTResult(msg->hwnd, *data);
|
||||
*result = getHitTestResult();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -2155,7 +2136,7 @@ void WinNativeEventFilter::setWindowData(QObject *window, const WINDOWDATA *data
|
|||
setWindowData(getHWNDFromQObject(window), data);
|
||||
}
|
||||
|
||||
WinNativeEventFilter::WINDOWDATA *WinNativeEventFilter::windowData(void *window)
|
||||
WinNativeEventFilter::WINDOWDATA *WinNativeEventFilter::getWindowData(void *window)
|
||||
{
|
||||
Q_ASSERT(window);
|
||||
const auto hwnd = reinterpret_cast<HWND>(window);
|
||||
|
@ -2167,10 +2148,10 @@ WinNativeEventFilter::WINDOWDATA *WinNativeEventFilter::windowData(void *window)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
WinNativeEventFilter::WINDOWDATA *WinNativeEventFilter::windowData(QObject *window)
|
||||
WinNativeEventFilter::WINDOWDATA *WinNativeEventFilter::getWindowData(QObject *window)
|
||||
{
|
||||
Q_ASSERT(window);
|
||||
return windowData(getHWNDFromQObject(window));
|
||||
return getWindowData(getHWNDFromQObject(window));
|
||||
}
|
||||
|
||||
void WinNativeEventFilter::setBorderWidth(const int bw)
|
||||
|
@ -2386,7 +2367,7 @@ bool WinNativeEventFilter::displaySystemMenu(void *handle,
|
|||
WNEF_EXECUTE_WINAPI(SetMenuItemInfoW, hMenu, SC_MAXIMIZE, FALSE, &mii)
|
||||
WNEF_EXECUTE_WINAPI(SetMenuItemInfoW, hMenu, SC_MINIMIZE, FALSE, &mii)
|
||||
mii.fState = MF_GRAYED;
|
||||
const auto data = windowData(hwnd);
|
||||
const auto data = getWindowData(hwnd);
|
||||
const bool fixedSize = data ? data->fixedSize : false;
|
||||
if (fixedSize) {
|
||||
WNEF_EXECUTE_WINAPI(SetMenuItemInfoW, hMenu, SC_SIZE, FALSE, &mii)
|
||||
|
@ -2515,7 +2496,7 @@ void WinNativeEventFilter::setWindowResizable(void *handle, const bool resizable
|
|||
Q_ASSERT(handle);
|
||||
const auto hwnd = reinterpret_cast<HWND>(handle);
|
||||
if (WNEF_EXECUTE_WINAPI_RETURN(IsWindow, FALSE, hwnd)) {
|
||||
const auto data = windowData(hwnd);
|
||||
const auto data = getWindowData(hwnd);
|
||||
if (data) {
|
||||
data->fixedSize = !resizable;
|
||||
}
|
||||
|
@ -2532,7 +2513,7 @@ void WinNativeEventFilter::setWindowResizable(void *handle, const bool resizable
|
|||
}
|
||||
}
|
||||
|
||||
bool WinNativeEventFilter::colorizationEnabled()
|
||||
bool WinNativeEventFilter::isColorizationEnabled()
|
||||
{
|
||||
if (!isWin10OrGreater()) {
|
||||
return false;
|
||||
|
@ -2544,7 +2525,7 @@ bool WinNativeEventFilter::colorizationEnabled()
|
|||
return (ok && colorPrevalence);
|
||||
}
|
||||
|
||||
QColor WinNativeEventFilter::colorizationColor()
|
||||
QColor WinNativeEventFilter::getColorizationColor()
|
||||
{
|
||||
DWORD color = 0;
|
||||
BOOL opaqueBlend = FALSE;
|
||||
|
@ -2554,18 +2535,18 @@ QColor WinNativeEventFilter::colorizationColor()
|
|||
: Qt::white;
|
||||
}
|
||||
|
||||
bool WinNativeEventFilter::lightThemeEnabled()
|
||||
bool WinNativeEventFilter::isLightThemeEnabled()
|
||||
{
|
||||
return !darkThemeEnabled();
|
||||
return !isDarkThemeEnabled();
|
||||
}
|
||||
|
||||
bool WinNativeEventFilter::darkThemeEnabled()
|
||||
bool WinNativeEventFilter::isDarkThemeEnabled()
|
||||
{
|
||||
return coreData()->m_lpShouldSystemUseDarkMode ? coreData()->m_lpShouldSystemUseDarkMode()
|
||||
: false;
|
||||
}
|
||||
|
||||
bool WinNativeEventFilter::highContrastModeEnabled()
|
||||
bool WinNativeEventFilter::isHighContrastModeEnabled()
|
||||
{
|
||||
HIGHCONTRASTW hc;
|
||||
SecureZeroMemory(&hc, sizeof(hc));
|
||||
|
@ -2575,7 +2556,7 @@ bool WinNativeEventFilter::highContrastModeEnabled()
|
|||
: false;
|
||||
}
|
||||
|
||||
bool WinNativeEventFilter::darkFrameEnabled(void *handle)
|
||||
bool WinNativeEventFilter::isDarkFrameEnabled(void *handle)
|
||||
{
|
||||
Q_ASSERT(handle);
|
||||
if (!isWin10OrGreater(17763)) {
|
||||
|
@ -2601,7 +2582,7 @@ bool WinNativeEventFilter::darkFrameEnabled(void *handle)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool WinNativeEventFilter::transparencyEffectEnabled()
|
||||
bool WinNativeEventFilter::isTransparencyEffectEnabled()
|
||||
{
|
||||
if (!isWin10OrGreater()) {
|
||||
return false;
|
||||
|
|
|
@ -54,7 +54,8 @@ public:
|
|||
{
|
||||
bool initialized = false /* Internal use only, don't modify it from outside */,
|
||||
fixedSize = false, mouseTransparent = false, restoreDefaultWindowStyle = false,
|
||||
enableLayeredWindow = false, disableTitleBar = false, enableBlurBehindWindow = false;
|
||||
enableLayeredWindow = false, disableTitleBar = false, enableBlurBehindWindow = false,
|
||||
framelessModeEnabled = false;
|
||||
int borderWidth = -1, borderHeight = -1, titleBarHeight = -1;
|
||||
QList<QRect> ignoreAreas = {}, draggableAreas = {};
|
||||
QList<QObject *> ignoreObjects = {}, draggableObjects = {};
|
||||
|
@ -87,7 +88,6 @@ public:
|
|||
const int height = -1);
|
||||
static void removeFramelessWindow(void *window /* HWND */);
|
||||
static void removeFramelessWindow(QObject *window);
|
||||
static void clearFramelessWindows();
|
||||
|
||||
// Set borderWidth, borderHeight or titleBarHeight to a negative value to
|
||||
// restore default behavior.
|
||||
|
@ -97,8 +97,8 @@ public:
|
|||
static void setWindowData(QObject *window, const WINDOWDATA *data);
|
||||
// You can modify the given window's data directly, it's the same with using
|
||||
// setWindowData.
|
||||
static WINDOWDATA *windowData(void *window /* HWND */);
|
||||
static WINDOWDATA *windowData(QObject *window);
|
||||
static WINDOWDATA *getWindowData(void *window /* HWND */);
|
||||
static WINDOWDATA *getWindowData(QObject *window);
|
||||
|
||||
// Change settings globally, not a specific window.
|
||||
// These values will be scaled automatically according to DPI, don't scale
|
||||
|
@ -154,25 +154,25 @@ public:
|
|||
static void setWindowResizable(void *handle /* HWND */, const bool resizable = true);
|
||||
|
||||
// Query whether colorization is enabled or not.
|
||||
static bool colorizationEnabled();
|
||||
static bool isColorizationEnabled();
|
||||
|
||||
// Acquire the theme/colorization color set by the user.
|
||||
static QColor colorizationColor();
|
||||
static QColor getColorizationColor();
|
||||
|
||||
// Query whether the user is using the light theme or not.
|
||||
static bool lightThemeEnabled();
|
||||
static bool isLightThemeEnabled();
|
||||
|
||||
// Query whether the user is using the dark theme or not.
|
||||
static bool darkThemeEnabled();
|
||||
static bool isDarkThemeEnabled();
|
||||
|
||||
// Query whether the high contrast mode is enabled or not.
|
||||
static bool highContrastModeEnabled();
|
||||
static bool isHighContrastModeEnabled();
|
||||
|
||||
// Query whether the given window is using dark frame or not.
|
||||
static bool darkFrameEnabled(void *handle /* HWND */);
|
||||
static bool isDarkFrameEnabled(void *handle /* HWND */);
|
||||
|
||||
// Query whether the transparency effect is enabled or not.
|
||||
static bool transparencyEffectEnabled();
|
||||
static bool isTransparencyEffectEnabled();
|
||||
|
||||
///////////////////////////////////////////////
|
||||
/// CORE FUNCTION - THE SOUL OF THIS CODE
|
||||
|
|
Loading…
Reference in New Issue