diff --git a/src/FluFramelessHelper.cpp b/src/FluFramelessHelper.cpp index 3cef223c..4c1ee824 100644 --- a/src/FluFramelessHelper.cpp +++ b/src/FluFramelessHelper.cpp @@ -1,11 +1,13 @@ #include "FluFramelessHelper.h" #include +#include #include "FluTools.h" #ifdef Q_OS_WIN #pragma comment (lib,"user32.lib") #pragma comment (lib,"dwmapi.lib") #include +#include #include static inline QByteArray qtNativeEventType() @@ -87,7 +89,7 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void * } const auto msg = static_cast(message); const HWND hwnd = msg->hwnd; - if (!hwnd) { + if (!hwnd || !msg) { return false; } const qint64 wid = reinterpret_cast(hwnd); @@ -95,10 +97,6 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void * return false; } const UINT uMsg = msg->message; - if (!msg || !hwnd) - { - return false; - } const WPARAM wParam = msg->wParam; const LPARAM lParam = msg->lParam; if(uMsg == WM_WINDOWPOSCHANGING){ @@ -113,23 +111,29 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void * }else if(uMsg == WM_NCCALCSIZE){ const auto clientRect = ((wParam == FALSE) ? reinterpret_cast(lParam) : &(reinterpret_cast(lParam))->rgrc[0]); const LONG originalTop = clientRect->top; - const LONG originalBottom = clientRect->bottom; const LONG originalLeft = clientRect->left; - const LONG originalRight= clientRect->right; const LRESULT hitTestResult = ::DefWindowProcW(hwnd, WM_NCCALCSIZE, wParam, lParam); if ((hitTestResult != HTERROR) && (hitTestResult != HTNOWHERE)) { *result = hitTestResult; return true; } - if(IsZoomed(hwnd)){ + int offsetTop = 0; + bool isMax = IsZoomed(hwnd); + if(isMax){ _helper->setOriginalPos(QPoint(originalLeft,originalTop)); if(isTaskbarAutoHide()){ clientRect->bottom -= 1; } + offsetTop = 0; }else{ _helper->setOriginalPos({}); + if(FluTools::getInstance()->isWindows11OrGreater()){ + offsetTop = 0; + }else{ + offsetTop = 1; + } } - clientRect->top = originalTop + 1; + clientRect->top = originalTop+offsetTop; *result = WVR_REDRAW; return true; }if(uMsg == WM_NCHITTEST){ @@ -156,10 +160,15 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void * }else if(uMsg == WM_NCPAINT){ *result = 0; return true; - } - else if(uMsg == WM_NCACTIVATE){ + }else if(uMsg == WM_NCACTIVATE){ *result = DefWindowProcW(hwnd, WM_NCACTIVATE, wParam, -1); return true; + }else if(uMsg == WM_SYSCOMMAND){ + const WPARAM filteredWParam = (wParam & 0xFFF0); + if (filteredWParam == SC_MAXIMIZE) { + _helper->window->showMaximized(); + return true; + } } return false; #endif @@ -278,7 +287,7 @@ void FluFramelessHelper::componentComplete(){ _appBarHeight = QQmlProperty(window,"_appBarHeight"); #ifdef Q_OS_WIN if(isCompositionEnabled()){ - window->setFlags(Qt::Window|Qt::CustomizeWindowHint); + window->setFlag(Qt::CustomizeWindowHint,true); _nativeEvent =new FramelessEventFilter(this); qApp->installNativeEventFilter(_nativeEvent); HWND hwnd = reinterpret_cast(window->winId()); @@ -308,6 +317,7 @@ void FluFramelessHelper::componentComplete(){ _stayTop.connectNotifySignal(this,SLOT(_onStayTopChange())); _screen.connectNotifySignal(this,SLOT(_onScreenChanged())); window->installEventFilter(this); + Q_EMIT loadCompleted(); } } @@ -324,7 +334,7 @@ void FluFramelessHelper::showSystemMenu(){ QPoint point = QCursor::pos(); HWND hwnd = reinterpret_cast(window->winId()); DWORD style = GetWindowLongPtr(hwnd,GWL_STYLE); - SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_THICKFRAME | WS_CAPTION | WS_SYSMENU | WS_MAXIMIZEBOX); + SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_SYSMENU); const HMENU hMenu = ::GetSystemMenu(hwnd, FALSE); DeleteMenu(hMenu, SC_MOVE, MF_BYCOMMAND); DeleteMenu(hMenu, SC_SIZE, MF_BYCOMMAND); @@ -342,7 +352,7 @@ void FluFramelessHelper::showSystemMenu(){ if (result != FALSE) { PostMessageW(hwnd, WM_SYSCOMMAND, result, 0); } - SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_THICKFRAME | WS_CAPTION &~ WS_SYSMENU); + SetWindowLongPtr(hwnd, GWL_STYLE, style &~ WS_SYSMENU); #endif } diff --git a/src/FluFramelessHelper.h b/src/FluFramelessHelper.h index 0da38a6e..445e67af 100644 --- a/src/FluFramelessHelper.h +++ b/src/FluFramelessHelper.h @@ -41,6 +41,7 @@ public: QObject* maximizeButton(); void setOriginalPos(QVariant pos); Q_INVOKABLE void showSystemMenu(); + Q_SIGNAL void loadCompleted(); protected: bool eventFilter(QObject *obj, QEvent *event) override; private: diff --git a/src/Qt5/imports/FluentUI/Controls/FluProgressButton.qml b/src/Qt5/imports/FluentUI/Controls/FluProgressButton.qml index 7864270b..dfd89632 100644 --- a/src/Qt5/imports/FluentUI/Controls/FluProgressButton.qml +++ b/src/Qt5/imports/FluentUI/Controls/FluProgressButton.qml @@ -8,7 +8,7 @@ Button { property string contentDescription: "" QtObject{ id:d - property bool checked: rect_back.height == background.height + property bool checked: (rect_back.height === background.height) && (progress === 1) } property color normalColor: { if(d.checked){ diff --git a/src/Qt5/imports/FluentUI/Controls/FluWindow.qml b/src/Qt5/imports/FluentUI/Controls/FluWindow.qml index b90ef747..6f925706 100644 --- a/src/Qt5/imports/FluentUI/Controls/FluWindow.qml +++ b/src/Qt5/imports/FluentUI/Controls/FluWindow.qml @@ -70,6 +70,7 @@ Window { _realHeight = height _realWidth = width moveWindowToDesktopCenter() + fixWindowSize() useSystemAppBar = FluApp.useSystemAppBar if(!useSystemAppBar){ loader_frameless_helper.sourceComponent = com_frameless @@ -120,7 +121,11 @@ Window { } Component{ id:com_frameless - FluFramelessHelper{} + FluFramelessHelper{ + onLoadCompleted:{ + window.moveWindowToDesktopCenter() + } + } } Component{ id:com_background @@ -301,11 +306,13 @@ Window { function moveWindowToDesktopCenter(){ screen = Qt.application.screens[FluTools.cursorScreenIndex()] window.setGeometry((Screen.width-window.width)/2+Screen.virtualX,(Screen.height-window.height)/2+Screen.virtualY,window.width,window.height) + } + function fixWindowSize(){ if(fixSize){ - maximumWidth = width - maximumHeight = height - minimumWidth = width - minimumHeight = height + window.maximumWidth = window.width + window.maximumHeight = window.height + window.minimumWidth = window.width + window.minimumHeight = window.height } } function onResult(data){ diff --git a/src/Qt6/imports/FluentUI/Controls/FluProgressButton.qml b/src/Qt6/imports/FluentUI/Controls/FluProgressButton.qml index d57cdfd0..37ee248b 100644 --- a/src/Qt6/imports/FluentUI/Controls/FluProgressButton.qml +++ b/src/Qt6/imports/FluentUI/Controls/FluProgressButton.qml @@ -9,7 +9,7 @@ Button { property string contentDescription: "" QtObject{ id:d - property bool checked: rect_back.height == background.height + property bool checked: (rect_back.height === background.height) && (progress === 1) } property color normalColor: { if(d.checked){ diff --git a/src/Qt6/imports/FluentUI/Controls/FluWindow.qml b/src/Qt6/imports/FluentUI/Controls/FluWindow.qml index f6d7a9d0..2d047743 100644 --- a/src/Qt6/imports/FluentUI/Controls/FluWindow.qml +++ b/src/Qt6/imports/FluentUI/Controls/FluWindow.qml @@ -69,6 +69,7 @@ Window { _realHeight = height _realWidth = width moveWindowToDesktopCenter() + fixWindowSize() useSystemAppBar = FluApp.useSystemAppBar if(!useSystemAppBar){ loader_frameless_helper.sourceComponent = com_frameless @@ -119,7 +120,11 @@ Window { } Component{ id:com_frameless - FluFramelessHelper{} + FluFramelessHelper{ + onLoadCompleted:{ + window.moveWindowToDesktopCenter() + } + } } Component{ id:com_background @@ -300,11 +305,13 @@ Window { function moveWindowToDesktopCenter(){ screen = Qt.application.screens[FluTools.cursorScreenIndex()] window.setGeometry((Screen.width-window.width)/2+Screen.virtualX,(Screen.height-window.height)/2+Screen.virtualY,window.width,window.height) + } + function fixWindowSize(){ if(fixSize){ - maximumWidth = width - maximumHeight = height - minimumWidth = width - minimumHeight = height + window.maximumWidth = window.width + window.maximumHeight = window.height + window.minimumWidth = window.width + window.minimumHeight = window.height } } function onResult(data){