Skip to content

Commit

Permalink
better RawInput exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Taskeren committed May 10, 2024
1 parent be012b8 commit 8ec2304
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/main/java/cn/taskeren/gtnn/client/rawinput/RawInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,33 +52,42 @@ public class RawInput {
}

private static long getWindowHandle() {
checkSuccessInit();
try {
return (long) DISPLAY_WINDOW_HANDLE.invokeExact();
} catch(Throwable e) {
throw new RuntimeException(e);
throw new RawInputException("Failed to invoke getWindowHandle", e);
}
}

private static void glfwSetInputMode(long window, int type, int value) {
checkSuccessInit();
try {
GLFW_SET_INPUT_MODE.invokeExact(window, type, value);
} catch(Throwable ex) {
throw new RuntimeException(ex);
} catch(Throwable e) {
throw new RawInputException("Failed to invoke glfwSetInputMode", e);
}
}

public static boolean isSuccessInit() {
return successInit;
}

public static void checkSuccessInit() {
if(!isSuccessInit()) {
throw new RawInputException("Not successfully initialized");
}
}

/**
* Test if Raw Mouse Motion is supported.
*/
public static boolean isRawMouseMotionSupported() {
checkSuccessInit();
try {
return (boolean) GLFW_RAW_MOUSE_MOTION_SUPPORTED_HANDLE.invokeExact();
} catch(Throwable throwable) {
throw new RuntimeException(throwable);
throw new RawInputException("Failed to invoke isRawMouseMotionSupported", throwable);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package cn.taskeren.gtnn.client.rawinput;

public class RawInputException extends RuntimeException {
public RawInputException(String message) {
super(message);
}

public RawInputException(String message, Throwable cause) {
super(message, cause);
}
}

0 comments on commit 8ec2304

Please sign in to comment.