Browse Source

[Avalonia.Native] Add shouldResize value to SetWindowState, don't resize on Window move (#19088)

* [Avalonia.Native] Add shouldResize value to SetWindowState, don't resize on Window move

* Handle Window move as well

* Wrap around Switch
pull/19096/head
Tim Miller 8 months ago
committed by GitHub
parent
commit
b25a438d6f
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 18
      native/Avalonia.Native/src/OSX/AvnWindow.mm
  2. 2
      native/Avalonia.Native/src/OSX/WindowImpl.h
  3. 94
      native/Avalonia.Native/src/OSX/WindowImpl.mm

18
native/Avalonia.Native/src/OSX/AvnWindow.mm

@ -435,9 +435,23 @@
return; return;
} }
if(window->WindowState() == Maximized) // If the window has been moved into a position where it's "zoomed"
// Then it should be set as Maximized.
if (window->WindowState() != Maximized && window->IsZoomed())
{ {
window->SetWindowState(Normal); window->SetWindowState(Maximized, false);
}
// We should only return the window state to normal if
// the internal window state is maximized, and macOS says
// the window is no longer zoomed (I.E, the user has moved it)
// Stage Manager will "move" the window when repositioning it
// So if the window was "maximized" before, it should stay maximized
else if(window->WindowState() == Maximized && !window->IsZoomed())
{
// If we're moving the window while maximized,
// we need to let macOS handle if it should be resized
// And not handle it ourselves.
window->SetWindowState(Normal, false);
} }
} }

2
native/Avalonia.Native/src/OSX/WindowImpl.h

@ -71,6 +71,8 @@ BEGIN_INTERFACE_MAP()
void ExitFullScreenMode (); void ExitFullScreenMode ();
virtual HRESULT SetWindowState (AvnWindowState state) override; virtual HRESULT SetWindowState (AvnWindowState state) override;
virtual HRESULT SetWindowState (AvnWindowState state, bool shouldResize);
virtual bool IsModal() override; virtual bool IsModal() override;

94
native/Avalonia.Native/src/OSX/WindowImpl.mm

@ -451,6 +451,10 @@ void WindowImpl::ExitFullScreenMode() {
} }
HRESULT WindowImpl::SetWindowState(AvnWindowState state) { HRESULT WindowImpl::SetWindowState(AvnWindowState state) {
return SetWindowState(state, true);
}
HRESULT WindowImpl::SetWindowState(AvnWindowState state, bool shouldResize) {
START_COM_CALL; START_COM_CALL;
@autoreleasepool { @autoreleasepool {
@ -474,61 +478,63 @@ HRESULT WindowImpl::SetWindowState(AvnWindowState state) {
if (_shown) { if (_shown) {
_actualWindowState = _lastWindowState; _actualWindowState = _lastWindowState;
switch (state) { if (shouldResize) {
case Maximized: switch (state) {
if (currentState == FullScreen) { case Maximized:
ExitFullScreenMode(); if (currentState == FullScreen) {
} ExitFullScreenMode();
}
lastPositionSet.X = 0; lastPositionSet.X = 0;
lastPositionSet.Y = 0; lastPositionSet.Y = 0;
if ([Window isMiniaturized]) { if ([Window isMiniaturized]) {
[Window deminiaturize:Window]; [Window deminiaturize:Window];
} }
if (!IsZoomed()) { if (!IsZoomed()) {
DoZoom(); DoZoom();
} }
break; break;
case Minimized: case Minimized:
if (currentState == FullScreen) { if (currentState == FullScreen) {
ExitFullScreenMode(); ExitFullScreenMode();
} else { } else {
[Window miniaturize:Window]; [Window miniaturize:Window];
} }
break; break;
case FullScreen: case FullScreen:
if ([Window isMiniaturized]) { if ([Window isMiniaturized]) {
[Window deminiaturize:Window]; [Window deminiaturize:Window];
} }
EnterFullScreenMode(); EnterFullScreenMode();
break; break;
case Normal: case Normal:
if ([Window isMiniaturized]) { if ([Window isMiniaturized]) {
[Window deminiaturize:Window]; [Window deminiaturize:Window];
} }
if (currentState == FullScreen) { if (currentState == FullScreen) {
ExitFullScreenMode(); ExitFullScreenMode();
} }
if (IsZoomed()) { if (IsZoomed()) {
if (_decorations == SystemDecorationsFull) { if (_decorations == SystemDecorationsFull) {
DoZoom(); DoZoom();
} else { } else {
[Window setFrame:_preZoomSize display:true]; [Window setFrame:_preZoomSize display:true];
auto newFrame = [Window contentRectForFrameRect:[Window frame]].size; auto newFrame = [Window contentRectForFrameRect:[Window frame]].size;
[View setFrameSize:newFrame]; [View setFrameSize:newFrame];
} }
} }
break; break;
}
} }
WindowEvents->WindowStateChanged(_actualWindowState); WindowEvents->WindowStateChanged(_actualWindowState);

Loading…
Cancel
Save