screencopy: Render cursor for toplevel capture at right position

`CosmicMapped::cursor_positon` may have worked previously, but doesn't
now.

This is based on the code used for seperate cursor capture sessions.
Maybe this could be consolidated in some way.

But this seems to work. Including for rotated outputs.
This commit is contained in:
Ian Douglas Scott 2025-09-12 12:40:17 -07:00 committed by Victoria Brekenfeld
parent 0c941b802d
commit f63d901406

View file

@ -41,7 +41,7 @@ use crate::{
},
shell::{CosmicMappedRenderElement, CosmicSurface, WorkspaceRenderElement},
state::{Common, KmsNodes, State},
utils::prelude::SeatExt,
utils::prelude::{PointExt, PointGlobalExt, RectExt, RectLocalExt, SeatExt},
wayland::{
handlers::screencopy::{
constraints_for_output, constraints_for_toplevel, SessionData, SessionUserData,
@ -531,7 +531,7 @@ pub fn render_window_to_buffer(
additional_damage: Vec<Rectangle<i32, BufferCoords>>,
draw_cursor: bool,
common: &mut Common,
window: &CosmicSurface,
toplevel: &CosmicSurface,
geometry: Rectangle<i32, Logical>,
) -> Result<RenderOutputResult<'d>, DTError<R::Error>>
where
@ -560,17 +560,22 @@ pub fn render_window_to_buffer(
let shell = common.shell.read();
let seat = shell.seats.last_active().clone();
let location = if let Some(mapped) = shell.element_for_surface(window) {
mapped.cursor_position(&seat).and_then(|mut p| {
p -= mapped.active_window_offset().to_f64();
if p.x < 0. || p.y < 0. {
None
} else {
Some(p)
let pointer = seat.get_pointer().unwrap();
let pointer_loc = pointer.current_location().to_i32_round().as_global();
let mut location = None;
if let Some(element) = shell.element_for_surface(toplevel) {
if element.has_active_window(toplevel) {
if let Some(workspace) = shell.space_for(element) {
if let Some(geometry) = workspace.element_geometry(element) {
let mut surface_geo = element.active_window_geometry().as_local();
surface_geo.loc += geometry.loc;
let global_geo = surface_geo.to_global(workspace.output());
if global_geo.contains(pointer_loc) {
location = Some((pointer_loc - global_geo.loc).as_logical().to_f64());
}
}
}
})
} else {
None
}
};
std::mem::drop(shell);
@ -614,7 +619,7 @@ pub fn render_window_to_buffer(
elements.extend(AsRenderElements::<R>::render_elements::<
WindowCaptureElement<R>,
>(
window,
toplevel,
renderer,
(-geometry.loc.x, -geometry.loc.y).into(),
Scale::from(1.0),