11package net .vulkanmod .config ;
22
3+ import net .minecraft .Util ;
34import org .apache .commons .lang3 .SystemUtils ;
45import org .lwjgl .glfw .GLFW ;
5- import org .lwjgl .system .Configuration ;
66
7+ import static net .vulkanmod .Initializer .CONFIG ;
78import static net .vulkanmod .Initializer .LOGGER ;
89import static org .lwjgl .glfw .GLFW .*;
910
1011public abstract class Platform {
11- private static final int activePlat = getSupportedPlat ();
12- private static final String activeDE = determineDE ();
12+ public static final Util .OS OS = Util .getPlatform ();
13+ private static int activePlat ;
14+ private static String activeDE ;
1315
1416 public static void init () {
17+ activePlat = getSupportedPlat ();
18+ activeDE = determineDE ();
19+
1520 GLFW .glfwInitHint (GLFW_PLATFORM , activePlat );
1621 LOGGER .info ("Selecting Platform: {}" , getStringFromPlat ());
1722 LOGGER .info ("GLFW: {}" , GLFW .glfwGetVersionString ());
1823 GLFW .glfwInit ();
1924 }
2025
21- //Actually detect the currently active Display Server (if both Wayland and X11 are present on the system and/or GLFW is compiled to support both)
22- private static int determineDisplayServer () {
23-
24- //Return Null platform if not on Linux (i.e. no X11 or Wayland)
26+ // Actually detect the currently active Display Server (if both Wayland and X11 are present on the system and/or GLFW is compiled to support both)
27+ private static int determineLinuxDisplayServer () {
28+ // Return Null platform if not on Linux (i.e. no X11 or Wayland)
2529 String xdgSessionType = System .getenv ("XDG_SESSION_TYPE" );
26- if (xdgSessionType == null ) return GLFW_ANY_PLATFORM ; //Likely Android
30+ if (xdgSessionType == null ) return GLFW_ANY_PLATFORM ; // Likely Android
2731 return switch (xdgSessionType ) {
28- case "wayland" -> GLFW_PLATFORM_WAYLAND ; //Wayland
29- case "x11" -> GLFW_PLATFORM_X11 ; //X11
32+ case "wayland" -> {
33+ if (CONFIG .useWayland ) {
34+ yield GLFW_PLATFORM_WAYLAND ;
35+ }
36+ else {
37+ yield GLFW_PLATFORM_X11 ;
38+ }
39+ }
40+ case "x11" -> GLFW_PLATFORM_X11 ;
3041 default -> GLFW_ANY_PLATFORM ; //Either unknown Platform or Display Server
3142 };
3243 }
@@ -35,7 +46,7 @@ private static int getSupportedPlat() {
3546 //Switch statement would be ideal, but couldn't find a good way of implementing it, so fell back to basic if statements/branches
3647 if (SystemUtils .IS_OS_WINDOWS ) return GLFW_PLATFORM_WIN32 ;
3748 if (SystemUtils .IS_OS_MAC_OSX ) return GLFW_PLATFORM_COCOA ;
38- if (SystemUtils .IS_OS_LINUX ) return determineDisplayServer (); //Linux Or Android
49+ if (SystemUtils .IS_OS_LINUX ) return determineLinuxDisplayServer (); //Linux Or Android
3950
4051 return GLFW_ANY_PLATFORM ; //Unknown platform
4152 }
@@ -61,10 +72,26 @@ private static String determineDE() {
6172 return "N/A" ;
6273 }
6374
75+ public static boolean isWindows () {
76+ return OS == Util .OS .LINUX ;
77+ }
78+
79+ public static boolean isLinux () {
80+ return OS == Util .OS .LINUX ;
81+ }
82+
83+ public static boolean isMacOS () {
84+ return OS == Util .OS .OSX ;
85+ }
86+
6487 public static int getActivePlat () {
6588 return activePlat ;
6689 }
6790
91+ public static boolean isAndroid () {
92+ return activePlat == GLFW_ANY_PLATFORM ;
93+ }
94+
6895 //Allows platform specific checks to be handled
6996 public static boolean isWayLand () {
7097 return activePlat == GLFW_PLATFORM_WAYLAND ;
@@ -74,18 +101,6 @@ public static boolean isX11() {
74101 return activePlat == GLFW_PLATFORM_X11 ;
75102 }
76103
77- public static boolean isWindows () {
78- return activePlat == GLFW_PLATFORM_WIN32 ;
79- }
80-
81- public static boolean isMacOS () {
82- return activePlat == GLFW_PLATFORM_COCOA ;
83- }
84-
85- public static boolean isAndroid () {
86- return activePlat == GLFW_ANY_PLATFORM ;
87- }
88-
89104 //Desktop Environment Names: https://wiki.archlinux.org/title/Xdg-utils#Usage
90105 public static boolean isGnome () {
91106 return activeDE .contains ("gnome" );
0 commit comments