cosmic-comp/src/wayland/handlers/data_device.rs

58 lines
1.5 KiB
Rust
Raw Normal View History

// SPDX-License-Identifier: GPL-3.0-only
2022-07-04 16:00:29 +02:00
use crate::state::State;
use smithay::{
2022-07-04 16:00:29 +02:00
delegate_data_device,
2022-08-31 13:01:23 +02:00
input::Seat,
2022-07-04 16:00:29 +02:00
reexports::wayland_server::protocol::{wl_data_source::WlDataSource, wl_surface::WlSurface},
2022-08-30 13:28:36 +02:00
utils::IsAlive,
wayland::selection::data_device::{
ClientDndGrabHandler, DataDeviceHandler, DataDeviceState, ServerDndGrabHandler,
},
};
use std::sync::Mutex;
pub struct DnDIcon {
surface: Mutex<Option<WlSurface>>,
}
pub fn get_dnd_icon(seat: &Seat<State>) -> Option<WlSurface> {
let userdata = seat.user_data();
userdata
.get::<DnDIcon>()
.and_then(|x| x.surface.lock().unwrap().clone())
2022-08-05 16:28:05 +02:00
.filter(IsAlive::alive)
}
impl ClientDndGrabHandler for State {
fn started(
2022-07-04 16:00:29 +02:00
&mut self,
_source: Option<WlDataSource>,
icon: Option<WlSurface>,
seat: Seat<Self>,
) {
let user_data = seat.user_data();
user_data.insert_if_missing_threadsafe(|| DnDIcon {
surface: Mutex::new(None),
});
*user_data.get::<DnDIcon>().unwrap().surface.lock().unwrap() = icon;
}
fn dropped(&mut self, seat: Seat<Self>) {
seat.user_data()
.get::<DnDIcon>()
.unwrap()
.surface
.lock()
.unwrap()
.take();
}
}
impl ServerDndGrabHandler for State {}
impl DataDeviceHandler for State {
fn data_device_state(&self) -> &DataDeviceState {
&self.common.data_device_state
}
}
delegate_data_device!(State);