From c57c8acba77560c389e0bafa512170340b2da1f9 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Thu, 17 Nov 2022 19:11:49 -0500 Subject: [PATCH] Changed the API for scrolling --- application.go | 6 ++++++ backends/x/event.go | 16 +++++++++++++++- event.go | 6 ++++++ input.go | 4 ---- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/application.go b/application.go index a97ccd3..4929cc7 100644 --- a/application.go +++ b/application.go @@ -63,6 +63,12 @@ func (application *Application) OnMouseMove ( application.callbackManager.onMouseMove = onMouseMove } +func (application *Application) OnScroll ( + onScroll func (x, y int), +) { + application.callbackManager.onScroll = onScroll +} + func (application *Application) OnStart ( onStart func (), ) { diff --git a/backends/x/event.go b/backends/x/event.go index 3631ca6..17726f4 100644 --- a/backends/x/event.go +++ b/backends/x/event.go @@ -68,7 +68,20 @@ func (backend *Backend) handleButtonPress ( event xevent.ButtonPressEvent, ) { buttonEvent := *event.ButtonPressEvent - backend.callbackManager.RunPress(stone.Button(buttonEvent.Detail + 127)) + if buttonEvent.Detail >= 4 && buttonEvent.Detail <= 7 { + switch buttonEvent.Detail { + case 4: + backend.callbackManager.RunScroll(0, -1) + case 5: + backend.callbackManager.RunScroll(0, 1) + case 6: + backend.callbackManager.RunScroll(-1, 0) + case 7: + backend.callbackManager.RunScroll(1, 0) + } + } else { + backend.callbackManager.RunPress(stone.Button(buttonEvent.Detail + 127)) + } } func (backend *Backend) handleButtonRelease ( @@ -76,6 +89,7 @@ func (backend *Backend) handleButtonRelease ( event xevent.ButtonReleaseEvent, ) { buttonEvent := *event.ButtonReleaseEvent + if buttonEvent.Detail >= 4 && buttonEvent.Detail <= 7 { return } backend.callbackManager.RunRelease(stone.Button(buttonEvent.Detail + 127)) } diff --git a/event.go b/event.go index 1032e32..edbaf2c 100644 --- a/event.go +++ b/event.go @@ -6,6 +6,7 @@ type CallbackManager struct { onRelease func (button Button) onResize func () onMouseMove func (x, y int) + onScroll func (x, y int) onStart func () } @@ -34,6 +35,11 @@ func (manager *CallbackManager) RunMouseMove (x, y int) { manager.onMouseMove(x, y) } +func (manager *CallbackManager) RunScroll (x, y int) { + if manager.onScroll == nil { return } + manager.onScroll(x, y) +} + func (manager *CallbackManager) RunStart () { if manager.onStart == nil { return } manager.onStart() diff --git a/input.go b/input.go index 570d35d..e3aba82 100644 --- a/input.go +++ b/input.go @@ -52,10 +52,6 @@ const ( MouseButtonLeft Button = MouseButton1 MouseButtonMiddle Button = MouseButton2 MouseButtonRight Button = MouseButton3 - MouseButtonScrollUp Button = MouseButton4 - MouseButtonScrollDown Button = MouseButton5 - MouseButtonScrollLeft Button = MouseButton6 - MouseButtonScrollRight Button = MouseButton7 MouseButtonBack Button = MouseButton8 MouseButtonForward Button = MouseButton9