windowsGetPreferredColorScheme
Gets the preferred color scheme from the Windows registry
Source
Implementation
pub fn windowsGetPreferredColorScheme() ?dvui.enums.ColorScheme {
const winapi = struct {
pub extern "advapi32" fn RegGetValueW(
hkey: std.os.windows.HKEY,
lpSubKey: std.os.windows.LPCWSTR,
lpValue: std.os.windows.LPCWSTR,
dwFlags: std.os.windows.DWORD,
pdwType: ?*std.os.windows.DWORD,
pvData: ?*anyopaque,
pcbData: ?*std.os.windows.DWORD,
) callconv(.winapi) std.os.windows.LSTATUS;
};
var out: [4]u8 = undefined;
var len: u32 = 4;
const res = winapi.RegGetValueW(
std.os.windows.HKEY_CURRENT_USER,
std.unicode.utf8ToUtf16LeStringLiteral("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"),
std.unicode.utf8ToUtf16LeStringLiteral("AppsUseLightTheme"),
0x10, //advapi32.RRF.RT_REG_DWORD,
null,
&out,
&len,
);
if (res != 0) return null;
const val = std.mem.littleToNative(i32, @bitCast(out));
return if (val > 0) .light else .dark;
}