From 8e4606d104f9be838689ae665ee7a928eb847885 Mon Sep 17 00:00:00 2001 From: stffabi Date: Mon, 9 Jan 2023 12:15:43 +0100 Subject: [PATCH] [windows] Improve fullscreen mode for frameless windows (#2279) * Improve fullscreen mode for frameless windows * Set Window background color in addition to WebView2 background color --- .../frontend/desktop/windows/frontend.go | 8 +++++++ .../frontend/desktop/windows/winc/form.go | 7 +++--- .../frontend/desktop/windows/window.go | 22 +++++++++++++------ website/src/pages/changelog.mdx | 6 +++++ 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/v2/internal/frontend/desktop/windows/frontend.go b/v2/internal/frontend/desktop/windows/frontend.go index 162be3e28..6267777d6 100644 --- a/v2/internal/frontend/desktop/windows/frontend.go +++ b/v2/internal/frontend/desktop/windows/frontend.go @@ -296,6 +296,9 @@ func (f *Frontend) WindowToggleMaximise() { func (f *Frontend) WindowUnmaximise() { runtime.LockOSThread() defer runtime.UnlockOSThread() + if f.mainWindow.Form.IsFullScreen() { + return + } f.mainWindow.Restore() } @@ -312,6 +315,9 @@ func (f *Frontend) WindowMinimise() { func (f *Frontend) WindowUnminimise() { runtime.LockOSThread() defer runtime.UnlockOSThread() + if f.mainWindow.Form.IsFullScreen() { + return + } f.mainWindow.Restore() } @@ -332,6 +338,8 @@ func (f *Frontend) WindowSetBackgroundColour(col *options.RGBA) { } f.mainWindow.Invoke(func() { + win32.SetBackgroundColour(f.mainWindow.Handle(), col.R, col.G, col.B) + controller := f.chromium.GetController() controller2 := controller.GetICoreWebView2Controller2() diff --git a/v2/internal/frontend/desktop/windows/winc/form.go b/v2/internal/frontend/desktop/windows/winc/form.go index c719582e2..e7da1b59e 100644 --- a/v2/internal/frontend/desktop/windows/winc/form.go +++ b/v2/internal/frontend/desktop/windows/winc/form.go @@ -176,14 +176,15 @@ func (fm *Form) Fullscreen() { if !w32.GetWindowPlacement(fm.hwnd, &fm.previousWindowPlacement) { return } - w32.SetWindowLong(fm.hwnd, w32.GWL_STYLE, fm.previousWindowStyle & ^uint32(w32.WS_OVERLAPPEDWINDOW)) + // According to https://devblogs.microsoft.com/oldnewthing/20050505-04/?p=35703 one should use w32.WS_POPUP | w32.WS_VISIBLE + w32.SetWindowLong(fm.hwnd, w32.GWL_STYLE, fm.previousWindowStyle & ^uint32(w32.WS_OVERLAPPEDWINDOW) | (w32.WS_POPUP|w32.WS_VISIBLE)) + fm.isFullscreen = true w32.SetWindowPos(fm.hwnd, w32.HWND_TOP, int(monitorInfo.RcMonitor.Left), int(monitorInfo.RcMonitor.Top), int(monitorInfo.RcMonitor.Right-monitorInfo.RcMonitor.Left), int(monitorInfo.RcMonitor.Bottom-monitorInfo.RcMonitor.Top), w32.SWP_NOOWNERZORDER|w32.SWP_FRAMECHANGED) - fm.isFullscreen = true } func (fm *Form) UnFullscreen() { @@ -192,9 +193,9 @@ func (fm *Form) UnFullscreen() { } w32.SetWindowLong(fm.hwnd, w32.GWL_STYLE, fm.previousWindowStyle) w32.SetWindowPlacement(fm.hwnd, &fm.previousWindowPlacement) + fm.isFullscreen = false w32.SetWindowPos(fm.hwnd, 0, 0, 0, 0, 0, w32.SWP_NOMOVE|w32.SWP_NOSIZE|w32.SWP_NOZORDER|w32.SWP_NOOWNERZORDER|w32.SWP_FRAMECHANGED) - fm.isFullscreen = false } func (fm *Form) IsFullScreen() bool { diff --git a/v2/internal/frontend/desktop/windows/window.go b/v2/internal/frontend/desktop/windows/window.go index 5d1a01373..f57b4cb6a 100644 --- a/v2/internal/frontend/desktop/windows/window.go +++ b/v2/internal/frontend/desktop/windows/window.go @@ -137,7 +137,7 @@ func (w *Window) Fullscreen() { } func (w *Window) UnFullscreen() { - if !w.IsFullScreen() { + if !w.Form.IsFullScreen() { return } w.Form.UnFullscreen() @@ -145,6 +145,14 @@ func (w *Window) UnFullscreen() { w.SetMaxSize(w.maxWidth, w.maxHeight) } +func (w *Window) Restore() { + if w.Form.IsFullScreen() { + w.UnFullscreen() + } else { + w.Form.Restore() + } +} + func (w *Window) SetMinSize(minWidth int, minHeight int) { w.minWidth = minWidth w.minHeight = minHeight @@ -205,7 +213,6 @@ func (w *Window) WndProc(msg uint32, wparam, lparam uintptr) uintptr { //} } - // TODO move WM_DPICHANGED handling into winc case 0x02E0: //w32.WM_DPICHANGED newWindowSize := (*w32.RECT)(unsafe.Pointer(lparam)) w32.SetWindowPos(w.Handle(), @@ -235,9 +242,10 @@ func (w *Window) WndProc(msg uint32, wparam, lparam uintptr) uintptr { // shown. We still need the WS_THICKFRAME style to enable resizing from the frontend. if wparam != 0 { rgrc := (*w32.RECT)(unsafe.Pointer(lparam)) - - style := uint32(w32.GetWindowLong(w.Handle(), w32.GWL_STYLE)) - if style&w32.WS_MAXIMIZE != 0 { + if w.Form.IsFullScreen() { + // In Full-Screen mode we don't need to adjust anything + w.chromium.SetPadding(edge.Rect{}) + } else if w.IsMaximised() { // If the window is maximized we must adjust the client area to the work area of the monitor. Otherwise // some content goes beyond the visible part of the monitor. // Make sure to use the provided RECT to get the monitor, because during maximizig there might be @@ -268,6 +276,7 @@ func (w *Window) WndProc(msg uint32, wparam, lparam uintptr) uintptr { } } w.chromium.SetPadding(edge.Rect{}) + return 0 } else { // This is needed to workaround the resize flickering in frameless mode with WindowDecorations // See: https://stackoverflow.com/a/6558508 @@ -277,9 +286,8 @@ func (w *Window) WndProc(msg uint32, wparam, lparam uintptr) uintptr { // therefore let's pad the content with 1px at the bottom. rgrc.Bottom += 1 w.chromium.SetPadding(edge.Rect{Bottom: 1}) + return 0 } - - return 0 } } } diff --git a/website/src/pages/changelog.mdx b/website/src/pages/changelog.mdx index 8ada62fcc..ede7f6935 100644 --- a/website/src/pages/changelog.mdx +++ b/website/src/pages/changelog.mdx @@ -18,8 +18,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added Webview GPU acceleration options for [Windows](/docs/reference/options#webviewgpuisdisabled) and [Linux](/docs/reference/options#webviewgpupolicy). Added by @Lyimmi in [PR](https://github.com/wailsapp/wails/pull/2266) - Added `EnableFraudulentWebsiteDetection` option to opt-in to scan services for fraudulent content, such as malware or phishing attempts. Older releases had the scan services per default activated. Added by @stffabi in [PR](https://github.com/wailsapp/wails/pull/2269) +### Changed +- Improved fullscreen mode for frameless window on Windows. Changed by @stffabi in [PR](https://github.com/wailsapp/wails/pull/2279) +- On Windows unmaximising a window has no effect anymore when the window is in fullscreen mode, this makes it consistent with e.g. macOS. Changed by @stffabi in [PR](https://github.com/wailsapp/wails/pull/2279) + ### Fixed - Fixed failing build hooks when `build/bin` was missing. Fixed by @Lyimmi in [PR](https://github.com/wailsapp/wails/pull/2273) +- Fixed fullscreen mode for frameless window on Windows to fully cover the taskbar when changing into fullscreen from maximised state. Fixed by @stffabi in [PR](https://github.com/wailsapp/wails/pull/2279) +- Fixed set window background colour on Windows when setting the colour via runtime. Fixed by @stffabi in [PR](https://github.com/wailsapp/wails/pull/2279) ## v2.3.0 - 2022-12-29