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

rename CompostionEvent to IMEPreeditEvent #1622

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 10 additions & 8 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ pub enum WindowEvent<'a> {
ModifiersChanged(ModifiersState),

/// An event from IME
IME(IMEEvent),
IME(IME),

/// The cursor has moved on the window.
CursorMoved {
Expand Down Expand Up @@ -627,23 +627,25 @@ pub struct KeyboardInput {
pub modifiers: ModifiersState,
}

/// Describes an event from input method.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum IMEEvent {
/// The user enables IME
pub enum IME {
/// Notifies when the IME was enabled.
Enabled,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does X11 have an event to tell you when you actually have IME running or how to you obtain that information? Also does it tell you when disable happens, since if X11 doesn't have those events they should be issued at some points, since users may only handle IME things after you've actually got those, since IME is user initiated, I guess.

Or it's not the case for X11 and it just always works?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sorry. This is WIP commit. I think we can get those status with XIMPreeditStateNotifyCallback, so will implement that and test it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New line here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added


/// The user updates preedit status on IME.
/// Notifies when a new composing text should be set at the cursor position.
///
/// The value represents a pair of the preedit string and the cursor begin position and end
/// position. When both indices are `None`, the cursor should be hidden.
///
/// The value represents a pair of the preedit string and the cursor begin position and end position.
/// When the cursor is hidden, both value will be None
/// The cursor position is byte-wise indexed.
Preedit(String, Option<usize>, Option<usize>),

/// The user completes the current IME session with the value.
/// Notifies when text should be inserted into the editor widget.
Commit(String),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New line here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added


/// The user disables IME
/// Notifies when the IME was disabled.
Disabled,
}

Expand Down
12 changes: 6 additions & 6 deletions src/platform_impl/linux/x11/event_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use crate::platform_impl::platform::x11::ime::{ImeEvent, ImeEventReceiver};
use crate::{
dpi::{PhysicalPosition, PhysicalSize},
event::{
DeviceEvent, ElementState, Event, IMEEvent, KeyboardInput, ModifiersState, TouchPhase,
WindowEvent,
DeviceEvent, ElementState, Event, KeyboardInput, ModifiersState, TouchPhase, WindowEvent,
IME,
},
event_loop::EventLoopWindowTarget as RootELW,
};
Expand Down Expand Up @@ -1241,22 +1241,22 @@ impl<T: 'static> EventProcessor<T> {
ImeEvent::Enabled => {
callback(Event::WindowEvent {
window_id: mkwid(window),
event: WindowEvent::IME(IMEEvent::Enabled),
event: WindowEvent::IME(IME::Enabled),
});
}
ImeEvent::Start => {
self.is_composing = true;
self.composed_text = None;
callback(Event::WindowEvent {
window_id: mkwid(window),
event: WindowEvent::IME(IMEEvent::Preedit("".to_owned(), None, None)),
event: WindowEvent::IME(IME::Preedit("".to_owned(), None, None)),
});
}
ImeEvent::Update(text, position) => {
if self.is_composing {
callback(Event::WindowEvent {
window_id: mkwid(window),
event: WindowEvent::IME(IMEEvent::Preedit(
event: WindowEvent::IME(IME::Preedit(
text,
Some(position),
Some(position),
Expand All @@ -1268,7 +1268,7 @@ impl<T: 'static> EventProcessor<T> {
self.is_composing = false;
callback(Event::WindowEvent {
window_id: mkwid(window),
event: WindowEvent::IME(IMEEvent::Commit(
event: WindowEvent::IME(IME::Commit(
self.composed_text.take().unwrap_or("".to_owned()),
)),
});
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/linux/x11/ime/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ extern "C" fn preedit_draw_callback(
.collect()
};
let mut old_text_tail = client_data.text.split_off(chg_range.end);
client_data.text.split_off(chg_range.start);
let _ = client_data.text.split_off(chg_range.start);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ignore is intentional right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

client_data.text.append(&mut new_chars);
client_data.text.append(&mut old_text_tail);
let cursor_byte_pos = calc_byte_position(&client_data.text, client_data.cursor_pos);
Expand Down