diff --git a/src/FluFramelessHelper.cpp b/src/FluFramelessHelper.cpp index 2a5bb0d5..4b5fa3cd 100644 --- a/src/FluFramelessHelper.cpp +++ b/src/FluFramelessHelper.cpp @@ -98,6 +98,20 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void * } return false; }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 originalLeft = clientRect->left; + const LRESULT hitTestResult = ::DefWindowProcW(hwnd, WM_NCCALCSIZE, wParam, lParam); + if ((hitTestResult != HTERROR) && (hitTestResult != HTNOWHERE)) { + *result = hitTestResult; + return true; + } + if(IsZoomed(hwnd)){ + _helper->setOriginalPos(QPoint(originalLeft,originalTop)); + }else{ + _helper->setOriginalPos({}); + } + clientRect->top = originalTop; *result = WVR_REDRAW; return true; }else if(uMsg == WM_NCPAINT){ @@ -243,7 +257,7 @@ void FluFramelessHelper::componentComplete(){ } if(!window.isNull()){ #ifdef Q_OS_WIN - window->setFlags(window->flags() | Qt::FramelessWindowHint | Qt::WindowMinimizeButtonHint); + // window->setFlags(window->flags() | Qt::FramelessWindowHint | Qt::WindowMinimizeButtonHint); _nativeEvent =new FramelessEventFilter(this); qApp->installNativeEventFilter(_nativeEvent); HWND hwnd = reinterpret_cast(window->winId()); @@ -254,12 +268,12 @@ void FluFramelessHelper::componentComplete(){ SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_THICKFRAME | WS_CAPTION); } SetWindowPos(hwnd,nullptr,0,0,0,0,SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED); - showShadow(hwnd); #else window->setFlags((window->flags() & (~Qt::WindowMinMaxButtonsHint) & (~Qt::Dialog)) | Qt::FramelessWindowHint | Qt::Window); #endif _stayTop = QQmlProperty(window,"stayTop"); _screen = QQmlProperty(window,"screen"); + _originalPos = QQmlProperty(window,"_originalPos"); _onStayTopChange(); _stayTop.connectNotifySignal(this,SLOT(_onStayTopChange())); _screen.connectNotifySignal(this,SLOT(_onScreenChanged())); @@ -353,6 +367,10 @@ QObject* FluFramelessHelper::maximizeButton(){ return var.value(); } +void FluFramelessHelper::setOriginalPos(QVariant pos){ + _originalPos.write(pos); +} + bool FluFramelessHelper::resizeable(){ return !(window->width() == window->maximumWidth() && window->width() == window->minimumWidth() && window->height() == window->maximumHeight() && window->height() == window->minimumHeight()); } diff --git a/src/FluFramelessHelper.h b/src/FluFramelessHelper.h index 09334533..e271c485 100644 --- a/src/FluFramelessHelper.h +++ b/src/FluFramelessHelper.h @@ -39,6 +39,7 @@ public: bool hoverMaxBtn(); bool resizeable(); QObject* maximizeButton(); + void setOriginalPos(QVariant pos); Q_INVOKABLE void showSystemMenu(); protected: bool eventFilter(QObject *obj, QEvent *event) override; @@ -54,6 +55,7 @@ private: FramelessEventFilter* _nativeEvent = nullptr; QQmlProperty _stayTop; QQmlProperty _screen; + QQmlProperty _originalPos; }; #endif // FLUFRAMELESSHELPER_H diff --git a/src/Qt5/imports/FluentUI/Controls/FluWindow.qml b/src/Qt5/imports/FluentUI/Controls/FluWindow.qml index f97de0ca..eeb68b8b 100644 --- a/src/Qt5/imports/FluentUI/Controls/FluWindow.qml +++ b/src/Qt5/imports/FluentUI/Controls/FluWindow.qml @@ -54,6 +54,7 @@ Window { signal initArgument(var argument) signal firstVisible() property point _offsetXY : Qt.point(0,0) + property var _originalPos id:window color:"transparent" Component.onCompleted: { @@ -73,12 +74,12 @@ Window { Component.onDestruction: { lifecycle.onDestruction() } - onVisibilityChanged: { - if(visibility === Window.Maximized || visibility === Window.FullScreen){ - var dx = window.x-Screen.virtualX - var dy = window.y-Screen.virtualY + on_OriginalPosChanged: { + if(_originalPos){ + var dx = (_originalPos.x - screen.virtualX)/screen.devicePixelRatio + var dy = _originalPos.y - screen.virtualY/screen.devicePixelRatio if(dx<0 && dy<0){ - _offsetXY = Qt.point(Math.abs(dx+1),Math.abs(dy+1)) + _offsetXY = Qt.point(Math.abs(dx),Math.abs(dy)) }else{ _offsetXY = Qt.point(0,0) } @@ -191,10 +192,7 @@ Window { id:layout_container anchors{ fill:parent - leftMargin: _offsetXY.x - rightMargin: _offsetXY.x - topMargin: _offsetXY.y - bottomMargin: _offsetXY.y + topMargin: _offsetXY.x } onWidthChanged: { window.appBar.width = width diff --git a/src/Qt6/imports/FluentUI/Controls/FluWindow.qml b/src/Qt6/imports/FluentUI/Controls/FluWindow.qml index ecc18978..485e33a2 100644 --- a/src/Qt6/imports/FluentUI/Controls/FluWindow.qml +++ b/src/Qt6/imports/FluentUI/Controls/FluWindow.qml @@ -53,6 +53,7 @@ Window { signal initArgument(var argument) signal firstVisible() property point _offsetXY : Qt.point(0,0) + property var _originalPos id:window color:"transparent" Component.onCompleted: { @@ -72,12 +73,12 @@ Window { Component.onDestruction: { lifecycle.onDestruction() } - onVisibilityChanged: { - if(visibility === Window.Maximized || visibility === Window.FullScreen){ - var dx = window.x-Screen.virtualX - var dy = window.y-Screen.virtualY + on_OriginalPosChanged: { + if(_originalPos){ + var dx = (_originalPos.x - screen.virtualX)/screen.devicePixelRatio + var dy = _originalPos.y - screen.virtualY/screen.devicePixelRatio if(dx<0 && dy<0){ - _offsetXY = Qt.point(Math.abs(dx+1),Math.abs(dy+1)) + _offsetXY = Qt.point(Math.abs(dx),Math.abs(dy)) }else{ _offsetXY = Qt.point(0,0) } @@ -190,10 +191,7 @@ Window { id:layout_container anchors{ fill:parent - leftMargin: _offsetXY.x - rightMargin: _offsetXY.x - topMargin: _offsetXY.y - bottomMargin: _offsetXY.y + topMargin: _offsetXY.x } onWidthChanged: { window.appBar.width = width