Skip to content

Commit 389a4f2

Browse files
authored
Data offer source actions (#372)
* fix: track source actions before data_device enter event * cleanup: remove unused variable
1 parent 67b5b52 commit 389a4f2

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

examples/data_device.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ impl DataDeviceWindow {
500500

501501
impl DataDeviceHandler for DataDeviceWindow {
502502
fn enter(&mut self, _conn: &Connection, _qh: &QueueHandle<Self>, data_device: DataDevice) {
503-
let mut drag_offer = data_device.drag_offer().unwrap();
503+
let drag_offer = data_device.drag_offer().unwrap();
504504
println!("data offer entered x: {:.2} y: {:.2}", drag_offer.x, drag_offer.y);
505505

506506
// accept the first mime type we support

src/data_device_manager/data_offer.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use super::{DataDeviceManagerState, ReadPipe};
1919
#[derive(Debug, Clone)]
2020
pub struct UndeterminedOffer {
2121
pub(crate) data_offer: Option<WlDataOffer>,
22+
pub actions: DndAction,
2223
}
2324
impl PartialEq for UndeterminedOffer {
2425
fn eq(&self, other: &Self) -> bool {
@@ -60,8 +61,6 @@ pub struct DragOffer {
6061
pub y: f64,
6162
/// the timestamp a motion event was received in millisecond granularity
6263
pub time: Option<u32>,
63-
/// accepted mime type
64-
pub accepted_mime_type: Option<String>,
6564
/// the advertised drag actions
6665
pub source_actions: DndAction,
6766
/// the compositor selected drag action
@@ -100,8 +99,7 @@ impl DragOffer {
10099
/// Accept the given mime type, or None to reject the offer.
101100
/// In version 2, this request is used for feedback, but doesn't affect the final result of the drag-and-drop operation.
102101
/// In version 3, this request determines the final result of the drag-and-drop operation.
103-
pub fn accept_mime_type(&mut self, serial: u32, mime_type: Option<String>) {
104-
self.accepted_mime_type = mime_type.clone();
102+
pub fn accept_mime_type(&self, serial: u32, mime_type: Option<String>) {
105103
self.data_offer.accept(serial, mime_type);
106104
}
107105

@@ -162,7 +160,10 @@ pub enum DataDeviceOffer {
162160

163161
impl Default for DataDeviceOffer {
164162
fn default() -> Self {
165-
DataDeviceOffer::Undetermined(UndeterminedOffer { data_offer: None })
163+
DataDeviceOffer::Undetermined(UndeterminedOffer {
164+
data_offer: None,
165+
actions: DndAction::empty(),
166+
})
166167
}
167168
}
168169

@@ -196,15 +197,15 @@ impl DataDeviceOffer {
196197
receive(inner, mime_type).map_err(DataOfferError::Io)
197198
}
198199

199-
pub fn accept_mime_type(&mut self, serial: u32, mime_type: Option<String>) {
200+
pub fn accept_mime_type(&self, serial: u32, mime_type: Option<String>) {
200201
match self {
201202
DataDeviceOffer::Drag(o) => o.accept_mime_type(serial, mime_type),
202203
DataDeviceOffer::Selection(_) => {}
203204
DataDeviceOffer::Undetermined(_) => {} // error?
204205
};
205206
}
206207

207-
pub fn set_actions(&mut self, actions: DndAction, preferred_action: DndAction) {
208+
pub fn set_actions(&self, actions: DndAction, preferred_action: DndAction) {
208209
match self {
209210
DataDeviceOffer::Drag(o) => o.set_actions(actions, preferred_action),
210211
DataDeviceOffer::Selection(_) => {}
@@ -234,7 +235,7 @@ impl DataOfferData {
234235
match &mut inner.deref_mut().offer {
235236
DataDeviceOffer::Drag(ref mut o) => o.source_actions = action,
236237
DataDeviceOffer::Selection(_) => {}
237-
DataDeviceOffer::Undetermined(_) => {}
238+
DataDeviceOffer::Undetermined(ref mut o) => o.actions = action,
238239
};
239240
}
240241

@@ -266,14 +267,16 @@ impl DataOfferData {
266267
pub(crate) fn init_undetermined_offer(&self, offer: &WlDataOffer) {
267268
let mut inner = self.inner.lock().unwrap();
268269
match &mut inner.deref_mut().offer {
269-
DataDeviceOffer::Drag(_) => {
270+
DataDeviceOffer::Drag(o) => {
270271
inner.offer = DataDeviceOffer::Undetermined(UndeterminedOffer {
271272
data_offer: Some(offer.clone()),
273+
actions: o.source_actions,
272274
});
273275
}
274276
DataDeviceOffer::Selection(_) => {
275277
inner.offer = DataDeviceOffer::Undetermined(UndeterminedOffer {
276278
data_offer: Some(offer.clone()),
279+
actions: DndAction::empty(),
277280
});
278281
}
279282
DataDeviceOffer::Undetermined(o) => {
@@ -296,7 +299,6 @@ impl DataOfferData {
296299
DataDeviceOffer::Selection(o) => {
297300
inner.offer = DataDeviceOffer::Drag(DragOffer {
298301
data_offer: o.data_offer.clone(),
299-
accepted_mime_type: None,
300302
source_actions: DndAction::empty(),
301303
selected_action: DndAction::empty(),
302304
serial,
@@ -309,8 +311,7 @@ impl DataOfferData {
309311
DataDeviceOffer::Undetermined(o) => {
310312
inner.offer = DataDeviceOffer::Drag(DragOffer {
311313
data_offer: o.data_offer.clone().unwrap(),
312-
accepted_mime_type: None,
313-
source_actions: DndAction::empty(),
314+
source_actions: o.actions,
314315
selected_action: DndAction::empty(),
315316
serial,
316317
surface,

0 commit comments

Comments
 (0)