diff --git a/v2/go.mod b/v2/go.mod index 37a7e8edc..2db072e09 100644 --- a/v2/go.mod +++ b/v2/go.mod @@ -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 diff --git a/v2/go.sum b/v2/go.sum index 9c879d706..b1a681194 100644 --- a/v2/go.sum +++ b/v2/go.sum @@ -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= diff --git a/v2/internal/frontend/desktop/windows/frontend.go b/v2/internal/frontend/desktop/windows/frontend.go index ba3a68b3a..13d568b86 100644 --- a/v2/internal/frontend/desktop/windows/frontend.go +++ b/v2/internal/frontend/desktop/windows/frontend.go @@ -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 } diff --git a/v2/internal/frontend/desktop/windows/window.go b/v2/internal/frontend/desktop/windows/window.go index cdd277ad0..f89abb19b 100644 --- a/v2/internal/frontend/desktop/windows/window.go +++ b/v2/internal/frontend/desktop/windows/window.go @@ -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 + } + } } }