Skip to content

Commit

Permalink
Merge pull request #211 from chewing/style-light-theme
Browse files Browse the repository at this point in the history
feat: change icon based on system theme
  • Loading branch information
kanru authored Dec 15, 2024
2 parents b2aff6c + 01c44e1 commit ca0516b
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 4 deletions.
Binary file modified ChewingPreferences/ChewingPreferences.rc
Binary file not shown.
41 changes: 38 additions & 3 deletions ChewingTextService/ChewingTextService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
#include <assert.h>
#include <libIME/LangBarButton.h>
#include <libIME/Utils.h>
#include <minwindef.h>
#include <sys/stat.h>
#include <winerror.h>
#include <winreg.h>
#include <winrt/base.h>
#include <winuser.h>

Expand Down Expand Up @@ -106,7 +109,11 @@ TextService::TextService(ImeModule* module):
// Windows 8 systray IME mode icon
if(IsWindows8OrGreater()) {
imeModeIcon_ = new Ime::LangBarButton(this, _GUID_LBI_INPUTMODE, ID_MODE_ICON);
imeModeIcon_->setIcon(IDI_ENG);
if (isLightTheme()) {
imeModeIcon_->setIcon(IDI_ENG);
} else {
imeModeIcon_->setIcon(IDI_ENG_DARK);
}
addButton(imeModeIcon_);
}

Expand Down Expand Up @@ -885,18 +892,46 @@ 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;
}
// 0 = dark theme, 1 = light theme
return value > 0;
}

void TextService::updateLangButtons() {
if(!chewingContext_)
return;

int langMode = ::chewing_get_ChiEngMode(chewingContext_);
if(langMode != langMode_) {
langMode_ = langMode;
switchLangButton_->setIcon(langMode == CHINESE_MODE ? IDI_CHI : IDI_ENG);
if (isLightTheme()) {
switchLangButton_->setIcon(langMode == CHINESE_MODE ? IDI_CHI : IDI_ENG);
} else {
switchLangButton_->setIcon(langMode == CHINESE_MODE ? IDI_CHI_DARK : IDI_ENG_DARK);
}
if(imeModeIcon_) {
// FIXME: we need a better set of icons to meet the
// WIndows 8 IME guideline and UX guidelines.
imeModeIcon_->setIcon(langMode == CHINESE_MODE ? IDI_CHI : IDI_ENG);
if (isLightTheme()) {
imeModeIcon_->setIcon(langMode == CHINESE_MODE ? IDI_CHI : IDI_ENG);
} else {
imeModeIcon_->setIcon(langMode == CHINESE_MODE ? IDI_CHI_DARK : IDI_ENG_DARK);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions ChewingTextService/ChewingTextService.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class TextService: public Ime::TextService {
void showMessage(Ime::EditSession* session, std::wstring message, int duration = 3);
void hideMessage();

bool isLightTheme();
void updateLangButtons(); // update status of language bar buttons

// reload configurations if changes are detected
Expand Down
Binary file modified ChewingTextService/ChewingTextService.rc
Binary file not shown.
Binary file modified ChewingTextService/chi.ico
Binary file not shown.
Binary file added ChewingTextService/chi_dark.ico
Binary file not shown.
Binary file modified ChewingTextService/eng.ico
Binary file not shown.
Binary file added ChewingTextService/eng_dark.ico
Binary file not shown.
2 changes: 2 additions & 0 deletions ChewingTextService/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#define IDI_FULL_SHAPE 106
#define IDS_CONFIG_TITLE 106
#define IDI_HALF_SHAPE 107
#define IDI_CHI_DARK 108
#define IDI_ENG_DARK 109
#define IDR_MENU1 108
#define IDR_MENU2 109
#define IDR_MENU 109
Expand Down
2 changes: 1 addition & 1 deletion scripts/build_installer_debug.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mkdir build\installer
mkdir build\installer\assets
copy assets\* build\installer\assets\
copy installer\* build\installer\
copy ChewingTextService\mainicon2.ico build\installer\chewing.ico
copy ChewingTextService\im.chewing.Chewing.ico build\installer\chewing.ico
mkdir build\installer\Dictionary
copy libchewing\data\*.dat build\installer\Dictionary\
copy build\x64\libchewing\data\*.dat build\installer\Dictionary\
Expand Down

0 comments on commit ca0516b

Please sign in to comment.