From 657ed1b3d7981a8d6f29043b794ad7077596f8cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matheus=20Catarino=20Fran=C3=A7a?= Date: Thu, 11 Jan 2024 08:45:33 -0300 Subject: [PATCH] update https://github.com/floooh/sokol/commit/058d9b5feb67800a62f07ef3712094fecedaa0c2 --- src/sokol/c/sokol_app.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/sokol/c/sokol_app.h b/src/sokol/c/sokol_app.h index a9fca16..14c0457 100644 --- a/src/sokol/c/sokol_app.h +++ b/src/sokol/c/sokol_app.h @@ -3560,6 +3560,7 @@ _SOKOL_PRIVATE void _sapp_macos_update_dimensions(void) { else { _sapp.dpi_scale = 1.0f; } + _sapp.macos.view.layer.contentsScale = _sapp.dpi_scale; // NOTE: needed because we set layerContentsPlacement to a non-scaling value in windowWillStartLiveResize. const NSRect bounds = [_sapp.macos.view bounds]; _sapp.window_width = (int)roundf(bounds.size.width); _sapp.window_height = (int)roundf(bounds.size.height); @@ -3915,6 +3916,24 @@ _SOKOL_PRIVATE void _sapp_macos_frame(void) { } } +#if defined(SOKOL_METAL) +- (void)windowWillStartLiveResize:(NSNotification *)notification { + // Work around the MTKView resizing glitch by "anchoring" the layer to the window corner opposite + // to the currently manipulated corner (or edge). This prevents the content stretching back and + // forth during resizing. This is a workaround for this issue: https://github.com/floooh/sokol/issues/700 + // Can be removed if/when migrating to CAMetalLayer: https://github.com/floooh/sokol/issues/727 + bool resizing_from_left = _sapp.mouse.x < _sapp.window_width/2; + bool resizing_from_top = _sapp.mouse.y < _sapp.window_height/2; + NSViewLayerContentsPlacement placement; + if (resizing_from_left) { + placement = resizing_from_top ? NSViewLayerContentsPlacementBottomRight : NSViewLayerContentsPlacementTopRight; + } else { + placement = resizing_from_top ? NSViewLayerContentsPlacementBottomLeft : NSViewLayerContentsPlacementTopLeft; + } + _sapp.macos.view.layerContentsPlacement = placement; +} +#endif + - (void)windowDidResize:(NSNotification*)notification { _SOKOL_UNUSED(notification); _sapp_macos_update_dimensions();