Provide a way to set cursor area for IME cursor

Rename `Window::set_ime_position` to `Window::set_ime_cursor_area`
adding a way to create cursor exclusive zone.

Fixes #2886.
This commit is contained in:
Kirill Chibisov 2023-06-22 19:12:14 +00:00 committed by GitHub
parent 66ff52b012
commit 05444628e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 72 additions and 43 deletions

View file

@ -512,8 +512,8 @@ impl Window {
}
#[inline]
pub fn set_ime_position(&self, position: Position) {
x11_or_wayland!(match self; Window(w) => w.set_ime_position(position))
pub fn set_ime_cursor_area(&self, position: Position, size: Size) {
x11_or_wayland!(match self; Window(w) => w.set_ime_cursor_area(position, size))
}
#[inline]

View file

@ -534,12 +534,13 @@ impl Window {
}
#[inline]
pub fn set_ime_position(&self, position: Position) {
pub fn set_ime_cursor_area(&self, position: Position, size: Size) {
let window_state = self.window_state.lock().unwrap();
if window_state.ime_allowed() {
let scale_factor = window_state.scale_factor();
let position = position.to_logical(scale_factor);
window_state.set_ime_position(position);
let size = size.to_logical(scale_factor);
window_state.set_ime_cursor_area(position, size);
}
}

View file

@ -741,13 +741,14 @@ impl WindowState {
}
/// Set the IME position.
pub fn set_ime_position(&self, position: LogicalPosition<u32>) {
pub fn set_ime_cursor_area(&self, position: LogicalPosition<u32>, size: LogicalSize<u32>) {
// XXX This won't fly unless user will have a way to request IME window per seat, since
// the ime windows will be overlapping, but winit doesn't expose API to specify for
// which seat we're setting IME position.
let (x, y) = (position.x as i32, position.y as i32);
let (width, height) = (size.width as i32, size.height as i32);
for text_input in self.text_inputs.iter() {
text_input.set_cursor_rectangle(x, y, 0, 0);
text_input.set_cursor_rectangle(x, y, width, height);
text_input.commit();
}
}

View file

@ -1510,7 +1510,7 @@ impl UnownedWindow {
}
#[inline]
pub fn set_ime_position(&self, spot: Position) {
pub fn set_ime_cursor_area(&self, spot: Position, _size: Size) {
let (x, y) = spot.to_physical::<i32>(self.scale_factor()).into();
let _ = self
.ime_sender