Add cursor_image_status/set_cursor_image_status to SeatExt

The `cursor_image_status()` function saves some duplication in various
places. The `set_cursor_image_status()` saves a bit less, but is also
handy.
This commit is contained in:
Ian Douglas Scott 2025-06-06 15:33:58 -07:00 committed by Victoria Brekenfeld
parent ddc23fcaa5
commit fa4bffdbe6
8 changed files with 52 additions and 105 deletions

View file

@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-only
use crate::state::State;
use crate::{state::State, utils::prelude::SeatExt};
use smithay::{
delegate_data_device,
input::{
@ -70,26 +70,20 @@ impl ClientDndGrabHandler for State {
let user_data = seat.user_data();
user_data.insert_if_missing_threadsafe::<Mutex<Option<DnDIcon>>, _>(|| Default::default());
let offset = seat
.user_data()
.get::<Mutex<CursorImageStatus>>()
.map(|guard| {
if let CursorImageStatus::Surface(ref surface) = *guard.lock().unwrap() {
compositor::with_states(surface, |states| {
let hotspot = states
.data_map
.get::<CursorImageSurfaceData>()
.unwrap()
.lock()
.unwrap()
.hotspot;
Point::from((-hotspot.x, -hotspot.y))
})
} else {
(0, 0).into()
}
let offset = if let CursorImageStatus::Surface(ref surface) = seat.cursor_image_status() {
compositor::with_states(surface, |states| {
let hotspot = states
.data_map
.get::<CursorImageSurfaceData>()
.unwrap()
.lock()
.unwrap()
.hotspot;
Point::from((-hotspot.x, -hotspot.y))
})
.unwrap_or_default();
} else {
(0, 0).into()
};
*user_data
.get::<Mutex<Option<DnDIcon>>>()

View file

@ -4,12 +4,12 @@ use crate::{
shell::focus::target::{KeyboardFocusTarget, PointerFocusTarget},
shell::Devices,
state::State,
utils::prelude::SeatExt,
};
use smithay::{
delegate_cursor_shape, delegate_seat,
input::{keyboard::LedState, pointer::CursorImageStatus, SeatHandler, SeatState},
};
use std::sync::Mutex;
impl SeatHandler for State {
type KeyboardFocus = KeyboardFocusTarget;
@ -20,17 +20,8 @@ impl SeatHandler for State {
&mut self.common.seat_state
}
fn cursor_image(
&mut self,
seat: &smithay::input::Seat<Self>,
image: smithay::input::pointer::CursorImageStatus,
) {
*seat
.user_data()
.get::<Mutex<CursorImageStatus>>()
.unwrap()
.lock()
.unwrap() = image;
fn cursor_image(&mut self, seat: &smithay::input::Seat<Self>, image: CursorImageStatus) {
seat.set_cursor_image_status(image);
}
fn focus_changed(