Skip to content

Commit

Permalink
(macOS) respect alt key configs for ime
Browse files Browse the repository at this point in the history
  • Loading branch information
n-p-e committed Sep 1, 2021
1 parent 3ff5ea7 commit df68147
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions window/src/os/macos/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1736,7 +1736,12 @@ impl WindowView {
return;
};

let use_ime = config::configuration().use_ime;
let config_handle = config::configuration();
let use_ime = config_handle.use_ime;
let send_composed_key_when_left_alt_is_pressed =
config_handle.send_composed_key_when_left_alt_is_pressed;
let send_composed_key_when_right_alt_is_pressed =
config_handle.send_composed_key_when_right_alt_is_pressed;

// `Delete` on macos is really Backspace and emits BS.
// `Fn-Delete` emits DEL.
Expand Down Expand Up @@ -1771,10 +1776,29 @@ impl WindowView {
modifiers
};

let only_alt = (modifiers & !(Modifiers::LEFT_ALT | Modifiers::RIGHT_ALT | Modifiers::ALT))
== Modifiers::NONE;
// Also respect `send_composed_key_when_(left|right)_alt_is_pressed` configs
// when `use_ime` is true.
let forward_to_ime = {
let only_alt = (modifiers
& !(Modifiers::LEFT_ALT | Modifiers::RIGHT_ALT | Modifiers::ALT))
== Modifiers::NONE;
let only_left_alt =
(modifiers & !(Modifiers::LEFT_ALT | Modifiers::ALT)) == Modifiers::NONE;
let only_right_alt =
(modifiers & !(Modifiers::RIGHT_ALT | Modifiers::ALT)) == Modifiers::NONE;

if modifiers.is_empty() {
true
} else if only_left_alt && !send_composed_key_when_left_alt_is_pressed {
false
} else if only_right_alt && !send_composed_key_when_right_alt_is_pressed {
false
} else {
only_alt
}
};

if key_is_down && use_ime && (modifiers.is_empty() || only_alt) {
if key_is_down && use_ime && forward_to_ime {
if let Some(myself) = Self::get_this(this) {
let mut inner = myself.inner.borrow_mut();
inner.key_is_down.replace(key_is_down);
Expand Down

0 comments on commit df68147

Please sign in to comment.