mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
app: support horizontal scrolling on Windows and Linux
Fixes #181. Signed-off-by: pierre <pierre.curto@gmail.com>
This commit is contained in:
@@ -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(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user