Skip to content

Instantly share code, notes, and snippets.

@Determinant
Created June 23, 2017 18:14
Show Gist options
  • Save Determinant/9c87925bed3c637a661ae72da4689e54 to your computer and use it in GitHub Desktop.
Save Determinant/9c87925bed3c637a661ae72da4689e54 to your computer and use it in GitHub Desktop.
IME on winit
extern crate winit;
extern crate libc;
extern crate x11_dl;
fn main() {
let mut events_loop = winit::EventsLoop::new();
unsafe {
libc::setlocale(libc::LC_CTYPE, b"zh_CN.utf8\0".as_ptr() as *const _);
let xlib = x11_dl::xlib::Xlib::open().expect("get xlib");
(xlib.XSetLocaleModifiers)(b"@im=fcitx\0".as_ptr() as *const _);
}
let _window = winit::Window::new(&events_loop)
.unwrap();
events_loop.run_forever(|event| {
match event {
winit::Event::WindowEvent {
event: winit::WindowEvent::ReceivedCharacter(chr), ..} => {
println!("{:?}", chr);
winit::ControlFlow::Continue
}
winit::Event::WindowEvent { event: winit::WindowEvent::Closed, .. } => {
winit::ControlFlow::Break
},
_ => winit::ControlFlow::Continue,
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment