From 7953d4e810e97e73117a55d24b6c39d9ba4f17f2 Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Sat, 21 Dec 2024 20:49:33 +0900 Subject: [PATCH] fix: attempt to fix incorrect light theme detection --- .editorconfig | 3 +- ChewingTextService/ChewingTextService.cpp | 35 ++++++++++++----------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/.editorconfig b/.editorconfig index eb127e6..95cc410 100644 --- a/.editorconfig +++ b/.editorconfig @@ -6,7 +6,8 @@ charset = "utf-8" end_of_line = lf insert_final_newline = true trim_trailing_whitespace = true -indent_style = tab +indent_style = space +indent_size = 4 [*.md] indent_style = space diff --git a/ChewingTextService/ChewingTextService.cpp b/ChewingTextService/ChewingTextService.cpp index 0093c31..e002bf2 100644 --- a/ChewingTextService/ChewingTextService.cpp +++ b/ChewingTextService/ChewingTextService.cpp @@ -940,23 +940,26 @@ void TextService::hideMessage() { } bool TextService::isLightTheme() { - DWORD value = 0; - DWORD len = sizeof(value); - LSTATUS st = RegGetValueW( - HKEY_CURRENT_USER, - L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", - L"AppsUseLightTheme", - RRF_RT_REG_DWORD, - nullptr, - &value, - &len - ); - if (st != ERROR_SUCCESS) { - // assume light theme - return true; - } + DWORD value = 1; + DWORD dataSize = sizeof(value); + + LSTATUS result = RegGetValueW( + HKEY_CURRENT_USER, + L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", + L"AppsUseLightTheme", + RRF_RT_DWORD, + nullptr, + &value, + &dataSize + ); + + if (result != ERROR_SUCCESS) { + OutputDebugStringW(L"Determine isLightTheme failed, fallback to light theme"); + return true; + } + // 0 = dark theme, 1 = light theme - return value > 0; + return value > 0; } void TextService::updateLangButtons() {