Skip to content
Open
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
21 changes: 19 additions & 2 deletions src/platform/win/drop_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ use windows::Win32::System::Ole::*;
use windows::Win32::System::SystemServices::MODIFIERKEYS_FLAGS;
use windows_core::Ref;
use windows_sys::Win32::{
Foundation::POINT, Graphics::Gdi::ScreenToClient, UI::Shell::DragQueryFileW,
Foundation::POINT,
Graphics::Gdi::ScreenToClient,
UI::{
HiDpi::{LogicalToPhysicalPointForPerMonitorDPI, PhysicalToLogicalPointForPerMonitorDPI},
Shell::DragQueryFileW,
},
};

use crate::{DropData, DropEffect, Event, EventStatus, MouseEvent, PhyPoint, Point};
Expand Down Expand Up @@ -63,7 +68,19 @@ impl DropTarget {
return;
};
let mut pt = POINT { x: pt.x, y: pt.y };
unsafe { ScreenToClient(window_state.hwnd, &mut pt as *mut POINT) };

// ScreenToClient isn't DPI-aware
if unsafe { PhysicalToLogicalPointForPerMonitorDPI(null_mut(), &mut pt) == 0 } {
return;
}

if unsafe { ScreenToClient(window_state.hwnd, &mut pt) == 0 } {
return;
}

if unsafe { LogicalToPhysicalPointForPerMonitorDPI(null_mut(), &mut pt) == 0 } {
return;
}
let phy_point = PhyPoint::new(pt.x, pt.y);
self.drag_position.set(phy_point.to_logical(&window_state.window_info()));
}
Expand Down