~eliasnaur/gio

e188d0e6ffb269ccbc83bcee16c3786c3503d349 — Gordon Klaus a month ago 275a91f
io/pointer,gesture,app/internal/window: add pointer.Scroll event type

Signed-off-by: Gordon Klaus <gordon.klaus@gmail.com>
M app/internal/window/gl_macos.m => app/internal/window/gl_macos.m +1 -1
@@ 73,7 73,7 @@ static void handleMouse(NSView *view, NSEvent *event, int typ, CGFloat dx, CGFlo
- (void)scrollWheel:(NSEvent *)event {
	CGFloat dx = -event.scrollingDeltaX;
	CGFloat dy = -event.scrollingDeltaY;
	handleMouse(self, event, GIO_MOUSE_MOVE, dx, dy);
	handleMouse(self, event, GIO_MOUSE_SCROLL, dx, dy);
}
- (void)keyDown:(NSEvent *)event {
	NSString *keys = [event charactersIgnoringModifiers];

M app/internal/window/os_js.go => app/internal/window/os_js.go +1 -1
@@ 146,7 146,7 @@ func (w *window) addEventListeners() {
			dx *= 120
			dy *= 120
		}
		w.pointerEvent(pointer.Move, float32(dx), float32(dy), e)
		w.pointerEvent(pointer.Scroll, float32(dx), float32(dy), e)
		return nil
	})
	w.addEventListener(w.cnv, "touchstart", func(this js.Value, args []js.Value) interface{} {

M app/internal/window/os_macos.go => app/internal/window/os_macos.go +3 -0
@@ 30,6 30,7 @@ import (
#define GIO_MOUSE_MOVE 1
#define GIO_MOUSE_UP 2
#define GIO_MOUSE_DOWN 3
#define GIO_MOUSE_SCROLL 4

__attribute__ ((visibility ("hidden"))) void gio_main(CFTypeRef viewRef, const char *title, CGFloat width, CGFloat height);
__attribute__ ((visibility ("hidden"))) CGFloat gio_viewWidth(CFTypeRef viewRef);


@@ 160,6 161,8 @@ func gio_onMouse(view C.CFTypeRef, cdir C.int, cbtns C.NSUInteger, x, y, dx, dy 
		typ = pointer.Release
	case C.GIO_MOUSE_DOWN:
		typ = pointer.Press
	case C.GIO_MOUSE_SCROLL:
		typ = pointer.Scroll
	default:
		panic("invalid direction")
	}

M app/internal/window/os_wayland.go => app/internal/window/os_wayland.go +1 -1
@@ 1293,7 1293,7 @@ func (w *window) flushScroll() {
		return
	}
	w.w.Event(pointer.Event{
		Type:      pointer.Move,
		Type:      pointer.Scroll,
		Source:    pointer.Mouse,
		Buttons:   w.pointerBtns,
		Position:  w.lastPos,

M app/internal/window/os_windows.go => app/internal/window/os_windows.go +1 -1
@@ 278,7 278,7 @@ func (w *window) scrollEvent(wParam, lParam uintptr) {
	p := f32.Point{X: float32(np.X), Y: float32(np.Y)}
	dist := float32(int16(wParam >> 16))
	w.w.Event(pointer.Event{
		Type:     pointer.Move,
		Type:     pointer.Scroll,
		Source:   pointer.Mouse,
		Position: p,
		Buttons:  w.pointerBtns,

M app/internal/window/os_x11.go => app/internal/window/os_x11.go +2 -2
@@ 310,11 310,11 @@ func (h *x11EventHandler) handleEvents() bool {
				btn = pointer.ButtonRight
			case C.Button4:
				// scroll up
				ev.Type = pointer.Move
				ev.Type = pointer.Scroll
				ev.Scroll.Y = -scrollScale
			case C.Button5:
				// scroll down
				ev.Type = pointer.Move
				ev.Type = pointer.Scroll
				ev.Scroll.Y = +scrollScale
			default:
				continue

M gesture/gesture.go => gesture/gesture.go +2 -3
@@ 217,8 217,7 @@ func (s *Scroll) Scroll(cfg unit.Converter, q event.Queue, t time.Time, axis Axi
		case pointer.Cancel:
			s.dragging = false
			s.grab = false
		case pointer.Move:
			// Scroll
		case pointer.Scroll:
			switch s.axis {
			case Horizontal:
				s.scroll += e.Scroll.X


@@ 228,10 227,10 @@ func (s *Scroll) Scroll(cfg unit.Converter, q event.Queue, t time.Time, axis Axi
			iscroll := int(s.scroll)
			s.scroll -= float32(iscroll)
			total += iscroll
		case pointer.Move:
			if !s.dragging || s.pid != e.PointerID {
				continue
			}
			// Drag
			val := s.val(e.Position)
			s.estimator.Sample(e.Time, val)
			v := int(math.Round(float64(val)))

M io/pointer/pointer.go => io/pointer/pointer.go +4 -0
@@ 94,6 94,8 @@ const (
	Enter
	// Pointer leaves an area watching for pointer input
	Leave
	// Scroll of a pointer.
	Scroll
)

const (


@@ 179,6 181,8 @@ func (t Type) String() string {
		return "Enter"
	case Leave:
		return "Leave"
	case Scroll:
		return "Scroll"
	default:
		panic("unknown Type")
	}