From af28c01182f95e497d3b6d8c1364af03f86c097b Mon Sep 17 00:00:00 2001 From: John Factotum <50942278+johnfactotum@users.noreply.github.com> Date: Mon, 9 Oct 2023 16:54:25 +0800 Subject: [PATCH] Bring back cursor autohiding Also change "Scrolled Layout" to "Scrolled Mode" --- ...om.github.johnfactotum.Foliate.gschema.xml | 3 ++ data/gschemas.compiled | Bin 3082 -> 3138 bytes src/book-viewer.js | 2 + src/reader/reader.js | 41 +++++++++++++++++- src/ui/book-viewer.ui | 18 +++++--- 5 files changed, 55 insertions(+), 9 deletions(-) diff --git a/data/com.github.johnfactotum.Foliate.gschema.xml b/data/com.github.johnfactotum.Foliate.gschema.xml index ba2b40de..b43ddff5 100644 --- a/data/com.github.johnfactotum.Foliate.gschema.xml +++ b/data/com.github.johnfactotum.Foliate.gschema.xml @@ -85,6 +85,9 @@ 'default' + + false + q|cLU?4@87cY~uq`RAYvHJ)WEm3LA zLly=SL240(3Pu=PC>j-oVESNU50PCc%NL8aI%nJ+ID5{V|J#}G|Gw{^%g*P{W>qUU zi(J~;Szr;7LHuM(seA*sCX3k3=8g0(q%8Okz(=eiUy6R2=*OUQ5Wg-}qz|wx75Rs& zWHA?($X1@%LF9F!FU3%G=Nu00{FY60e0X_ zckh0rD%^)d!lHuxz^XfAlk}-G;5ULJ!2Rz@ZS<+r;kTGYlQ!JUhaxsEP$yxb9oz$C zp5Mh<7}^Fu3hxzT_T)wBQ}YE=;EzC}2-GaXG}wuqynIt~gYnd?o z#)5@nunIUQYaRRpHGMz$43PP(Ge(~}1%3p46>s$eiIf2YB-KvU~=2YqVB z&w;a%{qdhm{?MmRgI^5Z21L&;w3nLkrQiT{{IF1CPSPa^!IO5>=M5I>{nniB=HxV! z#skNBQNeXU*-#-z$j}_%MtBimY`XU@eQG=W7H}JoHF1rdH#GC=g4YWq@}g#5QSevl zcwW@VD_Ool#Plrd4~=J>M_?HI8b~{weT%)L=46e7r+|^cqDAznnfeU)H;{NVHIGIN zY(>KpsZcW&2bkZE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_=<4vqmOkk9?d-Ul35^3JHAPu zNcvtJJ7L@zyA{90cZ}Jjdz-(qANu85dD2lJb1mIRjlsGvM`0BAI)ya<4^P~y2-00Q aah`PWW^yi3^J%?PE94@b%BIGY { footnoteDialog.addEventListener('click', e => e.target === footnoteDialog ? footnoteDialog.close() : null) +class CursorAutohider { + #timeout + #el + #check + #state + constructor(el, check, state = {}) { + this.#el = el + this.#check = check + this.#state = state + if (this.#state.hidden) this.hide() + this.#el.addEventListener('mousemove', ({ screenX, screenY }) => { + // check if it actually moved + if (screenX === this.#state.x && screenY === this.#state.y) return + this.#state.x = screenX, this.#state.y = screenY + this.show() + if (this.#timeout) clearTimeout(this.#timeout) + if (check()) this.#timeout = setTimeout(this.hide.bind(this), 1000) + }, false) + } + cloneFor(el) { + return new CursorAutohider(el, this.#check, this.#state) + } + hide() { + this.#el.style.cursor = 'none' + this.#state.hidden = true + } + show() { + this.#el.style.cursor = 'auto' + this.#state.hidden = false + } +} + class Reader { - #tocView + autohideCursor + #cursorAutohider = new CursorAutohider( + document.documentElement, () => this.autohideCursor) style = { spacing: 1.4, justify: true, @@ -338,7 +372,7 @@ class Reader { await this.view.open(this.book) document.body.append(this.view) } - setAppearance({ style, layout }) { + setAppearance({ style, layout, autohideCursor }) { Object.assign(this.style, style) const { theme } = style const $style = document.documentElement.style @@ -356,6 +390,7 @@ class Reader { renderer.setStyles?.(getCSS(this.style)) } document.body.classList.toggle('invert', this.style.invert) + this.autohideCursor = autohideCursor } #handleEvents() { this.view.addEventListener('relocate', e => { @@ -452,6 +487,8 @@ class Reader { if (selRange.compareBoundaryPoints(Range.END_TO_END, lastLocation.range) >= 0) this.view.next() }, 1000)) + + this.#cursorAutohider.cloneFor(doc.documentElement) } #showAnnotation({ index, range, value, pos }) { globalThis.showSelection({ type: 'annotation', value, pos }) diff --git a/src/ui/book-viewer.ui b/src/ui/book-viewer.ui index 966f35f3..1ccd7f61 100644 --- a/src/ui/book-viewer.ui +++ b/src/ui/book-viewer.ui @@ -85,18 +85,22 @@
- Invert Colors in Dark Mode - view.invert + Font & Layout Settings + viewer.preferences +
+
- Scrolled Layout + Scrolled Mode view.scrolled -
-
- Font & Layout Settings - viewer.preferences + Invert Colors in Dark Mode + view.invert + + + Autohide Cursor + view.autohide-cursor