Skip to content
Open
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
17 changes: 16 additions & 1 deletion winit-x11/src/event_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ impl EventProcessor {
self.process_xevent(xev, app);

// Handle IME requests.
let mut ime_focus = None;
while let Ok(request) = self.ime_receiver.try_recv() {
let ime = match self.target.ime.as_mut() {
Some(ime) => ime,
Expand All @@ -97,11 +98,25 @@ impl EventProcessor {
ime.send_xim_area(window_id, x, y, w, h);
},
ImeRequest::Allow(window_id, allowed) => {
ime.set_ime_allowed(window_id, allowed);
let result = ime.set_ime_allowed(window_id, allowed);
if self.active_window == Some(window_id as xproto::Window) {
match result {
Ok(true) => ime_focus = Some(window_id),
Err(_) => ime_focus = None,
Ok(false) => {},
}
}
},
}
}

// Replacing the context does not generate a window focus event. Transfer
// focus after draining requests, so contexts replaced again in this batch
// do not activate the input method unnecessarily.
if let (Some(window_id), Some(ime)) = (ime_focus, self.target.ime.as_mut()) {
let _ = ime.get_mut().focus(window_id);
}

// Drain IME events.
while let Ok((window, event)) = self.ime_event_receiver.try_recv() {
let window_id = mkwid(window as xproto::Window);
Expand Down
12 changes: 8 additions & 4 deletions winit-x11/src/ime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,22 +202,26 @@ impl Ime {
}
}

pub fn set_ime_allowed(&mut self, window: ffi::Window, allowed: bool) {
pub fn set_ime_allowed(
&mut self,
window: ffi::Window,
allowed: bool,
) -> Result<bool, ImeContextCreationError> {
if self.is_destroyed() {
return;
return Ok(false);
}

if let Some(&mut Some(ref mut context)) = self.inner.contexts.get_mut(&window) {
if allowed == context.is_allowed() {
return;
return Ok(false);
}
}

// Remove context for that window.
let _ = self.remove_context(window);

// Create new context supporting IME input.
let _ = self.create_context(window, allowed);
self.create_context(window, allowed)
}

pub fn is_ime_allowed(&self, window: ffi::Window) -> bool {
Expand Down
3 changes: 3 additions & 0 deletions winit/src/changelog/unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ changelog entry.
- On Wayland, use the touch serial for `Window::drag_window`, `Window::drag_resize_window` and `Window::show_window_menu` when the interaction was started by touch.
- On Windows, fix a crash when moving a window that owns windows not created by winit, such as native dialogs or application helper windows.

- On X11, preserve input context focus when enabling or disabling IME on a
focused window.

### Changed

- Removed the `url` dependency from `winit-core`, along with `SendData::from_file_paths`,
Expand Down
Loading