From 81ec2a8a26519000c82f9b55735e8fd92f5816cd Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sat, 2 Nov 2019 18:08:18 -0700 Subject: [PATCH] find a better way to decide that the IME is active on windows wparam is set to VK_PROCESSKEY so gate on that; this helps to prevent emitting the initial character of a composition sequence to the terminal. --- window/src/os/windows/connection.rs | 4 +++- window/src/os/windows/window.rs | 37 ++--------------------------- 2 files changed, 5 insertions(+), 36 deletions(-) diff --git a/window/src/os/windows/connection.rs b/window/src/os/windows/connection.rs index 237c9a853..e76bf2d13 100644 --- a/window/src/os/windows/connection.rs +++ b/window/src/os/windows/connection.rs @@ -47,7 +47,9 @@ impl ConnectionOps for Connection { } unsafe { - TranslateMessage(&mut msg); + // We don't use TranslateMessage because we don't + // want to generate WM_CHAR internally + // TranslateMessage(&mut msg); DispatchMessageW(&mut msg); } } else { diff --git a/window/src/os/windows/window.rs b/window/src/os/windows/window.rs index d9978ae64..45a378470 100644 --- a/window/src/os/windows/window.rs +++ b/window/src/os/windows/window.rs @@ -16,7 +16,6 @@ use std::io::Error as IoError; use std::os::windows::ffi::OsStringExt; use std::ptr::{null, null_mut}; use std::rc::Rc; -use std::sync::atomic::{AtomicBool, Ordering}; use winapi::shared::minwindef::*; use winapi::shared::ntdef::*; use winapi::shared::windef::*; @@ -40,7 +39,6 @@ pub(crate) struct WindowInner { hwnd: HWindow, callbacks: RefCell>, bitmap: RefCell, - ime_active: AtomicBool, #[cfg(feature = "opengl")] gl_state: Option>, } @@ -178,7 +176,6 @@ impl Window { hwnd: HWindow(null_mut()), callbacks: RefCell::new(callbacks), bitmap: RefCell::new(GdiBitmap::new_empty()), - ime_active: AtomicBool::new(false), #[cfg(feature = "opengl")] gl_state: None, })); @@ -717,20 +714,6 @@ impl Drop for ImmContext { } } -unsafe fn ime_endcomposition( - hwnd: HWND, - _msg: UINT, - _wparam: WPARAM, - _lparam: LPARAM, -) -> Option { - if let Some(inner) = rc_from_hwnd(hwnd) { - let inner = inner.borrow(); - // Note that we are no longer in the IME composer - inner.ime_active.store(false, Ordering::Relaxed); - } - None -} - unsafe fn ime_composition( hwnd: HWND, _msg: UINT, @@ -740,11 +723,6 @@ unsafe fn ime_composition( if let Some(inner) = rc_from_hwnd(hwnd) { let inner = inner.borrow(); - // Note that we are now composing. - // the WM_IME_ENDCOMPOSITION message will call ime_endcomposition - // and turn this off when the IME is dismissed - inner.ime_active.store(true, Ordering::Relaxed); - if (lparam as DWORD) & GCS_RESULTSTR == 0 { // No finished result; continue with the default // processing @@ -792,7 +770,7 @@ unsafe fn key(hwnd: HWND, msg: UINT, wparam: WPARAM, lparam: LPARAM) -> Option> 16) & 0xff) as u8; let releasing = (lparam & (1 << 31)) != 0; - let ime_active = inner.ime_active.load(Ordering::Relaxed); + let ime_active = wparam == VK_PROCESSKEY as _; /* let alt_pressed = (lparam & (1 << 29)) != 0; @@ -860,7 +838,7 @@ unsafe fn key(hwnd: HWND, msg: UINT, wparam: WPARAM, lparam: LPARAM) -> Option None, 0 => { @@ -949,16 +927,6 @@ unsafe fn key(hwnd: HWND, msg: UINT, wparam: WPARAM, lparam: LPARAM) -> Option { - None - } - key @ _ => key, } }; @@ -992,7 +960,6 @@ unsafe fn do_wnd_proc(hwnd: HWND, msg: UINT, wparam: WPARAM, lparam: LPARAM) -> key(hwnd, msg, wparam, lparam) } WM_IME_COMPOSITION => ime_composition(hwnd, msg, wparam, lparam), - WM_IME_ENDCOMPOSITION => ime_endcomposition(hwnd, msg, wparam, lparam), WM_MOUSEMOVE => mouse_move(hwnd, msg, wparam, lparam), WM_MOUSEHWHEEL | WM_MOUSEWHEEL => mouse_wheel(hwnd, msg, wparam, lparam), WM_LBUTTONDBLCLK | WM_RBUTTONDBLCLK | WM_MBUTTONDBLCLK | WM_LBUTTONDOWN | WM_LBUTTONUP