Skip to content

Commit

Permalink
🐛 Fix cursor issues on macos
Browse files Browse the repository at this point in the history
  • Loading branch information
MrCrayfish committed Jan 31, 2025
1 parent 0d01ed7 commit 9f97c41
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public int getY()
public int getScreenX()
{
Minecraft mc = Minecraft.getInstance();
return (int) (this.x * (double) mc.getWindow().getGuiScaledWidth() / (double) mc.getWindow().getScreenWidth());
return (int) (this.x * (double) mc.getWindow().getGuiScaledWidth() / (double) mc.getWindow().getWidth());
}

/**
Expand All @@ -116,7 +116,7 @@ public int getScreenX()
public int getScreenY()
{
Minecraft mc = Minecraft.getInstance();
return (int) (this.y * (double) mc.getWindow().getGuiScaledHeight() / (double) mc.getWindow().getScreenHeight());
return (int) (this.y * (double) mc.getWindow().getGuiScaledHeight() / (double) mc.getWindow().getHeight());
}

/**
Expand All @@ -141,7 +141,7 @@ public double getRenderY()
public double getRenderScreenX()
{
Minecraft mc = Minecraft.getInstance();
return this.renderX * (double) mc.getWindow().getGuiScaledWidth() / (double) mc.getWindow().getScreenWidth();
return this.renderX * (double) mc.getWindow().getGuiScaledWidth() / (double) mc.getWindow().getWidth();
}

/**
Expand All @@ -150,7 +150,7 @@ public double getRenderScreenX()
public double getRenderScreenY()
{
Minecraft mc = Minecraft.getInstance();
return this.renderY * (double) mc.getWindow().getGuiScaledHeight() / (double) mc.getWindow().getScreenHeight();
return this.renderY * (double) mc.getWindow().getGuiScaledHeight() / (double) mc.getWindow().getHeight();
}

/**
Expand Down Expand Up @@ -294,8 +294,8 @@ private void updateInputVector(Controller controller)
private void clampCursorToWindowBounds()
{
Minecraft mc = Minecraft.getInstance();
this.x = Math.max(0, Math.min(this.x, mc.getWindow().getScreenWidth()));
this.y = Math.max(0, Math.min(this.y, mc.getWindow().getScreenHeight()));
this.x = Math.max(0, Math.min(this.x, mc.getWindow().getWidth()));
this.y = Math.max(0, Math.min(this.y, mc.getWindow().getHeight()));
}

/**
Expand Down Expand Up @@ -350,8 +350,8 @@ private boolean isHoveringEventListener()
if(mc.screen == null)
return false;
// Convert the position to screen space before passing off
double cursorScreenX = this.x * (double) mc.getWindow().getGuiScaledWidth() / (double) mc.getWindow().getScreenWidth();
double cursorScreenY = this.y * (double) mc.getWindow().getGuiScaledHeight() / (double) mc.getWindow().getScreenHeight();
double cursorScreenX = this.x * (double) mc.getWindow().getGuiScaledWidth() / (double) mc.getWindow().getWidth();
double cursorScreenY = this.y * (double) mc.getWindow().getGuiScaledHeight() / (double) mc.getWindow().getHeight();
return ScreenHelper.findHoveredEventListenerExcludeList(mc.screen, cursorScreenX, cursorScreenY).isPresent();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ public static void invokeMouseMoved(Screen screen, double cursorX, double cursor
if(screen != null && mc.getOverlay() == null)
{
// Send mouse moved event to screen
double screenCursorX = cursorX * (double) mc.getWindow().getGuiScaledWidth() / (double) mc.getWindow().getScreenWidth();
double screenCursorY = cursorY * (double) mc.getWindow().getGuiScaledHeight() / (double) mc.getWindow().getScreenHeight();
double screenCursorX = cursorX * (double) mc.getWindow().getGuiScaledWidth() / (double) mc.getWindow().getWidth();
double screenCursorY = cursorY * (double) mc.getWindow().getGuiScaledHeight() / (double) mc.getWindow().getHeight();
Screen.wrapScreenError(() -> {
screen.mouseMoved(screenCursorX, screenCursorY);
}, "Controllable mouseMoved event handler", screen.getClass().getCanonicalName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public boolean sendScreenInput(Screen screen, int key, int action, int modifiers
public void sendMouseDrag(Screen screen, double dragX, double dragY, double finalMouseX, double finalMouseY, int activeButton)
{
Minecraft mc = Minecraft.getInstance();
double finalDragX = dragX * (double) mc.getWindow().getGuiScaledWidth() / (double) mc.getWindow().getScreenWidth();
double finalDragY = dragY * (double) mc.getWindow().getGuiScaledHeight() / (double) mc.getWindow().getScreenHeight();
double finalDragX = dragX * (double) mc.getWindow().getGuiScaledWidth() / (double) mc.getWindow().getWidth();
double finalDragY = dragY * (double) mc.getWindow().getGuiScaledHeight() / (double) mc.getWindow().getHeight();
Screen.wrapScreenError(() -> {
screen.mouseDragged(finalMouseX, finalMouseY, activeButton, finalDragX, finalDragY);
}, "Controllable mouseDragged event handler", screen.getClass().getCanonicalName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ public void sendMouseDrag(Screen screen, double dragX, double dragY, double fina
{
Screen.wrapScreenError(() -> {
Minecraft mc = screen.getMinecraft();
double finalDragX = dragX * (double) mc.getWindow().getGuiScaledWidth() / (double) mc.getWindow().getScreenWidth();
double finalDragY = dragY * (double) mc.getWindow().getGuiScaledHeight() / (double) mc.getWindow().getScreenHeight();
double finalDragX = dragX * (double) mc.getWindow().getGuiScaledWidth() / (double) mc.getWindow().getWidth();
double finalDragY = dragY * (double) mc.getWindow().getGuiScaledHeight() / (double) mc.getWindow().getHeight();
if(ClientHooks.onScreenMouseDragPre(screen, finalMouseX, finalMouseY, activeButton, finalDragX, finalDragY))
return;
if(screen.mouseDragged(finalMouseX, finalMouseY, activeButton, finalDragX, finalDragY))
Expand Down

0 comments on commit 9f97c41

Please sign in to comment.