From 1fb788cc09fa349957da501dd911435f1957c03a Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Tue, 19 Dec 2023 20:59:23 +1300 Subject: Use logical position for cursor position Previously the physical cursor position instead of the logical cursor position was being passed to WindowController::on_cursor_move, which meant that the cursor position that the application was receiving would be incorrect when the window scale was greater than 1. --- src/window.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/window.rs b/src/window.rs index 327cbea..fcb5b2a 100644 --- a/src/window.rs +++ b/src/window.rs @@ -126,11 +126,14 @@ impl Window { } pub fn move_cursor(&mut self, position: Point) { + // Convert cursor position from physical position to logical position. + let pixel_scale = self.controller.pixel_scale().get() as i32; + let logical_position = Point::new(position.x / pixel_scale, position.y / pixel_scale); // The cursor position is rounded to i32 from f64, so we need to ignore // duplicate consecutive cursor positions. - if self.previous_cursor_position != Some(position) { - self.previous_cursor_position = Some(position); - self.controller.on_cursor_move(position); + if self.previous_cursor_position != Some(logical_position) { + self.previous_cursor_position = Some(logical_position); + self.controller.on_cursor_move(logical_position); } } -- cgit v1.2.3-70-g09d2