forked from joejulian/gio
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:
@@ -236,6 +236,10 @@ func (w *window) addEventListeners() {
|
||||
w.addEventListener(w.cnv, "wheel", func(this js.Value, args []js.Value) interface{} {
|
||||
e := args[0]
|
||||
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()
|
||||
switch mode {
|
||||
case 0x01: // DOM_DELTA_LINE
|
||||
|
||||
+12
-2
@@ -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:
|
||||
w.scroll.dist.X += v
|
||||
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:
|
||||
w.scroll.steps.X += int(discrete)
|
||||
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
@@ -531,7 +531,12 @@ func (w *window) scrollEvent(wParam, lParam uintptr, horizontal bool, kmods key.
|
||||
if horizontal {
|
||||
sp.X = dist
|
||||
} 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{
|
||||
Type: pointer.Scroll,
|
||||
|
||||
+13
-5
@@ -569,16 +569,24 @@ func (h *x11EventHandler) handleEvents() bool {
|
||||
case C.Button3:
|
||||
btn = pointer.ButtonSecondary
|
||||
case C.Button4:
|
||||
// scroll up
|
||||
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:
|
||||
// scroll down
|
||||
// scroll down or right (if shift is pressed).
|
||||
ev.Type = pointer.Scroll
|
||||
ev.Scroll.Y = +scrollScale
|
||||
if ev.Modifiers == key.ModShift {
|
||||
ev.Scroll.X = +scrollScale
|
||||
} else {
|
||||
ev.Scroll.Y = +scrollScale
|
||||
}
|
||||
case 6:
|
||||
// http://xahlee.info/linux/linux_x11_mouse_button_number.html
|
||||
// scroll left
|
||||
// scroll left.
|
||||
ev.Type = pointer.Scroll
|
||||
ev.Scroll.X = -scrollScale * 2
|
||||
case 7:
|
||||
|
||||
Reference in New Issue
Block a user