-
Notifications
You must be signed in to change notification settings - Fork 912
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
rename CompostionEvent to IMEPreeditEvent #1622
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m in favor of renaming these events from CompositionEvent
, but I don’t like the name IMEPreeditEvent
. Is there anything wrong with just IMEEvent
or ImeEvent
?
@Osspial it makes sense for me. Will rename them. |
@Osspial Could you check my change? I renamed them. One CI check was failed, but I think this is not related to this change. |
d3bcee3
to
84f26b0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've rebased composition-event branch.
I also think that we can apply the proposed changes(about event restructure) from the issue I've mentioned in that PR, right now we only have X11 backend, so that's why I think it should be done here.
If you have any questions or concerns let me know.
src/event.rs
Outdated
CompositionStart(String), | ||
CompositionUpdate(String, usize), | ||
CompositionEnd(String), | ||
pub enum PreeditState { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can name it a bit differently, since it's not only about preedit state, since you have commit
, etc. I'd also like to see adoption of
pub enum CompositionEvent {
CompositionEnabled,
CompositionPreedit(String, Option<usize>, Option<usize>),
CompositionCommit(String),
CompositionDisabled,
}
That I've mentioned on #1497 if you don't have any objects, unfortunately I don't really know much about X11, so it's a bit hard for me to update its code myself.
Also we can name rename PreeditState
to IMEEvent
, and have
pub enum IMEEvent {
Enabled,
Preedit(String, Option<usize>, Option<usize>),
Commit(String),
Disabled,
}
So I guess Start and Update should be transformed into Preedit
, and End should be transformed into Commit.
Enabled and Disabled should be implemented, and I guess you have that information from X server, at least I can see something like that in xim docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you miss Start (or maybe PreeditStart?) event. Other than that, I think it looks fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you miss Start (or maybe PreeditStart?) event. Other than that, I think it looks fine.
Could you explain why PreeditStart
is required? on Wayland for example everything starts with just Preedit
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Wep API, CompositionStart exist in the specification. And in x11, every IME session starts with preedit start event. So, I believe something to tell us when a new IME session starts is necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By start you mean that input method got open or just new input? Since Wayland has a concept of 'Enabled', when user uses its IME, like they opened 'fcitx' or 'ibus' and focused your app. But there's no notion of 'Start', and everything is communicated via 'Preedit' and 'Commit'.
My question was about start, since it looked like Preedit("", None, None)
to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, your suggestion is the application can detect the session start by checking the second argument is empty?
But why do you need to detect session start at all? The start is when you've got any IME event.
I mean, I don't understand how end users will handle Start
differently to Preedit
? Could you give an example where handling of those 2 are different and it makes sense? I get that it's common API for X11 and Web, but it really feels like someone decided to add redundant event that you can mirror with other events.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I don't have an idea of specific usage for Start event for now, but Start event looks relatively common, so I'm afraid that there is some needs.
But if there is no special use case, it might be OK to combine them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, I don't understand how end users will handle Start differently to Preedit? Could you give an example where handling of those 2 are different and it makes sense?
An example I met before was, I need to know whether I should handle ReceiveCharacter
or not. When I get PreeditStart
, I can set a flag like isPreediting
. If isPreediting
is true, I will ignore ReceiveCharacter
event.
(However, we can do it in winit though: when preediting, we don't trigger ReceiveCharacter
.)
I think it may be useful when user need to do stuff depend on IME state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we do preedit we don't need to send receivedchar, since the data is being send via preedit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure, but there may be other events in the similar situation. For example, user may also want to ignore KeyboardInput
when do preedit (IME will handle arrow keys and backspace, so user may want to ignore them). We can't take into account all the cases I suppose.
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | ||
pub enum IMEEvent { | ||
/// The user enables IME | ||
Enabled, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
I tried to implement Enable/Disable event, but it seems difficult in X11. @kchibisov do you think we should give up enable/disable event only on X11? |
Have you looked into something like that gtk on that? It seems strange that there's no indication that IME got opened, though, we can just always send enable when creating IME object and send The thing is that we must send it, but what we use to indicate that could be something not really optimal, if implementing it is something that complicated. |
Yeah, GTK doesn't support enable events either (and won't support XIM at all in GTK4). In X11, we don't destory IME object basically, so the current solution would be never sending |
Looks fine to me, I guess. |
I've looked into things again, and I think we can go for now with |
Sorry for late response. I think I can update the change in this weekend. |
Since you've kept enable and removed disable is that correct that there's no way to know that something got disabled? Also, would you mind rebasing the branch? |
Yes. Also, actually, it doesn't know IME enabled. It just sends enable event when it creates the context object, as we discussed before.
Sure. Will do it later |
0684ebd
to
d5220bb
Compare
Squash and rebased |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should also fix formatting. After that it should be good to go, I think.
Preedit(String, Option<usize>, Option<usize>), | ||
|
||
/// The user completes the current IME session with the value. | ||
Commit(String), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New line here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
CompositionEnd(String), | ||
pub enum IMEEvent { | ||
/// The user enables IME | ||
Enabled, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New line here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
src/event.rs
Outdated
/// The value represents a pair of the preedit string and the cursor position. | ||
/// The cursor position is byte-wise indexed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should document that the first argument is a cursor begin and second is cursor end. Also if your cursor being and end are equal you should send both of them the same, so in your code you should always send Some(position), Some(position)?
Also, both None
should represent a hidden cursor, we should state it as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added those description
event: WindowEvent::Composition(CompositionEvent::CompositionUpdate( | ||
text, position, | ||
)), | ||
event: WindowEvent::IME(IMEEvent::Preedit(text, Some(position), None)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, is there a way to inform that cursor is hidden, thus shouldn't be drawn, if there's such thing we should inform about that via sending None
and None
?
event: WindowEvent::IME(IMEEvent::Preedit(text, Some(position), None)), | |
event: WindowEvent::IME(IMEEvent::Preedit(text, Some(position), Some(position))), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
In X11, I cannot find any event related to hidden cursor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@garasubo I've decided to rename the event one more time, and call it IME
, since event suffix seems redundant here. I've also slightly updated the docs, are you fine with proposed changes?
@@ -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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
From this guide:
Could we just simply think that when winit window gets focused, send |
The problem is on Wayland it works differently, the system tells you that IME enabled only when you get So I wanted to expose this, since if you don't have text-input you won't ever get Enabled, thus there's no point in requesting ime updates all the time. |
@kchibisov Thanks. LGTM. |
Ref: #1497 (comment)
To avoid confusion from users, rename
CompositionEvent
toIMEPreeditEvent
to make it clear that those events are related to IME.Also, added documents
cargo fmt
has been run on this branchcargo doc
builds successfullyCHANGELOG.md
if knowledge of this change could be valuable to users