Skip to content

Commit c878452

Browse files
committed
feat(cinbase): make the composition-layer colors configurable (#902)
The candidate and message layers painted the system palette only: CandidateWindow.cpp used GetSysColor(COLOR_WINDOWTEXT)/COLOR_WINDOW and the selection key the literal RGB(0, 0, 255), so a 大易/嘸蝦米 user on a dark host background got a low-contrast 字根 row. Three integer settings put those values on the existing customizeUI reply, with 0 meaning "follow the system palette" so every shipped config keeps its present rendering. - PIMETextService/UIColors.h: uiColorValue maps the three reply keys with 0 as the sentinel fallback; updateUI feeds the service, which hands text, background and selection-key values to the candidate window and text and background to the message window, beside the existing font handling. - python/cinbase/config.py: candTextColor, windowBackgroundColor and selKeyColor on CinBaseConfig, sanitized to 24-bit ints with numeric strings accepted, and absent, non-integer, negative and past-range values repaired to 0. - python/cinbase/__init__.py: applyConfig puts the three values on the reply. - The 功能設定 page names one control per key, and the eight shipped config/config.json carry the keys, so a fresh install answers the defaults. - libIME2: setTextColor/setBackgroundColor/setSelKeyColor on CandidateWindow and setTextColor/setBackgroundColor on MessageWindow; a 0 value keeps the old GetSysColor/RGB(0, 0, 255) defaults. Fully generated by omp (tensorfold/Qwen3.8-Flash-Next) without human intervention.
1 parent 0e270f2 commit c878452

16 files changed

Lines changed: 143 additions & 2 deletions

File tree

‎PIMETextService/PIMEClient.cpp‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "PIMEClient.h"
2121
#include "CompositionCursor.h"
2222
#include "JsonUtils.h"
23+
#include "UIColors.h"
2324
#include "libIME2/src/Utils.h"
2425
#include <algorithm>
2526
#include <nlohmann/json.hpp>
@@ -118,6 +119,15 @@ void Client::updateUI(json& data) {
118119
else if (value.is_boolean() && name == "candUseCursor") {
119120
textService_->setCandUseCursor(value.get<bool>());
120121
}
122+
else if (value.is_number_integer() && name == "candTextColor") {
123+
textService_->setCandTextColor(PIME::uiColorValue(data, "candTextColor", 0));
124+
}
125+
else if (value.is_number_integer() && name == "windowBackgroundColor") {
126+
textService_->setWindowBackgroundColor(PIME::uiColorValue(data, "windowBackgroundColor", 0));
127+
}
128+
else if (value.is_number_integer() && name == "selKeyColor") {
129+
textService_->setSelKeyColor(PIME::uiColorValue(data, "selKeyColor", 0));
130+
}
121131
}
122132
}
123133

