Revert "Use native window resize on Windows 11"
This reverts commit 2e9aec239d.
This commit is contained in:
parent
2246d16daf
commit
74cd53e1d1
6 changed files with 38 additions and 102 deletions
|
|
@ -218,14 +218,10 @@ void TitleControls::raise() {
|
|||
HitTestResult TitleControls::hitTest(QPoint point, int padding) const {
|
||||
const auto test = [&](const object_ptr<Button> &button, bool close) {
|
||||
return button && button->geometry().marginsAdded(
|
||||
{ 0, padding, 0, 0 }
|
||||
{ close ? padding : 0, padding, close ? padding : 0, 0 }
|
||||
).contains(point);
|
||||
};
|
||||
if (::Platform::IsWindows11OrGreater()
|
||||
&& !_maximizedState
|
||||
&& (point.y() < style::ConvertScale(style::DevicePixelRatio()))) {
|
||||
return HitTestResult::Top;
|
||||
} else if (test(_minimize, false)) {
|
||||
if (test(_minimize, false)) {
|
||||
return HitTestResult::Minimize;
|
||||
} else if (test(_maximizeRestore, false)) {
|
||||
return HitTestResult::MaximizeRestore;
|
||||
|
|
@ -501,9 +497,9 @@ std::unique_ptr<SeparateTitleControls> SetupSeparateTitleControls(
|
|||
controlsTop ? std::move(controlsTop) : rpl::single(0)
|
||||
) | rpl::start_with_next([=](int width, int padding, int top) {
|
||||
raw->wrap.setGeometry(
|
||||
0,
|
||||
padding,
|
||||
top,
|
||||
width,
|
||||
width - 2 * padding,
|
||||
raw->controls.geometry().height());
|
||||
}, lifetime);
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,8 @@ base::flat_map<HWND, not_null<WindowShadow*>> ShadowByHandle;
|
|||
|
||||
WindowShadow::WindowShadow(not_null<RpWidget*> window, QColor color)
|
||||
: _window(window)
|
||||
, _handle(GetWindowHandle(window)) {
|
||||
, _handle(GetWindowHandle(window))
|
||||
, _windows11(::Platform::IsWindows11OrGreater()) {
|
||||
init(color);
|
||||
}
|
||||
|
||||
|
|
@ -316,7 +317,7 @@ void WindowShadow::horCorners(int w, Gdiplus::Graphics *pgraphics0, Gdiplus::Gra
|
|||
}
|
||||
|
||||
Gdiplus::Color WindowShadow::getColor(uchar alpha) const {
|
||||
return Gdiplus::Color(BYTE(alpha), _r, _g, _b);
|
||||
return Gdiplus::Color(BYTE(_windows11 ? 1 : alpha), _r, _g, _b);
|
||||
}
|
||||
|
||||
Gdiplus::SolidBrush WindowShadow::getBrush(uchar alpha) const {
|
||||
|
|
|
|||
|
|
@ -78,6 +78,7 @@ private:
|
|||
|
||||
const not_null<RpWidget*> _window;
|
||||
const HWND _handle;
|
||||
const bool _windows11 = false;
|
||||
|
||||
int _x = 0;
|
||||
int _y = 0;
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ void TitleWidget::initInWindow(not_null<RpWindow*> window) {
|
|||
) | rpl::filter([=](not_null<HitTestRequest*> request) {
|
||||
return !isHidden() && geometry().contains(request->point);
|
||||
}) | rpl::start_with_next([=](not_null<HitTestRequest*> request) {
|
||||
request->result = hitTest(request->point, request->result);
|
||||
request->result = hitTest(request->point);
|
||||
}, lifetime());
|
||||
|
||||
SetupSemiNativeSystemButtons(&_controls, window, lifetime(), [=] {
|
||||
|
|
@ -98,9 +98,9 @@ void TitleWidget::refreshGeometryWithWidth(int width) {
|
|||
setGeometry(0, 0, width, _controls.st()->height + add);
|
||||
if (_paddingHelper) {
|
||||
_paddingHelper->controlsParent.setGeometry(
|
||||
0,
|
||||
add,
|
||||
width,
|
||||
add,
|
||||
width - 2 * add,
|
||||
_controls.st()->height);
|
||||
}
|
||||
update();
|
||||
|
|
@ -126,9 +126,7 @@ void TitleWidget::resizeEvent(QResizeEvent *e) {
|
|||
_shadow->setGeometry(0, height() - thickness, width(), thickness);
|
||||
}
|
||||
|
||||
HitTestResult TitleWidget::hitTest(
|
||||
QPoint point,
|
||||
HitTestResult oldResult) const {
|
||||
HitTestResult TitleWidget::hitTest(QPoint point) const {
|
||||
const auto origin = _paddingHelper
|
||||
? _paddingHelper->controlsParent.pos()
|
||||
: QPoint();
|
||||
|
|
@ -138,8 +136,6 @@ HitTestResult TitleWidget::hitTest(
|
|||
const auto controlsResult = _controls.hitTest(point - origin, padding);
|
||||
return (controlsResult != HitTestResult::None)
|
||||
? controlsResult
|
||||
: (oldResult != HitTestResult::Client)
|
||||
? oldResult
|
||||
: HitTestResult::Caption;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -55,9 +55,7 @@ protected:
|
|||
private:
|
||||
struct PaddingHelper;
|
||||
|
||||
[[nodiscard]] HitTestResult hitTest(
|
||||
QPoint point,
|
||||
HitTestResult oldResult) const;
|
||||
[[nodiscard]] HitTestResult hitTest(QPoint point) const;
|
||||
[[nodiscard]] bool additionalPaddingRequired() const;
|
||||
void refreshGeometryWithWidth(int width);
|
||||
void setAdditionalPadding(int padding);
|
||||
|
|
|
|||
|
|
@ -41,13 +41,6 @@ int(__stdcall *GetSystemMetricsForDpi)(
|
|||
_In_ int nIndex,
|
||||
_In_ UINT dpi);
|
||||
|
||||
BOOL(__stdcall *AdjustWindowRectExForDpi)(
|
||||
_Inout_ LPRECT lpRect,
|
||||
_In_ DWORD dwStyle,
|
||||
_In_ BOOL bMenu,
|
||||
_In_ DWORD dwExStyle,
|
||||
_In_ UINT dpi);
|
||||
|
||||
[[nodiscard]] bool GetDpiForWindowSupported() {
|
||||
static const auto Result = [&] {
|
||||
#define LOAD_SYMBOL(lib, name) base::Platform::LoadMethod(lib, #name, name)
|
||||
|
|
@ -68,16 +61,6 @@ BOOL(__stdcall *AdjustWindowRectExForDpi)(
|
|||
return Result;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool AdjustWindowRectExForDpiSupported() {
|
||||
static const auto Result = [&] {
|
||||
#define LOAD_SYMBOL(lib, name) base::Platform::LoadMethod(lib, #name, name)
|
||||
const auto user32 = base::Platform::SafeLoadLibrary(L"User32.dll");
|
||||
return LOAD_SYMBOL(user32, AdjustWindowRectExForDpi);
|
||||
#undef LOAD_SYMBOL
|
||||
}();
|
||||
return Result;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool IsCompositionEnabled() {
|
||||
auto result = BOOL(FALSE);
|
||||
const auto success = (DwmIsCompositionEnabled(&result) == S_OK);
|
||||
|
|
@ -143,6 +126,7 @@ WindowHelper::WindowHelper(not_null<RpWidget*> window)
|
|||
, _handle(GetWindowHandle(window))
|
||||
, _title(Ui::CreateChild<TitleWidget>(window.get()))
|
||||
, _body(Ui::CreateChild<RpWidget>(window.get()))
|
||||
, _shadow(std::in_place, window, st::windowShadowFg->c)
|
||||
, _dpi(GetDpiForWindowSupported() ? GetDpiForWindow(_handle) : 0) {
|
||||
Expects(_handle != nullptr);
|
||||
|
||||
|
|
@ -198,14 +182,13 @@ void WindowHelper::setNativeFrame(bool enabled) {
|
|||
enabled ? (style | WS_CAPTION) : (style & ~WS_CAPTION));
|
||||
}
|
||||
_title->setVisible(!enabled);
|
||||
if (enabled || ::Platform::IsWindows11OrGreater()) {
|
||||
if (enabled) {
|
||||
_shadow.reset();
|
||||
} else {
|
||||
_shadow.emplace(window(), st::windowShadowFg->c);
|
||||
_shadow->setResizeEnabled(!fixedSize());
|
||||
initialShadowUpdate();
|
||||
}
|
||||
updateCornersRounding();
|
||||
updateWindowFrameColors();
|
||||
SetWindowPos(
|
||||
_handle,
|
||||
|
|
@ -222,9 +205,6 @@ void WindowHelper::setNativeFrame(bool enabled) {
|
|||
}
|
||||
|
||||
void WindowHelper::initialShadowUpdate() {
|
||||
if (!_shadow) {
|
||||
return;
|
||||
}
|
||||
using Change = WindowShadow::Change;
|
||||
const auto noShadowStates = (Qt::WindowMinimized | Qt::WindowMaximized);
|
||||
if ((window()->windowState() & noShadowStates) || window()->isHidden()) {
|
||||
|
|
@ -232,6 +212,7 @@ void WindowHelper::initialShadowUpdate() {
|
|||
} else {
|
||||
_shadow->update(Change::Moved | Change::Resized | Change::Shown);
|
||||
}
|
||||
updateCornersRounding();
|
||||
}
|
||||
|
||||
void WindowHelper::updateCornersRounding() {
|
||||
|
|
@ -318,39 +299,10 @@ void WindowHelper::init() {
|
|||
size.height() - (titleShown ? titleHeight : 0));
|
||||
}, _body->lifetime());
|
||||
|
||||
hitTestRequests(
|
||||
) | rpl::filter([=](not_null<HitTestRequest*> request) {
|
||||
return ::Platform::IsWindows11OrGreater();
|
||||
}) | rpl::start_with_next([=](not_null<HitTestRequest*> request) {
|
||||
request->result = [=] {
|
||||
RECT r{};
|
||||
const auto style = GetWindowLongPtr(_handle, GWL_STYLE)
|
||||
& ~WS_CAPTION;
|
||||
const auto styleEx = GetWindowLongPtr(_handle, GWL_EXSTYLE);
|
||||
const auto dpi = style::ConvertScale(
|
||||
96 * style::DevicePixelRatio());
|
||||
if (AdjustWindowRectExForDpiSupported() && dpi) {
|
||||
AdjustWindowRectExForDpi(&r, style, false, styleEx, dpi);
|
||||
} else {
|
||||
AdjustWindowRectEx(&r, style, false, styleEx);
|
||||
}
|
||||
const auto maximized = window()->isMaximized()
|
||||
|| window()->isFullScreen();
|
||||
return (!maximized && (request->point.y() < -r.top))
|
||||
? HitTestResult::Top
|
||||
: HitTestResult::Client;
|
||||
}();
|
||||
}, window()->lifetime());
|
||||
|
||||
if (!::Platform::IsWindows11OrGreater()) {
|
||||
_shadow.emplace(window(), st::windowShadowFg->c);
|
||||
}
|
||||
|
||||
if (!::Platform::IsWindows8OrGreater()) {
|
||||
SetWindowTheme(_handle, L" ", L" ");
|
||||
QApplication::setStyle(QStyleFactory::create("Windows"));
|
||||
}
|
||||
|
||||
updateWindowFrameColors();
|
||||
|
||||
const auto handleStateChanged = [=](Qt::WindowState state) {
|
||||
|
|
@ -367,7 +319,6 @@ void WindowHelper::init() {
|
|||
handleStateChanged);
|
||||
|
||||
initialShadowUpdate();
|
||||
updateCornersRounding();
|
||||
}
|
||||
|
||||
bool WindowHelper::nativeEvent(
|
||||
|
|
@ -424,16 +375,11 @@ bool WindowHelper::handleNativeEvent(
|
|||
if (_title->isHidden() || window()->isFullScreen() || !wParam) {
|
||||
return false;
|
||||
}
|
||||
const auto r = &((LPNCCALCSIZE_PARAMS)lParam)->rgrc[0];
|
||||
const auto maximized = [&] {
|
||||
WINDOWPLACEMENT wp;
|
||||
wp.length = sizeof(WINDOWPLACEMENT);
|
||||
return GetWindowPlacement(_handle, &wp)
|
||||
&& (wp.showCmd == SW_SHOWMAXIMIZED);
|
||||
}();
|
||||
const auto addBorders = maximized
|
||||
|| ::Platform::IsWindows11OrGreater();
|
||||
if (addBorders) {
|
||||
WINDOWPLACEMENT wp;
|
||||
wp.length = sizeof(WINDOWPLACEMENT);
|
||||
if (GetWindowPlacement(_handle, &wp)
|
||||
&& (wp.showCmd == SW_SHOWMAXIMIZED)) {
|
||||
const auto r = &((LPNCCALCSIZE_PARAMS)lParam)->rgrc[0];
|
||||
const auto dpi = _dpi.current();
|
||||
const auto style = GetWindowLongPtr(_handle, GWL_STYLE);
|
||||
const auto borderWidth = ((GetSystemMetricsForDpiSupported() && dpi)
|
||||
|
|
@ -444,12 +390,8 @@ bool WindowHelper::handleNativeEvent(
|
|||
- ((style & WS_CAPTION) ? 0 : 1);
|
||||
r->left += borderWidth;
|
||||
r->right -= borderWidth;
|
||||
if (maximized) {
|
||||
r->top += borderWidth;
|
||||
}
|
||||
r->top += borderWidth;
|
||||
r->bottom -= borderWidth;
|
||||
}
|
||||
if (maximized) {
|
||||
const auto hMonitor = MonitorFromWindow(
|
||||
_handle,
|
||||
MONITOR_DEFAULTTONEAREST);
|
||||
|
|
@ -465,8 +407,10 @@ bool WindowHelper::handleNativeEvent(
|
|||
case ABE_BOTTOM: r->bottom -= 1; break;
|
||||
}
|
||||
}
|
||||
if (result) *result = 0;
|
||||
} else {
|
||||
if (result) *result = WVR_REDRAW;
|
||||
}
|
||||
if (result) *result = addBorders ? 0 : WVR_REDRAW;
|
||||
} return true;
|
||||
|
||||
case WM_NCRBUTTONUP: {
|
||||
|
|
@ -495,15 +439,15 @@ bool WindowHelper::handleNativeEvent(
|
|||
|
||||
case WM_WINDOWPOSCHANGING:
|
||||
case WM_WINDOWPOSCHANGED: {
|
||||
auto placement = WINDOWPLACEMENT{
|
||||
.length = sizeof(WINDOWPLACEMENT),
|
||||
};
|
||||
if (!GetWindowPlacement(_handle, &placement)) {
|
||||
LOG(("System Error: GetWindowPlacement failed."));
|
||||
return false;
|
||||
}
|
||||
_title->refreshAdditionalPaddings(_handle, placement);
|
||||
if (_shadow) {
|
||||
auto placement = WINDOWPLACEMENT{
|
||||
.length = sizeof(WINDOWPLACEMENT),
|
||||
};
|
||||
if (!GetWindowPlacement(_handle, &placement)) {
|
||||
LOG(("System Error: GetWindowPlacement failed."));
|
||||
return false;
|
||||
}
|
||||
_title->refreshAdditionalPaddings(_handle, placement);
|
||||
if (placement.showCmd == SW_SHOWMAXIMIZED
|
||||
|| placement.showCmd == SW_SHOWMINIMIZED) {
|
||||
_shadow->update(WindowShadow::Change::Hidden);
|
||||
|
|
@ -529,8 +473,8 @@ bool WindowHelper::handleNativeEvent(
|
|||
}
|
||||
window()->windowHandle()->windowStateChanged(state);
|
||||
}
|
||||
_title->refreshAdditionalPaddings(_handle);
|
||||
if (_shadow) {
|
||||
_title->refreshAdditionalPaddings(_handle);
|
||||
const auto changes = (wParam == SIZE_MINIMIZED
|
||||
|| wParam == SIZE_MAXIMIZED)
|
||||
? WindowShadow::Change::Hidden
|
||||
|
|
@ -574,8 +518,8 @@ bool WindowHelper::handleNativeEvent(
|
|||
} return false;
|
||||
|
||||
case WM_MOVE: {
|
||||
_title->refreshAdditionalPaddings(_handle);
|
||||
if (_shadow) {
|
||||
_title->refreshAdditionalPaddings(_handle);
|
||||
_shadow->update(WindowShadow::Change::Moved);
|
||||
}
|
||||
} return false;
|
||||
|
|
@ -588,9 +532,9 @@ bool WindowHelper::handleNativeEvent(
|
|||
POINT p{ GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
|
||||
ScreenToClient(_handle, &p);
|
||||
const auto mapped = QPoint(p.x, p.y) / window()->devicePixelRatioF();
|
||||
*result = [&]() -> LRESULT {
|
||||
*result = [&] {
|
||||
if (!window()->rect().contains(mapped)) {
|
||||
return DefWindowProc(_handle, msg, wParam, lParam);
|
||||
return HTTRANSPARENT;
|
||||
}
|
||||
auto request = HitTestRequest{
|
||||
.point = mapped,
|
||||
|
|
@ -613,7 +557,7 @@ bool WindowHelper::handleNativeEvent(
|
|||
case HitTestResult::Close: return systemButtonHitTest(result);
|
||||
|
||||
case HitTestResult::None:
|
||||
default: return DefWindowProc(_handle, msg, wParam, lParam);
|
||||
default: return HTTRANSPARENT;
|
||||
};
|
||||
}();
|
||||
_systemButtonOver.fire(systemButtonHitTest(*result));
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue