Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ReceivedImeText #251

Merged
merged 5 commits into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 29 additions & 18 deletions src/platform_impl/linux/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,24 +446,18 @@ impl<T: 'static> EventLoop<T> {
});

let tx_clone = event_tx.clone();
window.connect_motion_notify_event(move |window, _| {
let display = window.display();
if let Some(cursor) = display
.default_seat()
.and_then(|device_manager| device_manager.pointer())
{
let (_, x, y) = cursor.position();
if let Err(e) = tx_clone.send(Event::WindowEvent {
window_id: RootWindowId(id),
event: WindowEvent::CursorMoved {
position: PhysicalPosition::new(x as f64, y as f64),
device_id: DEVICE_ID,
// this field is depracted so it is fine to pass empty state
modifiers: ModifiersState::empty(),
},
}) {
log::warn!("Failed to send cursor moved event to event channel: {}", e);
}
window.connect_motion_notify_event(move |_window, event| {
let (x, y) = event.position();
if let Err(e) = tx_clone.send(Event::WindowEvent {
window_id: RootWindowId(id),
event: WindowEvent::CursorMoved {
position: PhysicalPosition::new(x, y),
device_id: DEVICE_ID,
// this field is depracted so it is fine to pass empty state
modifiers: ModifiersState::empty(),
},
}) {
log::warn!("Failed to send cursor moved event to event channel: {}", e);
}
Inhibit(false)
});
Expand Down Expand Up @@ -576,9 +570,25 @@ impl<T: 'static> EventLoop<T> {
Continue(true)
});

let tx_clone = event_tx.clone();
// TODO Add actual IME from system
let ime = gtk::IMContextSimple::default();
ime.set_client_window(window.window().as_ref());
ime.focus_in();
ime.connect_commit(move |_, s| {
if let Err(e) = tx_clone.send(Event::WindowEvent {
window_id: RootWindowId(id),
event: WindowEvent::ReceivedImeText(s.to_string()),
}) {
log::warn!("Failed to send received IME text event to event channel: {}", e);
}
});

let handler = keyboard_handler.clone();
window.connect_key_press_event(move |_, event_key| {
handler(event_key.to_owned(), ElementState::Pressed);
ime.filter_keypress(event_key);

Inhibit(false)
});

Expand All @@ -587,6 +597,7 @@ impl<T: 'static> EventLoop<T> {
handler(event_key.to_owned(), ElementState::Released);
Inhibit(false)
});

}
WindowRequest::Redraw => window.queue_draw(),
WindowRequest::Menu(m) => match m {
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/linux/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ impl Window {
}

pub fn set_ime_position<P: Into<Position>>(&self, _position: P) {
todo!()
//TODO
}

pub fn request_user_attention(&self, request_type: Option<UserAttentionType>) {
Expand Down
10 changes: 4 additions & 6 deletions src/platform_impl/macos/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,13 +557,11 @@ extern "C" fn insert_text(this: &Object, _sel: Sel, string: id, _replacement_ran
// We don't need this now, but it's here if that changes.
//let event: id = msg_send![NSApp(), currentEvent];

// We only send the IME text input here. The text coming from the
// keyboard is handled by `key_down`
AppState::queue_event(EventWrapper::StaticEvent(Event::WindowEvent {
window_id: WindowId(get_window_id(state.ns_window)),
event: WindowEvent::ReceivedImeText(string),
}));
if state.in_ime_preedit {
AppState::queue_event(EventWrapper::StaticEvent(Event::WindowEvent {
window_id: WindowId(get_window_id(state.ns_window)),
event: WindowEvent::ReceivedImeText(string),
}));
state.in_ime_preedit = false;
state.key_triggered_ime = true;
}
Expand Down
3 changes: 3 additions & 0 deletions src/platform_impl/windows/minimal_ime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ impl MinimalIme {
self.getting_ime_text = false;
return result;
}
} else {
*result = ProcResult::Value(LRESULT::default());
return String::from_utf16(&[wparam.0 as u16]).ok();
}
}
_ => (),
Expand Down