Windows 11 上日志窗口标题栏颜色应当跟随主题模式设置 (#4910)

This commit is contained in:
Glavo
2025-12-04 01:24:36 +08:00
committed by GitHub
parent ed4fec6c42
commit 7ac22ad567
6 changed files with 228 additions and 2 deletions

View File

@@ -0,0 +1,32 @@
/*
* Hello Minecraft! Launcher
* Copyright (C) 2025 huangyuhui <huanghongxun2008@126.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.jackhuang.hmcl.util.platform.windows;
import com.sun.jna.PointerType;
import com.sun.jna.win32.StdCallLibrary;
import org.jackhuang.hmcl.util.platform.NativeUtils;
/// @author Glavo
public interface Dwmapi extends StdCallLibrary {
Dwmapi INSTANCE = NativeUtils.USE_JNA && com.sun.jna.Platform.isWindows()
? NativeUtils.load("dwmapi", Dwmapi.class)
: null;
/// @see <a href="https://learn.microsoft.com/windows/win32/api/dwmapi/nf-dwmapi-dwmsetwindowattribute">DwmSetWindowAttribute function</a>
int DwmSetWindowAttribute(WinTypes.HANDLE hwnd, int dwAttribute, PointerType pvAttribute, int cbAttribute);
}

View File

@@ -96,4 +96,8 @@ public interface WinConstants {
int RelationNumaNodeEx = 6;
int RelationProcessorModule = 7;
int RelationAll = 0xffff;
// https://learn.microsoft.com/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute
int DWMWA_USE_IMMERSIVE_DARK_MODE = 20;
}

View File

@@ -18,6 +18,7 @@
package org.jackhuang.hmcl.util.platform.windows;
import com.sun.jna.*;
import com.sun.jna.ptr.ByReference;
import com.sun.jna.ptr.LongByReference;
import java.util.Arrays;
@@ -27,6 +28,97 @@ import java.util.List;
* @author Glavo
*/
public interface WinTypes {
/// @see <a href="https://learn.microsoft.com/windows/win32/winprog/windows-data-types">Windows Data Types</a>
final class BOOL extends IntegerType {
public static final int SIZE = 4;
public BOOL() {
this(0);
}
public BOOL(boolean value) {
this(value ? 1L : 0L);
}
public BOOL(long value) {
super(SIZE, value, false);
assert value == 0 || value == 1;
}
public boolean booleanValue() {
return this.intValue() > 0;
}
@Override
public String toString() {
return Boolean.toString(booleanValue());
}
}
/// @see <a href="https://learn.microsoft.com/windows/win32/winprog/windows-data-types">Windows Data Types</a>
final class BOOLByReference extends ByReference {
public BOOLByReference() {
this(new BOOL(0));
}
public BOOLByReference(BOOL value) {
super(BOOL.SIZE);
setValue(value);
}
public void setValue(BOOL value) {
getPointer().setInt(0, value.intValue());
}
public BOOL getValue() {
return new BOOL(getPointer().getInt(0));
}
}
/// @see <a href="https://learn.microsoft.com/windows/win32/winprog/windows-data-types">Windows Data Types</a>
final class HANDLE extends PointerType {
public static final long INVALID_VALUE = Native.POINTER_SIZE == 8 ? -1 : 0xFFFFFFFFL;
public static final HANDLE INVALID = new HANDLE(Pointer.createConstant(INVALID_VALUE));
private boolean immutable;
public HANDLE() {
}
public HANDLE(Pointer p) {
setPointer(p);
immutable = true;
}
@Override
public Object fromNative(Object nativeValue, FromNativeContext context) {
Object o = super.fromNative(nativeValue, context);
if (INVALID.equals(o)) {
return INVALID;
}
return o;
}
@Override
public void setPointer(Pointer p) {
if (immutable) {
throw new UnsupportedOperationException("immutable reference");
}
super.setPointer(p);
}
@Override
public String toString() {
return String.valueOf(getPointer());
}
}
/**
* @see <a href="https://learn.microsoft.com/windows/win32/api/winnt/ns-winnt-osversioninfoexw">OSVERSIONINFOEXW structure</a>
*/