Skip to content

Commit

Permalink
Fix window resizing on macOS by considering current screen scale factor
Browse files Browse the repository at this point in the history
  • Loading branch information
Misha999777 authored and SWinxy committed Dec 16, 2024
1 parent c3d4375 commit 5e7e122
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/org/lwjgl/opengl/awt/PlatformMacOSXGLCanvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.HierarchyEvent;
import java.awt.geom.AffineTransform;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.DoubleBuffer;
Expand Down Expand Up @@ -88,13 +89,15 @@ public class PlatformMacOSXGLCanvas implements PlatformGLCanvas {
}

public JAWTDrawingSurface ds;
private Canvas canvas;
private long view;
private int width;
private int height;

@Override
public long create(Canvas canvas, GLData attribs, GLData effective) throws AWTException {
this.ds = JAWT_GetDrawingSurface(canvas, awt.GetDrawingSurface());
this.canvas = canvas;
canvas.addHierarchyListener(e -> {
// if the canvas, or a parent component is hidden/shown, we must update the hidden state of the layer
if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) > 0) {
Expand Down Expand Up @@ -356,7 +359,10 @@ public boolean makeCurrent(long context) {
int height = dsi.bounds().height();
if (width != this.width || height != this.height) {
// [NSOpenGLCotext update] seems bugged. Updating renderer context with CGL works.
CGLSetParameter(context, kCGLCPSurfaceBackingSize, new int[]{width, height});
AffineTransform transform = canvas.getGraphicsConfiguration().getDefaultTransform();
int backingWidth = (int) (width * transform.getScaleX());
int backingHeight = (int) (height * transform.getScaleY());
CGLSetParameter(context, kCGLCPSurfaceBackingSize, new int[]{backingWidth, backingHeight});
CGLEnable(context, kCGLCESurfaceBackingSize);
this.width = width;
this.height = height;
Expand Down

0 comments on commit 5e7e122

Please sign in to comment.