mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 01:15:35 +00:00
app: [Windows] compute min, max window sizes correctly when un-minimzing
Fixes: https://todo.sr.ht/~eliasnaur/gio/608 Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+24
-18
@@ -46,14 +46,13 @@ type window struct {
|
|||||||
cursorIn bool
|
cursorIn bool
|
||||||
cursor syscall.Handle
|
cursor syscall.Handle
|
||||||
|
|
||||||
// placement saves the previous window position when in full screen mode.
|
|
||||||
placement *windows.WindowPlacement
|
|
||||||
|
|
||||||
animating bool
|
animating bool
|
||||||
|
|
||||||
borderSize image.Point
|
borderSize image.Point
|
||||||
config Config
|
config Config
|
||||||
loop *eventLoop
|
// frameDims stores the last seen window frame width and height.
|
||||||
|
frameDims image.Point
|
||||||
|
loop *eventLoop
|
||||||
}
|
}
|
||||||
|
|
||||||
const _WM_WAKEUP = windows.WM_USER + iota
|
const _WM_WAKEUP = windows.WM_USER + iota
|
||||||
@@ -189,17 +188,24 @@ func (w *window) init() error {
|
|||||||
// It reads the window style and size/position and updates w.config.
|
// It reads the window style and size/position and updates w.config.
|
||||||
// If anything has changed it emits a ConfigEvent to notify the application.
|
// If anything has changed it emits a ConfigEvent to notify the application.
|
||||||
func (w *window) update() {
|
func (w *window) update() {
|
||||||
cr := windows.GetClientRect(w.hwnd)
|
p := windows.GetWindowPlacement(w.hwnd)
|
||||||
w.config.Size = image.Point{
|
if !p.IsMinimized() {
|
||||||
X: int(cr.Right - cr.Left),
|
r := windows.GetWindowRect(w.hwnd)
|
||||||
Y: int(cr.Bottom - cr.Top),
|
cr := windows.GetClientRect(w.hwnd)
|
||||||
|
w.config.Size = image.Point{
|
||||||
|
X: int(cr.Right - cr.Left),
|
||||||
|
Y: int(cr.Bottom - cr.Top),
|
||||||
|
}
|
||||||
|
w.frameDims = image.Point{
|
||||||
|
X: int(r.Right - r.Left),
|
||||||
|
Y: int(r.Bottom - r.Top),
|
||||||
|
}.Sub(w.config.Size)
|
||||||
}
|
}
|
||||||
|
|
||||||
w.borderSize = image.Pt(
|
w.borderSize = image.Pt(
|
||||||
windows.GetSystemMetrics(windows.SM_CXSIZEFRAME),
|
windows.GetSystemMetrics(windows.SM_CXSIZEFRAME),
|
||||||
windows.GetSystemMetrics(windows.SM_CYSIZEFRAME),
|
windows.GetSystemMetrics(windows.SM_CYSIZEFRAME),
|
||||||
)
|
)
|
||||||
p := windows.GetWindowPlacement(w.hwnd)
|
|
||||||
style := windows.GetWindowLong(w.hwnd, windows.GWL_STYLE)
|
style := windows.GetWindowLong(w.hwnd, windows.GWL_STYLE)
|
||||||
switch {
|
switch {
|
||||||
case p.IsMaximized() && style&windows.WS_OVERLAPPEDWINDOW != 0:
|
case p.IsMaximized() && style&windows.WS_OVERLAPPEDWINDOW != 0:
|
||||||
@@ -347,23 +353,23 @@ func windowProc(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr
|
|||||||
w.update()
|
w.update()
|
||||||
case windows.WM_GETMINMAXINFO:
|
case windows.WM_GETMINMAXINFO:
|
||||||
mm := (*windows.MinMaxInfo)(unsafe.Pointer(lParam))
|
mm := (*windows.MinMaxInfo)(unsafe.Pointer(lParam))
|
||||||
var bw, bh int32
|
|
||||||
|
var frameDims image.Point
|
||||||
if w.config.Decorated {
|
if w.config.Decorated {
|
||||||
r := windows.GetWindowRect(w.hwnd)
|
frameDims = w.frameDims
|
||||||
cr := windows.GetClientRect(w.hwnd)
|
|
||||||
bw = r.Right - r.Left - (cr.Right - cr.Left)
|
|
||||||
bh = r.Bottom - r.Top - (cr.Bottom - cr.Top)
|
|
||||||
}
|
}
|
||||||
if p := w.config.MinSize; p.X > 0 || p.Y > 0 {
|
if p := w.config.MinSize; p.X > 0 || p.Y > 0 {
|
||||||
|
p = p.Add(frameDims)
|
||||||
mm.PtMinTrackSize = windows.Point{
|
mm.PtMinTrackSize = windows.Point{
|
||||||
X: int32(p.X) + bw,
|
X: int32(p.X),
|
||||||
Y: int32(p.Y) + bh,
|
Y: int32(p.Y),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if p := w.config.MaxSize; p.X > 0 || p.Y > 0 {
|
if p := w.config.MaxSize; p.X > 0 || p.Y > 0 {
|
||||||
|
p = p.Add(frameDims)
|
||||||
mm.PtMaxTrackSize = windows.Point{
|
mm.PtMaxTrackSize = windows.Point{
|
||||||
X: int32(p.X) + bw,
|
X: int32(p.X),
|
||||||
Y: int32(p.Y) + bh,
|
Y: int32(p.Y),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
Reference in New Issue
Block a user