Skip to content

Commit

Permalink
Disable Mica when switching to fullscreen
Browse files Browse the repository at this point in the history
resolve #4
  • Loading branch information
LemonCaramel committed Apr 24, 2024
1 parent f54c14a commit 4f4e73d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
4 changes: 3 additions & 1 deletion common/src/main/java/moe/caramel/mica/ModConfig.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -104,6 +105,7 @@ public <T> void setConfig(Settings<ModConfig>.MutableValue<T> 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());
}
}
14 changes: 13 additions & 1 deletion common/src/main/java/moe/caramel/mica/mixin/MixinWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
public final class MixinWindow {

@Shadow @Final private long window;
@Shadow private boolean fullscreen;

@Inject(method = "<init>", at = @At(value = "TAIL"))
private void init(
Expand All @@ -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);
}
}
18 changes: 17 additions & 1 deletion common/src/main/java/moe/caramel/mica/natives/DwmApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 4f4e73d

Please sign in to comment.