Skip to content

Commit

Permalink
[macOS] Fix redraw lag at the edge of the resizing window.
Browse files Browse the repository at this point in the history
  • Loading branch information
bruvzg committed Sep 15, 2022
1 parent 4ba934b commit 734b891
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions platform/macos/display_server_macos.h
Expand Up @@ -85,6 +85,8 @@ class DisplayServerMacOS : public DisplayServer {
Size2i max_size;
Size2i size;

NSRect last_frame_rect;

bool im_active = false;
Size2i im_position;

Expand Down
18 changes: 18 additions & 0 deletions platform/macos/godot_content_view.mm
Expand Up @@ -61,6 +61,24 @@ - (void)displayLayer:(CALayer *)layer {
@implementation GodotContentView

- (void)setFrameSize:(NSSize)newSize {
DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
if (ds && ds->has_window(window_id)) {
DisplayServerMacOS::WindowData &wd = ds->get_window(window_id);
NSRect frameRect = [wd.window_object frame];
bool left = (wd.last_frame_rect.origin.x != frameRect.origin.x);
bool top = (wd.last_frame_rect.origin.y == frameRect.origin.y);
if (left && top) {
self.layerContentsPlacement = NSViewLayerContentsPlacementBottomRight;
} else if (left && !top) {
self.layerContentsPlacement = NSViewLayerContentsPlacementTopRight;
} else if (!left && top) {
self.layerContentsPlacement = NSViewLayerContentsPlacementBottomLeft;
} else {
self.layerContentsPlacement = NSViewLayerContentsPlacementTopLeft;
}
wd.last_frame_rect = frameRect;
}

[super setFrameSize:newSize];
[self.layer setNeedsDisplay]; // Force "drawRect" call.
}
Expand Down
4 changes: 3 additions & 1 deletion platform/macos/godot_window_delegate.mm
Expand Up @@ -151,7 +151,9 @@ - (void)windowDidChangeBackingProperties:(NSNotification *)notification {

- (void)windowWillStartLiveResize:(NSNotification *)notification {
DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
if (ds) {
if (ds && ds->has_window(window_id)) {
DisplayServerMacOS::WindowData &wd = ds->get_window(window_id);
wd.last_frame_rect = [wd.window_object frame];
ds->set_is_resizing(true);
}
}
Expand Down

0 comments on commit 734b891

Please sign in to comment.