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:
parent
ddc23fcaa5
commit
fa4bffdbe6
8 changed files with 52 additions and 105 deletions
|
|
@ -1333,8 +1333,7 @@ impl PointerTarget<State> for CosmicStack {
|
|||
.lock()
|
||||
.unwrap();
|
||||
cursor_state.set_shape(next.cursor_shape());
|
||||
let cursor_status = seat.user_data().get::<Mutex<CursorImageStatus>>().unwrap();
|
||||
*cursor_status.lock().unwrap() = CursorImageStatus::default_named();
|
||||
seat.set_cursor_image_status(CursorImageStatus::default_named());
|
||||
});
|
||||
|
||||
event.location -= self.0.with_program(|p| {
|
||||
|
|
@ -1363,8 +1362,7 @@ impl PointerTarget<State> for CosmicStack {
|
|||
.lock()
|
||||
.unwrap();
|
||||
cursor_state.set_shape(next.cursor_shape());
|
||||
let cursor_status = seat.user_data().get::<Mutex<CursorImageStatus>>().unwrap();
|
||||
*cursor_status.lock().unwrap() = CursorImageStatus::default_named();
|
||||
seat.set_cursor_image_status(CursorImageStatus::default_named());
|
||||
});
|
||||
|
||||
let active_window_geo = self.0.with_program(|p| {
|
||||
|
|
|
|||
|
|
@ -711,8 +711,7 @@ impl PointerTarget<State> for CosmicWindow {
|
|||
|
||||
let cursor_state = seat.user_data().get::<CursorState>().unwrap();
|
||||
cursor_state.lock().unwrap().set_shape(next.cursor_shape());
|
||||
let cursor_status = seat.user_data().get::<Mutex<CursorImageStatus>>().unwrap();
|
||||
*cursor_status.lock().unwrap() = CursorImageStatus::default_named();
|
||||
seat.set_cursor_image_status(CursorImageStatus::default_named());
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -736,8 +735,7 @@ impl PointerTarget<State> for CosmicWindow {
|
|||
|
||||
let cursor_state = seat.user_data().get::<CursorState>().unwrap();
|
||||
cursor_state.lock().unwrap().set_shape(next.cursor_shape());
|
||||
let cursor_status = seat.user_data().get::<Mutex<CursorImageStatus>>().unwrap();
|
||||
*cursor_status.lock().unwrap() = CursorImageStatus::default_named();
|
||||
seat.set_cursor_image_status(CursorImageStatus::default_named());
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1427,12 +1427,7 @@ impl Common {
|
|||
}
|
||||
|
||||
let is_cursor_image = shell.seats.iter().any(|seat| {
|
||||
seat.user_data()
|
||||
.get::<Mutex<CursorImageStatus>>()
|
||||
.map(|guard| {
|
||||
matches!(*guard.lock().unwrap(), CursorImageStatus::Surface(ref cursor_surface) if cursor_surface == surface)
|
||||
})
|
||||
.unwrap_or(false)
|
||||
matches!(seat.cursor_image_status(), CursorImageStatus::Surface(ref cursor_surface) if cursor_surface == surface)
|
||||
});
|
||||
|
||||
if is_cursor_image {
|
||||
|
|
|
|||
|
|
@ -252,6 +252,8 @@ pub trait SeatExt {
|
|||
loc: impl Into<Point<f64, Buffer>>,
|
||||
time: Time<Monotonic>,
|
||||
) -> Option<(Rectangle<i32, Buffer>, Point<i32, Buffer>)>;
|
||||
fn cursor_image_status(&self) -> CursorImageStatus;
|
||||
fn set_cursor_image_status(&self, status: CursorImageStatus);
|
||||
}
|
||||
|
||||
impl SeatExt for Seat<State> {
|
||||
|
|
@ -337,21 +339,7 @@ impl SeatExt for Seat<State> {
|
|||
) -> Option<(Rectangle<i32, Buffer>, Point<i32, Buffer>)> {
|
||||
let location = loc.into().to_i32_round();
|
||||
|
||||
let cursor_status = self
|
||||
.user_data()
|
||||
.get::<Mutex<CursorImageStatus>>()
|
||||
.map(|lock| {
|
||||
let mut cursor_status = lock.lock().unwrap();
|
||||
if let CursorImageStatus::Surface(ref surface) = *cursor_status {
|
||||
if !surface.alive() {
|
||||
*cursor_status = CursorImageStatus::default_named();
|
||||
}
|
||||
}
|
||||
cursor_status.clone()
|
||||
})
|
||||
.unwrap_or(CursorImageStatus::default_named());
|
||||
|
||||
match cursor_status {
|
||||
match self.cursor_image_status() {
|
||||
CursorImageStatus::Surface(surface) => {
|
||||
let hotspot = with_states(&surface, |states| {
|
||||
states
|
||||
|
|
@ -387,4 +375,25 @@ impl SeatExt for Seat<State> {
|
|||
CursorImageStatus::Hidden => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn cursor_image_status(&self) -> CursorImageStatus {
|
||||
self.user_data()
|
||||
.get::<Mutex<CursorImageStatus>>()
|
||||
// Reset the cursor if the surface is no longer alive
|
||||
.map(|lock| {
|
||||
let mut cursor_status = lock.lock().unwrap();
|
||||
if let CursorImageStatus::Surface(ref surface) = *cursor_status {
|
||||
if !surface.alive() {
|
||||
*cursor_status = CursorImageStatus::default_named();
|
||||
}
|
||||
}
|
||||
cursor_status.clone()
|
||||
})
|
||||
.unwrap_or(CursorImageStatus::default_named())
|
||||
}
|
||||
|
||||
fn set_cursor_image_status(&self, status: CursorImageStatus) {
|
||||
let cursor_status = self.user_data().get::<Mutex<CursorImageStatus>>().unwrap();
|
||||
*cursor_status.lock().unwrap() = status;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue