Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
kassane committed Jan 11, 2024
1 parent ad3ca49 commit 657ed1b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/sokol/c/sokol_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 657ed1b

Please sign in to comment.