Skip to content

Commit e040e07

Browse files
author
Atterpac
committed
fix dnd build windows
1 parent abd5d09 commit e040e07

2 files changed

Lines changed: 112 additions & 28 deletions

File tree

v3/pkg/application/webview_window_windows.go

Lines changed: 103 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,8 @@ func (w *windowsWebviewWindow) run() {
273273

274274
exStyle := w32.WS_EX_CONTROLPARENT
275275
if options.BackgroundType != BackgroundTypeSolid {
276-
if (options.Frameless && options.BackgroundType == BackgroundTypeTransparent) || w.parent.options.IgnoreMouseEvents {
276+
if (options.Frameless && options.BackgroundType == BackgroundTypeTransparent) ||
277+
w.parent.options.IgnoreMouseEvents {
277278
// Always if transparent and frameless
278279
exStyle |= w32.WS_EX_TRANSPARENT | w32.WS_EX_LAYERED
279280
} else {
@@ -359,10 +360,14 @@ func (w *windowsWebviewWindow) run() {
359360
if options.Windows.WindowDidMoveDebounceMS == 0 {
360361
options.Windows.WindowDidMoveDebounceMS = 50
361362
}
362-
w.moveDebouncer = debounce.New(time.Duration(options.Windows.WindowDidMoveDebounceMS) * time.Millisecond)
363+
w.moveDebouncer = debounce.New(
364+
time.Duration(options.Windows.WindowDidMoveDebounceMS) * time.Millisecond,
365+
)
363366

364367
if options.Windows.ResizeDebounceMS > 0 {
365-
w.resizeDebouncer = debounce.New(time.Duration(options.Windows.ResizeDebounceMS) * time.Millisecond)
368+
w.resizeDebouncer = debounce.New(
369+
time.Duration(options.Windows.ResizeDebounceMS) * time.Millisecond,
370+
)
366371
}
367372

368373
// Initialise the window buttons
@@ -494,7 +499,12 @@ func (w *windowsWebviewWindow) update() {
494499
func (w *windowsWebviewWindow) getBorderSizes() *LRTB {
495500
var result LRTB
496501
var frame w32.RECT
497-
w32.DwmGetWindowAttribute(w.hwnd, w32.DWMWA_EXTENDED_FRAME_BOUNDS, unsafe.Pointer(&frame), unsafe.Sizeof(frame))
502+
w32.DwmGetWindowAttribute(
503+
w.hwnd,
504+
w32.DWMWA_EXTENDED_FRAME_BOUNDS,
505+
unsafe.Pointer(&frame),
506+
unsafe.Sizeof(frame),
507+
)
498508
rect := w32.GetWindowRect(w.hwnd)
499509
result.Left = int(frame.Left - rect.Left)
500510
result.Top = int(frame.Top - rect.Top)
@@ -528,7 +538,15 @@ func (w *windowsWebviewWindow) setPhysicalBounds(physicalBounds Rect) {
528538
// for the target position, this prevents double resizing issue when the window is moved between screens
529539
previousFlag := w.ignoreDPIChangeResizing
530540
w.ignoreDPIChangeResizing = true
531-
w32.SetWindowPos(w.hwnd, 0, physicalBounds.X, physicalBounds.Y, physicalBounds.Width, physicalBounds.Height, w32.SWP_NOZORDER|w32.SWP_NOACTIVATE)
541+
w32.SetWindowPos(
542+
w.hwnd,
543+
0,
544+
physicalBounds.X,
545+
physicalBounds.Y,
546+
physicalBounds.Width,
547+
physicalBounds.Height,
548+
w32.SWP_NOZORDER|w32.SWP_NOACTIVATE,
549+
)
532550
w.ignoreDPIChangeResizing = previousFlag
533551
}
534552

@@ -720,8 +738,16 @@ func (w *windowsWebviewWindow) fullscreen() {
720738
return
721739
}
722740
// According to https://devblogs.microsoft.com/oldnewthing/20050505-04/?p=35703 one should use w32.WS_POPUP | w32.WS_VISIBLE
723-
w32.SetWindowLong(w.hwnd, w32.GWL_STYLE, w.previousWindowStyle & ^uint32(w32.WS_OVERLAPPEDWINDOW) | (w32.WS_POPUP|w32.WS_VISIBLE))
724-
w32.SetWindowLong(w.hwnd, w32.GWL_EXSTYLE, w.previousWindowExStyle & ^uint32(w32.WS_EX_DLGMODALFRAME))
741+
w32.SetWindowLong(
742+
w.hwnd,
743+
w32.GWL_STYLE,
744+
w.previousWindowStyle & ^uint32(w32.WS_OVERLAPPEDWINDOW) | (w32.WS_POPUP|w32.WS_VISIBLE),
745+
)
746+
w32.SetWindowLong(
747+
w.hwnd,
748+
w32.GWL_EXSTYLE,
749+
w.previousWindowExStyle & ^uint32(w32.WS_EX_DLGMODALFRAME),
750+
)
725751
w.isCurrentlyFullscreen = true
726752
w32.SetWindowPos(w.hwnd, w32.HWND_TOP,
727753
int(monitorInfo.RcMonitor.Left),
@@ -982,7 +1008,15 @@ func (w *windowsWebviewWindow) setFrameless(b bool) {
9821008
} else {
9831009
w32.SetWindowLong(w.hwnd, w32.GWL_STYLE, w32.WS_VISIBLE|w32.WS_OVERLAPPEDWINDOW)
9841010
}
985-
w32.SetWindowPos(w.hwnd, 0, 0, 0, 0, 0, w32.SWP_NOMOVE|w32.SWP_NOSIZE|w32.SWP_NOZORDER|w32.SWP_FRAMECHANGED)
1011+
w32.SetWindowPos(
1012+
w.hwnd,
1013+
0,
1014+
0,
1015+
0,
1016+
0,
1017+
0,
1018+
w32.SWP_NOMOVE|w32.SWP_NOSIZE|w32.SWP_NOZORDER|w32.SWP_FRAMECHANGED,
1019+
)
9861020
}
9871021

9881022
func newWindowImpl(parent *WebviewWindow) *windowsWebviewWindow {
@@ -1533,7 +1567,10 @@ func (w *windowsWebviewWindow) processMessage(message string) {
15331567
}
15341568
}
15351569

1536-
func (w *windowsWebviewWindow) processRequest(req *edge.ICoreWebView2WebResourceRequest, args *edge.ICoreWebView2WebResourceRequestedEventArgs) {
1570+
func (w *windowsWebviewWindow) processRequest(
1571+
req *edge.ICoreWebView2WebResourceRequest,
1572+
args *edge.ICoreWebView2WebResourceRequestedEventArgs,
1573+
) {
15371574

15381575
// Setting the UserAgent on the CoreWebView2Settings clears the whole default UserAgent of the Edge browser, but
15391576
// we want to just append our ApplicationIdentifier. So we adjust the UserAgent for every request.
@@ -1544,7 +1581,10 @@ func (w *windowsWebviewWindow) processRequest(req *edge.ICoreWebView2WebResource
15441581
if err != nil {
15451582
globalApplication.fatal("error setting UserAgent header: %w", err)
15461583
}
1547-
err = reqHeaders.SetHeader(webViewRequestHeaderWindowId, strconv.FormatUint(uint64(w.parent.id), 10))
1584+
err = reqHeaders.SetHeader(
1585+
webViewRequestHeaderWindowId,
1586+
strconv.FormatUint(uint64(w.parent.id), 10),
1587+
)
15481588
if err != nil {
15491589
globalApplication.fatal("error setting WindowId header: %w", err)
15501590
}
@@ -1599,7 +1639,9 @@ func (w *windowsWebviewWindow) setupChromium() {
15991639

16001640
opts := w.parent.options.Windows
16011641

1602-
webview2version, err := webviewloader.GetAvailableCoreWebView2BrowserVersionString(globalApplication.options.Windows.WebviewBrowserPath)
1642+
webview2version, err := webviewloader.GetAvailableCoreWebView2BrowserVersionString(
1643+
globalApplication.options.Windows.WebviewBrowserPath,
1644+
)
16031645
if err != nil {
16041646
globalApplication.error("error getting WebView2 version: %w", err)
16051647
return
@@ -1655,12 +1697,9 @@ func (w *windowsWebviewWindow) setupChromium() {
16551697
}
16561698
if w.parent.options.EnableDragAndDrop {
16571699
w.dropTarget = w32.NewDropTarget()
1658-
w.dropTarget.OnDrop = func(files []string) {
1700+
w.dropTarget.OnDrop = func(files []string, x int, y int) {
16591701
w.parent.emit(events.Windows.WindowDragDrop)
1660-
windowDragAndDropBuffer <- &dragAndDropMessage{
1661-
windowId: windowID,
1662-
filenames: files,
1663-
}
1702+
w.parent.InitiateFrontendDropProcessing(files, x, y)
16641703
}
16651704
if opts.OnEnterEffect != 0 {
16661705
w.dropTarget.OnEnterEffect = convertEffect(opts.OnEnterEffect)
@@ -1731,7 +1770,9 @@ func (w *windowsWebviewWindow) setupChromium() {
17311770
if settings == nil {
17321771
globalApplication.fatal("error getting settings")
17331772
}
1734-
err = settings.PutAreDefaultContextMenusEnabled(debugMode || !w.parent.options.DefaultContextMenuDisabled)
1773+
err = settings.PutAreDefaultContextMenusEnabled(
1774+
debugMode || !w.parent.options.DefaultContextMenuDisabled,
1775+
)
17351776
if err != nil {
17361777
globalApplication.handleFatalError(err)
17371778
}
@@ -1765,7 +1806,12 @@ func (w *windowsWebviewWindow) setupChromium() {
17651806

17661807
// Set background colour
17671808
w.setBackgroundColour(w.parent.options.BackgroundColour)
1768-
chromium.SetBackgroundColour(w.parent.options.BackgroundColour.Red, w.parent.options.BackgroundColour.Green, w.parent.options.BackgroundColour.Blue, w.parent.options.BackgroundColour.Alpha)
1809+
chromium.SetBackgroundColour(
1810+
w.parent.options.BackgroundColour.Red,
1811+
w.parent.options.BackgroundColour.Green,
1812+
w.parent.options.BackgroundColour.Blue,
1813+
w.parent.options.BackgroundColour.Alpha,
1814+
)
17691815

17701816
chromium.SetGlobalPermission(edge.CoreWebView2PermissionStateAllow)
17711817
chromium.AddWebResourceRequestedFilter("*", edge.COREWEBVIEW2_WEB_RESOURCE_CONTEXT_ALL)
@@ -1776,7 +1822,10 @@ func (w *windowsWebviewWindow) setupChromium() {
17761822
script = w.parent.options.JS
17771823
}
17781824
if w.parent.options.CSS != "" {
1779-
script += fmt.Sprintf("; addEventListener(\"DOMContentLoaded\", (event) => { document.head.appendChild(document.createElement('style')).innerHTML=\"%s\"; });", strings.ReplaceAll(w.parent.options.CSS, `"`, `\"`))
1825+
script += fmt.Sprintf(
1826+
"; addEventListener(\"DOMContentLoaded\", (event) => { document.head.appendChild(document.createElement('style')).innerHTML=\"%s\"; });",
1827+
strings.ReplaceAll(w.parent.options.CSS, `"`, `\"`),
1828+
)
17801829
}
17811830
if script != "" {
17821831
chromium.Init(script)
@@ -1793,7 +1842,10 @@ func (w *windowsWebviewWindow) setupChromium() {
17931842

17941843
}
17951844

1796-
func (w *windowsWebviewWindow) fullscreenChanged(sender *edge.ICoreWebView2, _ *edge.ICoreWebView2ContainsFullScreenElementChangedEventArgs) {
1845+
func (w *windowsWebviewWindow) fullscreenChanged(
1846+
sender *edge.ICoreWebView2,
1847+
_ *edge.ICoreWebView2ContainsFullScreenElementChangedEventArgs,
1848+
) {
17971849
isFullscreen, err := sender.GetContainsFullScreenElement()
17981850
if err != nil {
17991851
globalApplication.fatal("fatal error in callback fullscreenChanged: %w", err)
@@ -1822,7 +1874,10 @@ func (w *windowsWebviewWindow) flash(enabled bool) {
18221874
w32.FlashWindow(w.hwnd, enabled)
18231875
}
18241876

1825-
func (w *windowsWebviewWindow) navigationCompleted(sender *edge.ICoreWebView2, args *edge.ICoreWebView2NavigationCompletedEventArgs) {
1877+
func (w *windowsWebviewWindow) navigationCompleted(
1878+
sender *edge.ICoreWebView2,
1879+
args *edge.ICoreWebView2NavigationCompletedEventArgs,
1880+
) {
18261881

18271882
// Install the runtime core
18281883
w.execJS(runtime.Core())
@@ -1885,7 +1940,9 @@ func (w *windowsWebviewWindow) processKeyBinding(vkey uint) bool {
18851940
acc.Modifiers = append(acc.Modifiers, SuperKey)
18861941
}
18871942

1888-
if vkey != w32.VK_CONTROL && vkey != w32.VK_MENU && vkey != w32.VK_SHIFT && vkey != w32.VK_LWIN && vkey != w32.VK_RWIN {
1943+
if vkey != w32.VK_CONTROL && vkey != w32.VK_MENU && vkey != w32.VK_SHIFT &&
1944+
vkey != w32.VK_LWIN &&
1945+
vkey != w32.VK_RWIN {
18891946
// Convert the vkey to a string
18901947
accKey, ok := VirtualKeyCodes[vkey]
18911948
if !ok {
@@ -1910,7 +1967,11 @@ func (w *windowsWebviewWindow) processKeyBinding(vkey uint) bool {
19101967
return false
19111968
}
19121969

1913-
func (w *windowsWebviewWindow) processMessageWithAdditionalObjects(message string, sender *edge.ICoreWebView2, args *edge.ICoreWebView2WebMessageReceivedEventArgs) {
1970+
func (w *windowsWebviewWindow) processMessageWithAdditionalObjects(
1971+
message string,
1972+
sender *edge.ICoreWebView2,
1973+
args *edge.ICoreWebView2WebMessageReceivedEventArgs,
1974+
) {
19141975
if strings.HasPrefix(message, "FilesDropped") {
19151976
objs, err := args.GetAdditionalObjects()
19161977
if err != nil {
@@ -1953,7 +2014,19 @@ func (w *windowsWebviewWindow) processMessageWithAdditionalObjects(message strin
19532014
filenames = append(filenames, filepath)
19542015
}
19552016

1956-
addDragAndDropMessage(w.parent.id, filenames)
2017+
// Extract X/Y coordinates from message - format should be "FilesDropped:x:y"
2018+
var x, y int
2019+
parts := strings.Split(message, ":")
2020+
if len(parts) >= 3 {
2021+
if parsedX, err := strconv.Atoi(parts[1]); err == nil {
2022+
x = parsedX
2023+
}
2024+
if parsedY, err := strconv.Atoi(parts[2]); err == nil {
2025+
y = parsedY
2026+
}
2027+
}
2028+
2029+
w.parent.InitiateFrontendDropProcessing(filenames, x, y)
19572030
return
19582031
}
19592032
}
@@ -1989,7 +2062,12 @@ func (w *windowsWebviewWindow) toggleMenuBar() {
19892062

19902063
func (w *windowsWebviewWindow) enableRedraw() {
19912064
w32.SendMessage(w.hwnd, w32.WM_SETREDRAW, 1, 0)
1992-
w32.RedrawWindow(w.hwnd, nil, 0, w32.RDW_ERASE|w32.RDW_FRAME|w32.RDW_INVALIDATE|w32.RDW_ALLCHILDREN)
2065+
w32.RedrawWindow(
2066+
w.hwnd,
2067+
nil,
2068+
0,
2069+
w32.RDW_ERASE|w32.RDW_FRAME|w32.RDW_INVALIDATE|w32.RDW_ALLCHILDREN,
2070+
)
19932071
}
19942072

19952073
func (w *windowsWebviewWindow) disableRedraw() {

v3/pkg/w32/idroptarget.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@ func init() {
3333
)
3434
}
3535

36-
func _iDropTargetDragEnter(this uintptr, dataObject *IDataObject, grfKeyState DWORD, point POINT, pdfEffect *DWORD) uintptr {
36+
func _iDropTargetDragEnter(
37+
this uintptr,
38+
dataObject *IDataObject,
39+
grfKeyState DWORD,
40+
point POINT,
41+
pdfEffect *DWORD,
42+
) uintptr {
3743
return combridge.Resolve[iDropTarget](this).DragEnter(dataObject, grfKeyState, point, pdfEffect)
3844
}
3945

@@ -67,7 +73,7 @@ type DropTarget struct {
6773
OnEnter func()
6874
OnLeave func()
6975
OnOver func()
70-
OnDrop func(filenames []string)
76+
OnDrop func(filenames []string, x int, y int)
7177
}
7278

7379
func NewDropTarget() *DropTarget {
@@ -128,7 +134,7 @@ func (d *DropTarget) Drop(dataObject *IDataObject, grfKeyState DWORD, point POIN
128134
filenames = append(filenames, filename)
129135
}
130136

131-
d.OnDrop(filenames)
137+
d.OnDrop(filenames, int(point.X), int(point.Y))
132138

133139
return uintptr(windows.S_OK)
134140
}

0 commit comments

Comments
 (0)