From 27956e6e007c2efa96ce6cc25df494216d0d4b2e Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Mon, 15 Jun 2026 13:52:32 -0700 Subject: [PATCH] Make `cursor_geometry()` return a `CursorGeometry` struct A bit better than just a tuple. --- src/input/mod.rs | 14 +++++----- src/shell/focus/target.rs | 4 +-- src/shell/seats.rs | 26 ++++++++++++++----- .../handlers/image_copy_capture/mod.rs | 6 ++--- .../handlers/image_copy_capture/render.rs | 4 +-- 5 files changed, 33 insertions(+), 21 deletions(-) diff --git a/src/input/mod.rs b/src/input/mod.rs index 48db97db..a9351310 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -11,7 +11,7 @@ use crate::{ }, input::gestures::{GestureState, SwipeAction}, shell::{ - LastModifierChange, SeatExt, Trigger, + CursorGeometry, LastModifierChange, SeatExt, Trigger, focus::{ Stage, render_input_order, target::{KeyboardFocusTarget, PointerFocusTarget}, @@ -651,7 +651,7 @@ impl State { } for session in cursor_sessions_for_output(&shell, &output) { - if let Some((geometry, offset)) = seat.cursor_geometry( + if let Some(CursorGeometry { geometry, hotspot }) = seat.cursor_geometry( (position - output_geometry.loc.to_f64()) .as_logical() .to_buffer( @@ -677,7 +677,7 @@ impl State { dma: None, }); } - session.set_cursor_hotspot(offset); + session.set_cursor_hotspot(hotspot); session.set_cursor_pos(Some(geometry.loc)); } } @@ -720,7 +720,7 @@ impl State { let shell = self.common.shell.read(); for session in cursor_sessions_for_output(&shell, &output) { - if let Some((geometry, offset)) = seat.cursor_geometry( + if let Some(CursorGeometry { geometry, hotspot }) = seat.cursor_geometry( (position - output_geometry.loc.to_f64()) .as_logical() .to_buffer( @@ -746,7 +746,7 @@ impl State { dma: None, }); } - session.set_cursor_hotspot(offset); + session.set_cursor_hotspot(hotspot); session.set_cursor_pos(Some(geometry.loc)); } } @@ -2482,7 +2482,7 @@ impl State { let output_geometry = output.geometry(); for session in cursor_sessions_for_output(&shell, &output) { - if let Some((geometry, offset)) = seat.cursor_geometry( + if let Some(CursorGeometry { geometry, hotspot }) = seat.cursor_geometry( point.to_buffer( output.current_scale().fractional_scale(), output.current_transform(), @@ -2501,7 +2501,7 @@ impl State { dma: None, }); } - session.set_cursor_hotspot(offset); + session.set_cursor_hotspot(hotspot); session.set_cursor_pos(Some(geometry.loc)); } } diff --git a/src/shell/focus/target.rs b/src/shell/focus/target.rs index fff77282..929cd92e 100644 --- a/src/shell/focus/target.rs +++ b/src/shell/focus/target.rs @@ -6,7 +6,7 @@ use std::{ use crate::{ shell::{ - CosmicSurface, SeatExt, + CosmicSurface, CursorGeometry, SeatExt, element::{CosmicMapped, CosmicStack, CosmicWindow}, layout::tiling::ResizeForkTarget, zoom::ZoomFocusTarget, @@ -272,7 +272,7 @@ impl PointerFocusTarget { None }; - let cursor_hotspot = if let Some((_, hotspot)) = + let cursor_hotspot = if let Some(CursorGeometry { hotspot, .. }) = seat.cursor_geometry((0.0, 0.0), Duration::from_millis(event.time as u64).into()) { hotspot diff --git a/src/shell/seats.rs b/src/shell/seats.rs index 5273e97f..11211e90 100644 --- a/src/shell/seats.rs +++ b/src/shell/seats.rs @@ -243,6 +243,12 @@ pub fn create_seat( seat } +#[derive(Debug, Copy, Clone)] +pub struct CursorGeometry { + pub geometry: Rectangle, + pub hotspot: Point, +} + pub trait SeatExt { fn id(&self) -> usize; @@ -266,7 +272,7 @@ pub trait SeatExt { &self, loc: impl Into>, time: Time, - ) -> Option<(Rectangle, Point)>; + ) -> Option; fn cursor_image_status(&self) -> CursorImageStatus; fn set_cursor_image_status(&self, status: CursorImageStatus); } @@ -367,7 +373,7 @@ impl SeatExt for Seat { &self, loc: impl Into>, time: Time, - ) -> Option<(Rectangle, Point)> { + ) -> Option { let location = loc.into().to_i32_round(); match self.cursor_image_status() { @@ -386,7 +392,10 @@ impl SeatExt for Seat { (geo.loc.x, geo.loc.y).into(), geo.size.to_buffer(1, Transform::Normal), ); - Some((buffer_geo, (hotspot.x, hotspot.y).into())) + Some(CursorGeometry { + geometry: buffer_geo, + hotspot: (hotspot.x, hotspot.y).into(), + }) } CursorImageStatus::Named(cursor_icon) => { let seat_userdata = self.user_data(); @@ -398,10 +407,13 @@ impl SeatExt for Seat { .get_named_cursor(cursor_icon) .get_image(1, time.as_millis()); - Some(( - Rectangle::new(location, (frame.width as i32, frame.height as i32).into()), - (frame.xhot as i32, frame.yhot as i32).into(), - )) + Some(CursorGeometry { + geometry: Rectangle::new( + location, + (frame.width as i32, frame.height as i32).into(), + ), + hotspot: (frame.xhot as i32, frame.yhot as i32).into(), + }) } CursorImageStatus::Hidden => None, } diff --git a/src/wayland/handlers/image_copy_capture/mod.rs b/src/wayland/handlers/image_copy_capture/mod.rs index 3f08b2dd..f76e96b5 100644 --- a/src/wayland/handlers/image_copy_capture/mod.rs +++ b/src/wayland/handlers/image_copy_capture/mod.rs @@ -31,7 +31,7 @@ use smithay::{ }; use crate::{ - shell::{CosmicSurface, Shell}, + shell::{CosmicSurface, CursorGeometry, Shell}, state::{BackendData, State}, utils::prelude::{ OutputExt, PointExt, PointGlobalExt, PointLocalExt, RectExt, RectLocalExt, SeatExt, @@ -86,7 +86,7 @@ impl ImageCopyCaptureHandler for State { ) -> Option { let shell = self.common.shell.read(); let seat = seat_for_wl_pointer(&shell, pointer)?; - let size = if let Some((geometry, _)) = + let size = if let Some(CursorGeometry { geometry, .. }) = seat.cursor_geometry((0.0, 0.0), self.common.clock.now()) { geometry.size @@ -160,7 +160,7 @@ impl ImageCopyCaptureHandler for State { let pointer = seat.get_pointer().unwrap(); let pointer_loc = pointer.current_location().to_i32_round().as_global(); - let (pointer_size, hotspot) = if let Some((geometry, hotspot)) = + let (pointer_size, hotspot) = if let Some(CursorGeometry { geometry, hotspot }) = seat.cursor_geometry((0.0, 0.0), self.common.clock.now()) { (geometry.size, hotspot) diff --git a/src/wayland/handlers/image_copy_capture/render.rs b/src/wayland/handlers/image_copy_capture/render.rs index 0cb62529..21976fcb 100644 --- a/src/wayland/handlers/image_copy_capture/render.rs +++ b/src/wayland/handlers/image_copy_capture/render.rs @@ -45,7 +45,7 @@ use crate::{ render_workspace, wayland::SurfaceRenderElement, }, - shell::{CosmicMappedRenderElement, CosmicSurface, WorkspaceRenderElement}, + shell::{CosmicMappedRenderElement, CosmicSurface, CursorGeometry, WorkspaceRenderElement}, state::{Common, KmsNodes, State}, utils::prelude::{PointExt, PointGlobalExt, RectExt, RectLocalExt, SeatExt}, wayland::{ @@ -804,7 +804,7 @@ pub fn render_cursor_to_buffer( let buffer = frame.buffer(); let mut cursor_size = seat .cursor_geometry((0.0, 0.0), state.common.clock.now()) - .map(|(geo, _hotspot)| geo.size) + .map(|CursorGeometry { geometry, .. }| geometry.size) .unwrap_or_else(|| Size::from((64, 64))); let buffer_size = buffer_dimensions(&buffer).unwrap(); // Client shouldn't try to allocate 0x0 buffer