Skip to content

Commit 5f6745b

Browse files
author
朱子楚\zhuzi
committed
udpate
1 parent 4f20283 commit 5f6745b

File tree

3 files changed

+53
-80
lines changed

3 files changed

+53
-80
lines changed

src/FluFrameless.cpp

+51-66
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,7 @@ void FluFrameless::componentComplete() {
7373
int w = window()->width();
7474
int h = window()->height();
7575
_current = window()->winId();
76-
window()->setFlags((window()->flags()) | Qt::CustomizeWindowHint | Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint | Qt::FramelessWindowHint);
77-
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
78-
if (QQuickWindow::sceneGraphBackend() == "software") {
79-
window()->setFlag(Qt::FramelessWindowHint, false);
80-
}
81-
#endif
76+
window()->setFlags((window()->flags()) | Qt::CustomizeWindowHint | Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint);
8277
if (!_fixSize) {
8378
window()->setFlag(Qt::WindowMaximizeButtonHint);
8479
}
@@ -97,14 +92,14 @@ void FluFrameless::componentComplete() {
9792
HWND hwnd = reinterpret_cast<HWND>(window()->winId());
9893
DWORD style = ::GetWindowLongPtr(hwnd, GWL_STYLE);
9994
if (_fixSize) {
100-
::SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_THICKFRAME);
95+
::SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_CAPTION);
10196
for (int i = 0; i <= QGuiApplication::screens().count() - 1; ++i) {
10297
connect(QGuiApplication::screens().at(i), &QScreen::logicalDotsPerInchChanged, this, [=] {
10398
SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_FRAMECHANGED);
10499
});
105100
}
106101
} else {
107-
::SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_MAXIMIZEBOX | WS_THICKFRAME);
102+
::SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_MAXIMIZEBOX | WS_CAPTION);
108103
}
109104
SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
110105
connect(window(), &QQuickWindow::screenChanged, this, [hwnd] {
@@ -151,29 +146,22 @@ void FluFrameless::componentComplete() {
151146
return false;
152147
} else if (uMsg == WM_NCCALCSIZE) {
153148
const auto clientRect = ((wParam == FALSE) ? reinterpret_cast<LPRECT>(lParam) : &(reinterpret_cast<LPNCCALCSIZE_PARAMS>(lParam))->rgrc[0]);
154-
const LONG originalTop = clientRect->top;
155-
const LONG originalLeft = clientRect->left;
156-
const LONG originalRight = clientRect->right;
157-
const LONG originalBottom = clientRect->bottom;
158-
const LRESULT hitTestResult = ::DefWindowProcW(hwnd, WM_NCCALCSIZE, wParam, lParam);
159-
if ((hitTestResult != HTERROR) && (hitTestResult != HTNOWHERE)) {
160-
*result = static_cast<QT_NATIVE_EVENT_RESULT_TYPE>(hitTestResult);
161-
return true;
162-
}
163-
int offsetSize;
164149
bool isMaximum = ::IsZoomed(hwnd);
165-
if (isMaximum || _isFullScreen()) {
166-
offsetSize = 0;
167-
} else {
168-
offsetSize = 1;
169-
}
170-
if (!isCompositionEnabled()) {
171-
offsetSize = 0;
150+
if (!isMaximum){
151+
if (clientRect->top != 0)
152+
{
153+
clientRect->top -= 1;
154+
clientRect->bottom -= 1;
155+
}
156+
} else{
157+
const LONG originalTop = clientRect->top;
158+
const LRESULT hitTestResult = ::DefWindowProcW(hwnd, WM_NCCALCSIZE, wParam, lParam);
159+
if ((hitTestResult != HTERROR) && (hitTestResult != HTNOWHERE)) {
160+
*result = static_cast<QT_NATIVE_EVENT_RESULT_TYPE>(hitTestResult);
161+
return true;
162+
}
163+
clientRect->top = originalTop-originalTop;
172164
}
173-
clientRect->top = originalTop + offsetSize;
174-
clientRect->bottom = originalBottom - offsetSize;
175-
clientRect->left = originalLeft + offsetSize;
176-
clientRect->right = originalRight - offsetSize;
177165
_setMaximizeHovered(false);
178166
*result = WVR_REDRAW;
179167
return true;
@@ -230,6 +218,18 @@ void FluFrameless::componentComplete() {
230218
}
231219
*result = HTCLIENT;
232220
return true;
221+
} else if (uMsg == WM_NCPAINT) {
222+
if(isCompositionEnabled()){
223+
return false;
224+
}
225+
*result = FALSE;
226+
return true;
227+
} else if (uMsg == WM_NCACTIVATE) {
228+
if(isCompositionEnabled()){
229+
return false;
230+
}
231+
*result = TRUE;
232+
return true;
233233
} else if (_isWindows11OrGreater && (uMsg == WM_NCLBUTTONDBLCLK || uMsg == WM_NCLBUTTONDOWN)) {
234234
if (_hitMaximizeButton()) {
235235
QMouseEvent event = QMouseEvent(QEvent::MouseButtonPress, QPoint(), QPoint(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
@@ -244,23 +244,8 @@ void FluFrameless::componentComplete() {
244244
_setMaximizePressed(false);
245245
return true;
246246
}
247-
} else if (uMsg == WM_NCPAINT) {
248-
*result = FALSE;
249-
return true;
250-
} else if (uMsg == WM_NCACTIVATE) {
251-
*result = static_cast<QT_NATIVE_EVENT_RESULT_TYPE>(::DefWindowProcW(hwnd, WM_NCACTIVATE, wParam, -1));
247+
} else if (uMsg == WM_ERASEBKGND) {
252248
return true;
253-
} else if (uMsg == WM_GETMINMAXINFO) {
254-
auto *minmaxInfo = reinterpret_cast<MINMAXINFO *>(lParam);
255-
auto pixelRatio = window()->devicePixelRatio();
256-
auto geometry = window()->screen()->availableGeometry();
257-
RECT rect;
258-
SystemParametersInfo(SPI_GETWORKAREA, 0, &rect, 0);
259-
minmaxInfo->ptMaxPosition.x = rect.left;
260-
minmaxInfo->ptMaxPosition.y = rect.top;
261-
minmaxInfo->ptMaxSize.x = qRound(geometry.width() * pixelRatio);
262-
minmaxInfo->ptMaxSize.y = qRound(geometry.height() * pixelRatio);
263-
return false;
264249
} else if (uMsg == WM_NCRBUTTONDOWN) {
265250
if (wParam == HTCAPTION) {
266251
_showSystemMenu(QCursor::pos());
@@ -358,27 +343,27 @@ void FluFrameless::_setMaximizeHovered(bool val) {
358343

359344
void FluFrameless::_updateCursor(int edges) {
360345
switch (edges) {
361-
case 0:
362-
window()->setCursor(Qt::ArrowCursor);
363-
break;
364-
case Qt::LeftEdge:
365-
case Qt::RightEdge:
366-
window()->setCursor(Qt::SizeHorCursor);
367-
break;
368-
case Qt::TopEdge:
369-
case Qt::BottomEdge:
370-
window()->setCursor(Qt::SizeVerCursor);
371-
break;
372-
case Qt::LeftEdge | Qt::TopEdge:
373-
case Qt::RightEdge | Qt::BottomEdge:
374-
window()->setCursor(Qt::SizeFDiagCursor);
375-
break;
376-
case Qt::RightEdge | Qt::TopEdge:
377-
case Qt::LeftEdge | Qt::BottomEdge:
378-
window()->setCursor(Qt::SizeBDiagCursor);
379-
break;
380-
default:
381-
break;
346+
case 0:
347+
window()->setCursor(Qt::ArrowCursor);
348+
break;
349+
case Qt::LeftEdge:
350+
case Qt::RightEdge:
351+
window()->setCursor(Qt::SizeHorCursor);
352+
break;
353+
case Qt::TopEdge:
354+
case Qt::BottomEdge:
355+
window()->setCursor(Qt::SizeVerCursor);
356+
break;
357+
case Qt::LeftEdge | Qt::TopEdge:
358+
case Qt::RightEdge | Qt::BottomEdge:
359+
window()->setCursor(Qt::SizeFDiagCursor);
360+
break;
361+
case Qt::RightEdge | Qt::TopEdge:
362+
case Qt::LeftEdge | Qt::BottomEdge:
363+
window()->setCursor(Qt::SizeBDiagCursor);
364+
break;
365+
default:
366+
break;
382367
}
383368
}
384369

src/Qt5/imports/FluentUI/Controls/FluWindow.qml

+1-7
Original file line numberDiff line numberDiff line change
@@ -279,13 +279,7 @@ Window {
279279
id:loader_border
280280
anchors.fill: parent
281281
sourceComponent: {
282-
if(window.useSystemAppBar){
283-
return undefined
284-
}
285-
if(FluTools.isWindows10OrGreater()){
286-
return undefined
287-
}
288-
if(window.visibility === Window.Maximized || window.visibility === Window.FullScreen){
282+
if(window.useSystemAppBar || FluTools.isWin() || window.visibility === Window.Maximized || window.visibility === Window.FullScreen){
289283
return undefined
290284
}
291285
return com_border

src/Qt6/imports/FluentUI/Controls/FluWindow.qml

+1-7
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,7 @@ Window {
278278
id:loader_border
279279
anchors.fill: parent
280280
sourceComponent: {
281-
if(window.useSystemAppBar){
282-
return undefined
283-
}
284-
if(FluTools.isWindows10OrGreater()){
285-
return undefined
286-
}
287-
if(window.visibility === Window.Maximized || window.visibility === Window.FullScreen){
281+
if(window.useSystemAppBar || FluTools.isWin() || window.visibility === Window.Maximized || window.visibility === Window.FullScreen){
288282
return undefined
289283
}
290284
return com_border

0 commit comments

Comments
 (0)