better cursor capture

This commit is contained in:
KingKDot
2026-03-06 19:11:39 -06:00
parent c0580c559f
commit 1577493853
@@ -612,6 +612,7 @@ type duplicationState struct {
lastFrame *image.RGBA lastFrame *image.RGBA
lastFrameAt time.Time lastFrameAt time.Time
lastFail time.Time lastFail time.Time
cursorScratch *image.RGBA
} }
func SetDesktopDuplication(enabled bool) { func SetDesktopDuplication(enabled bool) {
@@ -673,6 +674,7 @@ func (s *duplicationState) closeLocked() {
s.lastBase = nil s.lastBase = nil
s.lastFrame = nil s.lastFrame = nil
s.lastFrameAt = time.Time{} s.lastFrameAt = time.Time{}
s.cursorScratch = nil
} }
func (s *duplicationState) capture(display int) (*image.RGBA, error) { func (s *duplicationState) capture(display int) (*image.RGBA, error) {
@@ -767,7 +769,8 @@ func (s *duplicationState) composeFrame(base *image.RGBA) *image.RGBA {
img := base img := base
if withCursor { if withCursor {
img = cloneRGBA(base) img = s.ensureCursorScratch(base.Rect)
copy(img.Pix, base.Pix)
} }
bounds := s.bounds bounds := s.bounds
if bounds.Dx() != int(s.desc.ModeDesc.Width) || bounds.Dy() != int(s.desc.ModeDesc.Height) { if bounds.Dx() != int(s.desc.ModeDesc.Width) || bounds.Dy() != int(s.desc.ModeDesc.Height) {
@@ -787,6 +790,13 @@ func (s *duplicationState) composeFrame(base *image.RGBA) *image.RGBA {
return img return img
} }
func (s *duplicationState) ensureCursorScratch(rect image.Rectangle) *image.RGBA {
if s.cursorScratch == nil || s.cursorScratch.Rect != rect {
s.cursorScratch = image.NewRGBA(rect)
}
return s.cursorScratch
}
func cloneRGBA(src *image.RGBA) *image.RGBA { func cloneRGBA(src *image.RGBA) *image.RGBA {
if src == nil { if src == nil {
return nil return nil