Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -513,22 +513,24 @@ public static Object[] getModOptions()
loadInterface(); //load the elements if they are not loaded yet
if (Common.IS_SYSTEM_MAC)
{
//on macOS show reverse scrolling, reverse hotbar scrolling, trackpad sensitivity, momentum scrolling, interface smooth scroll options, disable ctrl+click fix
Object[] arr = new Object[6];
//on macOS show reverse scrolling, reverse hotbar scrolling, trackpad sensitivity, momentum scrolling, interface smooth scroll options, disable ctrl+click fix, lock scroll while attacking
Object[] arr = new Object[7];
arr[0] = REVERSE_SCROLLING;
arr[1] = REVERSE_HOTBAR_SCROLLING;
arr[2] = TRACKPAD_SENSITIVITY;
arr[3] = MOMENTUM_SCROLLING;
arr[4] = INTERFACE_SMOOTH_SCROLL;
arr[5] = DISABLE_CTRL_CLICK_FIX;
arr[6] = LOCK_SCROLL_WHILE_ATTACKING;
return arr;
}
else
{
//otherwise show reverse scrolling, and reverse hotbar scrolling options only
Object[] arr = new Object[2];
//otherwise show reverse scrolling, reverse hotbar scrolling, and lock scroll while attacking options only
Object[] arr = new Object[3];
arr[0] = REVERSE_SCROLLING;
arr[1] = REVERSE_HOTBAR_SCROLLING;
arr[2] = LOCK_SCROLL_WHILE_ATTACKING;
return arr;
}
}
Expand Down Expand Up @@ -580,6 +582,13 @@ private static void loadInterface()
(value) -> reverseHotbarScrolling = value,
"Reverses the direction that scrolling goes for the hotbar when enabled.");

LOCK_SCROLL_WHILE_ATTACKING = booleanOption(
"options.macos_input_fixes.lock_scroll_while_attacking",
"Lock Scroll While Attacking",
() -> lockScrollWhileAttacking,
(value) -> lockScrollWhileAttacking = value,
"Ignores scrolling while the attack key is held down and you are in game (no screen open).\nUseful on a Magic Mouse or trackpad, where a small finger movement while mining\ncauses an accidental scroll that switches the selected hotbar item.\nDefault: OFF\nOFF: scrolling always works.\nON: scrolling is ignored while the attack key is held down.");

REVERSE_SCROLLING = booleanOption(
"options.macos_input_fixes.reverse_scrolling",
"Reverse Scrolling",
Expand Down Expand Up @@ -748,6 +757,20 @@ public static void loadOptions()
}
disableCtrlClickFix = actualValue;
}
if (compoundTag.contains("lockScrollWhileAttacking")) //read lockScrollWhileAttacking option
{
boolean actualValue = false; //default value
try
{
Boolean value = Boolean.parseBoolean(getStringHelper(compoundTag, "lockScrollWhileAttacking"));
actualValue = value;
}
catch (Exception ex1)
{
ex1.printStackTrace(System.err); //failed to parse
}
lockScrollWhileAttacking = actualValue;
}

loadedInterface = false;
}
Expand All @@ -768,6 +791,7 @@ public static void saveOptions()
printWriter.println("momentumScrolling:" + momentumScrolling);
printWriter.println("interfaceSmoothScroll:" + interfaceSmoothScroll);
printWriter.println("disableCtrlClickFix:" + disableCtrlClickFix);
printWriter.println("lockScrollWhileAttacking:" + lockScrollWhileAttacking);
}
catch (Exception ex2)
{
Expand Down Expand Up @@ -828,4 +852,12 @@ public static void setInterfaceSmoothScroll(boolean value)

public static boolean disableCtrlClickFix = false;
public static Object DISABLE_CTRL_CLICK_FIX;

//lock scroll while attacking option code:
//when enabled, scroll events are ignored while the attack key is held down and we're in game (no screen open)
//this stops a small finger movement on a Magic Mouse / trackpad from changing the selected hotbar slot while mining
//this option works on all platforms

public static boolean lockScrollWhileAttacking = false;
public static Object LOCK_SCROLL_WHILE_ATTACKING;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.hamarb123.macos_input_fixes.client.mixin;

import net.minecraft.client.Minecraft;
import net.minecraft.client.MouseHandler;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
Expand All @@ -10,9 +12,41 @@
import com.hamarb123.macos_input_fixes.client.Common;
import com.hamarb123.macos_input_fixes.client.ModOptions;

//? if >=26.1 {
import com.hamarb123.macos_input_fixes.client.ModernFabricReflectionHelper;
//?}

@Mixin(MouseHandler.class)
public class MouseHandlerMixin
{
@Shadow
private Minecraft minecraft;

//if the lock scroll while attacking option is enabled, ignore scroll events while the attack key is held down in game
//this stops a small finger movement on a Magic Mouse / trackpad from changing the selected hotbar slot while mining
//this works on all platforms
@Inject(at = @At("HEAD"), method = "onScroll(JDD)V", cancellable = true)
private void lockScrollWhileAttacking(long window, double horizontal, double vertical, CallbackInfo info)
{
//only act if the option is on and we're actually in game (no screen or overlay open)
if (!ModOptions.lockScrollWhileAttacking) return;
//? if >=26.1 {
if (ModernFabricReflectionHelper.getOverlay(this.minecraft) != null) return;
if (ModernFabricReflectionHelper.getScreen(this.minecraft) != null) return;
//?} else {
/*
if (this.minecraft.getOverlay() != null) return;
if (this.minecraft.screen != null) return;
*///?}
if (this.minecraft.player == null) return;

//cancel the scroll while the attack key is held down (default left click, follows any rebind of the attack key)
if (this.minecraft.options.keyAttack.isDown())
{
info.cancel();
}
}

@Inject(at = @At("HEAD"), method = "onScroll(JDD)V", cancellable = true)
private void onMouseScroll(long window, double horizontal, double vertical, CallbackInfo info)
{
Expand Down