From 43696543d84276139215db7c7617936d8f3b6ab7 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Thu, 17 Nov 2022 19:01:16 -0500 Subject: [PATCH] Compress motion notify events --- backends/x/event.go | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) 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 +}