Skip to content

Commit

Permalink
Also emit all appropriate cursor events
Browse files Browse the repository at this point in the history
  • Loading branch information
SludgePhD committed Aug 13, 2022
1 parent c3a61fa commit b7e4286
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion src/platform_impl/linux/wayland/seat/dnd/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ use sctk::data_device::{DataOffer, DndEvent};
use wayland_client::Display;

use crate::{
dpi::PhysicalPosition,
event::WindowEvent,
platform_impl::wayland::{event_loop::WinitState, make_wid},
platform_impl::wayland::{event_loop::WinitState, make_wid, DeviceId},
};

use super::DndInner;
Expand All @@ -21,13 +22,35 @@ pub(super) fn handle_dnd(event: DndEvent<'_>, inner: &mut DndInner, winit_state:
DndEvent::Enter {
offer: Some(offer),
surface,
x,
y,
..
} => {
let window_id = make_wid(&surface);

if let Ok(paths) = parse_offer(&winit_state.display, offer) {
if !paths.is_empty() {
offer.accept(Some(MIME_TYPE.into()));

winit_state.event_sink.push_window_event(
WindowEvent::CursorEntered {
device_id: crate::event::DeviceId(
crate::platform_impl::DeviceId::Wayland(DeviceId),
),
},
window_id,
);
winit_state.event_sink.push_window_event(
WindowEvent::CursorMoved {
device_id: crate::event::DeviceId(
crate::platform_impl::DeviceId::Wayland(DeviceId),
),
position: PhysicalPosition::new(x, y),
modifiers: Default::default(),
},
window_id,
);

for path in paths {
winit_state
.event_sink
Expand Down Expand Up @@ -57,6 +80,28 @@ pub(super) fn handle_dnd(event: DndEvent<'_>, inner: &mut DndInner, winit_state:
winit_state
.event_sink
.push_window_event(WindowEvent::HoveredFileCancelled, window_id);
winit_state.event_sink.push_window_event(
WindowEvent::CursorLeft {
device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland(
DeviceId,
)),
},
window_id,
);
}
}
DndEvent::Motion { x, y, .. } => {
if let Some(window_id) = inner.window_id {
winit_state.event_sink.push_window_event(
WindowEvent::CursorMoved {
device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland(
DeviceId,
)),
position: PhysicalPosition::new(x, y),
modifiers: Default::default(),
},
window_id,
);
}
}
_ => {}
Expand Down

0 comments on commit b7e4286

Please sign in to comment.