Skip to content

Commit

Permalink
Make touchscreen/touchpad gesture 1-to-1
Browse files Browse the repository at this point in the history
For the reflowable renderer only. This breaks gestures for fixed-layout.

Fixes #862
  • Loading branch information
johnfactotum committed May 26, 2023
1 parent d4b1d22 commit d3619e7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
33 changes: 14 additions & 19 deletions src/book-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ GObject.registerClass({
.catch(e => console.error(e)),
}))

// handle scroll and swipe events
// handle scroll events
let isDiscrete = true, dxLast, dyLast
const scrollPageAsync = utils.debounce((dx, dy) => {
if (Math.abs(dx) > Math.abs(dy)) {
if (dx > 0) return this.goRight()
Expand All @@ -266,30 +267,24 @@ GObject.registerClass({
this.#webView.add_controller(utils.connect(new Gtk.EventControllerScroll({
flags: Gtk.EventControllerScrollFlags.BOTH_AXES,
}), {
'scroll-begin': () => isDiscrete = false,
'scroll': (_, dx, dy) => {
if (this.#pinchFactor > 1) return false
if (this.viewSettings.scrolled) return false
scrollPageAsync(dx, dy)
return true
},
}))
this.add_controller(utils.connect(new Gtk.GestureSwipe({
propagation_phase: Gtk.PropagationPhase.CAPTURE,
touch_only: true,
}), {
'swipe': (_, vx, vy) => {
if (this.#pinchFactor > 1) return false
if (Math.max(Math.abs(vx), Math.abs(vy)) < 200) return false
if (this.viewSettings.scrolled) return false
if (Math.abs(vx) > Math.abs(vy)) {
if (vx > 0) return this.goLeft()
else if (vx < 0) return this.goRight()
} else {
if (vy > 0) return this.prev()
else if (vy < 0) return this.next()
if (isDiscrete) scrollPageAsync(dx, dy)
else {
dxLast = dx
dyLast = dy
this.#exec('reader.scrollBy', [dx, dy])
}
return true
},
'scroll-end': () => {
if (dxLast != null) this.#exec('reader.snap', [dxLast, dyLast])
isDiscrete = false
dxLast = null
dyLast = null
},
}))

const applyStyle = () => this.#applyStyle().catch(e => console.error(e))
Expand Down
2 changes: 1 addition & 1 deletion src/foliate-js
Submodule foliate-js updated 2 files
+103 −27 paginator.js
+2 −0 view.js
9 changes: 9 additions & 0 deletions src/reader/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,15 @@ class Reader {
return null
}
}

// wrap these renderer methods
// because `FoliateWebView.exec()` can only pass one argument
scrollBy([x, y]) {
return this.view.renderer.scrollBy?.(x, y)
}
snap([x, y]) {
return this.view.renderer.snap?.(x, y)
}
}

globalThis.init = () => document.getElementById('file-input').click()
Expand Down

0 comments on commit d3619e7

Please sign in to comment.