fix: windowed mode size not saved in borderless fullscreen mode

This commit is contained in:
deechael 2024-10-13 19:05:42 +08:00
parent 7daed8f7d1
commit 27b5414d48
11 changed files with 82 additions and 46 deletions

View File

@ -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 {
}

View File

@ -89,7 +89,11 @@ public abstract class VideoSettingsScreenMixin extends OptionsSubScreen {
@Unique
private static OptionInstance<Boolean> 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

View File

@ -7,7 +7,6 @@
"mixins": [],
"client": [
"KeyboardHandlerMixin",
"MainMixin",
"VideoSettingsScreenMixin",
"accessor.WindowAccessor"
],

View File

@ -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"
}

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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");

View File

@ -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 = "<init>", 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) {

View File

@ -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");

View File

@ -1,4 +1,4 @@
version=2.2.2
version=2.2.3
group=net.deechael.concentration
java_version=21

View File

@ -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;