Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- **Wayland: fall back to the offered action when `wl_data_source.dnd_finished` arrives without `wl_data_source.action`.** On compositors such as Hyprland <= v0.57.2 that emit `dnd_finished` without sending `wl_data_source.action`, `El::drag_out` now reports `DragOutcome::Copied` when Copy (or Copy | Move) was offered and `DragOutcome::Moved` when only Move was offered, instead of reporting `DragOutcome::Cancelled` on every completed drop.
31 changes: 26 additions & 5 deletions crates/rune/src/platform/wayland/drag_source/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,31 @@ impl SourceAction {
}
}

/// Resolves the final [`DragOutcome`] when `wl_data_source.dnd_finished` arrives.
///
/// Per the Wayland protocol, `dnd_finished` only fires after the drop destination accepted
/// and finished the transfer (`wl_data_source.cancelled` fires on cancellation). Compliant
/// v3 compositors send `wl_data_source.action` first, populating `self` with `Copy` or `Move`.
///
/// Some compositors (notably Hyprland <= v0.57.2) emit `dnd_finished` without ever sending
/// `wl_data_source.action`, leaving `self` as `None`. In that case fall back to `Copied`
/// whenever `Copy` was offered (including `Copy | Move`, so a caller never deletes its
/// original on an ambiguous move), to `Moved` when only `Move` was offered, and to
/// `Cancelled` when neither action was offered.
#[inline]
pub(crate) const fn to_outcome(self) -> DragOutcome {
pub(crate) const fn finished_outcome(self, offered_actions: u32) -> DragOutcome {
match self {
Self::Copy => DragOutcome::Copied,
Self::Move => DragOutcome::Moved,
Self::None => DragOutcome::Cancelled,
Self::None => {
if offered_actions & DND_ACTION_COPY != 0 {
DragOutcome::Copied
} else if offered_actions & DND_ACTION_MOVE != 0 {
DragOutcome::Moved
} else {
DragOutcome::Cancelled
}
}
}
}
}
Expand All @@ -65,6 +84,7 @@ pub(crate) struct DragSession {
pub version: u32,
pub within_app: bool,
pub offers: Vec<OfferedMime>,
pub offered_actions: u32,
pub accepted_mime: Option<String>,
pub selected_action: SourceAction,
pub sent_any: bool,
Expand Down Expand Up @@ -189,14 +209,15 @@ pub(crate) fn step(state: &mut State, event: Event) -> Vec<Effect> {
return out;
}
let mimes: Vec<String> = offers.iter().map(|o| o.mime.clone()).collect();
let actions_mask = (version >= 3).then_some(actions_mask);
let wire_actions_mask = (version >= 3).then_some(actions_mask);
*state = State::Active(DragSession {
drag_id,
seat,
origin_surface,
version,
within_app,
offers,
offered_actions: actions_mask,
accepted_mime: None,
selected_action: SourceAction::None,
sent_any: false,
Expand All @@ -208,7 +229,7 @@ pub(crate) fn step(state: &mut State, event: Event) -> Vec<Effect> {
origin_surface,
serial,
mimes,
actions_mask,
actions_mask: wire_actions_mask,
with_icon,
});
out.push(Effect::Flush);
Expand Down Expand Up @@ -258,7 +279,7 @@ pub(crate) fn step(state: &mut State, event: Event) -> Vec<Effect> {
if state.active_drag_id() == Some(drag_id) {
if let Some(s) = take_session(state) {
let outcome = if s.version >= 3 {
s.selected_action.to_outcome()
s.selected_action.finished_outcome(s.offered_actions)
} else {
DragOutcome::Copied
};
Expand Down
96 changes: 93 additions & 3 deletions crates/rune/src/platform/wayland/drag_source/machine_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,24 @@ fn dnd_action_mask_maps_copy_and_move_only() {
assert_eq!(dnd_action_mask(true, false), DND_ACTION_COPY);
assert_eq!(dnd_action_mask(false, true), DND_ACTION_MOVE);
assert_eq!(dnd_action_mask(true, true), DND_ACTION_COPY | DND_ACTION_MOVE);
assert_eq!(SourceAction::from_wayland_mask(DND_ACTION_COPY).to_outcome(), DragOutcome::Copied);
assert_eq!(SourceAction::from_wayland_mask(DND_ACTION_MOVE).to_outcome(), DragOutcome::Moved);
assert_eq!(SourceAction::from_wayland_mask(DND_ACTION_NONE).to_outcome(), DragOutcome::Cancelled);
assert_eq!(SourceAction::from_wayland_mask(DND_ACTION_COPY), SourceAction::Copy);
assert_eq!(SourceAction::from_wayland_mask(DND_ACTION_MOVE), SourceAction::Move);
assert_eq!(SourceAction::from_wayland_mask(DND_ACTION_NONE), SourceAction::None);
assert_eq!(
SourceAction::Copy.finished_outcome(DND_ACTION_COPY | DND_ACTION_MOVE),
DragOutcome::Copied,
);
assert_eq!(
SourceAction::Move.finished_outcome(DND_ACTION_COPY | DND_ACTION_MOVE),
DragOutcome::Moved,
);
assert_eq!(SourceAction::None.finished_outcome(DND_ACTION_COPY), DragOutcome::Copied);
assert_eq!(
SourceAction::None.finished_outcome(DND_ACTION_COPY | DND_ACTION_MOVE),
DragOutcome::Copied,
);
assert_eq!(SourceAction::None.finished_outcome(DND_ACTION_MOVE), DragOutcome::Moved);
assert_eq!(SourceAction::None.finished_outcome(DND_ACTION_NONE), DragOutcome::Cancelled);
}

#[test]
Expand Down Expand Up @@ -259,3 +274,78 @@ fn compositor_event_order_variants_and_escape_after_hover_send_behave_per_protoc
assert!(drop_cancel_fx.contains(&Effect::Complete { drag_id: 22, outcome: DragOutcome::Cancelled }));
assert_eq!(state, State::Idle);
}

#[test]
fn v3_dnd_finished_without_action_falls_back_safely_to_offered_action() {
// Reproduces Hyprland <= v0.57.2, which emits target -> (optional send / dnd_drop_performed)
// -> dnd_finished without ever sending wl_data_source.action.
let offers = assemble_offers([], &[], None, Some("payload"));

// 1. Copy-only drag with DropPerformed -> Finished (no Action event) => Copied.
let mut state = State::Idle;
let _ = step(&mut state, Event::Start {
drag_id: 30, seat: 1, origin_surface: 1, serial: 1, version: 3,
within_app: false, offers: offers.clone(), actions_mask: DND_ACTION_COPY, with_icon: false,
});
let _ = step(&mut state, Event::Target { drag_id: 30, mime: Some(MIME_TEXT_UTF8.into()) });
let _ = step(&mut state, Event::DropPerformed { drag_id: 30 });
let fx = step(&mut state, Event::Finished { drag_id: 30 });
assert!(fx.contains(&Effect::Complete { drag_id: 30, outcome: DragOutcome::Copied }));
assert_eq!(state, State::Idle);

// 2. Copy | Move drag with Target -> Send -> Finished (no DropPerformed, no Action) => Copied
// (never falsely reports Moved on a Copy | Move drag).
let _ = step(&mut state, Event::Start {
drag_id: 31, seat: 1, origin_surface: 1, serial: 2, version: 3,
within_app: false, offers: offers.clone(),
actions_mask: DND_ACTION_COPY | DND_ACTION_MOVE, with_icon: false,
});
let _ = step(&mut state, Event::Target { drag_id: 31, mime: Some(MIME_TEXT_UTF8.into()) });
let _ = step(&mut state, Event::Send { drag_id: 31, mime: MIME_TEXT_UTF8.into(), fd_id: 1 });
let fx = step(&mut state, Event::Finished { drag_id: 31 });
assert!(fx.contains(&Effect::Complete { drag_id: 31, outcome: DragOutcome::Copied }));
assert_eq!(state, State::Idle);

// 3. Move-only drag without Action => Moved (single offered action).
let _ = step(&mut state, Event::Start {
drag_id: 32, seat: 1, origin_surface: 1, serial: 3, version: 3,
within_app: false, offers: offers.clone(), actions_mask: DND_ACTION_MOVE, with_icon: false,
});
let _ = step(&mut state, Event::DropPerformed { drag_id: 32 });
let fx = step(&mut state, Event::Finished { drag_id: 32 });
assert!(fx.contains(&Effect::Complete { drag_id: 32, outcome: DragOutcome::Moved }));
assert_eq!(state, State::Idle);

// 4. Drag offering neither Copy nor Move (e.g. Link-only on Wayland) without Action => Cancelled.
let _ = step(&mut state, Event::Start {
drag_id: 33, seat: 1, origin_surface: 1, serial: 4, version: 3,
within_app: false, offers: offers.clone(), actions_mask: DND_ACTION_NONE, with_icon: false,
});
let fx = step(&mut state, Event::Finished { drag_id: 33 });
assert!(fx.contains(&Effect::Complete { drag_id: 33, outcome: DragOutcome::Cancelled }));
assert_eq!(state, State::Idle);

// 5. Explicit Cancelled without Action still reports Cancelled (not Copied).
let _ = step(&mut state, Event::Start {
drag_id: 34, seat: 1, origin_surface: 1, serial: 5, version: 3,
within_app: false, offers: offers.clone(),
actions_mask: DND_ACTION_COPY | DND_ACTION_MOVE, with_icon: false,
});
let _ = step(&mut state, Event::Target { drag_id: 34, mime: Some(MIME_TEXT_UTF8.into()) });
let _ = step(&mut state, Event::Send { drag_id: 34, mime: MIME_TEXT_UTF8.into(), fd_id: 2 });
let fx = step(&mut state, Event::Cancelled { drag_id: 34 });
assert!(fx.contains(&Effect::Complete { drag_id: 34, outcome: DragOutcome::Cancelled }));
assert_eq!(state, State::Idle);

// 6. Explicit Action(Move) on Copy | Move drag still reports Moved on Finished.
let _ = step(&mut state, Event::Start {
drag_id: 35, seat: 1, origin_surface: 1, serial: 6, version: 3,
within_app: false, offers,
actions_mask: DND_ACTION_COPY | DND_ACTION_MOVE, with_icon: false,
});
let _ = step(&mut state, Event::Action { drag_id: 35, mask: DND_ACTION_MOVE });
let _ = step(&mut state, Event::DropPerformed { drag_id: 35 });
let fx = step(&mut state, Event::Finished { drag_id: 35 });
assert!(fx.contains(&Effect::Complete { drag_id: 35, outcome: DragOutcome::Moved }));
assert_eq!(state, State::Idle);
}
Loading