Since 0.1.4274 (dd77094ca) the main window on Windows is frameless, and Puremilk_chun on X couldn't resize it. Wails' frameless window answers WM_NCCALCSIZE with the whole window as the page, so Windows has no resize border left: the invisible band outside a window's edge, where Windows 11 users grab it, answered HTNOWHERE, and only Wails' 4px band inside the page resized, which on the right lies under the page's 10px scrollbar (.view is overflow-y: scroll) and did nothing. mainFrameCalc (mainframe_windows.go), asked first by appWndProc for the main window alone, lets DefWindowProc work out the frame as for a framed window and then puts the page's top back at the window's top. The left, right and bottom are Windows' own resize border again; the header is still the title bar, with the caption buttons, the shadow, the rounded corners and snap asdd77094camade them; the top is resized by Wails' band. Maximised or in full screen Wails sizes the window as before. keepResizeFrame names the window on Wails' runtime ready (the first main window is made before the main loop runs) and has Windows work the frame out again. gui-shell.md says so. Run (at this tree, rebased on origin/main3b643f397): - gofmt -l clean. mote: GOOS=windows go vet ./internal/gui, go vet ./internal/gui, go test -count=1 ./internal/gui: ok. - xiaomi-gpu (win-run): go test -count=1 ./internal/gui: TestMainWindowKeepsResizeBorder ok; 10 reds, all red the same at origin/main3b643f397run by name on the same box: TestPageAwayLetsStatsGo (filed #6810), the other nine in #6068, #5324, #5928 and #6059. WSL magpie-desktop: go vet -tags gtk3 ./internal/gui: ok. - TestMainWindowKeepsResizeBorder (Windows): a real window answering as Wails' frameless one; the main window's left, right, bottom and bottom-right hit HTLEFT/HTRIGHT/HTBOTTOM/HTBOTTOMRIGHT, its page starts at the window's top, maximised the page is the whole window, and another window is left alone. - Windows 11 on xiaomi-gpu, 100% scale, sandbox USERPROFILE, port 3481, a real mouse (mouse_event) on each edge and corner, 2px inside and 3px outside, the window placed at 200,133 1000x640: - 0.1.4281: outside every edge hits 0 and nothing moves; inside, the right edge and bottom-right do nothing (the scrollbar takes the press, no mousemove reaches drag.ts), the others resize. - this tree: outside, right/left/bottom/br/bl hit 11/10/15/17/16 and resize 60px; inside as 4281; the header drags the window; the maximise button maximises to the work area and restore brings back the same rect; a screenshot shows the header at the top edge with the caption buttons, the border and the shadow. Broken by hand: with mainFrameCalc answering false, TestMainWindowKeepsResizeBorder is red (left/right/bottom/br hit 1, "the page starts at the window's left edge"). Not tried: 150% scale (changing the display's scale would move other sessions' windows on that box); snap (WS_THICKFRAME and the styles are unchanged); the inside band under the scrollbar on the right is left as it was, the outside border now covers that edge. Rebased onf64c7e54f(routing, provider and a gui-shell.md paragraph elsewhere): on xiaomi-gpu TestMainWindowKeepsResizeBorder ok; on mica gofmt, GOOS=windows go vet and go vet ./internal/gui ok.
102 lines
3.5 KiB
Go
102 lines
3.5 KiB
Go
//go:build windows && !nogui
|
|
|
|
package gui
|
|
|
|
import (
|
|
"runtime"
|
|
"testing"
|
|
"unsafe"
|
|
|
|
"github.com/wailsapp/wails/v3/pkg/w32"
|
|
"golang.org/x/sys/windows"
|
|
)
|
|
|
|
// framelessTestProc answers as Wails' frameless window does: magpie's
|
|
// interceptor first (mainFrameCalc, which appWndProc asks first), then
|
|
// WM_NCCALCSIZE with the whole window as the client area.
|
|
var framelessTestProc = windows.NewCallback(func(hwnd, msg, wParam, lParam uintptr) uintptr {
|
|
if r, ok := mainFrameCalc(hwnd, uint32(msg), wParam, lParam); ok {
|
|
return r
|
|
}
|
|
if msg == w32.WM_NCCALCSIZE && wParam != 0 {
|
|
return 0
|
|
}
|
|
return w32.DefWindowProc(hwnd, uint32(msg), wParam, lParam)
|
|
})
|
|
|
|
func framelessTestWindow(t *testing.T) uintptr {
|
|
t.Helper()
|
|
cls, _ := windows.UTF16PtrFromString("magpieFramelessTest")
|
|
wc := w32.WNDCLASSEX{WndProc: framelessTestProc, Instance: w32.GetModuleHandle(""), ClassName: cls}
|
|
wc.Size = uint32(unsafe.Sizeof(wc))
|
|
w32.RegisterClassEx(&wc) // once a process; a second call fails harmlessly
|
|
title, _ := windows.UTF16PtrFromString("magpie frameless test")
|
|
hwnd := w32.CreateWindowEx(0, cls, title, w32.WS_OVERLAPPEDWINDOW, 100, 100, 800, 600, 0, 0, wc.Instance, nil)
|
|
if hwnd == 0 {
|
|
t.Fatalf("CreateWindowEx: %v", windows.GetLastError())
|
|
}
|
|
t.Cleanup(func() { w32.DestroyWindow(hwnd) })
|
|
return hwnd
|
|
}
|
|
|
|
func reframe(hwnd uintptr) {
|
|
w32.SetWindowPos(hwnd, 0, 0, 0, 0, 0, w32.SWP_NOMOVE|w32.SWP_NOSIZE|w32.SWP_NOZORDER|w32.SWP_NOACTIVATE|w32.SWP_FRAMECHANGED)
|
|
}
|
|
|
|
func hitAt(hwnd uintptr, x, y int) uintptr {
|
|
return w32.SendMessage(hwnd, w32.WM_NCHITTEST, 0, uintptr(uint32(uint16(int16(y)))<<16|uint32(uint16(int16(x)))))
|
|
}
|
|
|
|
// Puremilk_chun on X: the frameless main window (0.1.4274 on) couldn't be
|
|
// resized from outside its edge. Its left, right and bottom are Windows'
|
|
// resize border again, while its top is still the page's (the header is
|
|
// the title bar); maximised it fills the window, and any other window is
|
|
// left as Wails made it.
|
|
func TestMainWindowKeepsResizeBorder(t *testing.T) {
|
|
runtime.LockOSThread()
|
|
defer runtime.UnlockOSThread()
|
|
defer mainHwnd.Store(0)
|
|
|
|
main := framelessTestWindow(t)
|
|
mainHwnd.Store(main)
|
|
reframe(main)
|
|
r := w32.GetWindowRect(main)
|
|
cx, cy := w32.ClientToScreen(main, 0, 0)
|
|
if cy != int(r.Top) {
|
|
t.Errorf("the page starts %dpx below the window's top, want 0: the header is the title bar", cy-int(r.Top))
|
|
}
|
|
if cx <= int(r.Left) {
|
|
t.Errorf("the page starts at the window's left edge: no resize border is left there")
|
|
}
|
|
midX, midY := int(r.Left+r.Right)/2, int(r.Top+r.Bottom)/2
|
|
for _, c := range []struct {
|
|
name string
|
|
x, y int
|
|
want uintptr
|
|
}{
|
|
{"left", int(r.Left), midY, w32.HTLEFT},
|
|
{"right", int(r.Right) - 1, midY, w32.HTRIGHT},
|
|
{"bottom", midX, int(r.Bottom) - 1, w32.HTBOTTOM},
|
|
{"bottom right", int(r.Right) - 1, int(r.Bottom) - 1, w32.HTBOTTOMRIGHT},
|
|
{"top", midX, int(r.Top) + 1, w32.HTCLIENT},
|
|
} {
|
|
if got := hitAt(main, c.x, c.y); got != c.want {
|
|
t.Errorf("%s edge of the main window hits %d, want %d", c.name, got, c.want)
|
|
}
|
|
}
|
|
|
|
w32.ShowWindow(main, w32.SW_MAXIMIZE)
|
|
reframe(main)
|
|
mr, cr := w32.GetWindowRect(main), w32.GetClientRect(main)
|
|
if cr.Right-cr.Left != mr.Right-mr.Left {
|
|
t.Errorf("maximised, the page is %dpx narrower than the window: Wails fits a maximised window", (mr.Right-mr.Left)-(cr.Right-cr.Left))
|
|
}
|
|
|
|
other := framelessTestWindow(t)
|
|
reframe(other)
|
|
r = w32.GetWindowRect(other)
|
|
if got := hitAt(other, int(r.Right)-1, int(r.Top+r.Bottom)/2); got != w32.HTCLIENT {
|
|
t.Errorf("another window's right edge hits %d, want HTCLIENT as Wails made it", got)
|
|
}
|
|
}
|