Skip to content

Commit

Permalink
sctk: Fix handling of DnD with subsurfaces (#122)
Browse files Browse the repository at this point in the history
Map subsurface to parent and add offset.
  • Loading branch information
ids1024 authored Apr 3, 2024
1 parent 46ef2e2 commit 745d846
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
9 changes: 8 additions & 1 deletion sctk/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2275,7 +2275,14 @@ where
| SctkEvent::UpdateOutput { .. }
| SctkEvent::RemovedOutput(_) => false,
SctkEvent::ScaleFactorChanged { id, .. } => &id.id() == object_id,
SctkEvent::DndOffer { surface, .. } => &surface.id() == object_id,
SctkEvent::DndOffer { surface, .. } => {
let event_object_id = surface.id();
&event_object_id == object_id
|| state
.subsurfaces
.iter()
.any(|s| s.wl_surface.id() == event_object_id)
}
SctkEvent::DataSource(_) => true,
SctkEvent::SessionLocked => false,
SctkEvent::SessionLockFinished => false,
Expand Down
14 changes: 12 additions & 2 deletions sctk/src/sctk_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ impl SctkEvent {
id: _,
inner_size: _,
} => Default::default(),
SctkEvent::DndOffer { event, .. } => match event {
SctkEvent::DndOffer { event, surface } => match event {
DndOfferEvent::Enter { mime_types, x, y } => {
Some(iced_runtime::core::Event::PlatformSpecific(
PlatformSpecific::Wayland(wayland::Event::DndOffer(
Expand All @@ -796,9 +796,19 @@ impl SctkEvent {
.collect()
}
DndOfferEvent::Motion { x, y } => {
let offset = if let Some((x_offset, y_offset, _)) =
subsurface_ids.get(&surface.id())
{
(*x_offset, *y_offset)
} else {
(0, 0)
};
Some(iced_runtime::core::Event::PlatformSpecific(
PlatformSpecific::Wayland(wayland::Event::DndOffer(
wayland::DndOfferEvent::Motion { x, y },
wayland::DndOfferEvent::Motion {
x: x + offset.0 as f64,
y: y + offset.1 as f64,
},
)),
))
.into_iter()
Expand Down

0 comments on commit 745d846

Please sign in to comment.