diff --git a/common/src/main/java/net/deechael/concentration/mixin/MainMixin.java b/common/src/main/java/net/deechael/concentration/mixin/MainMixin.java deleted file mode 100644 index fe3d1bf..0000000 --- a/common/src/main/java/net/deechael/concentration/mixin/MainMixin.java +++ /dev/null @@ -1,10 +0,0 @@ -package net.deechael.concentration.mixin; - -import net.minecraft.client.main.Main; -import org.spongepowered.asm.mixin.Mixin; - -@Mixin(Main.class) -public class MainMixin { - - -} diff --git a/common/src/main/java/net/deechael/concentration/mixin/VideoSettingsScreenMixin.java b/common/src/main/java/net/deechael/concentration/mixin/VideoSettingsScreenMixin.java index e0b035f..3a3071f 100644 --- a/common/src/main/java/net/deechael/concentration/mixin/VideoSettingsScreenMixin.java +++ b/common/src/main/java/net/deechael/concentration/mixin/VideoSettingsScreenMixin.java @@ -89,7 +89,11 @@ public abstract class VideoSettingsScreenMixin extends OptionsSubScreen { @Unique private static OptionInstance concentration$wrapperFullscreen(Options options) { // Don't put a constant to the second parameter, or else whatever fullscreen you are, when you open video settings page, the value shown is always the same - return OptionInstance.createBoolean("options.fullscreen", options.fullscreen().get(), (value) -> Concentration.toggleFullScreenMode(options, value)); + return OptionInstance.createBoolean( + "options.fullscreen", + options.fullscreen().get(), + (value) -> Concentration.toggleFullScreenMode(options, value) + ); } @Shadow diff --git a/common/src/main/resources/concentration.mixins.json b/common/src/main/resources/concentration.mixins.json index f1dc87f..51c6753 100644 --- a/common/src/main/resources/concentration.mixins.json +++ b/common/src/main/resources/concentration.mixins.json @@ -7,7 +7,6 @@ "mixins": [], "client": [ "KeyboardHandlerMixin", - "MainMixin", "VideoSettingsScreenMixin", "accessor.WindowAccessor" ], diff --git a/fabric/build.gradle b/fabric/build.gradle index ebe191b..0dae75a 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -19,8 +19,8 @@ dependencies { modImplementation "net.fabricmc.fabric-api:fabric-api:${fabric_version}" modImplementation "maven.modrinth:modmenu:11.0.0" - modImplementation "maven.modrinth:sodium:mc1.21-0.5.11" modImplementation "maven.modrinth:sodium:mc1.21-0.6.0-beta.2-fabric" + modImplementation "maven.modrinth:sodium-extra:mc1.21.1-0.6.0-beta.3+fabric" modImplementation "maven.modrinth:vulkanmod:0.4.9-fabric,1.21" } diff --git a/fabric/src/main/java/net/deechael/concentration/fabric/ConcentrationFabricCaching.java b/fabric/src/main/java/net/deechael/concentration/fabric/ConcentrationFabricCaching.java index 07e718b..c753be2 100644 --- a/fabric/src/main/java/net/deechael/concentration/fabric/ConcentrationFabricCaching.java +++ b/fabric/src/main/java/net/deechael/concentration/fabric/ConcentrationFabricCaching.java @@ -6,7 +6,7 @@ public class ConcentrationFabricCaching { public static boolean cachedSize = false; public static boolean cachedPos = false; - public static boolean cacheSizeLock = false; + public static boolean cacheSizeLock = true; public static int cachedX = 0; public static int cachedY = 0; diff --git a/fabric/src/main/java/net/deechael/concentration/fabric/compat/SodiumExtraCompat.java b/fabric/src/main/java/net/deechael/concentration/fabric/compat/SodiumExtraCompat.java new file mode 100644 index 0000000..912f095 --- /dev/null +++ b/fabric/src/main/java/net/deechael/concentration/fabric/compat/SodiumExtraCompat.java @@ -0,0 +1,21 @@ +package net.deechael.concentration.fabric.compat; + +import me.flashyreese.mods.sodiumextra.client.SodiumExtraClientMod; +import net.fabricmc.loader.api.FabricLoader; + +public class SodiumExtraCompat { + + public static boolean checkMacReduceResolution() { + if (!FabricLoader.getInstance().isModLoaded("sodium-extra")) + return false; + String os = System.getProperty("os.name").toLowerCase(); + if (!(os.contains("mac") || os.contains("darwin"))) + return false; + return checkMacReduceResolution0(); + } + + private static boolean checkMacReduceResolution0() { + return SodiumExtraClientMod.options().extraSettings.reduceResolutionOnMac; + } + +} diff --git a/fabric/src/main/java/net/deechael/concentration/fabric/mixin/GLFWMixin.java b/fabric/src/main/java/net/deechael/concentration/fabric/mixin/GLFWMixin.java index 32e4cce..4f78eab 100644 --- a/fabric/src/main/java/net/deechael/concentration/fabric/mixin/GLFWMixin.java +++ b/fabric/src/main/java/net/deechael/concentration/fabric/mixin/GLFWMixin.java @@ -28,12 +28,13 @@ public class GLFWMixin { @Inject(method = "glfwSetWindowMonitor", at = @At("HEAD"), cancellable = true) private static void inject$glfwSetWindowMonitor(long window, long monitor, int xpos, int ypos, int width, int height, int refreshRate, CallbackInfo ci) { - ConcentrationConstants.LOGGER.info("================= [Concentration Start] ================="); - ConcentrationConstants.LOGGER.info("Trying to modify window monitor"); - Window windowInstance = Minecraft.getInstance().getWindow(); if (windowInstance == null) return; + + ConcentrationConstants.LOGGER.info("================= [Concentration Start] ================="); + ConcentrationConstants.LOGGER.info("Trying to modify window monitor"); + WindowAccessor accessor = (WindowAccessor) (Object) windowInstance; if (windowInstance.isFullscreen()) @@ -94,7 +95,7 @@ public class GLFWMixin { finalHeight = config.height + (config.height == height ? 1 : 0); } else { finalX = monitorInstance.getX(); - finalY = monitorInstance.getY() - 1; + finalY = monitorInstance.getY(); finalWidth = width; finalHeight = height + 1; } @@ -132,6 +133,10 @@ public class GLFWMixin { ConcentrationConstants.LOGGER.info("Unlocked size caching"); } + if (monitor != 0L) { + ConcentrationFabricCaching.lastMonitor = monitor; + } + ConcentrationConstants.LOGGER.info("Window size: {}, {}, position: {}, {}", finalWidth, finalHeight, finalX, finalY); ConcentrationConstants.LOGGER.info("Trying to resize and reposition the window"); diff --git a/fabric/src/main/java/net/deechael/concentration/fabric/mixin/WindowMixin.java b/fabric/src/main/java/net/deechael/concentration/fabric/mixin/WindowMixin.java index 2131804..74f2864 100644 --- a/fabric/src/main/java/net/deechael/concentration/fabric/mixin/WindowMixin.java +++ b/fabric/src/main/java/net/deechael/concentration/fabric/mixin/WindowMixin.java @@ -1,13 +1,12 @@ package net.deechael.concentration.fabric.mixin; -import com.mojang.blaze3d.platform.Monitor; -import com.mojang.blaze3d.platform.ScreenManager; -import com.mojang.blaze3d.platform.VideoMode; -import com.mojang.blaze3d.platform.Window; +import com.mojang.blaze3d.platform.*; import net.deechael.concentration.ConcentrationConstants; import net.deechael.concentration.FullscreenMode; import net.deechael.concentration.config.Config; +import net.deechael.concentration.config.ConfigProvider; import net.deechael.concentration.fabric.ConcentrationFabricCaching; +import net.deechael.concentration.fabric.compat.SodiumExtraCompat; import net.deechael.concentration.fabric.config.ConcentrationConfigFabric; import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFWNativeWin32; @@ -48,12 +47,20 @@ public abstract class WindowMixin { @Final private long window; - @Shadow - public abstract boolean isFullscreen(); - - @Shadow public abstract int getScreenWidth(); - - @Shadow public abstract int getScreenHeight(); + @Inject(method = "", at = @At("RETURN")) + private void inject$init(WindowEventHandler eventHandler, ScreenManager screenManager, DisplayData displayData, String preferredFullscreenVideoMode, String title, CallbackInfo ci) { + ConcentrationConstants.LOGGER.info(" ============================================="); + String osName = System.getProperty("os.name").toLowerCase(); + if (osName.contains("windows")) { + ConcentrationConstants.LOGGER.info(" == System: Windows =="); + } else if (osName.contains("darwin") || osName.contains("mac")) { + ConcentrationConstants.LOGGER.info(" == System: macOS =="); + } else { + ConcentrationConstants.LOGGER.info(" == System: Linux =="); + } + // ConcentrationConstants.LOGGER.info(" == =="); + ConcentrationConstants.LOGGER.info(" ============================================="); + } @Inject(method = "onMove", at = @At("HEAD")) private void inject$onMove$head(long window, int x, int y, CallbackInfo ci) { @@ -86,6 +93,7 @@ public abstract class WindowMixin { Monitor monitorInstance = this.screenManager.getMonitor(monitor); ConcentrationConstants.LOGGER.info("Current fullscreen monitor is {}", monitor); + ConcentrationConstants.LOGGER.info("Current fullscreen mode is {}", ConfigProvider.INSTANCE.ensureLoaded().getFullscreenMode()); if (monitor != 0L) { VideoMode currentMode = monitorInstance.getCurrentMode(); @@ -137,17 +145,20 @@ public abstract class WindowMixin { finalHeight = config.height + (config.height == height ? 1 : 0); } else { finalX = monitorInstance.getX(); - finalY = monitorInstance.getY() - 1; + finalY = monitorInstance.getY(); finalWidth = ignored$width; finalHeight = ignored$height + 1; } + if (SodiumExtraCompat.checkMacReduceResolution()) { + ConcentrationConstants.LOGGER.info("On macOS and reduce resolution in Sodium Extra enabled, reduce the resolution"); + } } - - this.x = finalX; - this.y = finalY; - this.width = finalWidth; - this.height = finalHeight; } + + this.x = finalX; + this.y = finalY; + this.width = finalWidth; + this.height = finalHeight; } else { ConcentrationConstants.LOGGER.info("Trying to switch to windowed mode"); finalMonitor = 0L; @@ -173,6 +184,10 @@ public abstract class WindowMixin { ConcentrationConstants.LOGGER.info("Unlocked size caching"); } + if (monitor != 0L) { + ConcentrationFabricCaching.lastMonitor = monitor; + } + ConcentrationConstants.LOGGER.info("Window size: {}, {}, position: {}, {}", finalWidth, finalHeight, finalX, finalY); ConcentrationConstants.LOGGER.info("Trying to resize and reposition the window"); @@ -202,7 +217,7 @@ public abstract class WindowMixin { } } else { GLFW.glfwSetWindowAttrib(window, GLFW.GLFW_DECORATED, GLFW.GLFW_FALSE); - GLFW.glfwSetWindowAttrib(this.window, 0x20006, 0); + GLFW.glfwSetWindowAttrib(this.window, 0x20006, 1); if (System.getProperty("os.name").contains("Windows")) { long hWnd = GLFWNativeWin32.glfwGetWin32Window(this.window); if (hWnd != 0) { diff --git a/forge/src/main/java/net/deechael/concentration/forge/mixin/WindowMixin.java b/forge/src/main/java/net/deechael/concentration/forge/mixin/WindowMixin.java index 7f81c18..65b694c 100644 --- a/forge/src/main/java/net/deechael/concentration/forge/mixin/WindowMixin.java +++ b/forge/src/main/java/net/deechael/concentration/forge/mixin/WindowMixin.java @@ -48,9 +48,6 @@ public abstract class WindowMixin { @Final private long window; - @Shadow - public abstract boolean isFullscreen(); - @Unique private long concentration$lastMonitor = -1; @@ -59,7 +56,7 @@ public abstract class WindowMixin { @Unique private boolean concentration$cachedPos = false; @Unique - private boolean concentration$cacheSizeLock = false; + private boolean concentration$cacheSizeLock = true; @Unique private int concentration$cachedX = 0; @@ -157,7 +154,7 @@ public abstract class WindowMixin { finalHeight = configHeight + (configHeight == height ? 1 : 0); } else { finalX = monitorInstance.getX(); - finalY = monitorInstance.getY() - 1; + finalY = monitorInstance.getY(); finalWidth = width; finalHeight = height + 1; } @@ -193,6 +190,10 @@ public abstract class WindowMixin { ConcentrationConstants.LOGGER.info("Unlocked size caching"); } + if (monitor != 0L) { + this.concentration$lastMonitor = monitor; + } + ConcentrationConstants.LOGGER.info("Window size: {}, {}, position: {}, {}", finalWidth, finalHeight, finalX, finalY); ConcentrationConstants.LOGGER.info("Trying to resize and reposition the window"); diff --git a/gradle.properties b/gradle.properties index 99d059a..c8051a6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -version=2.2.2 +version=2.2.3 group=net.deechael.concentration java_version=21 diff --git a/neoforge/src/main/java/net/deechael/concentration/neoforge/mixin/WindowMixin.java b/neoforge/src/main/java/net/deechael/concentration/neoforge/mixin/WindowMixin.java index 044754d..8f44980 100644 --- a/neoforge/src/main/java/net/deechael/concentration/neoforge/mixin/WindowMixin.java +++ b/neoforge/src/main/java/net/deechael/concentration/neoforge/mixin/WindowMixin.java @@ -48,9 +48,6 @@ public abstract class WindowMixin { @Final private long window; - @Shadow - public abstract boolean isFullscreen(); - @Unique private long concentration$lastMonitor = -1; @@ -59,7 +56,7 @@ public abstract class WindowMixin { @Unique private boolean concentration$cachedPos = false; @Unique - private boolean concentration$cacheSizeLock = false; + private boolean concentration$cacheSizeLock = true; @Unique private int concentration$cachedX = 0; @@ -157,12 +154,16 @@ public abstract class WindowMixin { finalHeight = configHeight + (configHeight == height ? 1 : 0); } else { finalX = monitorInstance.getX(); - finalY = monitorInstance.getY() - 1; + finalY = monitorInstance.getY(); finalWidth = width; finalHeight = height + 1; } } + if (monitor != 0L) { + this.concentration$lastMonitor = monitor; + } + this.x = finalX; this.y = finalY; this.width = finalWidth;