Merge pull request 'Compress mouse scroll and motion events' (#4) from compress-scroll into main
Reviewed-on: #4
This commit is contained in:
commit
594d1d07be
@ -63,6 +63,12 @@ func (application *Application) OnMouseMove (
|
|||||||
application.callbackManager.onMouseMove = onMouseMove
|
application.callbackManager.onMouseMove = onMouseMove
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (application *Application) OnScroll (
|
||||||
|
onScroll func (x, y int),
|
||||||
|
) {
|
||||||
|
application.callbackManager.onScroll = onScroll
|
||||||
|
}
|
||||||
|
|
||||||
func (application *Application) OnStart (
|
func (application *Application) OnStart (
|
||||||
onStart func (),
|
onStart func (),
|
||||||
) {
|
) {
|
||||||
|
|||||||
@ -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()
|
||||||
@ -68,14 +85,22 @@ func (backend *Backend) handleButtonPress (
|
|||||||
event xevent.ButtonPressEvent,
|
event xevent.ButtonPressEvent,
|
||||||
) {
|
) {
|
||||||
buttonEvent := *event.ButtonPressEvent
|
buttonEvent := *event.ButtonPressEvent
|
||||||
|
if buttonEvent.Detail >= 4 && buttonEvent.Detail <= 7 {
|
||||||
|
sum := scrollSum { }
|
||||||
|
sum.add(buttonEvent.Detail)
|
||||||
|
backend.compressScrollSum(&sum)
|
||||||
|
backend.callbackManager.RunScroll(sum.x, sum.y)
|
||||||
|
} else {
|
||||||
backend.callbackManager.RunPress(stone.Button(buttonEvent.Detail + 127))
|
backend.callbackManager.RunPress(stone.Button(buttonEvent.Detail + 127))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (backend *Backend) handleButtonRelease (
|
func (backend *Backend) handleButtonRelease (
|
||||||
connection *xgbutil.XUtil,
|
connection *xgbutil.XUtil,
|
||||||
event xevent.ButtonReleaseEvent,
|
event xevent.ButtonReleaseEvent,
|
||||||
) {
|
) {
|
||||||
buttonEvent := *event.ButtonReleaseEvent
|
buttonEvent := *event.ButtonReleaseEvent
|
||||||
|
if buttonEvent.Detail >= 4 && buttonEvent.Detail <= 7 { return }
|
||||||
backend.callbackManager.RunRelease(stone.Button(buttonEvent.Detail + 127))
|
backend.callbackManager.RunRelease(stone.Button(buttonEvent.Detail + 127))
|
||||||
}
|
}
|
||||||
|
|
||||||