Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions v3/UNRELEASED_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ After processing, the content will be moved to the main changelog and this file
- Track `HICON` ownership so only user-created handles are destroyed, preventing Explorer recycling crashes (#4653).
- Release the Windows system-theme listener and retained tray icons during destroy to stop leaking goroutines and device contexts (#4653).
- Truncate tray tooltips at 127 UTF-16 units to avoid corrupting surrogate pairs and multi-byte glyphs (#4653).
- Fixed DnD dropzone detection failing at non-100% display scaling on Windows (#4632).

## Deprecated
<!-- Soon-to-be removed features -->
Expand Down
4 changes: 2 additions & 2 deletions v3/internal/runtime/desktop/@wailsio/runtime/src/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,8 @@ class Window {
* Gathers information about the drop target element and sends it back to the Go backend.
*
* @param filenames - An array of file paths (strings) that were dropped.
* @param x - The x-coordinate of the drop event.
* @param y - The y-coordinate of the drop event.
* @param x - The x-coordinate of the drop event, in logical (CSS) pixels relative to the webview.
* @param y - The y-coordinate of the drop event, in logical (CSS) pixels relative to the webview.
*/
HandlePlatformFileDrop(filenames: string[], x: number, y: number): void {
const element = document.elementFromPoint(x, y);
Expand Down
27 changes: 23 additions & 4 deletions v3/pkg/application/webview_window_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package application
import (
"errors"
"fmt"
"math"
"net/url"
"strconv"
"strings"
Expand Down Expand Up @@ -605,12 +606,30 @@ func (w *windowsWebviewWindow) convertWindowToWebviewCoordinates(windowX, window
globalApplication.debug("[DragDropDebug] convertWindowToWebviewCoordinates: Calculated offset", "offsetX", offsetX, "offsetY", offsetY)

// Convert window-relative coordinates to webview-relative coordinates
webviewX := windowX - offsetX
webviewY := windowY - offsetY
webviewPhysicalX := windowX - offsetX
webviewPhysicalY := windowY - offsetY

globalApplication.debug("[DragDropDebug] convertWindowToWebviewCoordinates: Final webview coordinates", "webviewX", webviewX, "webviewY", webviewY)
globalApplication.debug("[DragDropDebug] convertWindowToWebviewCoordinates: Webview coordinates before DPI Scaling", "webviewPhysicalX", webviewPhysicalX, "webviewPhysicalY", webviewPhysicalY)

return webviewX, webviewY
// Get DPI for this window
dpi := w32.GetDpiForWindow(w.hwnd)
if dpi == 0 {
globalApplication.debug("[DragDropDebug] convertWindowToWebviewCoordinates: Failed to get dpi, returning physical coordinates", "webviewPhysicalX", webviewPhysicalX, "webviewPhysicalY", webviewPhysicalY)
return webviewPhysicalX, webviewPhysicalY
}

// Convert to scale factor: 96 DPI == 1.0 (100%)
scaleFactor := float64(dpi) / 96.0
globalApplication.debug("[DragDropDebug] convertWindowToWebviewCoordinates: DPI info", "dpi", dpi, "scaleFactor", scaleFactor)

// Convert physical pixels -> logical/CSS pixels by dividing by the scale factor
// Use rounding to avoid truncation artefacts
webviewLogicalX := int(math.Round(float64(webviewPhysicalX) / scaleFactor))
webviewLogicalY := int(math.Round(float64(webviewPhysicalY) / scaleFactor))
globalApplication.debug("[DragDropDebug] convertWindowToWebviewCoordinates: Final webview coordinates (logical/CSS pixels)",
"webviewLogicalX", webviewLogicalX, "webviewLogicalY", webviewLogicalY)

return webviewLogicalX, webviewLogicalY
}

func (w *windowsWebviewWindow) physicalBounds() Rect {
Expand Down
Loading