Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog.d/452-boot-cover-drag.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
开机时快速拖动模拟器窗口,开机画面能更快跟上窗口
The boot screen follows the emulator window more closely during fast drags
26 changes: 26 additions & 0 deletions internal/win/boot_input_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
64 changes: 49 additions & 15 deletions internal/win/cover_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,24 +360,26 @@ 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 {
input bootInput
hwnd uintptr
owner uintptr
rect Rect
inset int32 // title strip excluded from the main cover's client rectangle
shown bool
main bool
canvas Canvas
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
}
}
}

Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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) {
Expand Down
Loading