diff --git a/backends/x/event.go b/backends/x/event.go index 7a49f26..3631ca6 100644 --- a/backends/x/event.go +++ b/backends/x/event.go @@ -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 +}