Files
antidrift/internal/evidence/foreground_tracker.go
T
2026-06-02 12:23:54 -04:00

24 lines
903 B
Go

package evidence
// foregroundTracker remembers the last observed foreground window so the
// Windows polling Source emits only on change. hwnd is held as uintptr so this
// file stays platform-neutral (it must build and test on Linux).
type foregroundTracker struct {
primed bool
available bool
hwnd uintptr
title string
}
// changed reports whether (available, hwnd, title) differs from the last
// observation and records the new values. The first call always returns true.
// Callers pass the zero values (hwnd 0, title "") when available is false, so a
// steady "no foreground window" run does not re-emit.
func (t *foregroundTracker) changed(available bool, hwnd uintptr, title string) bool {
if t.primed && available == t.available && hwnd == t.hwnd && title == t.title {
return false
}
t.primed, t.available, t.hwnd, t.title = true, available, hwnd, title
return true
}