mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-02 09:31:48 +08:00
[v2, windows] Apply suggested window size during DPI changed event (#1131)
* [v2, windows] Apply suggested window size during DPI changed event This adjusts the window size if the window is moved from one monitor to another with a different DPI scaling * [v2, windows] Do not block processing of messages during frameless drag/resize * [v2, windows] Bump winc Improves the HiDPI handling by using newer APIs if available * [v2, windows] Constrain frameless maximize to MaxWidth/MaxHeight
This commit is contained in:
parent
3d02a314b9
commit
7bc51725c0
@ -27,7 +27,7 @@ require (
|
||||
github.com/leaanthony/idgen v1.0.0
|
||||
github.com/leaanthony/slicer v1.5.0
|
||||
github.com/leaanthony/typescriptify-golang-structs v0.1.7
|
||||
github.com/leaanthony/winc v0.0.0-20220202120322-32d63aaf77de
|
||||
github.com/leaanthony/winc v0.0.0-20220207200219-3173d94f373e
|
||||
github.com/leaanthony/winicon v1.0.0
|
||||
github.com/matryer/is v1.4.0
|
||||
github.com/olekukonko/tablewriter v0.0.4
|
||||
|
@ -128,8 +128,8 @@ github.com/leaanthony/slicer v1.5.0 h1:aHYTN8xbCCLxJmkNKiLB6tgcMARl4eWmH9/F+S/0H
|
||||
github.com/leaanthony/slicer v1.5.0/go.mod h1:FwrApmf8gOrpzEWM2J/9Lh79tyq8KTX5AzRtwV7m4AY=
|
||||
github.com/leaanthony/typescriptify-golang-structs v0.1.7 h1:yoznzWzyxkO/iWdlpq+aPcuJ5Y/hpjq/lmgMFmpjwl0=
|
||||
github.com/leaanthony/typescriptify-golang-structs v0.1.7/go.mod h1:cWtOkiVhMF77e6phAXUcfNwYmMwCJ67Sij24lfvi9Js=
|
||||
github.com/leaanthony/winc v0.0.0-20220202120322-32d63aaf77de h1:6z+HQCLE8m0cH4N8TauSdjmAJ1Su/aATTkCQyxGU55M=
|
||||
github.com/leaanthony/winc v0.0.0-20220202120322-32d63aaf77de/go.mod h1:OPfk8SNMAKRcSv8Vw1QL0yupmwcRtJyXZUgtMoaHUGc=
|
||||
github.com/leaanthony/winc v0.0.0-20220207200219-3173d94f373e h1:YYlAGeMoLcIPyXQMch6bMbTWBfhhyCSavlKs6an9Wik=
|
||||
github.com/leaanthony/winc v0.0.0-20220207200219-3173d94f373e/go.mod h1:OPfk8SNMAKRcSv8Vw1QL0yupmwcRtJyXZUgtMoaHUGc=
|
||||
github.com/leaanthony/winicon v1.0.0 h1:ZNt5U5dY71oEoKZ97UVwJRT4e+5xo5o/ieKuHuk8NqQ=
|
||||
github.com/leaanthony/winicon v1.0.0/go.mod h1:en5xhijl92aphrJdmRPlh4NI1L6wq3gEm0LpXAPghjU=
|
||||
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
|
||||
|
@ -473,7 +473,8 @@ func (f *Frontend) startDrag() error {
|
||||
if !w32.ReleaseCapture() {
|
||||
return fmt.Errorf("unable to release mouse capture")
|
||||
}
|
||||
w32.SendMessage(f.mainWindow.Handle(), w32.WM_NCLBUTTONDOWN, w32.HTCAPTION, 0)
|
||||
// Use PostMessage because we don't want to block the caller until dragging has been finished.
|
||||
w32.PostMessage(f.mainWindow.Handle(), w32.WM_NCLBUTTONDOWN, w32.HTCAPTION, 0)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -481,7 +482,8 @@ func (f *Frontend) startResize(border uintptr) error {
|
||||
if !w32.ReleaseCapture() {
|
||||
return fmt.Errorf("unable to release mouse capture")
|
||||
}
|
||||
w32.SendMessage(f.mainWindow.Handle(), w32.WM_NCLBUTTONDOWN, border, 0)
|
||||
// Use PostMessage because we don't want to block the caller until resizing has been finished.
|
||||
w32.PostMessage(f.mainWindow.Handle(), w32.WM_NCLBUTTONDOWN, border, 0)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -98,6 +98,17 @@ func (w *Window) WndProc(msg uint32, wparam, lparam uintptr) uintptr {
|
||||
if w.notifyParentWindowPositionChanged != nil {
|
||||
w.notifyParentWindowPositionChanged()
|
||||
}
|
||||
|
||||
// TODO move WM_DPICHANGED handling into winc
|
||||
case 0x02E0: //w32.WM_DPICHANGED
|
||||
newWindowSize := (*w32.RECT)(unsafe.Pointer(lparam))
|
||||
w32.SetWindowPos(w.Handle(),
|
||||
uintptr(0),
|
||||
int(newWindowSize.Left),
|
||||
int(newWindowSize.Top),
|
||||
int(newWindowSize.Right-newWindowSize.Left),
|
||||
int(newWindowSize.Bottom-newWindowSize.Top),
|
||||
w32.SWP_NOZORDER|w32.SWP_NOACTIVATE)
|
||||
}
|
||||
|
||||
if w.frontendOptions.Frameless {
|
||||
@ -130,6 +141,23 @@ func (w *Window) WndProc(msg uint32, wparam, lparam uintptr) uintptr {
|
||||
if w32.GetMonitorInfo(monitor, &monitorInfo) {
|
||||
rgrc := (*w32.RECT)(unsafe.Pointer(lparam))
|
||||
*rgrc = monitorInfo.RcWork
|
||||
|
||||
maxWidth := w.frontendOptions.MaxWidth
|
||||
maxHeight := w.frontendOptions.MaxHeight
|
||||
if maxWidth > 0 || maxHeight > 0 {
|
||||
var dpiX, dpiY uint
|
||||
w32.GetDPIForMonitor(monitor, w32.MDT_EFFECTIVE_DPI, &dpiX, &dpiY)
|
||||
|
||||
maxWidth := int32(winc.ScaleWithDPI(maxWidth, dpiX))
|
||||
if maxWidth > 0 && rgrc.Right-rgrc.Left > maxWidth {
|
||||
rgrc.Right = rgrc.Left + maxWidth
|
||||
}
|
||||
|
||||
maxHeight := int32(winc.ScaleWithDPI(maxHeight, dpiY))
|
||||
if maxHeight > 0 && rgrc.Bottom-rgrc.Top > maxHeight {
|
||||
rgrc.Bottom = rgrc.Top + maxHeight
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user