Mouse scroll events are properly compressed and summed up
This commit is contained in:
parent
c57c8acba7
commit
75200a7310
@ -8,6 +8,23 @@ import "github.com/jezek/xgbutil/xevent"
|
|||||||
|
|
||||||
import "git.tebibyte.media/sashakoshka/stone"
|
import "git.tebibyte.media/sashakoshka/stone"
|
||||||
|
|
||||||
|
type scrollSum struct {
|
||||||
|
x, y int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sum *scrollSum) add (button xproto.Button) {
|
||||||
|
switch button {
|
||||||
|
case 4:
|
||||||
|
sum.y --
|
||||||
|
case 5:
|
||||||
|
sum.y ++
|
||||||
|
case 6:
|
||||||
|
sum.x --
|
||||||
|
case 7:
|
||||||
|
sum.x ++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (backend *Backend) Run () {
|
func (backend *Backend) Run () {
|
||||||
backend.callbackManager.RunStart()
|
backend.callbackManager.RunStart()
|
||||||
backend.Draw()
|
backend.Draw()
|
||||||
@ -69,16 +86,10 @@ func (backend *Backend) handleButtonPress (
|
|||||||
) {
|
) {
|
||||||
buttonEvent := *event.ButtonPressEvent
|
buttonEvent := *event.ButtonPressEvent
|
||||||
if buttonEvent.Detail >= 4 && buttonEvent.Detail <= 7 {
|
if buttonEvent.Detail >= 4 && buttonEvent.Detail <= 7 {
|
||||||
switch buttonEvent.Detail {
|
sum := scrollSum { }
|
||||||
case 4:
|
sum.add(buttonEvent.Detail)
|
||||||
backend.callbackManager.RunScroll(0, -1)
|
backend.compressScrollSum(&sum)
|
||||||
case 5:
|
backend.callbackManager.RunScroll(sum.x, sum.y)
|
||||||
backend.callbackManager.RunScroll(0, 1)
|
|
||||||
case 6:
|
|
||||||
backend.callbackManager.RunScroll(-1, 0)
|
|
||||||
case 7:
|
|
||||||
backend.callbackManager.RunScroll(1, 0)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
backend.callbackManager.RunPress(stone.Button(buttonEvent.Detail + 127))
|
backend.callbackManager.RunPress(stone.Button(buttonEvent.Detail + 127))
|
||||||
}
|
}
|
||||||
@ -170,3 +181,23 @@ func (backend *Backend) compressMotionNotify (
|
|||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (backend *Backend) compressScrollSum (sum *scrollSum) {
|
||||||
|
backend.connection.Sync()
|
||||||
|
xevent.Read(backend.connection, false)
|
||||||
|
|
||||||
|
|
||||||
|
for index, untypedEvent := range xevent.Peek(backend.connection) {
|
||||||
|
if untypedEvent.Err != nil { continue }
|
||||||
|
|
||||||
|
typedEvent, ok := untypedEvent.Event.(xproto.ButtonPressEvent)
|
||||||
|
if !ok { continue }
|
||||||
|
|
||||||
|
sum.add(typedEvent.Detail)
|
||||||
|
defer func (index int) {
|
||||||
|
xevent.DequeueAt(backend.connection, index)
|
||||||
|
} (index)
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user