Skip to content

[v3] DnD Dropzones coordinates are incorrect on non-100% display scaling #4631

@yulesxoxo

Description

@yulesxoxo

Description

Fairly minimal repo to reproduce the problem: https://github.com/yulesxoxo/wails-dnd-dropzone-repro with videos and all that.

File drops were not registering correctly when display scaling was set to values other than 100%.

Setting the entire HTML content as a dropzone would work at 100% but at 200% scaling, dropping files would only register in the top left quadrant.

I believe the problem to be that the platform provides file drop coordinates in physical/device pixels, but document.elementFromPoint() expects CSS pixels (logical coordinates). Without conversion, at 150% scaling (devicePixelRatio = 1.5), a drop at physical coordinates (1200, 900) would be interpreted as CSS (1200, 900), causing elementFromPoint to look far outside the actual drop location.

#4632 only tested on Windows

To Reproduce

  1. Create a Window and add a Listener for events.Common.WindowDropZoneFilesDropped
  2. Add data-wails-dropzone to the top level <div> or <main> - at this point dropping a File anywhere in the window should trigger the Listener.
  3. Set Display Scaling to any value that is not 100%, e.g. 200%
Image 4. You'll see that only the top left quadrant will trigger the Listener and the rest of the Window no longer does. Instead you will see this in DevTools

Wails Runtime: Drop on element (or no element) at 1572,968 which is not a designated dropzone. Ignoring. Element: null

Expected behaviour

Wails runtime should factor in Scaling.

Screenshots

No response

Attempted Fixes

No response

System Details

Wails (v3.0.0-alpha.33)  Wails Doctor 
                                                                                                                                                                                        
# System 

┌────────────────────────────────────────────────────────────────────────────────────────────┐
| Name              | Windows 10 Pro                                                         |
| Version           | 2009 (Build: 26100)                                                    |
| ID                | 24H2                                                                   |
| Branding          | Windows 11 Pro                                                         |
| Platform          | windows                                                                |
| Architecture      | amd64                                                                  |
| Go WebView2Loader | true                                                                   |
| WebView2 Version  | 140.0.3485.94                                                          |
| CPU               | 13th Gen Intel(R) Core(TM) i7-13700K                                   |
| GPU 1             | NVIDIA GeForce RTX 4090 (NVIDIA) - Driver: 32.0.15.8129                |
| GPU 2             | Intel(R) UHD Graphics 770 (Intel Corporation) - Driver: 32.0.101.6987  |
| Memory            | 64GB                                                                   |
└────────────────────────────────────────────────────────────────────────────────────────────┘

# Build Environment 

┌────────────────────────────────┐
| Wails CLI    | v3.0.0-alpha.33 |
| Go Version   | go1.24.0        |
| -buildmode   | exe             |
| -compiler    | gc              |
| CGO_CFLAGS   |                 |
| CGO_CPPFLAGS |                 |
| CGO_CXXFLAGS |                 |
| CGO_ENABLED  | 1               |
| CGO_LDFLAGS  |                 |
| GOAMD64      | v1              |
| GOARCH       | amd64           |
| GOOS         | windows         |
└────────────────────────────────┘

# Dependencies 

┌────────────────────────────────────────────┐
| MakeAppx.exe (Windows SDK) | Not Installed |
| MSIX Packaging Tool        | Not Installed |
| SignTool.exe (Windows SDK) | Not Installed |
| npm                        | 10.9.3        |
| NSIS                       | Not Installed |
|                                            |
└───────── * - Optional Dependency ──────────┘

# Checking for issues 

 SUCCESS  No issues found

# Diagnosis 

 SUCCESS  Your system is ready for Wails development!

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions