diff --git a/examples/data_device.rs b/examples/data_device.rs index cce23b137..7b5468159 100644 --- a/examples/data_device.rs +++ b/examples/data_device.rs @@ -500,7 +500,7 @@ impl DataDeviceWindow { impl DataDeviceHandler for DataDeviceWindow { fn enter(&mut self, _conn: &Connection, _qh: &QueueHandle, data_device: DataDevice) { - let mut drag_offer = data_device.drag_offer().unwrap(); + let drag_offer = data_device.drag_offer().unwrap(); println!("data offer entered x: {:.2} y: {:.2}", drag_offer.x, drag_offer.y); // accept the first mime type we support diff --git a/src/data_device_manager/data_offer.rs b/src/data_device_manager/data_offer.rs index fffa49993..7efc0dd00 100755 --- a/src/data_device_manager/data_offer.rs +++ b/src/data_device_manager/data_offer.rs @@ -19,6 +19,7 @@ use super::{DataDeviceManagerState, ReadPipe}; #[derive(Debug, Clone)] pub struct UndeterminedOffer { pub(crate) data_offer: Option, + pub actions: DndAction, } impl PartialEq for UndeterminedOffer { fn eq(&self, other: &Self) -> bool { @@ -60,8 +61,6 @@ pub struct DragOffer { pub y: f64, /// the timestamp a motion event was received in millisecond granularity pub time: Option, - /// accepted mime type - pub accepted_mime_type: Option, /// the advertised drag actions pub source_actions: DndAction, /// the compositor selected drag action @@ -100,8 +99,7 @@ impl DragOffer { /// Accept the given mime type, or None to reject the offer. /// In version 2, this request is used for feedback, but doesn't affect the final result of the drag-and-drop operation. /// In version 3, this request determines the final result of the drag-and-drop operation. - pub fn accept_mime_type(&mut self, serial: u32, mime_type: Option) { - self.accepted_mime_type = mime_type.clone(); + pub fn accept_mime_type(&self, serial: u32, mime_type: Option) { self.data_offer.accept(serial, mime_type); } @@ -162,7 +160,10 @@ pub enum DataDeviceOffer { impl Default for DataDeviceOffer { fn default() -> Self { - DataDeviceOffer::Undetermined(UndeterminedOffer { data_offer: None }) + DataDeviceOffer::Undetermined(UndeterminedOffer { + data_offer: None, + actions: DndAction::empty(), + }) } } @@ -196,7 +197,7 @@ impl DataDeviceOffer { receive(inner, mime_type).map_err(DataOfferError::Io) } - pub fn accept_mime_type(&mut self, serial: u32, mime_type: Option) { + pub fn accept_mime_type(&self, serial: u32, mime_type: Option) { match self { DataDeviceOffer::Drag(o) => o.accept_mime_type(serial, mime_type), DataDeviceOffer::Selection(_) => {} @@ -204,7 +205,7 @@ impl DataDeviceOffer { }; } - pub fn set_actions(&mut self, actions: DndAction, preferred_action: DndAction) { + pub fn set_actions(&self, actions: DndAction, preferred_action: DndAction) { match self { DataDeviceOffer::Drag(o) => o.set_actions(actions, preferred_action), DataDeviceOffer::Selection(_) => {} @@ -234,7 +235,7 @@ impl DataOfferData { match &mut inner.deref_mut().offer { DataDeviceOffer::Drag(ref mut o) => o.source_actions = action, DataDeviceOffer::Selection(_) => {} - DataDeviceOffer::Undetermined(_) => {} + DataDeviceOffer::Undetermined(ref mut o) => o.actions = action, }; } @@ -266,14 +267,16 @@ impl DataOfferData { pub(crate) fn init_undetermined_offer(&self, offer: &WlDataOffer) { let mut inner = self.inner.lock().unwrap(); match &mut inner.deref_mut().offer { - DataDeviceOffer::Drag(_) => { + DataDeviceOffer::Drag(o) => { inner.offer = DataDeviceOffer::Undetermined(UndeterminedOffer { data_offer: Some(offer.clone()), + actions: o.source_actions, }); } DataDeviceOffer::Selection(_) => { inner.offer = DataDeviceOffer::Undetermined(UndeterminedOffer { data_offer: Some(offer.clone()), + actions: DndAction::empty(), }); } DataDeviceOffer::Undetermined(o) => { @@ -296,7 +299,6 @@ impl DataOfferData { DataDeviceOffer::Selection(o) => { inner.offer = DataDeviceOffer::Drag(DragOffer { data_offer: o.data_offer.clone(), - accepted_mime_type: None, source_actions: DndAction::empty(), selected_action: DndAction::empty(), serial, @@ -309,8 +311,7 @@ impl DataOfferData { DataDeviceOffer::Undetermined(o) => { inner.offer = DataDeviceOffer::Drag(DragOffer { data_offer: o.data_offer.clone().unwrap(), - accepted_mime_type: None, - source_actions: DndAction::empty(), + source_actions: o.actions, selected_action: DndAction::empty(), serial, surface,