diff --git a/graphics/glfw/src/main/java/de/staropensource/sosengine/graphics/glfw/GlfwSubsystem.java b/graphics/glfw/src/main/java/de/staropensource/sosengine/graphics/glfw/GlfwSubsystem.java
index e74f95c..c222f5e 100644
--- a/graphics/glfw/src/main/java/de/staropensource/sosengine/graphics/glfw/GlfwSubsystem.java
+++ b/graphics/glfw/src/main/java/de/staropensource/sosengine/graphics/glfw/GlfwSubsystem.java
@@ -106,7 +106,10 @@ public class GlfwSubsystem implements SubsystemMainClass {
/** {@inheritDoc} */
@Override
- public void initializeSubsystem() {}
+ public void initializeSubsystem() {
+ // Initialize configuration
+ new GlfwSubsystemConfiguration();
+ }
/** {@inheritDoc} */
@NotNull
@@ -131,6 +134,17 @@ public class GlfwSubsystem implements SubsystemMainClass {
// Set error callback
errorCallback.set();
+ // Set init hints
+ switch (GlfwSubsystemConfiguration.getInstance().getPlatform()) {
+ case ANY -> glfwInitHint(GLFW_PLATFORM, GLFW_ANY_PLATFORM);
+ case WAYLAND -> tryPlatform(GLFW_PLATFORM_WAYLAND);
+ case X11 -> tryPlatform(GLFW_PLATFORM_X11);
+ case WIN32 -> tryPlatform(GLFW_PLATFORM_WIN32);
+ case COCOA -> tryPlatform(GLFW_PLATFORM_COCOA);
+ case NONE -> glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_NULL);
+ }
+ glfwInitHint(GLFW_WAYLAND_LIBDECOR, GlfwSubsystemConfiguration.getInstance().isDisableLibdecor() ? GLFW_WAYLAND_DISABLE_LIBDECOR : GLFW_WAYLAND_PREFER_LIBDECOR);
+
// Initialize GLFW
if (!glfwInit())
throw new GlfwInitializationException();
@@ -152,4 +166,18 @@ public class GlfwSubsystem implements SubsystemMainClass {
glfwTerminate();
errorCallback.free();
}
+
+ /**
+ * Checks if the specified platform is compatible,
+ * and if so, specifies it as the platform to use.
+ *
+ * @param platform platform to try
+ * @since v1-alpha2
+ */
+ private void tryPlatform(int platform) {
+ if (glfwPlatformSupported(platform))
+ glfwInitHint(GLFW_PLATFORM, platform);
+ else
+ glfwInitHint(GLFW_PLATFORM, GLFW_ANY_PLATFORM);
+ }
}
diff --git a/graphics/glfw/src/main/java/de/staropensource/sosengine/graphics/glfw/GlfwSubsystemConfiguration.java b/graphics/glfw/src/main/java/de/staropensource/sosengine/graphics/glfw/GlfwSubsystemConfiguration.java
new file mode 100644
index 0000000..b4cc9dc
--- /dev/null
+++ b/graphics/glfw/src/main/java/de/staropensource/sosengine/graphics/glfw/GlfwSubsystemConfiguration.java
@@ -0,0 +1,166 @@
+/*
+ * STAROPENSOURCE ENGINE SOURCE FILE
+ * Copyright (c) 2024 The StarOpenSource Engine Contributors
+ * Licensed under the GNU Affero General Public License v3
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see
+ * Only affects the {@link GlfwPlatform#WAYLAND} platform.
+ *
+ * @since v1-alpha2
+ *
+ * -- GETTER --
+ * Gets the value for {@#link disableLibdecor}.
+ *
+ * @return variable value
+ * @see #disableLibdecor
+ * @since v1-alpha2
+ */
+ private boolean disableLibdecor;
+
+ /**
+ * Constructs this class.
+ *
+ * @see GlfwSubsystem
+ * @since v1-alpha0
+ */
+ public GlfwSubsystemConfiguration() {
+ // Only allow one instance
+ if (instance == null)
+ instance = this;
+ else
+ Logger.crash(new LogIssuer(getClass(), CodePart.ENGINE), "Tried initializing " + getClass().getName() + " twice");
+
+ loadDefaultConfiguration();
+ }
+
+ /** {@inheritDoc} */
+ public void loadConfiguration(@NotNull Properties properties) {
+ // Define variables
+ PropertyParser parser = new PropertyParser(properties);
+
+ for (String property : properties.stringPropertyNames()) {
+ // Check if property name starts with group
+ if (!property.startsWith(group)) continue;
+
+ // Skip to important stuff
+ property = property.substring(group.length());
+
+ // Match settings
+ try {
+ switch (property) {
+ case "platform" -> {
+ try {
+ platform = GlfwPlatform.valueOf(parser.getString(group + property).toUpperCase());
+ } catch (IllegalArgumentException ignored) {
+ System.out.println("Platform " + parser.getString(group + property) + " is not valid");
+ }
+ }
+ case "disableLibdecor" -> disableLibdecor = parser.getBoolean(group + property);
+ }
+ } catch (NullPointerException ignored) {}
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void loadConfiguration() {
+ loadConfiguration(System.getProperties());
+ }
+
+ /** {@inheritDoc} */
+ public void loadDefaultConfiguration() {
+ platform = GlfwPlatform.ANY;
+ disableLibdecor = false;
+ }
+
+ /** {@inheritDoc} */
+ @Nullable
+ public Object getSetting(@NotNull String setting) {
+ switch (setting) {
+ case "platform" -> { return platform; }
+ case "disableLibdecor" -> { return disableLibdecor; }
+ default -> { return null; }
+ }
+ }
+}
diff --git a/graphics/glfw/src/main/java/de/staropensource/sosengine/graphics/glfw/types/GlfwPlatform.java b/graphics/glfw/src/main/java/de/staropensource/sosengine/graphics/glfw/types/GlfwPlatform.java
new file mode 100644
index 0000000..4687b01
--- /dev/null
+++ b/graphics/glfw/src/main/java/de/staropensource/sosengine/graphics/glfw/types/GlfwPlatform.java
@@ -0,0 +1,72 @@
+/*
+ * STAROPENSOURCE ENGINE SOURCE FILE
+ * Copyright (c) 2024 The StarOpenSource Engine Contributors
+ * Licensed under the GNU Affero General Public License v3
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see