Skip to content

Commit a82f74c

Browse files
authored
Merge pull request #329 from chewing/push-wxopmrpmnxvw
feat: make notification configurable
2 parents 9f7e5a4 + 50585a5 commit a82f74c

File tree

5 files changed

+29
-7
lines changed

5 files changed

+29
-7
lines changed

chewing_tip/src/ts/chewing.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ impl ChewingTextService {
608608
unsafe {
609609
chewing_free(ptr.cast());
610610
}
611-
self.show_message(context, &text, Duration::from_secs(2))?;
611+
self.show_message(context, &text, Duration::from_millis(500))?;
612612
}
613613

614614
Ok(true)
@@ -648,7 +648,7 @@ impl ChewingTextService {
648648
CHINESE_MODE => HSTRING::from("中文模式"),
649649
_ => unreachable!(),
650650
};
651-
self.show_message(context, &msg, Duration::from_secs(2))?;
651+
self.show_message(context, &msg, Duration::from_millis(500))?;
652652
self.last_keydown_code = 0;
653653
return Ok(true);
654654
} else {
@@ -661,7 +661,7 @@ impl ChewingTextService {
661661
CHINESE_MODE => HSTRING::from("中文模式"),
662662
_ => unreachable!(),
663663
};
664-
self.show_message(context, &msg, Duration::from_secs(2))?;
664+
self.show_message(context, &msg, Duration::from_millis(500))?;
665665
self.last_keydown_code = 0;
666666
return Ok(true);
667667
}
@@ -677,7 +677,7 @@ impl ChewingTextService {
677677
CHINESE_MODE => HSTRING::from("中文模式"),
678678
_ => unreachable!(),
679679
};
680-
self.show_message(context, &msg, Duration::from_secs(2))?;
680+
self.show_message(context, &msg, Duration::from_millis(500))?;
681681
self.last_keydown_code = 0;
682682
return Ok(true);
683683
}
@@ -949,6 +949,9 @@ impl ChewingTextService {
949949
}
950950

951951
fn show_message(&mut self, context: &ITfContext, text: &HSTRING, dur: Duration) -> Result<()> {
952+
if !self.cfg.show_notification {
953+
return Ok(());
954+
}
952955
unsafe {
953956
let view = context.GetActiveView()?;
954957
let hwnd = view.GetWnd()?;
@@ -966,7 +969,10 @@ impl ChewingTextService {
966969
message_window.set_font_color(self.cfg.font_fg_color);
967970
message_window.set_text(text.clone())?;
968971

969-
let rect = self.get_selection_rect(context)?;
972+
let mut rect = self.get_selection_rect(context)?;
973+
// TODO: bound the position to the screen
974+
rect.bottom += 50;
975+
rect.left += 50;
970976
message_window.r#move(rect.left, rect.bottom);
971977
message_window.show();
972978

chewing_tip/src/ts/config.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use windows_registry::{CURRENT_USER, Key};
1111
pub(super) struct Config {
1212
pub(super) switch_lang_with_shift: bool,
1313
pub(super) enable_caps_lock: bool,
14+
pub(super) show_notification: bool,
1415
pub(super) enable_auto_learn: bool,
1516
pub(super) esc_clean_all_buf: bool,
1617
pub(super) full_shape_symbols: bool,
@@ -81,6 +82,7 @@ fn load_config() -> Result<Config> {
8182
let mut cfg = Config {
8283
cand_per_row: 3,
8384
switch_lang_with_shift: true,
85+
show_notification: true,
8486
add_phrase_forward: true,
8587
advance_after_selection: true,
8688
font_size: 16,
@@ -127,6 +129,9 @@ fn load_config() -> Result<Config> {
127129
if let Ok(value) = reg_get_bool(&key, "SwitchLangWithShift") {
128130
cfg.switch_lang_with_shift = value;
129131
}
132+
if let Ok(value) = reg_get_bool(&key, "ShowNotification") {
133+
cfg.show_notification = value;
134+
}
130135
if let Ok(value) = reg_get_bool(&key, "OutputSimpChinese") {
131136
cfg.output_simp_chinese = value;
132137
}

chewing_tip/src/ts/ui_elements/candidate_list.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,8 @@ impl View for RenderedView {
266266
let width = width as f32;
267267
let height = height as f32;
268268
// Convert to HW pixels
269-
let hw_width = width * scale + 10.0;
270-
let hw_height = height * scale + 10.0;
269+
let hw_width = width * scale + 25.0;
270+
let hw_height = height * scale + 25.0;
271271
Ok(RenderedMetrics {
272272
width,
273273
height,

preferences/src/config.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ fn load_config(ui: &ConfigWindow) -> Result<()> {
100100
// Init settings to default value
101101
ui.set_cand_per_row(3);
102102
ui.set_switch_lang_with_shift(true);
103+
ui.set_show_notification(true);
103104
ui.set_add_phrase_forward(true);
104105
ui.set_advance_after_selection(true);
105106
ui.set_conv_engine(1);
@@ -150,6 +151,9 @@ fn load_config(ui: &ConfigWindow) -> Result<()> {
150151
if let Ok(value) = reg_get_bool(&key, "SwitchLangWithShift") {
151152
ui.set_switch_lang_with_shift(value);
152153
}
154+
if let Ok(value) = reg_get_bool(&key, "ShowNotification") {
155+
ui.set_show_notification(value);
156+
}
153157
if let Ok(value) = reg_get_bool(&key, "OutputSimpChinese") {
154158
ui.set_output_simp_chinese(value);
155159
}
@@ -244,6 +248,7 @@ fn save_config(ui: &ConfigWindow) -> Result<()> {
244248
ui.get_show_cand_with_space_key(),
245249
);
246250
let _ = reg_set_bool(&key, "SwitchLangWithShift", ui.get_switch_lang_with_shift());
251+
let _ = reg_set_bool(&key, "ShowNotification", ui.get_show_notification());
247252
let _ = reg_set_bool(&key, "OutputSimpChinese", ui.get_output_simp_chinese());
248253
let _ = reg_set_bool(&key, "AddPhraseForward", ui.get_add_phrase_forward());
249254
let _ = reg_set_bool(

preferences/ui/config-window.slint

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export component ConfigWindow inherits Window {
1313

1414
in-out property <bool> switch-lang-with-shift;
1515
in-out property <bool> enable-caps-lock;
16+
in-out property <bool> show-notification;
1617
in-out property <bool> esc-clean-all-buf;
1718
in-out property <bool> full-shape-symbols;
1819
in-out property <bool> upper-case-with-shift;
@@ -94,6 +95,11 @@ export component ConfigWindow inherits Window {
9495
checked <=> enable-caps-lock;
9596
}
9697

98+
CheckBox {
99+
text: "顯示通知訊息";
100+
checked <=> show-notification;
101+
}
102+
97103
CheckBox {
98104
text: "使用 Esc 清空編輯區字串";
99105
checked <=> esc-clean-all-buf;

0 commit comments

Comments
 (0)