Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Unreleased

- On Windows, implement `Window::set_ime_position`.
- **Breaking:** On Windows, Renamed `WindowBuilderExtWindows`'s `is_dark_mode` to `theme`.
- On Windows, add `WindowBuilderExtWindows::with_theme` to set a preferred theme.
- On Windows, fix bug causing message boxes to appear delayed.
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ features = [
"commctrl",
"dwmapi",
"errhandlingapi",
"imm",
"hidusage",
"libloaderapi",
"objbase",
Expand Down
54 changes: 54 additions & 0 deletions examples/set_ime_position.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use simple_logger::SimpleLogger;
use winit::{
dpi::PhysicalPosition,
event::{ElementState, Event, WindowEvent},
event_loop::{ControlFlow, EventLoop},
window::WindowBuilder,
};

fn main() {
SimpleLogger::new().init().unwrap();
let event_loop = EventLoop::new();

let window = WindowBuilder::new().build(&event_loop).unwrap();
window.set_title("A fantastic window!");

println!("Ime position will system default");
println!("Click to set ime position to cursor's");

let mut cursor_position = PhysicalPosition::new(0.0, 0.0);
event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Wait;

match event {
Event::WindowEvent {
event: WindowEvent::CursorMoved { position, .. },
..
} => {
cursor_position = position;
}
Event::WindowEvent {
event:
WindowEvent::MouseInput {
state: ElementState::Released,
..
},
..
} => {
println!(
"Setting ime position to {}, {}",
cursor_position.x, cursor_position.y
);
window.set_ime_position(cursor_position);
}
Event::WindowEvent {
event: WindowEvent::CloseRequested,
..
} => {
*control_flow = ControlFlow::Exit;
return;
}
_ => (),
}
});
}
24 changes: 21 additions & 3 deletions src/platform_impl/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ use winapi::{
windef::{HWND, POINT, RECT},
},
um::{
combaseapi, dwmapi, libloaderapi,
combaseapi, dwmapi,
imm::{CFS_POINT, COMPOSITIONFORM},
libloaderapi,
objbase::COINIT_APARTMENTTHREADED,
ole2,
oleidl::LPDROPTARGET,
Expand Down Expand Up @@ -616,9 +618,25 @@ impl Window {
self.window_state.lock().taskbar_icon = taskbar_icon;
}

pub(crate) fn set_ime_position_physical(&self, x: i32, y: i32) {
if unsafe { winuser::GetSystemMetrics(winuser::SM_IMMENABLED) } != 0 {
let mut composition_form = COMPOSITIONFORM {
dwStyle: CFS_POINT,
ptCurrentPos: POINT { x, y },
rcArea: unsafe { mem::zeroed() },
};
unsafe {
let himc = winapi::um::imm::ImmGetContext(self.window.0);
winapi::um::imm::ImmSetCompositionWindow(himc, &mut composition_form);
winapi::um::imm::ImmReleaseContext(self.window.0, himc);
}
}
}

#[inline]
pub fn set_ime_position(&self, _position: Position) {
warn!("`Window::set_ime_position` is ignored on Windows")
pub fn set_ime_position(&self, spot: Position) {
let (x, y) = spot.to_physical::<i32>(self.scale_factor()).into();
self.set_ime_position_physical(x, y);
}

#[inline]
Expand Down
2 changes: 1 addition & 1 deletion src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ impl Window {
///
/// ## Platform-specific
///
/// - **iOS / Android / Web / Windows:** Unsupported.
/// - **iOS / Android / Web:** Unsupported.
#[inline]
pub fn set_ime_position<P: Into<Position>>(&self, position: P) {
self.window.set_ime_position(position.into())
Expand Down