render/cursor: Correctly convert hotspot coordinates

This commit is contained in:
Victoria Brekenfeld 2025-04-16 19:35:30 +02:00 committed by Victoria Brekenfeld
parent 244c174da4
commit e6a3f5373c

View file

@ -20,7 +20,8 @@ use smithay::{
reexports::wayland_server::protocol::wl_surface,
render_elements,
utils::{
Buffer as BufferCoords, IsAlive, Logical, Monotonic, Point, Scale, Size, Time, Transform,
Buffer as BufferCoords, IsAlive, Logical, Monotonic, Physical, Point, Scale, Size, Time,
Transform,
},
wayland::compositor::{get_role, with_states},
};
@ -128,7 +129,7 @@ pub fn draw_surface_cursor<R>(
surface: &wl_surface::WlSurface,
location: impl Into<Point<i32, Logical>>,
scale: impl Into<Scale<f64>>,
) -> Vec<(CursorRenderElement<R>, Point<i32, BufferCoords>)>
) -> Vec<(CursorRenderElement<R>, Point<i32, Physical>)>
where
R: Renderer + ImportAll,
R::TextureId: Clone + 'static,
@ -143,11 +144,7 @@ where
.lock()
.unwrap()
.hotspot
.to_buffer(
1,
Transform::Normal,
&Size::from((1, 1)), /* Size doesn't matter for Transform::Normal */
)
.to_physical_precise_round(scale)
});
render_elements_from_surface_tree(
@ -259,7 +256,7 @@ pub fn draw_cursor<R>(
buffer_scale: f64,
time: Time<Monotonic>,
draw_default: bool,
) -> Vec<(CursorRenderElement<R>, Point<i32, BufferCoords>)>
) -> Vec<(CursorRenderElement<R>, Point<i32, Physical>)>
where
R: Renderer + ImportMem + ImportAll,
R::TextureId: Send + Clone + 'static,
@ -320,7 +317,12 @@ where
}
};
let hotspot = Point::<i32, BufferCoords>::from((frame.xhot as i32, frame.yhot as i32));
let hotspot = Point::<i32, BufferCoords>::from((frame.xhot as i32, frame.yhot as i32))
.to_logical(
actual_scale as i32,
Transform::Normal,
&Size::from((frame.width as i32, frame.height as i32)),
);
state.current_image = Some(frame);
return vec![(
@ -336,10 +338,10 @@ where
)
.expect("Failed to import cursor bitmap"),
),
hotspot,
hotspot.to_physical_precise_round(scale),
)];
} else if let CursorImageStatus::Surface(ref wl_surface) = cursor_status {
return draw_surface_cursor(renderer, wl_surface, location.to_i32_round(), scale);
return draw_surface_cursor(renderer, wl_surface, location, scale);
} else {
Vec::new()
}