Compress mouse scroll and motion events #4

Merged
sashakoshka merged 3 commits from compress-scroll into main 2022-11-17 18:32:35 -07:00
Showing only changes of commit 43696543d8 - Show all commits

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
}