~eliasnaur/gio-patches

gio: app: support horizontal scrolling on Windows and Linux v1 PROPOSED

~pierrec
~pierrec: 1
 app: support horizontal scrolling on Windows and Linux

 3 files changed, 19 insertions(+), 3 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~eliasnaur/gio-patches/patches/15327/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH gio] app: support horizontal scrolling on Windows and Linux Export this patch

~pierrec
From: Pierre Curto <pierre.curto@gmail.com>

Fixes #181.

Signed-off-by: pierre <pierre.curto@gmail.com>
---
 app/internal/window/os_windows.go | 12 +++++++++---
 app/internal/window/os_x11.go     |  9 +++++++++
 app/internal/windows/windows.go   |  1 +
 3 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/app/internal/window/os_windows.go b/app/internal/window/os_windows.go
index f6504cd..2a38d53 100644
--- a/app/internal/window/os_windows.go
+++ b/app/internal/window/os_windows.go
@@ -271,7 +271,9 @@ func windowProc(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr
			Time:     windows.GetMessageTime(),
		})
	case windows.WM_MOUSEWHEEL:
		w.scrollEvent(wParam, lParam)
		w.scrollEvent(wParam, lParam, false)
	case windows.WM_MOUSEHWHEEL:
		w.scrollEvent(wParam, lParam, true)
	case windows.WM_DESTROY:
		windows.PostQuitMessage(0)
	case windows.WM_PAINT:
@@ -352,7 +354,7 @@ func coordsFromlParam(lParam uintptr) (int, int) {
	return x, y
}

func (w *window) scrollEvent(wParam, lParam uintptr) {
func (w *window) scrollEvent(wParam, lParam uintptr, horizontal bool) {
	x, y := coordsFromlParam(lParam)
	// The WM_MOUSEWHEEL coordinates are in screen coordinates, in contrast
	// to other mouse events.
@@ -360,12 +362,16 @@ func (w *window) scrollEvent(wParam, lParam uintptr) {
	windows.ScreenToClient(w.hwnd, &np)
	p := f32.Point{X: float32(np.X), Y: float32(np.Y)}
	dist := float32(int16(wParam >> 16))
	sp := f32.Point{Y: -dist}
	if horizontal {
		sp.X, sp.Y = sp.Y, sp.X
	}
	w.w.Event(pointer.Event{
		Type:     pointer.Scroll,
		Source:   pointer.Mouse,
		Position: p,
		Buttons:  w.pointerBtns,
		Scroll:   f32.Point{Y: -dist},
		Scroll:   sp,
		Time:     windows.GetMessageTime(),
	})
}
diff --git a/app/internal/window/os_x11.go b/app/internal/window/os_x11.go
index 17bdd5a..413a959 100644
--- a/app/internal/window/os_x11.go
+++ b/app/internal/window/os_x11.go
@@ -346,6 +346,15 @@ func (h *x11EventHandler) handleEvents() bool {
				// scroll down
				ev.Type = pointer.Scroll
				ev.Scroll.Y = +scrollScale
			case 6:
				// http://xahlee.info/linux/linux_x11_mouse_button_number.html
				// scroll left
				ev.Type = pointer.Scroll
				ev.Scroll.X = -scrollScale * 2
			case 7:
				// scroll right
				ev.Type = pointer.Scroll
				ev.Scroll.X = +scrollScale * 2
			default:
				continue
			}
diff --git a/app/internal/windows/windows.go b/app/internal/windows/windows.go
index 29e7f99..21b1858 100644
--- a/app/internal/windows/windows.go
+++ b/app/internal/windows/windows.go
@@ -142,6 +142,7 @@ const (
	WM_MBUTTONUP     = 0x0208
	WM_MOUSEMOVE     = 0x0200
	WM_MOUSEWHEEL    = 0x020A
	WM_MOUSEHWHEEL   = 0x020E
	WM_PAINT         = 0x000F
	WM_CLOSE         = 0x0010
	WM_QUIT          = 0x0012
-- 
2.26.2
Thanks, applied.

Elias