Compress motion notify events

This commit is contained in:
Sasha Koshka 2022-11-17 19:01:16 -05:00
parent 19b744250f
commit 43696543d8
1 changed files with 25 additions and 1 deletions

View File

@ -101,7 +101,7 @@ func (backend *Backend) handleMotionNotify (
connection *xgbutil.XUtil,
event xevent.MotionNotifyEvent,
) {
motionEvent := *event.MotionNotifyEvent
motionEvent := backend.compressMotionNotify(*event.MotionNotifyEvent)
x, y := backend.cellAt (image.Point {
X: int(motionEvent.EventX),
Y: int(motionEvent.EventY),
@ -132,3 +132,27 @@ func (backend *Backend) compressConfigureNotify (
return
}
func (backend *Backend) compressMotionNotify (
firstEvent xproto.MotionNotifyEvent,
) (
lastEvent xproto.MotionNotifyEvent,
) {
backend.connection.Sync()
xevent.Read(backend.connection, false)
lastEvent = firstEvent
for index, untypedEvent := range xevent.Peek(backend.connection) {
if untypedEvent.Err != nil { continue }
typedEvent, ok := untypedEvent.Event.(xproto.MotionNotifyEvent)
if !ok { continue }
lastEvent = typedEvent
defer func (index int) {
xevent.DequeueAt(backend.connection, index)
} (index)
}
return
}