From 7220e9d0b0e2bf9d8cbfc59e753c82a2d0a08bea Mon Sep 17 00:00:00 2001 From: Take Weiland Date: Thu, 7 Jan 2021 21:03:46 +0100 Subject: [PATCH] Set WM_CLASS and WM_INSTANCE_NAME for early progress window (#7534) --- .../minecraftforge/fml/loading/FMLLoader.java | 5 +++-- .../loading/progress/ClientVisualization.java | 18 +++++++++++++++--- .../progress/EarlyProgressVisualization.java | 16 +++++++++++----- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/fmllauncher/java/net/minecraftforge/fml/loading/FMLLoader.java b/src/fmllauncher/java/net/minecraftforge/fml/loading/FMLLoader.java index bad4de6ede..9c63f0456d 100644 --- a/src/fmllauncher/java/net/minecraftforge/fml/loading/FMLLoader.java +++ b/src/fmllauncher/java/net/minecraftforge/fml/loading/FMLLoader.java @@ -185,11 +185,12 @@ public class FMLLoader naming = commonLaunchHandler.getNaming(); dist = commonLaunchHandler.getDist(); production = commonLaunchHandler.isProduction(); - progressWindowTick = EarlyProgressVisualization.INSTANCE.accept(dist, commonLaunchHandler.isData()); + + mcVersion = (String) arguments.get("mcVersion"); + progressWindowTick = EarlyProgressVisualization.INSTANCE.accept(dist, commonLaunchHandler.isData(), mcVersion); StartupMessageManager.modLoaderConsumer().ifPresent(c->c.accept("Early Loading!")); accessTransformer.getExtension().accept(Pair.of(naming, "srg")); - mcVersion = (String) arguments.get("mcVersion"); mcpVersion = (String) arguments.get("mcpVersion"); forgeVersion = (String) arguments.get("forgeVersion"); forgeGroup = (String) arguments.get("forgeGroup"); diff --git a/src/fmllauncher/java/net/minecraftforge/fml/loading/progress/ClientVisualization.java b/src/fmllauncher/java/net/minecraftforge/fml/loading/progress/ClientVisualization.java index ec9553a6e3..faa9055b68 100644 --- a/src/fmllauncher/java/net/minecraftforge/fml/loading/progress/ClientVisualization.java +++ b/src/fmllauncher/java/net/minecraftforge/fml/loading/progress/ClientVisualization.java @@ -43,6 +43,8 @@ import java.util.function.IntSupplier; import java.util.function.LongSupplier; import java.util.function.Supplier; +import javax.annotation.Nullable; + import static org.lwjgl.glfw.GLFW.*; import static org.lwjgl.glfw.GLFW.glfwCreateWindow; import static org.lwjgl.opengl.GL11.*; @@ -60,7 +62,7 @@ class ClientVisualization implements EarlyProgressVisualization.Visualization { private GLFWFramebufferSizeCallback framebufferSizeCallback; private int[] fbSize; - private void initWindow() { + private void initWindow(@Nullable String mcVersion) { GLFWErrorCallback.createPrint(System.err).set(); long glfwInitBegin = System.nanoTime(); @@ -82,6 +84,16 @@ class ClientVisualization implements EarlyProgressVisualization.Visualization { glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); + if (mcVersion != null) + { + // this emulates what we would get without early progress window + // as vanilla never sets these, so GLFW uses the first window title + // set them explicitly to avoid it using "FML early loading progress" as the class + String vanillaWindowTitle = "Minecraft* " + mcVersion; + glfwWindowHintString(GLFW_X11_CLASS_NAME, vanillaWindowTitle); + glfwWindowHintString(GLFW_X11_INSTANCE_NAME, vanillaWindowTitle); + } + window = glfwCreateWindow(screenWidth, screenHeight, "FML early loading progress", NULL, NULL); if (window == NULL) { throw new RuntimeException("Failed to create the GLFW window"); // ignore it and make the GUI optional? @@ -301,8 +313,8 @@ class ClientVisualization implements EarlyProgressVisualization.Visualization { } @Override - public Runnable start() { - initWindow(); + public Runnable start(@Nullable String mcVersion) { + initWindow(mcVersion); renderThread.setDaemon(true); // Don't hang the game if it terminates before handoff (i.e. datagen) renderThread.start(); return org.lwjgl.glfw.GLFW::glfwPollEvents; diff --git a/src/fmllauncher/java/net/minecraftforge/fml/loading/progress/EarlyProgressVisualization.java b/src/fmllauncher/java/net/minecraftforge/fml/loading/progress/EarlyProgressVisualization.java index 8563356c31..cf2d793afd 100644 --- a/src/fmllauncher/java/net/minecraftforge/fml/loading/progress/EarlyProgressVisualization.java +++ b/src/fmllauncher/java/net/minecraftforge/fml/loading/progress/EarlyProgressVisualization.java @@ -21,20 +21,26 @@ package net.minecraftforge.fml.loading.progress; import net.minecraftforge.api.distmarker.Dist; -import java.util.Locale; import java.util.function.IntConsumer; import java.util.function.IntSupplier; import java.util.function.LongSupplier; import java.util.function.Supplier; +import javax.annotation.Nullable; + public enum EarlyProgressVisualization { INSTANCE; private Visualization visualization; - public Runnable accept(final Dist dist, final boolean isData) { + public Runnable accept(Dist dist, boolean isData) + { + return accept(dist, isData, null); + } + + public Runnable accept(final Dist dist, final boolean isData, @Nullable String mcVersion) { visualization = !isData && dist.isClient() && Boolean.parseBoolean(System.getProperty("fml.earlyprogresswindow", "true")) ? new ClientVisualization() : new NoVisualization(); - return visualization.start(); + return visualization.start(mcVersion); } public long handOffWindow(final IntSupplier width, final IntSupplier height, final Supplier title, final LongSupplier monitor) { @@ -46,7 +52,7 @@ public enum EarlyProgressVisualization { } interface Visualization { - Runnable start(); + Runnable start(@Nullable String mcVersion); default long handOffWindow(final IntSupplier width, final IntSupplier height, final Supplier title, LongSupplier monitorSupplier) { return new LongSupplier() { @@ -63,7 +69,7 @@ public enum EarlyProgressVisualization { private static class NoVisualization implements Visualization { @Override - public Runnable start() { + public Runnable start(@Nullable String mcVersion) { return () -> {}; } }