Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2020-04-02 12:59:45 +08:00
parent 905f22876c
commit 07c3f47405
2 changed files with 17 additions and 14 deletions

View File

@ -312,8 +312,8 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
case WM_NCHITTEST: { case WM_NCHITTEST: {
const auto getHTResult = [this](HWND _hWnd, LPARAM _lParam, const auto getHTResult = [this](HWND _hWnd, LPARAM _lParam,
LPWINDOW _data) -> LRESULT { LPWINDOW _data) -> LRESULT {
const auto isInIgnoreArea = [](int x, int y, const auto isInSpecificAreas = [](int x, int y,
QVector<QRect> areas) -> bool { const QVector<QRect> &areas) -> bool {
for (auto &&area : qAsConst(areas)) { for (auto &&area : qAsConst(areas)) {
if (area.contains(x, y, true)) { if (area.contains(x, y, true)) {
return true; return true;
@ -344,7 +344,8 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
: titlebarHeight(_hWnd); : titlebarHeight(_hWnd);
const bool isInsideWindow = (mouse.x > 0) && (mouse.x < ww) && (mouse.y > 0) && (mouse.y < wh); const bool isInsideWindow = (mouse.x > 0) && (mouse.x < ww) && (mouse.y > 0) && (mouse.y < wh);
const bool isTitlebar = isInsideWindow && (mouse.y < tbh) && const bool isTitlebar = isInsideWindow && (mouse.y < tbh) &&
!isInIgnoreArea(mouse.x, mouse.y, _data->windowData.ignoreAreas); !isInSpecificAreas(mouse.x, mouse.y, _data->windowData.ignoreAreas)
&& (_data->windowData.draggableAreas.isEmpty() ? true : isInSpecificAreas(mouse.x, mouse.y, _data->windowData.draggableAreas));
if (IsMaximized(_hWnd)) { if (IsMaximized(_hWnd)) {
if (isTitlebar) { if (isTitlebar) {
return HTCAPTION; return HTCAPTION;
@ -405,6 +406,10 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
mmi.ptMaxSize.y = qAbs(rcWorkArea.bottom - rcWorkArea.top); mmi.ptMaxSize.y = qAbs(rcWorkArea.bottom - rcWorkArea.top);
mmi.ptMaxTrackSize.x = mmi.ptMaxSize.x; mmi.ptMaxTrackSize.x = mmi.ptMaxSize.x;
mmi.ptMaxTrackSize.y = mmi.ptMaxSize.y; mmi.ptMaxTrackSize.y = mmi.ptMaxSize.y;
if (!data->windowData.minimumSize.isEmpty()) {
mmi.ptMinTrackSize.x = qRound64(windowDpr(msg->hwnd) * data->windowData.minimumSize.width());
mmi.ptMinTrackSize.y = qRound64(windowDpr(msg->hwnd) * data->windowData.minimumSize.height());
}
*result = 0; *result = 0;
return true; return true;
} }
@ -435,6 +440,7 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
break; break;
} }
case WM_WINDOWPOSCHANGED: { case WM_WINDOWPOSCHANGED: {
// Repaint the non-client area immediately.
InvalidateRect(msg->hwnd, nullptr, TRUE); InvalidateRect(msg->hwnd, nullptr, TRUE);
break; break;
} }
@ -508,7 +514,8 @@ void WinNativeEventFilter::handleDwmCompositionChanged(LPWINDOW data) {
const MARGINS margins = {-1, -1, -1, -1}; const MARGINS margins = {-1, -1, -1, -1};
DwmExtendFrameIntoClientArea(data->hWnd, &margins); DwmExtendFrameIntoClientArea(data->hWnd, &margins);
} }
handleBlurForWindow(data); // Has big side-effect.
// handleBlurForWindow(data);
refreshWindow(data->hWnd); refreshWindow(data->hWnd);
} }
@ -554,12 +561,7 @@ void WinNativeEventFilter::handleBlurForWindow(LPWINDOW data) {
16299)) { 16299)) {
// Acrylic (Will also blur but is completely different with // Acrylic (Will also blur but is completely different with
// Windows Aero) // Windows Aero)
#if 0
// FIXME: Why causes strange problems?
accentPolicy.AccentState = ACCENT_ENABLE_ACRYLICBLURBEHIND; accentPolicy.AccentState = ACCENT_ENABLE_ACRYLICBLURBEHIND;
#else
accentPolicy.AccentState = ACCENT_ENABLE_BLURBEHIND;
#endif
} else if (QOperatingSystemVersion::current() >= } else if (QOperatingSystemVersion::current() >=
QOperatingSystemVersion::Windows10) { QOperatingSystemVersion::Windows10) {
// Blur (Something like Windows Aero in Windows 7) // Blur (Something like Windows Aero in Windows 7)
@ -644,14 +646,14 @@ void WinNativeEventFilter::setWindowData(HWND window, WINDOWDATA *data) {
} }
} }
WinNativeEventFilter::WINDOWDATA & WinNativeEventFilter::WINDOWDATA *
WinNativeEventFilter::windowData(HWND window) { WinNativeEventFilter::windowData(HWND window) {
if (window) { if (window) {
createUserData(window); createUserData(window);
return reinterpret_cast<LPWINDOW>( return &reinterpret_cast<LPWINDOW>(
GetWindowLongPtrW(window, GWLP_USERDATA))->windowData; GetWindowLongPtrW(window, GWLP_USERDATA))->windowData;
} }
return *(new WINDOWDATA); return nullptr;
} }
void WinNativeEventFilter::createUserData(HWND handle, WINDOWDATA *data) void WinNativeEventFilter::createUserData(HWND handle, WINDOWDATA *data)

View File

@ -12,7 +12,8 @@ public:
using WINDOWDATA = struct _WINDOWDATA { using WINDOWDATA = struct _WINDOWDATA {
BOOL blurEnabled = FALSE; BOOL blurEnabled = FALSE;
int borderWidth = -1, borderHeight = -1, titlebarHeight = -1; int borderWidth = -1, borderHeight = -1, titlebarHeight = -1;
QVector<QRect> ignoreAreas; QVector<QRect> ignoreAreas, draggableAreas;
QSize minimumSize = {-1, -1};
}; };
typedef struct tagWINDOW { typedef struct tagWINDOW {
HWND hWnd = nullptr; HWND hWnd = nullptr;
@ -39,7 +40,7 @@ public:
// Set borderWidth, borderHeight or titlebarHeight to a negative value to restore default behavior. // Set borderWidth, borderHeight or titlebarHeight to a negative value to restore default behavior.
static void setWindowData(HWND window, WINDOWDATA *data); static void setWindowData(HWND window, WINDOWDATA *data);
static WINDOWDATA &windowData(HWND window); static WINDOWDATA *windowData(HWND window);
// Dots-Per-Inch of the given window (or screen if the pointer is null). // Dots-Per-Inch of the given window (or screen if the pointer is null).
UINT windowDpi(HWND handle) const; UINT windowDpi(HWND handle) const;