Skip to content

Commit

Permalink
Add a raw mouse input mode toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
eigenraven committed Apr 6, 2024
1 parent 1e0a33c commit fdfc54e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/main/java/me/eigenraven/lwjgl3ify/client/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
import net.minecraftforge.common.MinecraftForge;

import org.lwjglx.input.Keyboard;
import org.lwjglx.opengl.Display;

import cpw.mods.fml.client.event.ConfigChangedEvent;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import me.eigenraven.lwjgl3ify.CommonProxy;
import me.eigenraven.lwjgl3ify.api.InputEvents;
Expand Down Expand Up @@ -34,6 +37,9 @@ public void runCompatHooks() {
// Populate keyboard-layout-dependent key lookup tables
Keyboard.populateKeyLookupTables();
registerKeybindHandler();
FMLCommonHandler.instance()
.bus()
.register(this);
}

private static final class McKeybindHandler implements InputEvents.KeyboardListener {
Expand Down Expand Up @@ -75,4 +81,15 @@ public void onRenderGameOverlayTextEvent(RenderGameOverlayEvent.Text event) {
}
}
}

@SubscribeEvent
@SuppressWarnings("unused") // event handler
public void onConfigChange(final ConfigChangedEvent.OnConfigChangedEvent event) {
if (!event.modID.equals("lwjgl3ify")) {
return;
}
Config.config.save();
Config.reloadConfigObject();
Display.lwjgl3ify$updateRawMouseMode(Config.INPUT_RAW_MOUSE);
}
}
3 changes: 3 additions & 0 deletions src/main/java/me/eigenraven/lwjgl3ify/core/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class Config {
public static double INPUT_SCROLL_SPEED = 1.0;
public static boolean INPUT_CTRL_ALT_TEXT = false;
public static boolean INPUT_ALTGR_ESCAPE_CODES = false;
public static boolean INPUT_RAW_MOUSE = false;

public static String X11_CLASS_NAME = "minecraft";
public static String COCOA_FRAME_NAME = "minecraft";
Expand Down Expand Up @@ -157,6 +158,8 @@ public static void reloadConfigObject() {
CATEGORY_INPUT,
INPUT_ALTGR_ESCAPE_CODES,
"Allows AltGr use in Ctrl+key special key combinations (disables text character input handling when AltGr is pressed)");
INPUT_RAW_MOUSE = config
.getBoolean("rawMouseInput", CATEGORY_INPUT, INPUT_RAW_MOUSE, "Use raw (unaccelerated) mouse input");

OPENGL_DEBUG_CONTEXT = config.getBoolean(
"debugContext",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public class Lwjgl3ifyCoremod implements IFMLLoadingPlugin, IEarlyMixinLoader {
public static final Logger LOGGER = LogManager.getLogger("lwjgl3ify");

public Lwjgl3ifyCoremod() {
Config.loadConfig();
try {
LaunchClassLoader launchLoader = (LaunchClassLoader) getClass().getClassLoader();
launchLoader.addClassLoaderExclusion("org.hotswap.agent");
Expand All @@ -36,6 +35,7 @@ public Lwjgl3ifyCoremod() {
.getClass(),
e);
}
Config.loadConfig();
if (Launch.blackboard.get("lwjgl3ify:rfb-booted") != Boolean.TRUE) {
return;
}
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/org/lwjglx/opengl/Display.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import me.eigenraven.lwjgl3ify.Lwjgl3ify;
import me.eigenraven.lwjgl3ify.api.InputEvents;
import me.eigenraven.lwjgl3ify.core.Config;
import me.eigenraven.lwjgl3ify.core.Lwjgl3ifyCoremod;

public class Display {

Expand Down Expand Up @@ -188,6 +189,8 @@ public static void create(PixelFormat pixelFormat, ContextAttribs attribs, long
glfwWindowHint(GLFW_COCOA_RETINA_FRAMEBUFFER, GLFW_FALSE); // request a non-hidpi framebuffer on Retina displays
// on MacOS

lwjgl3ify$updateRawMouseMode(Config.INPUT_RAW_MOUSE);

Window.handle = glfwCreateWindow(mode.getWidth(), mode.getHeight(), windowTitle, NULL, sharedWindow);
if (Window.handle == 0L) {
throw new IllegalStateException("Failed to create Display window");
Expand Down Expand Up @@ -470,6 +473,18 @@ public void invoke(long window, int width, int height) {
Window.framebufferSizeCallback.invoke(Window.handle, x[0], y[0]);
}

public static void lwjgl3ify$updateRawMouseMode(boolean mode) {
final boolean supported = GLFW.glfwRawMouseMotionSupported();
if (isCreated()) {
if (supported) {
GLFW.glfwSetInputMode(Window.handle, GLFW_RAW_MOUSE_MOTION, mode ? GLFW_TRUE : GLFW_FALSE);
Lwjgl3ifyCoremod.LOGGER.info("Updated raw mouse input mode to " + mode);
} else if (mode) {
Lwjgl3ifyCoremod.LOGGER.warn("Raw mouse input not supported on your system.");
}
}
}

public static boolean isCreated() {
return displayCreated;
}
Expand Down

0 comments on commit fdfc54e

Please sign in to comment.