Skip to content

Commit 3724a00

Browse files
authored
fix drag&drop coordinates on windows (#205)
the coordinates were previously in screen space, not in the coordinate space of the hwnd (= "client").
1 parent 3829510 commit 3724a00

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/win/drop_target.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::rc::{Rc, Weak};
77
use winapi::shared::guiddef::{IsEqualIID, REFIID};
88
use winapi::shared::minwindef::{DWORD, WPARAM};
99
use winapi::shared::ntdef::{HRESULT, ULONG};
10-
use winapi::shared::windef::POINTL;
10+
use winapi::shared::windef::{POINT, POINTL};
1111
use winapi::shared::winerror::{E_NOINTERFACE, E_UNEXPECTED, S_OK};
1212
use winapi::shared::wtypes::DVASPECT_CONTENT;
1313
use winapi::um::objidl::{IDataObject, FORMATETC, STGMEDIUM, TYMED_HGLOBAL};
@@ -17,7 +17,7 @@ use winapi::um::oleidl::{
1717
};
1818
use winapi::um::shellapi::{DragQueryFileW, HDROP};
1919
use winapi::um::unknwnbase::{IUnknown, IUnknownVtbl};
20-
use winapi::um::winuser::CF_HDROP;
20+
use winapi::um::winuser::{ScreenToClient, CF_HDROP};
2121
use winapi::Interface;
2222

2323
use crate::{DropData, DropEffect, Event, EventStatus, MouseEvent, PhyPoint, Point};
@@ -114,7 +114,8 @@ impl DropTarget {
114114
let Some(window_state) = self.window_state.upgrade() else {
115115
return;
116116
};
117-
117+
let mut pt = POINT { x: pt.x, y: pt.y };
118+
unsafe { ScreenToClient(window_state.hwnd, &mut pt as *mut POINT) };
118119
let phy_point = PhyPoint::new(pt.x, pt.y);
119120
self.drag_position = phy_point.to_logical(&window_state.window_info());
120121
}

0 commit comments

Comments
 (0)