Skip to content

Commit

Permalink
Revert "Windows QPA: improve Qt::FramlessWindowHint windows"
Browse files Browse the repository at this point in the history
This reverts commit 1a6ab68.

Reason for revert: Regression: FrameLessWindows have borders now when they should not.

Change-Id: Ia975acf6f63a44e2ff3362aa573b1d9b11f7edd9
Reviewed-by: Tor Arne Vestbø <[email protected]>
Reviewed-by: Oliver Wolff <[email protected]>
  • Loading branch information
Wladimir Leuschner authored and The Qt Project committed Nov 5, 2024
1 parent 12b41c3 commit 7d62b54
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 86 deletions.
4 changes: 2 additions & 2 deletions src/plugins/platforms/windows/qwindowscontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,7 @@ bool QWindowsContext::windowsProc(HWND hwnd, UINT message,
}
return false;
case QtWindows::CalculateSize:
return QWindowsGeometryHint::handleCalculateSize(d->m_creationContext->window, d->m_creationContext->customMargins, msg, result);
return QWindowsGeometryHint::handleCalculateSize(d->m_creationContext->customMargins, msg, result);
case QtWindows::GeometryChangingEvent:
return QWindowsWindow::handleGeometryChangingMessage(&msg, d->m_creationContext->window,
d->m_creationContext->margins + d->m_creationContext->customMargins);
Expand Down Expand Up @@ -1165,7 +1165,7 @@ bool QWindowsContext::windowsProc(HWND hwnd, UINT message,
platformWindow->getSizeHints(reinterpret_cast<MINMAXINFO *>(lParam));
return true;// maybe available on some SDKs revisit WM_NCCALCSIZE
case QtWindows::CalculateSize:
return QWindowsGeometryHint::handleCalculateSize(platformWindow->window(), platformWindow->customMargins(), msg, result);
return QWindowsGeometryHint::handleCalculateSize(platformWindow->customMargins(), msg, result);
case QtWindows::NonClientHitTest:
return platformWindow->handleNonClientHitTest(QPoint(msg.pt.x, msg.pt.y), result);
case QtWindows::GeometryChangingEvent:
Expand Down
112 changes: 32 additions & 80 deletions src/plugins/platforms/windows/qwindowswindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,12 @@ void WindowCreationData::fromWindow(const QWindow *w, const Qt::WindowFlags flag
if (popup || (type == Qt::ToolTip) || (type == Qt::SplashScreen)) {
style = WS_POPUP;
} else if (topLevel) {
style = WS_OVERLAPPED;
if (flags & Qt::FramelessWindowHint)
style = WS_POPUP; // no border
else if (flags & Qt::WindowTitleHint)
style = WS_OVERLAPPED;
else
style = 0;
} else {
style = WS_CHILD;
}
Expand All @@ -781,15 +786,16 @@ void WindowCreationData::fromWindow(const QWindow *w, const Qt::WindowFlags flag

if (topLevel) {
if ((type == Qt::Window || dialog || tool)) {
if (!(flags & Qt::FramelessWindowHint))
if (!(flags & Qt::FramelessWindowHint)) {
style |= WS_POPUP;
if (flags & Qt::MSWindowsFixedSizeDialogHint) {
style |= WS_DLGFRAME;
} else {
style |= WS_THICKFRAME;
if (flags & Qt::MSWindowsFixedSizeDialogHint) {
style |= WS_DLGFRAME;
} else {
style |= WS_THICKFRAME;
}
if (flags & Qt::WindowTitleHint)
style |= WS_CAPTION; // Contains WS_DLGFRAME
}
if (flags & Qt::WindowTitleHint)
style |= WS_CAPTION; // Contains WS_DLGFRAME
if (flags & Qt::WindowSystemMenuHint)
style |= WS_SYSMENU;
else if (dialog && (flags & Qt::WindowCloseButtonHint) && !(flags & Qt::FramelessWindowHint)) {
Expand All @@ -809,15 +815,8 @@ void WindowCreationData::fromWindow(const QWindow *w, const Qt::WindowFlags flag
if ((flags & Qt::WindowContextHelpButtonHint) && !showMinimizeButton
&& !showMaximizeButton)
exStyle |= WS_EX_CONTEXTHELP;
if (flags & Qt::FramelessWindowHint) {
style |= WS_CAPTION; // Needed for aero
style |= WS_SYSMENU; // Needed for taskbar shortcuts
style |= WS_THICKFRAME;
style |= WS_MINIMIZEBOX; // Needed for minimize animations
style |= WS_MAXIMIZEBOX; // Needed for maximize animations
}
} else {
exStyle |= WS_EX_TOOLWINDOW;
exStyle |= WS_EX_TOOLWINDOW;
}

// make mouse events fall through this window
Expand Down Expand Up @@ -976,13 +975,9 @@ void WindowCreationData::initialize(const QWindow *w, HWND hwnd, bool frameChang
if (flags & (Qt::CustomizeWindowHint|Qt::WindowTitleHint)) {
HMENU systemMenu = GetSystemMenu(hwnd, FALSE);
if (flags & Qt::WindowCloseButtonHint)
EnableMenuItem(systemMenu, SC_CLOSE, MF_BYCOMMAND | MF_ENABLED);
EnableMenuItem(systemMenu, SC_CLOSE, MF_BYCOMMAND|MF_ENABLED);
else
EnableMenuItem(systemMenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
}
if (flags & Qt::FramelessWindowHint) { // Gives us the rounded corners looks and the frame shadow
MARGINS margins = { -1, -1, -1, -1 };
DwmExtendFrameIntoClientArea(hwnd, &margins);
EnableMenuItem(systemMenu, SC_CLOSE, MF_BYCOMMAND|MF_GRAYED);
}
updateGLWindowSettings(w, hwnd, flags, opacityLevel);
} else { // child.
Expand Down Expand Up @@ -1111,29 +1106,8 @@ QMargins QWindowsGeometryHint::frame(const QWindow *w, const QRect &geometry,
return QWindowsGeometryHint::frame(w, style, exStyle, dpi);
}

bool QWindowsGeometryHint::handleCalculateSize(const QWindow *window, const QMargins &customMargins, const MSG &msg, LRESULT *result)
{
// Return 0 to remove the window's border
QWindowsWindow *w = QWindowsWindow::windowsWindowOf(window);
bool frameless = w ? w->isFrameless() : window->flags() & Qt::FramelessWindowHint;
if (msg.wParam && frameless) {
//Query for fullscreen
QUERY_USER_NOTIFICATION_STATE quns;
SHQueryUserNotificationState(&quns);

// Prevent content from being cutoff by border for maximized, but not fullscreened windows.
if (IsZoomed(msg.hwnd) && quns == QUNS_ACCEPTS_NOTIFICATIONS) {
auto *ncp = reinterpret_cast<NCCALCSIZE_PARAMS *>(msg.lParam);
RECT *clientArea = &ncp->rgrc[0];
const int border = getResizeBorderThickness(QWindowsWindow::windowsWindowOf(window)->savedDpi());
clientArea->top += border;
clientArea->bottom -= border;
clientArea->left += border;
clientArea->right -= border;
}
*result = msg.wParam ? WVR_REDRAW : 0;
return true;
}
bool QWindowsGeometryHint::handleCalculateSize(const QMargins &customMargins, const MSG &msg, LRESULT *result)
{
// NCCALCSIZE_PARAMS structure if wParam==TRUE
if (!msg.wParam || customMargins.isNull())
return false;
Expand Down Expand Up @@ -2203,11 +2177,13 @@ void QWindowsWindow::handleMoved()

void QWindowsWindow::handleResized(int wParam, LPARAM lParam)
{
/* Prevents windows with no frame from covering the taskbar when maximized. */
if (m_data.flags.testFlag(Qt::CustomizeWindowHint) && !m_data.flags.testFlag(Qt::WindowTitleHint)
/* Prevents borderless windows from covering the taskbar when maximized. */
if ((m_data.flags.testFlag(Qt::FramelessWindowHint)
|| (m_data.flags.testFlag(Qt::CustomizeWindowHint) && !m_data.flags.testFlag(Qt::WindowTitleHint)))
&& IsZoomed(m_data.hwnd)) {
const int resizedWidth = LOWORD(lParam);
const int resizedHeight = HIWORD(lParam);

const HMONITOR monitor = MonitorFromWindow(m_data.hwnd, MONITOR_DEFAULTTOPRIMARY);
MONITORINFO monitorInfo = {};
monitorInfo.cbSize = sizeof(MONITORINFO);
Expand All @@ -2218,11 +2194,13 @@ void QWindowsWindow::handleResized(int wParam, LPARAM lParam)
int correctWidth = monitorInfo.rcWork.right - monitorInfo.rcWork.left;
int correctHeight = monitorInfo.rcWork.bottom - monitorInfo.rcWork.top;

const int borderWidth = invisibleMargins(m_data.hwnd).left();
correctLeft -= borderWidth;
correctTop -= borderWidth;
correctWidth += borderWidth * 2;
correctHeight += borderWidth * 2;
if (!m_data.flags.testFlag(Qt::FramelessWindowHint)) {
const int borderWidth = invisibleMargins(m_data.hwnd).left();
correctLeft -= borderWidth;
correctTop -= borderWidth;
correctWidth += borderWidth * 2;
correctHeight += borderWidth * 2;
}

if (resizedWidth != correctWidth || resizedHeight != correctHeight) {
qCDebug(lcQpaWindow) << __FUNCTION__ << "correcting: " << resizedWidth << "x"
Expand Down Expand Up @@ -3161,35 +3139,8 @@ void QWindowsWindow::getSizeHints(MINMAXINFO *mmi) const

bool QWindowsWindow::handleNonClientHitTest(const QPoint &globalPos, LRESULT *result) const
{
const QWindow *w = window();
const QPoint localPos = w->mapFromGlobal(QHighDpi::fromNativePixels(globalPos, w));

if (m_data.flags & Qt::FramelessWindowHint) {
const int border = (IsZoomed(m_data.hwnd) || isFullScreen_sys()) ? 0 : getResizeBorderThickness(savedDpi());
if (border == 0) {
*result = HTCLIENT;
return true;
}

const bool left = (globalPos.x() >= geometry().left()) && (globalPos.x() < geometry().left() + border);
const bool right = (globalPos.x() > geometry().right() - border) && (globalPos.x() <= geometry().right());
const bool top = (globalPos.y() >= geometry().top()) && (globalPos.y() < geometry().top() + border);
const bool bottom = (globalPos.y() > geometry().bottom() - border) && (globalPos.y() <= geometry().bottom());

if (left || right || top || bottom) {
if (left)
*result = top ? HTTOPLEFT : (bottom ? HTBOTTOMLEFT : HTLEFT);
else if (right)
*result = top ? HTTOPRIGHT : (bottom ? HTBOTTOMRIGHT : HTRIGHT);
else
*result = top ? HTTOP : HTBOTTOM;
} else {
*result = HTCLIENT;
}
return true;
}

// QTBUG-32663, suppress resize cursor for fixed size windows.
const QWindow *w = window();
if (!w->isTopLevel() // Task 105852, minimized windows need to respond to user input.
|| (m_windowState != Qt::WindowNoState)
|| !isActive()
Expand All @@ -3204,6 +3155,7 @@ bool QWindowsWindow::handleNonClientHitTest(const QPoint &globalPos, LRESULT *re
const bool fixedHeight = minimumSize.height() == maximumSize.height();
if (!fixedWidth && !fixedHeight)
return false;
const QPoint localPos = w->mapFromGlobal(QHighDpi::fromNativePixels(globalPos, w));
const QSize size = w->size();
if (fixedHeight) {
if (localPos.y() >= size.height()) {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/platforms/windows/qwindowswindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct QWindowsGeometryHint
static QMargins frame(const QWindow *w, HWND hwnd);
static QMargins frame(const QWindow *w, const QRect &geometry,
DWORD style, DWORD exStyle);
static bool handleCalculateSize(const QWindow *window, const QMargins &customMargins, const MSG &msg, LRESULT *result);
static bool handleCalculateSize(const QMargins &customMargins, const MSG &msg, LRESULT *result);
static void applyToMinMaxInfo(const QWindow *w, const QScreen *screen,
const QMargins &margins, MINMAXINFO *mmi);
static void applyToMinMaxInfo(const QWindow *w, const QMargins &margins,
Expand Down
6 changes: 3 additions & 3 deletions tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ void tst_QWidget::getSetCheck()
#if defined (Q_OS_WIN)
obj1.setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint);
const HWND handle = reinterpret_cast<HWND>(obj1.winId()); // explicitly create window handle
QVERIFY((GetWindowLongPtr(handle, GWL_STYLE) & LONG_PTR(WS_OVERLAPPED)) == 0);
QVERIFY(GetWindowLongPtr(handle, GWL_STYLE) & LONG_PTR(WS_POPUP));
#endif
}

Expand Down Expand Up @@ -9838,7 +9838,7 @@ class MoveInResizeWidget : public QWidget

public slots:
void resizeMe() {
resize(150, 150);
resize(100, 100);
}
};

Expand All @@ -9850,7 +9850,7 @@ void tst_QWidget::moveInResizeEvent()
testWidget.show();
QVERIFY(QTest::qWaitForWindowExposed(&testWidget));

QRect expectedGeometry(100,100, 150, 150);
QRect expectedGeometry(100,100, 100, 100);
QTRY_COMPARE(testWidget.geometry(), expectedGeometry);
}

Expand Down

0 comments on commit 7d62b54

Please sign in to comment.