Skip to content

Commit e8a5384

Browse files
Test ime blocker
1 parent ebc783a commit e8a5384

File tree

4 files changed

+81
-1
lines changed

4 files changed

+81
-1
lines changed
Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
package com.cleanroommc.client;
22

3+
import com.cleanroommc.client.ime.WindowsIMEHandler;
4+
import net.minecraftforge.fml.common.FMLLog;
5+
import org.lwjgl.glfw.GLFW;
6+
7+
import java.util.function.Consumer;
8+
39
public class IMEHandler {
10+
private static Consumer<Boolean> instance;
11+
static {
12+
switch (GLFW.glfwGetPlatform()) {
13+
case GLFW.GLFW_PLATFORM_WIN32 -> instance = new WindowsIMEHandler();
14+
default -> FMLLog.log.warn("Unsupported platform: " + GLFW.glfwGetPlatform());
15+
}
16+
}
417
public static void setIME(boolean active) {
5-
18+
instance.accept(active);
619
}
720
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.cleanroommc.client.ime;
2+
3+
import com.sun.jna.Pointer;
4+
5+
import java.util.function.Consumer;
6+
7+
public class CocoaIMEHandler implements Consumer<Boolean> {
8+
9+
@Override
10+
public void accept(Boolean aBoolean) {
11+
12+
}
13+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.cleanroommc.client.ime;
2+
3+
import java.util.function.Consumer;
4+
5+
public class DummyIMEHandler implements Consumer<Boolean> {
6+
@Override
7+
public void accept(Boolean aBoolean) {
8+
9+
}
10+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.cleanroommc.client.ime;
2+
3+
import com.sun.jna.Native;
4+
import com.sun.jna.platform.win32.User32;
5+
import com.sun.jna.platform.win32.WinDef;
6+
import com.sun.jna.platform.win32.WinNT;
7+
8+
import java.util.function.Consumer;
9+
import java.util.function.Supplier;
10+
11+
public class WindowsIMEHandler implements Consumer<Boolean> {
12+
13+
private static native WinNT.HANDLE ImmGetContext(WinDef.HWND hwnd);
14+
private static native WinNT.HANDLE ImmAssociateContext(WinDef.HWND hwnd, WinNT.HANDLE himc);
15+
private static native boolean ImmReleaseContext(WinDef.HWND hwnd, WinNT.HANDLE himc);
16+
private static native WinNT.HANDLE ImmCreateContext();
17+
private static native boolean ImmDestroyContext(WinNT.HANDLE himc);
18+
19+
static {
20+
Native.register("imm32");
21+
}
22+
23+
User32 user32 = User32.INSTANCE;
24+
25+
@Override
26+
public void accept(Boolean active) {
27+
WinDef.HWND hwnd = user32.GetForegroundWindow();
28+
WinNT.HANDLE himc;
29+
if (active) {
30+
himc = ImmGetContext(hwnd);
31+
if (himc == null) {
32+
himc = ImmCreateContext();
33+
ImmAssociateContext(hwnd, himc);
34+
}
35+
} else {
36+
himc = ImmAssociateContext(hwnd, null);
37+
if (himc != null) {
38+
ImmDestroyContext(himc);
39+
}
40+
}
41+
ImmReleaseContext(hwnd, himc);
42+
}
43+
44+
}

0 commit comments

Comments
 (0)