data-device: Fix rendering DnD icons on separate threads
This commit is contained in:
parent
a97279147e
commit
492e16bfa5
1 changed files with 8 additions and 7 deletions
|
|
@ -10,17 +10,17 @@ use smithay::{
|
||||||
ClientDndGrabHandler, DataDeviceHandler, DataDeviceState, ServerDndGrabHandler,
|
ClientDndGrabHandler, DataDeviceHandler, DataDeviceState, ServerDndGrabHandler,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use std::cell::RefCell;
|
use std::sync::Mutex;
|
||||||
|
|
||||||
pub struct DnDIcon {
|
pub struct DnDIcon {
|
||||||
surface: RefCell<Option<WlSurface>>,
|
surface: Mutex<Option<WlSurface>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_dnd_icon(seat: &Seat<State>) -> Option<WlSurface> {
|
pub fn get_dnd_icon(seat: &Seat<State>) -> Option<WlSurface> {
|
||||||
let userdata = seat.user_data();
|
let userdata = seat.user_data();
|
||||||
userdata
|
userdata
|
||||||
.get::<DnDIcon>()
|
.get::<DnDIcon>()
|
||||||
.and_then(|x| x.surface.borrow().clone())
|
.and_then(|x| x.surface.lock().unwrap().clone())
|
||||||
.filter(IsAlive::alive)
|
.filter(IsAlive::alive)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -32,17 +32,18 @@ impl ClientDndGrabHandler for State {
|
||||||
seat: Seat<Self>,
|
seat: Seat<Self>,
|
||||||
) {
|
) {
|
||||||
let user_data = seat.user_data();
|
let user_data = seat.user_data();
|
||||||
user_data.insert_if_missing(|| DnDIcon {
|
user_data.insert_if_missing_threadsafe(|| DnDIcon {
|
||||||
surface: RefCell::new(None),
|
surface: Mutex::new(None),
|
||||||
});
|
});
|
||||||
*user_data.get::<DnDIcon>().unwrap().surface.borrow_mut() = icon;
|
*user_data.get::<DnDIcon>().unwrap().surface.lock().unwrap() = icon;
|
||||||
}
|
}
|
||||||
fn dropped(&mut self, seat: Seat<Self>) {
|
fn dropped(&mut self, seat: Seat<Self>) {
|
||||||
seat.user_data()
|
seat.user_data()
|
||||||
.get::<DnDIcon>()
|
.get::<DnDIcon>()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.surface
|
.surface
|
||||||
.borrow_mut()
|
.lock()
|
||||||
|
.unwrap()
|
||||||
.take();
|
.take();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue