@@ -5,6 +5,7 @@ package application
55import (
66 "errors"
77 "fmt"
8+ "math"
89 "net/url"
910 "strconv"
1011 "strings"
@@ -605,12 +606,25 @@ func (w *windowsWebviewWindow) convertWindowToWebviewCoordinates(windowX, window
605606 globalApplication .debug ("[DragDropDebug] convertWindowToWebviewCoordinates: Calculated offset" , "offsetX" , offsetX , "offsetY" , offsetY )
606607
607608 // Convert window-relative coordinates to webview-relative coordinates
608- webviewX := windowX - offsetX
609- webviewY := windowY - offsetY
609+ webviewPhysicalX := windowX - offsetX
610+ webviewPhysicalY := windowY - offsetY
610611
611- globalApplication .debug ("[DragDropDebug] convertWindowToWebviewCoordinates: Final webview coordinates" , "webviewX " , webviewX , "webviewY " , webviewY )
612+ globalApplication .debug ("[DragDropDebug] convertWindowToWebviewCoordinates: Webview coordinates before DPI Scaling " , "webviewPhysicalX " , webviewPhysicalX , "webviewPhysicalY " , webviewPhysicalY )
612613
613- return webviewX , webviewY
614+ // Get DPI for this window
615+ dpi := w32 .GetDpiForWindow (w .hwnd )
616+ // Convert to scale factor: 96 DPI == 1.0 (100%)
617+ scaleFactor := float64 (dpi ) / 96.0
618+ globalApplication .debug ("[DragDropDebug] convertWindowToWebviewCoordinates: DPI info" , "dpi" , dpi , "scaleFactor" , scaleFactor )
619+
620+ // Convert physical pixels -> logical/CSS pixels by dividing by the scale factor
621+ // Use rounding to avoid truncation artefacts
622+ webviewLogicalX := int (math .Round (float64 (webviewPhysicalX ) / scaleFactor ))
623+ webviewLogicalY := int (math .Round (float64 (webviewPhysicalY ) / scaleFactor ))
624+ globalApplication .debug ("[DragDropDebug] convertWindowToWebviewCoordinates: Final webview coordinates (logical/CSS pixels)" ,
625+ "webviewLogicalX" , webviewLogicalX , "webviewLogicalY" , webviewLogicalY )
626+
627+ return webviewLogicalX , webviewLogicalY
614628}
615629
616630func (w * windowsWebviewWindow ) physicalBounds () Rect {
0 commit comments