Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[windows] Improve fullscreen mode for frameless windows #2279

Merged
Merged
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
8 changes: 8 additions & 0 deletions v2/internal/frontend/desktop/windows/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand All @@ -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()
}

Expand All @@ -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()

Expand Down
7 changes: 4 additions & 3 deletions v2/internal/frontend/desktop/windows/winc/form.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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 {
Expand Down
22 changes: 15 additions & 7 deletions v2/internal/frontend/desktop/windows/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,22 @@ func (w *Window) Fullscreen() {
}

func (w *Window) UnFullscreen() {
if !w.IsFullScreen() {
if !w.Form.IsFullScreen() {
return
}
w.Form.UnFullscreen()
w.SetMinSize(w.minWidth, w.minHeight)
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
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions website/src/pages/changelog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down