app: [linux,windows,wasm] scroll horizontally when shift key is pressed

Adds support for horizontal scroll using mousewheel with a shift key.
Support is added for windows, linux (wayland and x11), js (wasm).

Fixes: https://todo.sr.ht/~eliasnaur/gio/398
Signed-off-by: Mearaj <mearajbhagad@gmail.com>
This commit is contained in:
Mearaj
2023-05-04 02:44:24 +05:30
committed by Elias Naur
parent 59695984e5
commit febadd3145
4 changed files with 35 additions and 8 deletions
+4
View File
@@ -236,6 +236,10 @@ func (w *window) addEventListeners() {
w.addEventListener(w.cnv, "wheel", func(this js.Value, args []js.Value) interface{} { w.addEventListener(w.cnv, "wheel", func(this js.Value, args []js.Value) interface{} {
e := args[0] e := args[0]
dx, dy := e.Get("deltaX").Float(), e.Get("deltaY").Float() dx, dy := e.Get("deltaX").Float(), e.Get("deltaY").Float()
// horizontal scroll if shift is pressed.
if e.Get("shiftKey").Bool() {
dx, dy = dy, dx
}
mode := e.Get("deltaMode").Int() mode := e.Get("deltaMode").Int()
switch mode { switch mode {
case 0x01: // DOM_DELTA_LINE case 0x01: // DOM_DELTA_LINE
+12 -2
View File
@@ -953,7 +953,12 @@ func gio_onPointerAxis(data unsafe.Pointer, p *C.struct_wl_pointer, t, axis C.ui
case C.WL_POINTER_AXIS_HORIZONTAL_SCROLL: case C.WL_POINTER_AXIS_HORIZONTAL_SCROLL:
w.scroll.dist.X += v w.scroll.dist.X += v
case C.WL_POINTER_AXIS_VERTICAL_SCROLL: case C.WL_POINTER_AXIS_VERTICAL_SCROLL:
w.scroll.dist.Y += v // horizontal scroll if shift + mousewheel(up/down) pressed.
if w.disp.xkb.Modifiers() == key.ModShift {
w.scroll.dist.X += v
} else {
w.scroll.dist.Y += v
}
} }
} }
@@ -1003,7 +1008,12 @@ func gio_onPointerAxisDiscrete(data unsafe.Pointer, p *C.struct_wl_pointer, axis
case C.WL_POINTER_AXIS_HORIZONTAL_SCROLL: case C.WL_POINTER_AXIS_HORIZONTAL_SCROLL:
w.scroll.steps.X += int(discrete) w.scroll.steps.X += int(discrete)
case C.WL_POINTER_AXIS_VERTICAL_SCROLL: case C.WL_POINTER_AXIS_VERTICAL_SCROLL:
w.scroll.steps.Y += int(discrete) // horizontal scroll if shift + mousewheel(up/down) pressed.
if w.disp.xkb.Modifiers() == key.ModShift {
w.scroll.steps.X += int(discrete)
} else {
w.scroll.steps.Y += int(discrete)
}
} }
} }
+6 -1
View File
@@ -531,7 +531,12 @@ func (w *window) scrollEvent(wParam, lParam uintptr, horizontal bool, kmods key.
if horizontal { if horizontal {
sp.X = dist sp.X = dist
} else { } else {
sp.Y = -dist // support horizontal scroll (shift + mousewheel)
if kmods == key.ModShift {
sp.X = -dist
} else {
sp.Y = -dist
}
} }
w.w.Event(pointer.Event{ w.w.Event(pointer.Event{
Type: pointer.Scroll, Type: pointer.Scroll,
+13 -5
View File
@@ -569,16 +569,24 @@ func (h *x11EventHandler) handleEvents() bool {
case C.Button3: case C.Button3:
btn = pointer.ButtonSecondary btn = pointer.ButtonSecondary
case C.Button4: case C.Button4:
// scroll up
ev.Type = pointer.Scroll ev.Type = pointer.Scroll
ev.Scroll.Y = -scrollScale // scroll up or left (if shift is pressed).
if ev.Modifiers == key.ModShift {
ev.Scroll.X = -scrollScale
} else {
ev.Scroll.Y = -scrollScale
}
case C.Button5: case C.Button5:
// scroll down // scroll down or right (if shift is pressed).
ev.Type = pointer.Scroll ev.Type = pointer.Scroll
ev.Scroll.Y = +scrollScale if ev.Modifiers == key.ModShift {
ev.Scroll.X = +scrollScale
} else {
ev.Scroll.Y = +scrollScale
}
case 6: case 6:
// http://xahlee.info/linux/linux_x11_mouse_button_number.html // http://xahlee.info/linux/linux_x11_mouse_button_number.html
// scroll left // scroll left.
ev.Type = pointer.Scroll ev.Type = pointer.Scroll
ev.Scroll.X = -scrollScale * 2 ev.Scroll.X = -scrollScale * 2
case 7: case 7: