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

add composition event support #1404

Merged
merged 10 commits into from
Mar 6, 2020

Conversation

garasubo
Copy link
Contributor

@garasubo garasubo commented Jan 17, 2020

Fix #1293

Added new window events to get information about preedit status in IME: CompositionStart, CompositionUpdate, CompositionEnd.

This change requires x11-dl crate. I've already send a pull request for it (AltF02/x11-rs#107)

TODO:

  • I'm not sure ImeContextClientData could be accessed at the same time. It might need to be wrapped with Mutex

  • This feature only available in X11. I don't have other platform, so need to help implementing this feature for other platforms.

  • We also need to provide a way to disable this feature, since some people don't want to receive these new events.

  • Tested on all platforms changed

  • Compilation warnings were addressed

  • cargo fmt has been run on this branch

  • cargo doc builds successfully

  • Added an entry to CHANGELOG.md if knowledge of this change could be valuable to users

  • Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior

  • Created or updated an example program if it would help users understand this functionality

  • Updated feature matrix, if new features were added or implemented

@goddessfreya goddessfreya added DS - x11 C - waiting on maintainer A maintainer must review this code labels Jan 19, 2020
@garasubo garasubo changed the title WIP: add composition event suppor prototype WIP: add composition event support Jan 25, 2020
@murarth
Copy link
Contributor

murarth commented Jan 25, 2020

This PR does not successfully build on any platform. You need to update your winit fork and rebase this branch against the current master.

@garasubo
Copy link
Contributor Author

@murarth I know that. This failure is because we need to update x11-dl crate, as mentioned in the description. If you want to try to build in your local:

  1. Pull this MR in your local
  2. Update Cargo.toml to use your local x11-dl

@garasubo garasubo changed the title WIP: add composition event support add composition event support Jan 31, 2020
@garasubo
Copy link
Contributor Author

garasubo commented Jan 31, 2020

Now the new version of x11-dl is available. I updated my branch to use it.
Only the build failure is in armv7-apple-ios. It seems the issue in CI?

error: component 'rust-std' for target 'armv7-apple-ios' is unavailable for download for channel nightly
Sometimes not all components are available in any given nightly.
error: backtrace:
error: stack backtrace:
   0: backtrace::capture::Backtrace::new_unresolved
   1: error_chain::backtrace::imp::InternalBacktrace::new
   2: rustup::dist::manifestation::Manifestation::update
   3: rustup::dist::dist::try_update_from_dist_
   4: rustup::toolchain::Toolchain::install
   5: rustup::toolchain::Toolchain::install_from_dist
   6: rustup_init::rustup_mode::update
   7: rustup_init::rustup_mode::main
   8: rustup_init::run_rustup_inner
   9: rustup_init::main
  10: std::rt::lang_start::{{closure}}
  11: main

Cargo.toml Outdated Show resolved Hide resolved
src/event.rs Outdated Show resolved Hide resolved
src/event.rs Outdated Show resolved Hide resolved
src/platform_impl/linux/x11/ime/context.rs Outdated Show resolved Hide resolved
src/platform_impl/linux/x11/ime/context.rs Outdated Show resolved Hide resolved
src/platform_impl/linux/x11/ime/context.rs Outdated Show resolved Hide resolved
src/platform_impl/linux/x11/ime/context.rs Outdated Show resolved Hide resolved
This change requires x11-dl crate
Also, I should send actual string in IME
After the discussion on the PR, I decided to follow the Web
specification for the composition events. I added a few states to filter
out unnecessary events.
@garasubo
Copy link
Contributor Author

  • Rebased my branch to resolve conflict
  • Change the event structure to follow web UI specification.

ptr::null_mut::<()>(),
);
println!("set preedit call back");
Copy link
Contributor

Choose a reason for hiding this comment

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

Forgot to delete this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

ffi::XNClientWindow_0.as_ptr() as *const _,
window,
ffi::XNPreeditAttributes_0.as_ptr() as *const _,
pre_edit_attr.ptr,
ptr::null_mut::<()>(),
);
println!("set preedit call back 2");
Copy link
Contributor

Choose a reason for hiding this comment

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

And this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

@murarth murarth changed the base branch from master to composition-events February 14, 2020 18:24
@murarth
Copy link
Contributor

murarth commented Feb 14, 2020

I think this PR is ready to merge (once those two println!s are gone).

I've created a new branch on winit so that we can merge this new API into master only once it's implemented on all platforms.