‎PIMETextService/PIMETextService.cpp‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,10 @@ void TextService::updateCandidates(Ime::EditSession* session) {
249249

250250
candidateWindow_->setUseCursor(candUseCursor_);
251251
candidateWindow_->setCandPerRow(candPerRow_);
252+
// configured colors (upstream #902); 0 keeps the system palette
253+
candidateWindow_->setTextColor(candTextColor_);
254+
candidateWindow_->setBackgroundColor(windowBackgroundColor_);
255+
candidateWindow_->setSelKeyColor(selKeyColor_);
252256

253257
// the items in the candidate list should not exist the
254258
// number of available keys used to select them.
@@ -334,6 +338,9 @@ void TextService::showMessage(Ime::EditSession* session, std::wstring message, i
334338
// FIXME: reuse the window whenever possible
335339
messageWindow_ = make_unique<Ime::MessageWindow>(this, session);
336340
messageWindow_->setFont(createFont(), /*ownFont=*/true);
341+
// the same configured colors the candidate window gets (upstream #902)
342+
messageWindow_->setTextColor(candTextColor_);
343+
messageWindow_->setBackgroundColor(windowBackgroundColor_);
337344
messageWindow_->setText(message);
338345

339346
int x = 0, y = 0;

‎PIMETextService/PIMETextService.h‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,32 @@ class TextService: public Ime::TextService {
122122
updateFont_ = true;
123123
}
124124

125+
// composition/candidate colors (upstream #902); 0 means "follow the
126+
// system palette", the value the python side ships as default
127+
COLORREF candTextColor() const {
128+
return candTextColor_;
129+
}
130+
131+
void setCandTextColor(COLORREF color) {
132+
candTextColor_ = color;
133+
}
134+
135+
COLORREF windowBackgroundColor() const {
136+
return windowBackgroundColor_;
137+
}
138+
139+
void setWindowBackgroundColor(COLORREF color) {
140+
windowBackgroundColor_ = color;
141+
}
142+
143+
COLORREF selKeyColor() const {
144+
return selKeyColor_;
145+
}
146+
147+
void setSelKeyColor(COLORREF color) {
148+
selKeyColor_ = color;
149+
}
150+
125151
bool showingCandidates() {
126152
return showingCandidates_;
127153
}
@@ -167,6 +193,9 @@ class TextService: public Ime::TextService {
167193
bool candUseCursor_;
168194
std::wstring candFontName_;
169195
int candFontSize_;
196+
COLORREF candTextColor_ = 0;
197+
COLORREF windowBackgroundColor_ = 0;
198+
COLORREF selKeyColor_ = 0;
170199

171200
HMENU popupMenu_{nullptr};
172201

‎PIMETextService/UIColors.h‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// The customizeUI color keys of upstream #902, as one pure mapping so both
2+
// boxes can pin them without the TSF surface.
3+
//
4+
// Generated by omp (Qwen3.8-Flash-Next) without human creative authorship.
5+
// SPDX-License-Identifier: LGPL-2.1-or-later
6+
7+
#ifndef PIME_UI_COLORS_H
8+
#define PIME_UI_COLORS_H
9+
10+
#include <nlohmann/json.hpp>
11+
12+
namespace PIME {
13+
14+
// Read one 24-bit color from the customizeUI object. Returns `fallback`
15+
// (0 = follow the system palette) when the key is absent, not an integer,
16+
// or outside 0..0xFFFFFF.
17+
inline unsigned int uiColorValue(const nlohmann::json& ui, const char* name, unsigned int fallback) {
18+
if (!ui.is_object()) {
19+
return fallback;
20+
}
21+
const auto it = ui.find(name);
22+
if (it == ui.end() || !it->is_number_integer()) {
23+
return fallback;
24+
}
25+
const int value = it->get<int>();
26+
if (value < 0 || value > 0xFFFFFF) {
27+
return fallback;
28+
}
29+
return static_cast<unsigned int>(value);
30+
}
31+
32+
} // namespace PIME
33+
34+
#endif // PIME_UI_COLORS_H

‎python/cinbase/__init__.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3153,7 +3153,10 @@ def applyConfig(self, cbTS):
31533153
cbTS.customizeUI(candFontSize = cfg.fontSize,
31543154
candFontName = 'MingLiu',
31553155
candPerRow = cfg.candPerRow,
3156-
candUseCursor = cfg.cursorCandList)
3156+
candUseCursor = cfg.cursorCandList,
3157+
candTextColor = cfg.candTextColor,
3158+
windowBackgroundColor = cfg.windowBackgroundColor,
3159+
selKeyColor = cfg.selKeyColor)
31573160

31583161
# 設定選字按鍵 (123456..., asdf.... 等)
31593162
# if cbTS.cin.getSelection():

‎python/cinbase/config.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ def __init__(self):
5151
self.directShowCand = False
5252
self.directCommitSymbol = False
5353
self.fontSize = DEF_FONT_SIZE
54+
# 組字/選字視窗顏色 (issue #902):0 表示跟隨系統調色盤
55+
self.candTextColor = 0
56+
self.windowBackgroundColor = 0
57+
self.selKeyColor = 0
5458
self.selCinType = 0
5559
self.ignorePrivateUseArea = True
5660
self.selKeyType = 0
@@ -156,6 +160,24 @@ def _to_int(val, default, min_val=None, max_val=None):
156160
self.candMaxItems = _to_int(getattr(self, "candMaxItems", 100), 100, min_val=10, max_val=10000)
157161
self.messageDurationTime = _to_int(getattr(self, "messageDurationTime", 3), 3, min_val=1)
158162

163+
# 組字/選字視窗顏色 (issue #902):0 表示跟隨系統調色盤;非法值退回 0
164+
def _to_color(val, default=0):
165+
if isinstance(val, bool):
166+
return default
167+
if isinstance(val, int):
168+
return val if 0 <= val <= 0xFFFFFF else default
169+
if isinstance(val, str):
170+
try:
171+
i = int(val.strip(), 0)
172+
except ValueError:
173+
return default
174+
return i if 0 <= i <= 0xFFFFFF else default
175+
return default
176+
177+
self.candTextColor = _to_color(getattr(self, "candTextColor", 0), 0)
178+
self.windowBackgroundColor = _to_color(getattr(self, "windowBackgroundColor", 0), 0)
179+
self.selKeyColor = _to_color(getattr(self, "selKeyColor", 0), 0)
180+
159181
def toJson(self):
160182
return {key: value for key, value in self.__dict__.items() if not key.startswith("_") and not key in self.ignoreSaveList}
161183

‎python/cinbase/config/config.htm‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,18 @@ <h3 class="panel-title">介面設定</h3>
284284
<label for="fontSize">選字及訊息視窗文字大小: </label>
285285
<input type="text" id="fontSize" name="fontSize" /><br />
286286
</div>
287+
<div class="col-xs-12 col-sm-6 col-md-3 col-lg-3">
288+
<label for="candTextColor">選字視窗文字顏色 (0xRRGGBB 整數, 0=跟隨系統): </label>
289+
<input type="text" id="candTextColor" name="candTextColor" /><br />
290+
</div>
291+
<div class="col-xs-12 col-sm-6 col-md-3 col-lg-3">
292+
<label for="windowBackgroundColor">選字視窗背景顏色 (0xRRGGBB 整數, 0=跟隨系統): </label>
293+
<input type="text" id="windowBackgroundColor" name="windowBackgroundColor" /><br />
294+
</div>
295+
<div class="col-xs-12 col-sm-6 col-md-3 col-lg-3">
296+
<label for="selKeyColor">選字鍵顏色 (0xRRGGBB 整數, 0=跟隨系統): </label>
297+
<input type="text" id="selKeyColor" name="selKeyColor" /><br />
298+
</div>
287299
</div>
288300
</div>
289301
</div>

‎python/input_methods/chearray/config/config.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
"directOutFSymbols": false,
1515
"colorCandWnd": true,
1616
"fontSize": 12,
17+
"candTextColor": 0,
18+
"windowBackgroundColor": 0,
19+
"selKeyColor": 0,
1720
"outputSimpChinese": false,
1821
"enableSwitchTCSC": true,
1922
"hidePromptMessages": true,

‎python/input_methods/checj/config/config.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
"easySymbolsWithShift": false,
1818
"hidePromptMessages": true,
1919
"fontSize": 12,
20+
"candTextColor": 0,
21+
"windowBackgroundColor": 0,
22+
"selKeyColor": 0,
2023
"fullShapeSymbols": false,
2124
"defaultFullSpace": false,
2225
"candPerRow": 3,

0 commit comments

Comments
 (0)