[windows] Improve fullscreen mode for frameless windows (#2279)

* Improve fullscreen mode for frameless windows
* Set Window background color in addition to WebView2 background color
This commit is contained in:
stffabi
2023-01-09 12:15:43 +01:00
committed by GitHub
parent 54ca6c7059
commit 8e4606d104
4 changed files with 33 additions and 10 deletions
@@ -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()
@@ -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 {
+15 -7
View File
@@ -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
}
}
}