app: [Windows] fix window state update after window restore

This patch ensures a correct transition from Minimized to Windowed.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2022-06-28 16:20:31 +01:00
parent 5dc8e0e39d
commit 4d593927ae
+23 -16
View File
@@ -198,13 +198,8 @@ func (w *window) update() {
} }
// Check the window mode. // Check the window mode.
p := windows.GetWindowPlacement(w.hwnd)
style := windows.GetWindowLong(w.hwnd, windows.GWL_STYLE) style := windows.GetWindowLong(w.hwnd, windows.GWL_STYLE)
if p.IsMinimized() { if style&windows.WS_OVERLAPPEDWINDOW == 0 {
w.config.Mode = Minimized
} else if p.IsMaximized() {
w.config.Mode = Maximized
} else if style&windows.WS_OVERLAPPEDWINDOW == 0 {
size = image.Point{ size = image.Point{
X: int(r.Right - r.Left), X: int(r.Right - r.Left),
Y: int(r.Bottom - r.Top), Y: int(r.Bottom - r.Top),
@@ -286,7 +281,7 @@ func windowProc(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr
case windows.WM_KILLFOCUS: case windows.WM_KILLFOCUS:
w.w.Event(key.FocusEvent{Focus: false}) w.w.Event(key.FocusEvent{Focus: false})
case windows.WM_NCHITTEST: case windows.WM_NCHITTEST:
if w.config.Decorated || w.config.Mode != Windowed { if w.config.Decorated {
// Let the system handle it. // Let the system handle it.
break break
} }
@@ -321,12 +316,18 @@ func windowProc(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr
case windows.WM_PAINT: case windows.WM_PAINT:
w.draw(true) w.draw(true)
case windows.WM_SIZE: case windows.WM_SIZE:
w.update()
switch wParam { switch wParam {
case windows.SIZE_MINIMIZED: case windows.SIZE_MINIMIZED:
w.update() w.config.Mode = Minimized
w.setStage(system.StagePaused) w.setStage(system.StagePaused)
case windows.SIZE_MAXIMIZED, windows.SIZE_RESTORED: case windows.SIZE_MAXIMIZED:
w.update() w.config.Mode = Maximized
w.setStage(system.StageRunning)
case windows.SIZE_RESTORED:
if w.config.Mode != Fullscreen {
w.config.Mode = Windowed
}
w.setStage(system.StageRunning) w.setStage(system.StageRunning)
} }
case windows.WM_GETMINMAXINFO: case windows.WM_GETMINMAXINFO:
@@ -429,6 +430,17 @@ func getModifiers() key.Modifiers {
// hitTest returns the non-client area hit by the point, needed to // hitTest returns the non-client area hit by the point, needed to
// process WM_NCHITTEST. // process WM_NCHITTEST.
func (w *window) hitTest(x, y int) uintptr { func (w *window) hitTest(x, y int) uintptr {
if w.config.Mode == Fullscreen {
return windows.HTCLIENT
}
p := f32.Pt(float32(x), float32(y))
if a, ok := w.w.ActionAt(p); ok && a == system.ActionMove {
return windows.HTCAPTION
}
if w.config.Mode != Windowed {
// Only windowed mode should allow resizing.
return windows.HTCLIENT
}
top := y <= w.borderSize.Y top := y <= w.borderSize.Y
bottom := y >= w.config.Size.Y-w.borderSize.Y bottom := y >= w.config.Size.Y-w.borderSize.Y
left := x <= w.borderSize.X left := x <= w.borderSize.X
@@ -437,11 +449,6 @@ func (w *window) hitTest(x, y int) uintptr {
default: default:
fallthrough fallthrough
case !top && !bottom && !left && !right: case !top && !bottom && !left && !right:
p := f32.Pt(float32(x), float32(y))
switch a, _ := w.w.ActionAt(p); a {
case system.ActionMove:
return windows.HTCAPTION
}
return windows.HTCLIENT return windows.HTCLIENT
case top && left: case top && left:
return windows.HTTOPLEFT return windows.HTTOPLEFT
@@ -644,6 +651,7 @@ func (w *window) Configure(options []Option) {
} }
switch w.config.Mode { switch w.config.Mode {
case Minimized: case Minimized:
style |= winStyle
swpStyle |= windows.SWP_NOMOVE | windows.SWP_NOSIZE swpStyle |= windows.SWP_NOMOVE | windows.SWP_NOSIZE
showMode = windows.SW_SHOWMINIMIZED showMode = windows.SW_SHOWMINIMIZED
@@ -677,7 +685,6 @@ func (w *window) Configure(options []Option) {
height = r.Bottom - r.Top height = r.Bottom - r.Top
case Fullscreen: case Fullscreen:
style &^= windows.WS_OVERLAPPEDWINDOW
mi := windows.GetMonitorInfo(w.hwnd) mi := windows.GetMonitorInfo(w.hwnd)
x, y = mi.Monitor.Left, mi.Monitor.Top x, y = mi.Monitor.Left, mi.Monitor.Top
width = mi.Monitor.Right - mi.Monitor.Left width = mi.Monitor.Right - mi.Monitor.Left