.event_sender
.send((
client_data.window,
ImeEvent::Update(client_data.text.iter().collect(), client_data.cursor_pos),
Copy link
Contributor

Choose a reason for hiding this comment

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

The cursor position field here also needs to be converted to a byte offset, correct?

I didn't notice this in my previous review because I didn't see any erroneous events generated in my testing. When is the "caret" callback actually called?

Copy link
Contributor Author

@garasubo garasubo Feb 22, 2020

Choose a reason for hiding this comment

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

Fixed byte offset calculation.

This event will be called when you move your cusor in IME

@garasubo
Copy link
Contributor Author

The checks were failed, but the errors comes from where I didn't change

##[error]    --> C:\Users\runneradmin\.cargo\registry\src\github.com-1ecc6299db9ec823\js-sys-0.3.35\src\lib.rs:4898:60
     |
4898 |                 let mem = buf.unchecked_ref::<WebAssembly::Memory>();
     |                                                            ^^^^^^ this struct is private
     |
note: the struct `Memory` is defined here
    --> C:\Users\runneradmin\.cargo\registry\src\github.com-1ecc6299db9ec823\js-sys-0.3.35\src\lib.rs:3516:5
     |
3516 |     #[wasm_bindgen]
     |     ^^^^^^^^^^^^^^^
     = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0603]: struct `Memory` is private
##[error]    --> C:\Users\runneradmin\.cargo\registry\src\github.com-1ecc6299db9ec823\js-sys-0.3.35\src\lib.rs:4908:60
     |
4908 |                 let mem = buf.unchecked_ref::<WebAssembly::Memory>();
     |                                                            ^^^^^^ this struct is private
     |
note: the struct `Memory` is defined here
    --> C:\Users\runneradmin\.cargo\registry\src\github.com-1ecc6299db9ec823\js-sys-0.3.35\src\lib.rs:3516:5
     |
3516 |     #[wasm_bindgen]
     |     ^^^^^^^^^^^^^^^
     = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 3 previous errors

@garasubo
Copy link
Contributor Author

garasubo commented Mar 6, 2020

@murarth The CI tests were passed. Could you merge it?

@murarth murarth merged commit a1bf8b5 into rust-windowing:composition-events Mar 6, 2020
@murarth
Copy link
Contributor

murarth commented Mar 6, 2020

Thank you for your work on this implementation, @garasubo.

A final note: I had named the new branch composition-events (with a trailing s), but I now feel that that name may be confusing and composition-event (no trailing s) is a better name. I've created the new branch composition-event and deleted the old one.

@garasubo garasubo deleted the composition-event branch June 26, 2020 06:22
Osspial pushed a commit that referenced this pull request Jun 30, 2020
* WIP: add composition event suppor prototype

This change requires x11-dl crate
Also, I should send actual string in IME

* send actual preedit string

* run cargo fmt

* update cargo.toml

* remove warning

* address comments in PR

* follow web spec

After the discussion on the PR, I decided to follow the Web
specification for the composition events. I added a few states to filter
out unnecessary events.

* remove println

* fix cursor pos calc

* Re-run CI

Co-authored-by: Murarth <murarth@gmail.com>
@@ -1188,6 +1197,40 @@ impl<T: 'static> EventProcessor<T> {
}
Err(_) => (),
}
match self.ime_event_receiver.try_recv() {
Copy link
Contributor

@kaiwk kaiwk Sep 4, 2020

Choose a reason for hiding this comment

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

Hi @garasubo and @murarth , I'm implementing this for Mac, should I handle both WindowEvent::ReceivedCharacter and CompositionEvent::End at the same time, or just ignore WindowEvent::ReceivedCharacter during composing?

I'm not sure how XIM work, but looks like here, in process_event, both x event and ime event are handled?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for get interested in this work. I don't have Mac dev environment, so that would be great.

I think we should handle both to keep compatibility, so in my implementation, both events are handled.
In XIM, IME events and receiving characters events are independent. So, I didn't touch any logic related to ReceivedCharacter event.

kchibisov pushed a commit that referenced this pull request Oct 10, 2020
* WIP: add composition event suppor prototype

This change requires x11-dl crate
Also, I should send actual string in IME

* send actual preedit string

* run cargo fmt

* update cargo.toml

* remove warning

* address comments in PR

* follow web spec

After the discussion on the PR, I decided to follow the Web
specification for the composition events. I added a few states to filter
out unnecessary events.

* remove println

* fix cursor pos calc

* Re-run CI

Co-authored-by: Murarth <murarth@gmail.com>
yuebansanren pushed a commit to gkd-rusters/winit that referenced this pull request Mar 15, 2021
* WIP: add composition event suppor prototype

This change requires x11-dl crate
Also, I should send actual string in IME

* send actual preedit string

* run cargo fmt

* update cargo.toml

* remove warning

* address comments in PR

* follow web spec

After the discussion on the PR, I decided to follow the Web
specification for the composition events. I added a few states to filter
out unnecessary events.

* remove println

* fix cursor pos calc

* Re-run CI

Co-authored-by: Murarth <murarth@gmail.com>
@komi1230 komi1230 mentioned this pull request Jan 11, 2022
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C - waiting on maintainer A maintainer must review this code DS - x11
Development

Successfully merging this pull request may close these issues.

Improve IME event handling
4 participants