This commit is contained in:
zhuzichu 2024-01-08 14:07:38 +08:00
parent cd7ce7fe67
commit 993de241cb
2 changed files with 22 additions and 49 deletions

View File

@ -16,24 +16,6 @@ static inline QByteArray qtNativeEventType()
return result; return result;
} }
static inline QColor getAccentColor(){
typedef HRESULT (WINAPI* DwmGetColorizationColorPtr)(DWORD* pcrColorization,BOOL* pfOpaqueBlend);
HMODULE module = LoadLibraryW(L"dwmapi.dll");
if (module)
{
DwmGetColorizationColorPtr dwm_get_colorization_color;
dwm_get_colorization_color= reinterpret_cast<DwmGetColorizationColorPtr>(GetProcAddress(module, "DwmGetColorizationColor"));
DWORD color = 0;
BOOL bOpaque = FALSE;
if (dwm_get_colorization_color)
{
dwm_get_colorization_color(&color,&bOpaque);
}
return QColor(color);
}
return QColor();
}
static inline bool isCompositionEnabled(){ static inline bool isCompositionEnabled(){
typedef HRESULT (WINAPI* DwmIsCompositionEnabledPtr)(BOOL *pfEnabled); typedef HRESULT (WINAPI* DwmIsCompositionEnabledPtr)(BOOL *pfEnabled);
HMODULE module = LoadLibraryW(L"dwmapi.dll"); HMODULE module = LoadLibraryW(L"dwmapi.dll");
@ -51,26 +33,6 @@ static inline bool isCompositionEnabled(){
return true; return true;
} }
static inline void showShadow(HWND hwnd){
if(isCompositionEnabled()){
const MARGINS shadow = { 0, 0, 1, 0 };
typedef HRESULT (WINAPI* DwmExtendFrameIntoClientAreaPtr)(HWND hWnd, const MARGINS *pMarInset);
HMODULE module = LoadLibraryW(L"dwmapi.dll");
if (module)
{
DwmExtendFrameIntoClientAreaPtr dwm_extendframe_into_client_area_;
dwm_extendframe_into_client_area_= reinterpret_cast<DwmExtendFrameIntoClientAreaPtr>(GetProcAddress(module, "DwmExtendFrameIntoClientArea"));
if (dwm_extendframe_into_client_area_)
{
dwm_extendframe_into_client_area_(hwnd, &shadow);
}
}
}else{
ULONG_PTR cNewStyle = GetClassLongPtr(hwnd, GCL_STYLE) | CS_DROPSHADOW;
SetClassLongPtr(hwnd, GCL_STYLE, cNewStyle);
}
}
#endif #endif
FramelessEventFilter::FramelessEventFilter(FluFramelessHelper* helper){ FramelessEventFilter::FramelessEventFilter(FluFramelessHelper* helper){
@ -109,26 +71,35 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void *
const auto clientRect = ((wParam == FALSE) ? reinterpret_cast<LPRECT>(lParam) : &(reinterpret_cast<LPNCCALCSIZE_PARAMS>(lParam))->rgrc[0]); const auto clientRect = ((wParam == FALSE) ? reinterpret_cast<LPRECT>(lParam) : &(reinterpret_cast<LPNCCALCSIZE_PARAMS>(lParam))->rgrc[0]);
const LONG originalTop = clientRect->top; const LONG originalTop = clientRect->top;
const LONG originalLeft = clientRect->left; const LONG originalLeft = clientRect->left;
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
const LONG originalRight = clientRect->right;
const LONG originalBottom = clientRect->bottom;
#endif
const LRESULT hitTestResult = ::DefWindowProcW(hwnd, WM_NCCALCSIZE, wParam, lParam); const LRESULT hitTestResult = ::DefWindowProcW(hwnd, WM_NCCALCSIZE, wParam, lParam);
if ((hitTestResult != HTERROR) && (hitTestResult != HTNOWHERE)) { if ((hitTestResult != HTERROR) && (hitTestResult != HTNOWHERE)) {
*result = hitTestResult; *result = hitTestResult;
return true; return true;
} }
int offsetTop = 0; int offsetSize = 0;
bool isMax = IsZoomed(hwnd); bool isMax = IsZoomed(hwnd);
offsetXY = QPoint(abs(clientRect->left - originalLeft),abs(clientRect->top - originalTop)); offsetXY = QPoint(abs(clientRect->left - originalLeft),abs(clientRect->top - originalTop));
if(isMax){ if(isCompositionEnabled()){
_helper->setOriginalPos(QPoint(originalLeft,originalTop)); if(isMax){
offsetTop = 0; _helper->setOriginalPos(QPoint(originalLeft,originalTop));
}else{ offsetSize = 0;
_helper->setOriginalPos({});
if(FluTools::getInstance()->isWindows11OrGreater()){
offsetTop = 0;
}else{ }else{
offsetTop = 1; _helper->setOriginalPos({});
offsetSize = 1;
} }
}else{
offsetSize = 0;
} }
clientRect->top = originalTop+offsetTop; clientRect->top = originalTop+offsetSize;
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
clientRect->bottom = originalBottom-offsetSize;
clientRect->left = originalLeft+offsetSize;
clientRect->right = originalRight-offsetSize;
#endif
*result = WVR_REDRAW; *result = WVR_REDRAW;
return true; return true;
}if(uMsg == WM_NCHITTEST){ }if(uMsg == WM_NCHITTEST){
@ -296,7 +267,6 @@ void FluFramelessHelper::componentComplete(){
SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_THICKFRAME); SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_THICKFRAME);
} }
SetWindowPos(hwnd,nullptr,0,0,0,0,SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED); SetWindowPos(hwnd,nullptr,0,0,0,0,SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
showShadow(hwnd);
#else #else
window->setFlags((window->flags() & (~Qt::WindowMinMaxButtonsHint) & (~Qt::Dialog)) | Qt::FramelessWindowHint | Qt::Window); window->setFlags((window->flags() & (~Qt::WindowMinMaxButtonsHint) & (~Qt::Dialog)) | Qt::FramelessWindowHint | Qt::Window);
#endif #endif

View File

@ -209,6 +209,9 @@ Window {
anchors{ anchors{
fill:parent fill:parent
topMargin: _offsetXY.y topMargin: _offsetXY.y
bottomMargin: _offsetXY.y
leftMargin: _offsetXY.x
rightMargin: _offsetXY.x
} }
onWidthChanged: { onWidthChanged: {
window.appBar.width = width window.appBar.width = width