Skip to content

Commit

Permalink
fix: load x11 controller from wayland
Browse files Browse the repository at this point in the history
  • Loading branch information
LemonCaramel committed Aug 25, 2023
1 parent 914909e commit 15fe798
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions common/src/main/java/moe/caramel/chat/driver/IController.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package moe.caramel.chat.driver;

import com.sun.jna.Platform;
import moe.caramel.chat.driver.arch.darwin.DarwinController;
import moe.caramel.chat.driver.arch.unknown.UnknownController;
import moe.caramel.chat.driver.arch.win.WinController;
import moe.caramel.chat.driver.arch.x11.X11Controller;
import moe.caramel.chat.util.ModLogger;
import moe.caramel.chat.wrapper.AbstractIMEWrapper;
import net.minecraft.client.gui.screens.Screen;
import org.lwjgl.glfw.GLFW;

/**
* Controller Interface
Expand Down Expand Up @@ -43,25 +43,21 @@ public interface IController {
*/
static IController getController() {
try {
// Windows
if (Platform.isWindows()) {
return new WinController();
}
// macOS
else if (Platform.isMac()) {
return new DarwinController();
}
// X11
else if (Platform.isX11()) {
return new X11Controller();
}
// What?
else {
throw new UnsupportedOperationException();
}
return switch (GLFW.glfwGetPlatform()) {
// Windows
case GLFW.GLFW_PLATFORM_WIN32 -> new WinController();
// macOS
case GLFW.GLFW_PLATFORM_COCOA -> new DarwinController();
// Linux (X11)
case GLFW.GLFW_PLATFORM_X11 -> new X11Controller();
// What?
default -> throw new UnsupportedOperationException();
};
} catch (final UnsupportedOperationException ignored) {
ModLogger.error("This platform is not supported by CocoaInput Driver.");
} catch (final Exception exception) {
ModLogger.error("Error while loading the CocoaInput Driver", exception);
return new UnknownController();
ModLogger.error("Error while loading the CocoaInput Driver.", exception);
}
return new UnknownController();
}
}

0 comments on commit 15fe798

Please sign in to comment.