From 9fde847cdd55dfe4f190f347fbb52004a882b7b3 Mon Sep 17 00:00:00 2001 From: luo-luo-o <129922074+luo-luo-o@users.noreply.github.com> Date: Sat, 5 Dec 2026 20:15:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E6=9C=BA=E9=81=AE=E7=BD=A9=E8=B7=9F?= =?UTF-8?q?=E9=9A=8F=E6=8B=96=E5=8A=A8=E7=9A=84=E7=AE=A1=E7=90=86=E5=99=A8?= =?UTF-8?q?=E5=8E=9F=E5=9E=8B=EF=BC=88#452=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog.d/452-boot-cover-drag.fix.md | 2 + internal/win/boot_input_windows_test.go | 26 ++++++++++ internal/win/cover_windows.go | 64 +++++++++++++++++++------ 3 files changed, 77 insertions(+), 15 deletions(-) create mode 100644 changelog.d/452-boot-cover-drag.fix.md diff --git a/changelog.d/452-boot-cover-drag.fix.md b/changelog.d/452-boot-cover-drag.fix.md new file mode 100644 index 00000000..244874d6 --- /dev/null +++ b/changelog.d/452-boot-cover-drag.fix.md @@ -0,0 +1,2 @@ +开机时快速拖动模拟器窗口,开机画面能更快跟上窗口 +The boot screen follows the emulator window more closely during fast drags diff --git a/internal/win/boot_input_windows_test.go b/internal/win/boot_input_windows_test.go index d7b4ee69..3d0d622b 100644 --- a/internal/win/boot_input_windows_test.go +++ b/internal/win/boot_input_windows_test.go @@ -5,8 +5,34 @@ package win import ( "testing" "unsafe" + + "modavd/internal/win/wintest" ) +// During a drag the next full Sync may still be queued. The location event +// alone must translate the live cover and keep the exposed title strip. +func TestBootCoverFollowsDragBeforeQueuedSync(t *testing.T) { + f := startFakeEmulator(t) + h := startOverlay(t, OverlayOptions{}) + const inset = 32 + h.on(func(o *Overlay) { + procSetPropW.Call(f.Main, uintptr(unsafe.Pointer(bootContentTop)), inset+1) + o.Sync(specsFor(f)) + hwnd := o.CoverOf(f.Main) + procSetPropW.Call(f.Main, uintptr(unsafe.Pointer(bootCoverAccepted)), hwnd) + o.Sync(specsFor(f)) + for _, dx := range []int{180, -40, 260} { + f.Move(wintest.X+dx, wintest.Y-dx, 640, 400) + winEventProc(0, eventObjectLocation, f.Main, objidWindow, 0, 0, 0) + want := GeometryOf(f.Main).Client + want.Top += inset + if got := GeometryOf(hwnd).Frame; got != want { + t.Errorf("drag by %d: cover %v, want %v before the queued sync", dx, got, want) + } + } + }) +} + func TestBootCoverWaitsForGuestInputBeforeExposingTitleBar(t *testing.T) { f := startFakeEmulator(t) set := func(hwnd uintptr, key *uint16, value uintptr) { diff --git a/internal/win/cover_windows.go b/internal/win/cover_windows.go index 5f669dd7..eaa6457f 100644 --- a/internal/win/cover_windows.go +++ b/internal/win/cover_windows.go @@ -360,17 +360,18 @@ type OverlayOptions struct { // Overlay is the running set of covers. Methods marked "any goroutine" may be called from anywhere, the others only // from the overlay's own functions. type Overlay struct { - header bootHeader - opt OverlayOptions - ctl uintptr - covers map[uintptr]*cover - calls chan func() - done chan struct{} - hooks []uintptr - quit atomic.Bool - pass bool // the covers only show (SetPassThrough) - alpha uint8 // how opaque they are while they only show (SetAlpha) - alphaSet bool + header bootHeader + opt OverlayOptions + ctl uintptr + covers map[uintptr]*cover + calls chan func() + done chan struct{} + hooks []uintptr + wakePending bool // a full scan is already queued on the window thread + quit atomic.Bool + pass bool // the covers only show (SetPassThrough) + alpha uint8 // how opaque they are while they only show (SetAlpha) + alphaSet bool } type cover struct { @@ -378,6 +379,7 @@ type cover struct { hwnd uintptr owner uintptr rect Rect + inset int32 // title strip excluded from the main cover's client rectangle shown bool main bool canvas Canvas @@ -578,6 +580,7 @@ func insertAfterFor(owner uintptr) (after uintptr, topmost bool) { // never activating anything, so nothing is covered for a moment that should not be): nothing is called when the cover is // already as it should be. func (o *Overlay) place(c *cover, s CoverSpec, w, h int) { + resized := w != c.rect.Width() || h != c.rect.Height() rectChanged := s.Rect != c.rect && w > 0 && h > 0 if !s.Show { flags := uintptr(swpNoActivate | swpNoZOrder) @@ -592,7 +595,9 @@ func (o *Overlay) place(c *cover, s CoverSpec, w, h int) { c.shown = false if rectChanged { c.rect = s.Rect - procInvalidateRect.Call(c.hwnd, 0, 0) + if resized { + procInvalidateRect.Call(c.hwnd, 0, 0) + } } } return @@ -618,7 +623,9 @@ func (o *Overlay) place(c *cover, s CoverSpec, w, h int) { c.shown = true if rectChanged { c.rect = s.Rect - procInvalidateRect.Call(c.hwnd, 0, 0) + if resized { + procInvalidateRect.Call(c.hwnd, 0, 0) + } } } @@ -673,11 +680,13 @@ func (o *Overlay) Sync(specs []CoverSpec) { o.covers[s.Owner] = c } c.main = s.Main + c.inset = 0 if s.Main && s.Owner != 0 { top := windowProperty(s.Owner, bootContentTop) c.requestBootInput(top != 0 && !o.pass) if top != 0 && top-1 <= uintptr(max(s.Rect.Height(), 0)) && (c.input.accepted || o.pass) { - s.Rect.Top += int32(top - 1) + c.inset = int32(top - 1) + s.Rect.Top += c.inset if c.input.accepted && s.Show { o.header.remember(s.Owner, int32(top-1)) } @@ -755,6 +764,7 @@ func ctlProc(hwnd, msg, wparam, lparam uintptr) uintptr { } return 0 case wmCoverWake: + o.wakePending = false if o.opt.Wake != nil && !o.quit.Load() { o.opt.Wake(o) } @@ -788,10 +798,34 @@ func winEventProc(_, event, hwnd, idObject, _, _, _ uintptr) uintptr { if o == nil || o.ctl == 0 || (idObject != objidWindow && uint32(event) != eventSystemMinStart && uint32(event) != eventSystemMinEnd) { return 0 } - procPostMessageW.Call(o.ctl, wmCoverWake, 0, 0) + // Out-of-context hooks run on the overlay thread. Move the existing bitmap + // before waiting for another message, enumerating windows or repainting. + if event == eventObjectLocation { + if c := o.covers[hwnd]; c != nil && c.shown && c.main { + c.followMove() + } + } + if !o.wakePending { + ok, _, _ := procPostMessageW.Call(o.ctl, wmCoverWake, 0, 0) + o.wakePending = ok != 0 + } return 0 } +func (c *cover) followMove() { + g := GeometryOf(c.owner) + r := g.Client + r.Top += c.inset + if !g.Visible || g.Minimized || r == c.rect || r.Width() != c.rect.Width() || r.Height() != c.rect.Height() { + return // Sync handles visibility, DPI and size changes. + } + ok, _, _ := procSetWindowPos.Call(c.hwnd, 0, uintptr(r.Left), uintptr(r.Top), 0, 0, + swpNoActivate|swpNoSize|swpNoZOrder) + if ok != 0 { + c.rect = r + } +} + func coverProc(hwnd, msg, wparam, lparam uintptr) uintptr { o := overlayCur.Load() switch uint32(msg) {