diff --git a/common/src/main/java/moe/caramel/mica/ModConfig.java b/common/src/main/java/moe/caramel/mica/ModConfig.java index 5e6799a..573f161 100644 --- a/common/src/main/java/moe/caramel/mica/ModConfig.java +++ b/common/src/main/java/moe/caramel/mica/ModConfig.java @@ -1,5 +1,6 @@ package moe.caramel.mica; +import com.mojang.blaze3d.platform.Window; import moe.caramel.mica.natives.DwmApi; import net.minecraft.client.Minecraft; import net.minecraft.core.RegistryAccess; @@ -104,6 +105,7 @@ public void setConfig(Settings.MutableValue config, T value) { } public static void update() { - DwmApi.updateDwm(Minecraft.getInstance().getWindow().getWindow()); + final Window window = Minecraft.getInstance().getWindow(); + DwmApi.updateDwm(window.isFullscreen(), window.getWindow()); } } diff --git a/common/src/main/java/moe/caramel/mica/mixin/MixinWindow.java b/common/src/main/java/moe/caramel/mica/mixin/MixinWindow.java index b09221b..d8a97d7 100644 --- a/common/src/main/java/moe/caramel/mica/mixin/MixinWindow.java +++ b/common/src/main/java/moe/caramel/mica/mixin/MixinWindow.java @@ -18,6 +18,7 @@ public final class MixinWindow { @Shadow @Final private long window; + @Shadow private boolean fullscreen; @Inject(method = "", at = @At(value = "TAIL")) private void init( @@ -32,6 +33,17 @@ private void init( // Initialize Mica NtDll.getBuildNumber(); - DwmApi.updateDwm(this.window); + DwmApi.updateDwm(this.fullscreen, this.window); + } + + @Inject(method = "updateFullscreen", at = @At(value = "TAIL")) + private void updateFullscreen(final boolean vsync, final CallbackInfo ci) { + // Check OS + if (Util.getPlatform() != Util.OS.WINDOWS) { + return; + } + + // Update DWM + DwmApi.updateDwm(this.fullscreen, this.window); } } diff --git a/common/src/main/java/moe/caramel/mica/natives/DwmApi.java b/common/src/main/java/moe/caramel/mica/natives/DwmApi.java index 8344878..0d54294 100644 --- a/common/src/main/java/moe/caramel/mica/natives/DwmApi.java +++ b/common/src/main/java/moe/caramel/mica/natives/DwmApi.java @@ -72,13 +72,18 @@ int DwmSetWindowAttribute( int cbAttribute ); - static void updateDwm(final long window) { + static void updateDwm(final boolean fullscreen, final long window) { // Check build number if (!Mica.checkCompatibility()) { return; } final HWND hwnd = new HWND(Pointer.createConstant(GLFWNativeWin32.glfwGetWin32Window(window))); + if (fullscreen) { + DwmApi.disableWindowEffect(hwnd); + return; + } + final ModConfig config = ModConfig.get(); // DWMWA_USE_IMMERSIVE_DARK_MODE @@ -122,6 +127,17 @@ static void updateDwm(final long window) { } } + static void disableWindowEffect(final HWND hwnd) { + // ... DWMWA_USE_IMMERSIVE_DARK_MODE + if (Mica.buildNumber >= Mica.BACKDROP_BUILD_NUM) { + INSTANCE.DwmSetWindowAttribute(hwnd, DWMWA_SYSTEMBACKDROP_TYPE, new IntByReference(DWM_SYSTEMBACKDROP_TYPE.DWMSBT_AUTO.ordinal()), INT_SIZE); + } + INSTANCE.DwmSetWindowAttribute(hwnd, DWMWA_WINDOW_CORNER_PREFERENCE, new IntByReference(DWM_WINDOW_CORNER_PREFERENCE.DWMWCP_DEFAULT.ordinal()), INT_SIZE); + INSTANCE.DwmSetWindowAttribute(hwnd, DWMWA_BORDER_COLOR, new IntByReference(DWMWA_COLOR_DEFAULT), INT_SIZE); + INSTANCE.DwmSetWindowAttribute(hwnd, DWMWA_CAPTION_COLOR, new IntByReference(DWMWA_COLOR_DEFAULT), INT_SIZE); + INSTANCE.DwmSetWindowAttribute(hwnd, DWMWA_TEXT_COLOR, new IntByReference(DWMWA_COLOR_DEFAULT), INT_SIZE); + } + private static int convert(final int color) { // Ignore Alpha final int b = (color >> 16) & 0xFF;