From 2bc25491600305132ad6450afa186b5622bf451d Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Sat, 26 Apr 2025 16:57:30 +1000 Subject: [PATCH] Fix GetPos and SetPos on Windows --- v3/BETA_READINESS.md | 81 ++++++++++---------- v3/pkg/application/webview_window_windows.go | 29 ++++--- 2 files changed, 55 insertions(+), 55 deletions(-) diff --git a/v3/BETA_READINESS.md b/v3/BETA_READINESS.md index 5724d79a0..eab6c37ca 100644 --- a/v3/BETA_READINESS.md +++ b/v3/BETA_READINESS.md @@ -4,48 +4,49 @@ This document is for tracking the status of the v3-alpha branch in readiness for ## Examples -| Example | Linux | Windows | macOS | -|--------------------|-------|--------------------------------------------------|-------------------------------------------------------| -| badge | | ✅ | | -| binding | | ✅ | ✅ | -| cancel-async | | ✅ | ✅ | -| cancel-chaining | | ✅ | ✅ | -| clipboard | | ✅ | ✅ | -| context-menus | | ✅ | 🚫 panic | -| dialogs | | ⚠️ custom icon not working | ⚠️ | -| dialogs-basic | | ✅ | ✅ | -| drag-n-drop | | ✅ | ✅ | -| environment | | ✅ | ✅ | -| events | | ✅ | ✅ | -| file-association | | ✅ | ✅ | -| frameless | | ✅ | ⚠️ minimise for 3 not working | -| gin-example | | ✅ | ✅ | -| gin-routing | | ✅ | ⚠️ cant see difference from gin-example (copy/paste?) | -| gin-service | | ✅ | ⚠️ half buttons does nothing? ( getuserbyid ) | -| html-dnd-api | | 🚫 | ✅ | -| ignore-mouse | | ✅ | ✅ | -| keybindings | | ✅ | ✅ | -| menu | | ⚠️ Hide/Unhide issue | ✅ | -| notifications | | ✅ | ⚠️ nothing happens on button click | -| panic-handling | | ✅ | ✅ | -| plain | | ✅ | ✅ | -| raw-message | | ✅ | ✅ | -| screen | | ✅ | ⚠️ slider bubble drags window | -| services | | ✅ | ✅ | -| show-macos-toolbar | | ➖ | ✅ | -| single-instance | | ✅ | ✅ | -| systray-basic | | ✅ | ✅ | -| systray-custom | | ✅ | ✅ | -| systray-menu | | ✅ | ✅ | -| video | | ✅ | ✅ | -| window | | ⚠️ SetPos 0,0 is going to 5,0. GetPos is correct | ✅ | -| window-api | | ✅ | ✅ | -| window-call | | ✅ | ✅ | -| window-menubar | | ✅ | ⚠️ not sure what should happen in osx | -| wml | | ✅ | ✅ | +| Example | Linux | Windows | macOS | +|--------------------|-------|----------------------------|-------------------------------------------------------| +| badge | | ✅ | | +| binding | | ✅ | ✅ | +| cancel-async | | ✅ | ✅ | +| cancel-chaining | | ✅ | ✅ | +| clipboard | | ✅ | ✅ | +| context-menus | | ✅ | 🚫 panic | +| dialogs | | ⚠️ custom icon not working | ⚠️ | +| dialogs-basic | | ✅ | ✅ | +| drag-n-drop | | ✅ | ✅ | +| environment | | ✅ | ✅ | +| events | | ✅ | ✅ | +| file-association | | ✅ | ✅ | +| frameless | | ✅ | ⚠️ minimise for 3 not working | +| gin-example | | ✅ | ✅ | +| gin-routing | | ✅ | ⚠️ cant see difference from gin-example (copy/paste?) | +| gin-service | | ✅ | ⚠️ half buttons does nothing? ( getuserbyid ) | +| html-dnd-api | | 🚫 | ✅ | +| ignore-mouse | | ✅ | ✅ | +| keybindings | | ✅ | ✅ | +| menu | | ⚠️ Hide/Unhide issue | ✅ | +| notifications | | ✅ | ⚠️ nothing happens on button click | +| panic-handling | | ✅ | ✅ | +| plain | | ✅ | ✅ | +| raw-message | | ✅ | ✅ | +| screen | | ✅ | ⚠️ slider bubble drags window | +| services | | ✅ | ✅ | +| show-macos-toolbar | | ➖ | ✅ | +| single-instance | | ✅ | ✅ | +| systray-basic | | ✅ | ✅ | +| systray-custom | | ✅ | ✅ | +| systray-menu | | ✅ | ✅ | +| video | | ✅ | ✅ | +| window | | ✅ | ✅ | +| window-api | | ✅ | ✅ | +| window-call | | ✅ | ✅ | +| window-menubar | | ✅ | ⚠️ not sure what should happen in osx | +| wml | | ✅ | ✅ | ## Open Bugs - + - https://github.com/wailsapp/wails/issues/3743 - https://github.com/wailsapp/wails/issues/3683 - needs checking - https://github.com/wailsapp/wails/issues/4235 @@ -58,4 +59,4 @@ This document is for tracking the status of the v3-alpha branch in readiness for - [ ] [Port DLL Directory Initialisation](https://github.com/wailsapp/wails/pull/4207) - [ ] Check if [this](https://github.com/wailsapp/wails/pull/4047#issuecomment-2814676117) needs porting. - [ ] Update docs - - [ ] Add tutorials + - [ ] Add tutorials diff --git a/v3/pkg/application/webview_window_windows.go b/v3/pkg/application/webview_window_windows.go index 92615a2d8..89743b41e 100644 --- a/v3/pkg/application/webview_window_windows.go +++ b/v3/pkg/application/webview_window_windows.go @@ -90,7 +90,7 @@ func (w *windowsWebviewWindow) paste() { try { // Try to read all available formats const clipboardItems = await navigator.clipboard.read(); - + for (const clipboardItem of clipboardItems) { // Check for image types for (const type of clipboardItem.types) { @@ -101,7 +101,7 @@ func (w *windowsWebviewWindow) paste() { return; } } - + // If no image found, try text if (clipboardItem.types.includes('text/plain')) { const text = await navigator.clipboard.readText(); @@ -504,25 +504,24 @@ func (w *windowsWebviewWindow) getBorderSizes() *LRTB { } func (w *windowsWebviewWindow) physicalBounds() Rect { - // var rect w32.RECT - // // Get the extended frame bounds instead of the window rect to offset the invisible borders in Windows 10 - // w32.DwmGetWindowAttribute(w.hwnd, w32.DWMWA_EXTENDED_FRAME_BOUNDS, unsafe.Pointer(&rect), unsafe.Sizeof(rect)) rect := w32.GetWindowRect(w.hwnd) + // Compensate for invisible borders + borderSize := w.getBorderSizes() return Rect{ - X: int(rect.Left), - Y: int(rect.Top), - Width: int(rect.Right - rect.Left), - Height: int(rect.Bottom - rect.Top), + X: int(rect.Left) + borderSize.Left, + Y: int(rect.Top) + borderSize.Top, + Width: int(rect.Right-rect.Left) - borderSize.Left - borderSize.Right, + Height: int(rect.Bottom-rect.Top) - borderSize.Top - borderSize.Bottom, } } func (w *windowsWebviewWindow) setPhysicalBounds(physicalBounds Rect) { - // // Offset invisible borders - // borderSize := w.getBorderSizes() - // physicalBounds.X -= borderSize.Left - // physicalBounds.Y -= borderSize.Top - // physicalBounds.Width += borderSize.Left + borderSize.Right - // physicalBounds.Height += borderSize.Top + borderSize.Bottom + // Offset invisible borders + borderSize := w.getBorderSizes() + physicalBounds.X -= borderSize.Left + physicalBounds.Y -= borderSize.Top + physicalBounds.Width += borderSize.Left + borderSize.Right + physicalBounds.Height += borderSize.Top + borderSize.Bottom // Set flag to ignore resizing the window with DPI change because we already calculated the correct size // for the target position, this prevents double resizing issue when the window is moved between screens