Commit Graph

919 Commits (master)

Author SHA1 Message Date
Borys Lykah 9b2201a438
Initial hotpluggable keyboard handling (#9540)
* Added a new plugin external-keyboard. It listens to USB events. When keyboard is plugged in or plugged out, it updates device and input configuration accordingly.
* Added new fake events UsbDevicePlugIn and UsbDevicePlugOut that are emitted when a device is connected to a book reader that plays the role of USB host. The usage of the existing events UsbPlugIn and UsbPlugOut has not changed - they are used when a reader is connected to a host. The koreader-base has a related PR for those events.
* Did a small refactoring of initialization for the modules FocusManager and InputText. They check device keyboard capabilities on their when the module is first loaded and store it. Some of the initialization code has been extracted into functions, so that we can re-initialize them when keyboard is (dis)connected.
* Initial implementation centered around text input, and tested with USB keyboards on devices with OTG support.
* Said OTG shenanigans are so far supported on devices with debugfs & the chipidea driver, or sunxi devices.
2 years ago
zwim d7c63edca6
Random optimizations (#9657) 2 years ago
NiLuJe 54fae2987e
Support Android AArch64 (#9645)
c.f., https://github.com/koreader/koreader-base/pull/1540 & https://github.com/koreader/android-luajit-launcher/pull/390
2 years ago
NiLuJe 854cbe9f94 Kobo: Unbreak frontlight toggle for some specific values
Because of floating point computery math stuff.

Regression since #9609
c.f., https://github.com/koreader/koreader/pull/9609#issuecomment-1288187080
2 years ago
NiLuJe d9eb6e9717
Kobo: Always use open/write/close for sysfs writes (#9635)
Also simplifies a few UIManager log messages (re: https://github.com/koreader/koreader-base/pull/1537)
2 years ago
NiLuJe da65ac8b02
Cleanup various varargs shenanigans (#9624)
* Iterate over varargs directly via select if possible
* Use table.pack otherwise (https://github.com/koreader/koreader-base/pull/1535).
* This allows us to simplify a few Logger calls, as logger now handles nil values.
2 years ago
zwim 4969811c08
Optimization: Use constant folding for divisions not a power of two (#9609) 2 years ago
NiLuJe c0dffe2012
Kobo: Add a debug option to turn the charging LED on PM entry failure (#9601)
This should be fairly unintrusive, but still noticeable enough without having to watch the battery gauge like a hawk, or resort to actual monitoring via kernel logs and/or usb meter and/or multimeter...
2 years ago
NiLuJe fadee1f5dc
Clarify our OOP semantics across the codebase (#9586)
Basically:

* Use `extend` for class definitions
* Use `new` for object instantiations

That includes some minor code cleanups along the way:

* Updated `Widget`'s docs to make the semantics clearer.
* Removed `should_restrict_JIT` (it's been dead code since https://github.com/koreader/android-luajit-launcher/pull/283)
* Minor refactoring of LuaSettings/LuaData/LuaDefaults/DocSettings to behave (mostly, they are instantiated via `open` instead of `new`) like everything else and handle inheritance properly (i.e., DocSettings is now a proper LuaSettings subclass).
* Default to `WidgetContainer` instead of `InputContainer` for stuff that doesn't actually setup key/gesture events.
* Ditto for explicit `*Listener` only classes, make sure they're based on `EventListener` instead of something uselessly fancier.
* Unless absolutely necessary, do not store references in class objects, ever; only values. Instead, always store references in instances, to avoid both sneaky inheritance issues, and sneaky GC pinning of stale references.
  * ReaderUI: Fix one such issue with its `active_widgets` array, with critical implications, as it essentially pinned *all* of ReaderUI's modules, including their reference to the `Document` instance (i.e., that was a big-ass leak).
* Terminal: Make sure the shell is killed on plugin teardown.
* InputText: Fix Home/End/Del physical keys to behave sensibly.
* InputContainer/WidgetContainer: If necessary, compute self.dimen at paintTo time (previously, only InputContainers did, which might have had something to do with random widgets unconcerned about input using it as a baseclass instead of WidgetContainer...).
* OverlapGroup: Compute self.dimen at *init* time, because for some reason it needs to do that, but do it directly in OverlapGroup instead of going through a weird WidgetContainer method that it was the sole user of.
* ReaderCropping: Under no circumstances should a Document instance member (here, self.bbox) risk being `nil`ed!
* Kobo: Minor code cleanups.
2 years ago
NiLuJe 9bf19d1bb3
Assorted bag'o tweaks & fixes (#9569)
* UIManager: Support more specialized update modes for corner-cases:
  * A2, which we'll use for the VirtualKeyboards keys (they'd... inadvertently switched to UI with the highlight refactor).
  * NO_MERGE variants of ui & partial (for sunxi). Use `[ui]` in ReaderHighlight's popup, because of a Sage kernel bug that could otherwise make it translucent, sometimes completely so (*sigh*).
* UIManager: Assorted code cleanups & simplifications.
* Logger & dbg: Unify logging style, and code cleanups.
* SDL: Unbreak suspend/resume outside of the emulator (fix #9567).
* NetworkMgr: Cache the network status, and allow it to be queried. (Used by AutoSuspend to avoid repeatedly poking the system when computing the standby schedule delay).
* OneTimeMigration: Don't forget about `NETWORK_PROXY` & `STARDICT_DATA_DIR` when migrating `defaults.persistent.lua` (fix #9573)
* WakeupMgr: Workaround an apparent limitation of the RTC found on i.MX5 Kobo devices, where setting a wakealarm further than UINT16_MAX seconds in the future would apparently overflow and wraparound... (fix #8039, many thanks to @yfede for the extensive deep-dive and for actually accurately pinpointing the issue!).
* Kobo: Handle standby transitions at full CPU clock speeds, in order to limit the latency hit.
* UIManager: Properly quit on reboot & exit. This ensures our exit code is preserved, as we exit on our own terms (instead of being killed by the init system). This is important on platforms where exit codes are semantically meaningful (e.g., Kobo).
* UIManager: Speaking of reboot & exit, make sure the Screensaver shows in all circumstances (e.g., autoshutdown, re: #9542)), and that there aren't any extraneous refreshes triggered. (Additionally, fix a minor regression since #9448 about tracking this very transient state on Kobo & Cervantes).
* Kindle: ID the upcoming Scribe.
* Bump base (https://github.com/koreader/koreader-base/pull/1524)
2 years ago
NiLuJe 8fcc712c76
Kobo: Clara 2E fixes (#9559)
* Handle the power button input device
* Handle the charging LED properly
* Handle the new Wi-Fi chip properly
* Handle frontlight warmth adjustments
* Handle the battery gauge properly
* Bump base (a lot of third-party updates) [https://github.com/koreader/koreader-base/pull/1523]
* Bump android-luajit-launcher to match the LuaJIT update [https://github.com/koreader/android-luajit-launcher/pull/386]

Fix #9552 (many thanks to @Bartvelp for bearing with my stupid tests ;)).
2 years ago
NiLuJe 4d48b6e2fe
Misc: Use the ^ operator instead of math.pow (#9550)
And some minor code simplifications, thanks to @zwim ;).
2 years ago
NiLuJe 62059f8d68
Misc: Get rid of the legacy defaults.lua globals (#9546)
* This removes support for the following deprecated constants: `DTAP_ZONE_FLIPPING`, `DTAP_ZONE_BOOKMARK`, `DCREREADER_CONFIG_DEFAULT_FONT_GAMMA`
* The "Advanced settings" panel now highlights modified values in bold (think about:config in Firefox ;)).
* LuaData: Isolate global table lookup shenanigans, and fix a few issues in unused-in-prod codepaths.
* CodeStyle: Require module locals for Lua/C modules, too.
* ScreenSaver: Actually garbage collect our widget on close (ScreenSaver itself is not an instantiated object).
* DateTimeWidget: Code cleanups to ensure child widgets can be GC'ed.
2 years ago
NiLuJe b0d8919399
ImageViewer: Followup to #9529 (#9544)
* ImageViewer: Minor code cleanups
* GestureDetector: Fix the `distance` field of `two_finger_pan` & `two_finger_swipe` gestures so that it's no longer the double of the actual distance traveled. Get rid of existing workarounds throughout the codebase that had to deal with this quirk.
2 years ago
NiLuJe ab4b4b31bd
Kobo: Initial Clara 2E support (#9545)
Will need an actual tester to confirm FBInk gets the rotation right, as well as the touch input & frontlight situation.

* Bump base

https://github.com/koreader/koreader-base/pull/1519
https://github.com/koreader/koreader-base/pull/1521
2 years ago
hasezoey 61415a3723
add custom mapping for tolino buttons (#9509) 2 years ago
NiLuJe 13e8213e0a
A random assortment of fixes (#9513)
* Android: Make sure sdcv can find the STL
* DocCache: Be less greedy when serializing to disk, and only do that for the *current* document ;).
* CanvasContext: Explicitly document API quirks.
* Fontlist: Switch the on-disk Persist format to zstd (it's ever so slightly faster).
* Bump base for https://github.com/koreader/koreader-base/pull/1515 (fix #9506)
2 years ago
zwim 6f5c229c90
[UIManager] Outsource device specific event handlers (was: some nits) (#9448) 2 years ago
NiLuJe e051d3d703
Kobo: Fix a few bad interactions between suspend & checkUnexpectedWakeup (#9499)
* Kobo: Make sure checkUnexpectedWakeup won't run between scheduled
suspend calls

Because of the suspend_wait_timeout, a previously scheduled check *could* shortcircuit a suspend scheduled a tiny bit later by a real Power event.
This led to fun breakage when you plugged/unplugged a "sleeping" device, for instance.

Fix #9457

* And clear up the unexpected_wakeup_count semantics

Bits of an older design seeped through and were causing weird corner-cases...
2 years ago
zwim d972b7fcfa
[core] Remove a bunch of superflous semicolons (#9449) 2 years ago
NiLuJe 96930f230f
Add "Invert page turn buttons" to Dispatcher (#9494)
Fix #9492
2 years ago
NiLuJe 8de4e8d785
Kindle: Attempt to deal with sticky "waking up" hibernation banners (#9491)
Fix #9482
2 years ago
NiLuJe 1ac35cb865
Input: Minor simplification for the Mk. 3 input quirk (#9481)
I was afraid that ABS_PRESSURE could be sent out of order, but that appears to never be the case, so we can simplify the code a bit :}.
2 years ago
NiLuJe 1b14ee36b3
Kobo: Fix input on Mk. 3 (i.e., Kobo Touch A/B). (#9474)
* Kobo: Discriminate between the Touch A/B and the Touch C properly, and implement actual support for the A/B input quirks. This means the clunky touchscreen probe widget shown on fresh installs on those devices is now gone :}.
* Input: Fix an off-by-one in most adjustTouchMirrorX/Y callers (only rM was doing it right), and adjust their documentation to avoid similar mistakes in the future.
* GestureDetector: Unify logging to always display transformed coordinates for simple gestures.
* GestureDetector: Fix two-contact hold lifts to be computed at the midpoint between the two contacts, like their holds counterpart already did.
2 years ago
NiLuJe 49e5200c8a
Kobo: Unbreak touch input on fresh setups on Trilogy (#9473)
By making sure we setup the right evdev parser first ;).
2 years ago
NiLuJe 8e1bb9bafc
GestureDetector: Full refactor for almost-sane(TM) MT gesture handling (#9463)
Should hopefully make two-contact gestures *much* more reliable, among other things.

See the PR for all the details ;).
2 years ago
NiLuJe 2678d2c49b
Input: Unbreak evdev handling on Kobo single-touch devices (#9465)
* Kobo: Switch ST devices to a dedicated input handler

Instead of shoehorning a hack into the standard handler.

* Use setCurrentMtSlotChecked in handleTouchEvLegacy
2 years ago
NiLuJe 2d5bde3ade
Input: Unbreak event handling on strict protocol B devices (#9445)
Regression since #9377
Fix #9444
2 years ago
Frans de Jonge f8e888c832
[fix, SDL] Remove useless Device call from exit (#9443)
Fixes #9439.
2 years ago
NiLuJe 939a64438a
Input: Minor comment tweaks (#9441) 2 years ago
NiLuJe 841e67e018 Input: Make sure GestureDetector:feedEvent will actually consume all
slots

This ensures we won't leave *any* slot in an undefined state because
we skipped parsing 'em because what we consumed first yielded a
gesture.

(In particular, this could leave a few slots dangling in the "hold"
state in corner cases involving spider-hand finger tapping ;p).

Cleans up the slot state clearing in GestureDetector to only clear the
necessary slots (e.g., two-finger gestures now only clear their own two
slots; and holds only clear their own slot).
The fact that every slot will be consumed ensures that every slot will
naturally get their contact up handled, which wasn't the case before,
hence those crappy workarounds.

As far as timerfd callbacks are concerned, this *does* introduce the
possibility of deadline collisions, so, do reimplement minimal safety
checks to ensure we run (and free) the right timerfd callback.
2 years ago
NiLuJe 32ff263294 Input: Don't insert duplicate references to the event list
Some drivers can bundle the same slot multiple times in the same input
frame. We were only correctly coalescing *consecutive* slots, but some
drivers can do that in non-consecutive sequences (e.g., 1a -> 2a -> 1b
-> 2b), so, handle that, too.

Seen on neonode v2 grids.
2 years ago
NiLuJe 36d0bcc703 Input: Don't re-run the slot creation check on key sets
Make sure we always create the storage table when we add its reference
to the MTSlots list instead.

(The reasoning being we only add the reference once, and it's the first
thing we do, and we kinda need the storage to be created to get its
reference anyway; while we may set multiple keys per frame).
2 years ago
NiLuJe ba43ac1833 Input: Actually fix the timer double-free
For realz, this time.

This reverts the original attempt, because it was gratuitous
overcomplexification that turns out to be completely unnecessary.

This also fixes a few subtle MT handling snafus on some devices.
2 years ago
NiLuJe db2ba08617 Kobo: Handle the IR grid wakeup workaround on the Glo HD, too
Because the sysfs path is different, of course ;).
2 years ago
NiLuJe 3768aa0b56 GestureDetector: Clear *all* pending hold states on hold_release.
We'll only honor one (the last one) anyway, and we've already cleared
the timers, so the others are essentially lost and stuck in limbo.

(Repro: do a series of staggered holds on different words with different
fingers in a CRe document; the one that'll "take" is the last one,
but *every* slot will be stuck in a hold state, which can essentially
semi lock you into broken input until you manage to clear the right
slots by doing duplicate multi-slot holds again...).
2 years ago
NiLuJe e3228abb19 ScreenSaver: On race-y platforms, only force a refresh on close if the
widget was actually closed *immediately*.

If it's delayed (by time, tap or gesture), leave it alone.

Fix #9285
2 years ago
NiLuJe 8e7dddd927 Input: Make sure we consume & clear the right timerfd callback
Multitouch gestures can create multiple timers on the same deadline, but
on different slots, so simply hoping that the head of the list would
match was somewhat optimistic... ;o).

Fix #9376

It's trickier in the !timerfd case, though,
so do the best we can there...
(It wouldn't crash, but it might fire the "wrong" callback).
2 years ago
yparitcher c4a802c486 kindle: allow stopping the framework on 5.X
this reclaims a bunch of memory useful on low memory devices
2 years ago
ElimGarak1 bbc5652c1d
Add PocketBook Era (PB700) (#9365) 2 years ago
NiLuJe f92dfeae21
Android: Leave the EV_MSC input handler alone. (#9335)
It's used to communicate state changes from Android to Lua, we really
really don't want to lose these ;).

Fix #9326
2 years ago
Stephane Albert fc7f0bacf1
[PocketBook] fix: Crash loading file extensions (#9327)
In some versions of the /ebrmain/config/extensions.cfg file there is a
comment #ebrcfg. This will not match the regex and crashes koreader as
the table is empty.
Add a check to ensure the table is not empty while reading extensions
from the default file.
2 years ago
NiLuJe e679b00d0a
Kobo: Autodetect the Elan input device on both i2c buses (#9322)
Hadn't noticed that the new Libra 2 has it on a different bus than the
Sage/Elipsa.

(Harmless because we kept the Sage & Elipsa hardcoded).

c.f., https://www.mobileread.com/forums/showpost.php?p=4238067&postcount=869,
thanks to @baskerville for the poke ;).
2 years ago
zwim 22fe3933c3
[fix, SDL] Time: fix crash when scrolling in continuous mode (#9314)
Introduced with #8999.

Fixes #9311.
2 years ago
yparitcher 7366a031d6
kindle: track suspend time (#9307)
This is useful for the sysstat plugin not to have 00:00 for suspend time :)

Something similar should probably be done for the other canSuspend platforms.
2 years ago
zwim 2c952eca4d
BottomMenu: show real sizes for margins and font size (#9205) 2 years ago
yparitcher 926223c192 Kindle: enable WakeupMgr & RTC support
This is acomplished through listening for the wakeupFromSuspend
& readyToSuspend powerd events to set the RTC via lipc at the
correct time.
2 years ago
zwim 05c586c4be
AutoWarmth: force setWarmth after resume (#9289) 2 years ago
Martín Fernández 4f7ed7e706
SDL: set WM_CLASS on Wayland/X11 (#9280) 2 years ago
NiLuJe c506d8b0ac
AutoSuspend: Some more fixes & cleanups (#9263)
* AutoSuspend: Use the canSuspend devcap check instead of reinventing the wheel.
* Device & UIManager: Cleanup canSuspend devcap check related stuff to avoid boilerplate code.
  (It also now defaults to no, and is explicitly set by device implementations where supported).
* AutoSuspend: Re-engage suspend/shutdown timers when fully charged.
  This restores the existing behavior pre #9036
  (c.f., https://github.com/koreader/koreader/pull/9258#issuecomment-1167672356)
* SDL: Unbreak the fake suspend behavior so that it actually works.
  Tweak the default screensaver message to remind users that Power is bound to F2.
  (Fix #9262)
* AutoSuspend: Re-engage suspend/shutdown timers on unplug.
  This matters on Kobo, because the unexpected wakeup guard might have stopped the suspend timer.
2 years ago
zwim 41e78b6ed3
userpatch: allow monkey-patching KOReader (#9104)
Supersede old android-only patch.lua.
2 years ago
Robert-Jan de Dreu 040dbfe1bd
Pocketbook: Keep wifi alive as long as wifi is enabled (#9208)
Schedule wifi keep-alive on wifi start but do not reschedule when
connection is lost. This will make sure this code is not run when
wifi is disabled again saving some battery and cpu cycles.
2 years ago
Martín Fernández b7a27a3db3
Fullscreen refactor (#9237)
Commonize fullscreen code across different devices.

Add fullscreen toggle on SDL desktop targets. 
Expose the toggle to the dispatcher and map it to F11.

Hide touchmenu when resizing.
2 years ago
NiLuJe 4f4b1e523a
Kobo: Handle the new Libra 2 hardware revision properly (#9234)
Includes a base bump for KoboUSBMS (https://github.com/koreader/koreader-base/pull/1493)

Fix #9218
2 years ago
NiLuJe dcb11c2542
Make luacheck >= 0.26 happy (#9174)
Re: https://github.com/koreader/koreader-base/pull/1487
2 years ago
Martín Fdez d644b1a851 android: update doShareText signature 2 years ago
NiLuJe e1ac3c4853
Minor Input:inhibitInput followup to #9065 (#9139)
* GestureDetector: Downgrade probeClockSource log messages to debug

We're seeing a bit more of 'em between autostandby and inhibitInput now,
and the whole thing was implemented long enough ago that it's no longer
critical to see this in random non-debug logs ;).

* Input: Reset gesture state in inhibitInput

Should prevent bogus gestures when re-enabling the handlers if we were
called in the middle of gesture detection.
2 years ago
NiLuJe ae5b2d68ca
AutoSuspend: Don't send LeaveStandby events from a zombie plugin instance (#9124)
Long story short: the LeaveStandby event is sent via `tickAfterNext`, so if we tear down the plugin right after calling it (in this case, that means that the very input event that wakes the device up from suspend is one that kills ReaderUI or FileManager), what's in UIManager's task queue isn't the actual function, but the anonymous nextTick wrapper constructed by `tickAfterNext` (c.f., 
https://github.com/koreader/koreader/issues/9112#issuecomment-1133999385).

Tweak `UIManager:tickAfterNext` to return a reference to said wrapper, so that we can store it and unschedule that one, too, in `AutoSuspend:onCloseWidget`.

Fix #9112 (many thanks to [@boredhominid](https://github.com/boredhominid) for his help in finding a repro for this ;)).
Re: #8638, as the extra debugging facilities (i.e., ebb81b9845) added during testing might help pinpoint the root issue for that one, too.

Also includes a minor simplification to `UIManager:_checkTasks`, and various other task queue related codepaths (e.g., `WakeupMgr`) ;).
2 years ago
yparitcher 8f316b1e8c
Merge `discardEvents` & `inhibitInput` (#9065)
Rename `discardEvents` to `inhibitInputUntil`
only discard Input events
2 years ago
Glen Sawyer cb95dcd4c9
Fix reMarkable crash bug v2022.05: event overwrite with new time module (#9121)
The change from timeval to time completely broke reMarkable.
frontend/device/remarkable/device.lua was using TimeVal:now() to manually overwrite event time values, as noted in the code comments.
Input:handleTouchEv is expecting those event time values to be timevals, not integer times.
So as soon as the user touches the screen, crash.
2 years ago
NiLuJe 118e063ae2
PocketBook: Don't break synthetic power input events on suspend
Regression since #9036
Fix #9095
2 years ago
NiLuJe fa76b9d615
Kindle: Fix retrieveNetworkInfo on the K4 (#9073)
Thanks to @hius07
(https://github.com/koreader/koreader/issues/7881#issuecomment-1028921755)
;).

Fix #7881
2 years ago
NiLuJe 2de2a8ab76
NetworkManager: Make sure we show an IM at the *start* of a Wi-Fi toggle action (#9064)
Ensures the worst-case scenario has minimal visual feedback.
2 years ago
zwim 9b9cfe29a4
[feat] Replace TimeVal (RIP) with time, fixed point time seconds (#8999) 2 years ago
yparitcher 54ead5fc88 Page turn animations
Kindle PW5 (MTK) with hardware support
Currently only in Crengine
2 years ago
NiLuJe 86c35ad066
A host of low power states related tweaks (#9036)
* Disable all non power management related input during suspend. (This prevents wonky touch events from being tripped when closing a sleep cover on an already-in-suspend device, among other things).
* Kobo: Use our WakeupMgr instance, not the class.
* WakupMgr: split `removeTask` in two: 
* `removeTask`, which *only* takes a queue index as input, and only removes a single task. Greatly simplifies the function (i.e., it's just a `table.remove`).
* `removeTasks`, which takes an epoch or a cb ref, and removes *every* task that matches.
* Both of these will also *always* re-schedule the next task (if any) on exit, since we can have multiple WakeupMgr tasks queued, but we can only have a single RTC wake alarm set ;).
* `wakeupAction` now takes a `proximity` argument, which it passes on to its `validateWakeupAlarmByProximity` call, allowing call sites to avoir having to duplicate that call themselves when they want to use a custom proximity window.
* `wakeupAction` now re-schedules the next task (if any) on exit.
* Simplify `Kobo:checkUnexpectedWakeup`, by removing the duplicate `WakerupMgr:validateWakeupAlarmByProximity` call, now that we can pass a proximity window to `WakeuoMgr:wakeupAction`.
* The various network activity timeouts are now halved when autostandby is enabled.
* Autostandby: get rid of the dummy deadline_guard task, as it's no longer necessary since #9009.
* UIManager: The previous change allows us to simplify `getNextTaskTimes` into a simpler `getNextTaskTime` variant, getting rid of a table & a loop.
* ReaderFooter & ReaderHeader: Make sure we only perform a single refresh when exiting standby.
* Kobo: Rewrite sysfs writes to use ANSI C via FFI instead of stdio via Lua, as it obscured some common error cases (e.g., EBUSY on /sys/power/state).
* Kobo: Simplify `suspend`, now that we have sane error handling in sysfs writes.
* Kobo.powerd: Change `isCharging` & `isAuxCharging` behavior to match the behavior of the NTX ioctl (i.e., Charging == Plugged-in). This has the added benefit of making the AutoSuspend checks behave sensibly in the "fully-charged but still plugged in" scenario (because being plugged in is enough to break PM on `!canPowerSaveWhileCharging` devices).
* AutoSuspend: Disable our `AllowStandby` handler when auto standby is disabled, so as to not interfere with other modules using `UIManager:allowStandby` (fix #9038).
* PowerD: Allow platforms to implement `isCharged`, indicating that the battery is full while still plugged in to a power source (battery icon becomes a power plug icon).
* Kobo.powerd: Implement `isCharged`, and kill charging LEDs once battery is full.
* Kindle.powerd: Implement `isCharged` on post-Wario devices. (`isCharging` is still true in that state, as it ought to).
2 years ago
slimpdev 7cac083db4
Kindle: Support warm light control on the Oasis 3 (#9054) 2 years ago
NiLuJe 5ac9463c09
AutoSuspend: Unbreak cohabitation between standby & suspend (#9009)
* Make sure AutoStandby cohabitates nicely with AutoSuspend (regression since #8985), specifically:
* Disable standby during suspend.
* Ensure that leaving standby restores the scheduled suspend properly, with the appropriate remaining amount of time based on the last user input.
* Handle devices with an auxiliary battery better when scheduling suspend (assume it's only charging when the aux battery is charging, not the ereader's).
* Tweak debug logging to be able to remote debug corner-cases more easily without requiring code changes.
* Fix erroneous behavior when awoken from standby by something that doesn't trigger an InputEvent Event (e.g., rtc alarm, gyro, or random bullshit).
2 years ago
NiLuJe bd17119d07
Kobo: Disable key repeat during suspend (#8987)
Might help avoiding evdev queue overflow on misbehaving covers (#8964).

At the very least shaves a fair bit of stupid from debug logs ;o).
2 years ago
NiLuJe 087b97457d
AutoSuspend: Handle standby scheduling in the same manner as suspend/shutdown (#8985)
Specifically, don't forcibly unschedule/schedule on every input event, instead, let the scheduled task figure out if the deadline came to pass or not ;).

c.f., https://github.com/koreader/koreader/pull/8970#issuecomment-1092775830

Besides getting rid of some overhead, this allows proper scheduling after a task that would have blocked for longer than the standby timeout.
2 years ago
zwim 0808560532
getElapsedTimeSinceBoot: Honor times in suspend, too (#8983) 2 years ago
NiLuJe 61cafab0e5
AutoSuspend: Avoid unbalanced prevent/allow Suspend calls (#8970)
This prevents crashing interactions with other prevent/allow callers when the feature is disabled.
2 years ago
zwim 7e2aa2a209
Kobo powerd: fix frequency in battery's getCapacity with enabled standby (#8958) 2 years ago
NiLuJe 815c078b89 Kobo: tone down the neocmd log chatter on unaffected devices 2 years ago
NiLuJe 2aa310a931
ScreenSaver: Minor refactor to avoid code duplication and weird rotation shenanigans (#8943)
* Handle said rotation shenanigans inside ScreenSaver & ScreenSaverWidget, which allows a more targeted approach; and prevents said rotation from affecting other widgets. (Also, gets rid of duplicated code).
* Handle the corner-case or exiting early from a "keep on screen for n sec" screensaver better, by unscheduling the extra refresh, since an early tap took care of that already.
2 years ago
zwim 158f4be724
Autosuspend: add autostandby (#8815)
Allows the device to go into standby (if available in `/sys/power/state`) to save power.
Adds an entry in the device menu to tune the timeout for standby.
(Shows total standby- and suspend-time in system statistics.)
2 years ago
Will c04fba943d
[reMarkable] Don't use KOReader suspend/screensaver/autosuspend when Oxide is running (#8900)
* Ignore hardware sleep button

When running KOReader with a launcher, having the power button trigger the Power event conflicts with the launcher's built-in screensaver (see https://github.com/koreader/koreader/issues/8891). This commit ignores the hardware power button in KOReader and lets the launcher handle sleep and wake normally.

* Disable autosuspend

If a launcher is active, there will be no way to un-suspend because the power button is ignored by KOReader and handled by the launcher.

* Ignore power button only if Oxide is running

Same with disabling auto suspend
2 years ago
NiLuJe 044341875f
Only toggle nightmode via the grayscale fb info flag on Kindle (#8931)
* Only toggle nightmode via the grayscale fb info flag on Kindle

Most NTX boards require elaborate trickery (see fbdepth) to actually
send a vput ioctl without the driver screwing with the rotation behind
your back.

This was causing spurious hardware rotations on exit on most Kobo
devices, something which might have gone mostly unnoticed, as current
Nickel versions will sanitize it on startup.
A simple repro was instead to start an USBMS session, as that exits
KOReader and restarts it without going through fbdepth again ;).
2 years ago
NiLuJe 23cd7e24bb
Minor Lua I/O cleanups (#8921)
Mostly making sure we always explicitly close io handles.
2 years ago
zwim 6a240b7d11
Kobo, Sage: better power cover detection (#8894) 2 years ago
NiLuJe 217a73f3c0
Initial Kindle PW5 support (#8856)
* Rejig frontlight warmth API to more closely match the existing API, and, hopefully, clarify some of its quirks, and reduce boilerplate and duplicate code in platform implementations.
* Tweak Kindle:setDateTime to prefer using the platform's custom script, as in interacts better with the stock UI. And make the fallbacks handle old busybox versions better.
* Add Kindle PW5 support ;).
* Add warmth support to the Kindle platform.
* Random TextBoxWidget cleanups: make sure we immediately free destroyed instances.
* FrontLightWidget: Refactor to make it slightly less obnoxious to grok and update; i.e., separate layout from update, and properly separate brightness from warmth handling. Move to simpler widgets instead of reinventing the wheel.
* TextBoxWidgets: Implement `setText` to match TextWidget's API, as some callers may be using the two interchangeably (i.e., Button).
* NaturalLightWidget: Make sure we pass a string to InputText
* InputText: Add debug guards to catch bad callers not passing strings ;).
2 years ago
Philip Chan 107156c0a8
[feat] Non-touch improvements (#8859)
FocusManager: fix round x use y layout
FocusManager: add tab and shift tab focus navigation support
FocusManager: handle Press key by default
FocusManager: make sure selected in instance level
FocusManager: add hold event support
FocusManager: Half move instead of edge move
FocusManager: add keymap override support
FocusManager: refocusWidget will delegate to parent FocusManager
Focusmanager: refocusWidget can execute on next tick
inputtext: can move out of focus on back
inputtext: fix cannot exit for non-touch device
inputtext: fix cannot input text with kindle dx physical keyboard
fontlightwidget: add non-touch support
datetimewidget: add non-touch support
datetimewidget: fix set date failed in kindle DX, fix datetimewidget month range to 1~23 by default
datetimewidget: make hour max value to 23
multiinputdialog: add non-touch support
checkbox: focusable and focus style
virtualkeyboard: no need to press two back to unfocus inputtext
virtualkeyboard: collect FocusManager event key names to let VirtualKeyboard disable them
openwithdialog: add non-touch support
inputdialog: can close via back button
enable all InputDialog and MultiInputDialog can be close by back
keyboardlayoutdialog: non-touch support
readertoc: non touch device can expand/collapse in toc
bookstatuswidget: non touch support
keyvaluepage: non-touch support
calendarview: non-touch support
2 years ago
Robert-Jan de Dreu 41e57fccd2
Fix Pocketbook crashes when filename is nil (#8823)
Function `SetSubtaskInfo` takes only chars as a valid book. Since
filename can be `nil` (not a char) the crash would happen. This
Change avoids the crash by using a char type nil value. See:

`int SetSubtaskInfo(int task, int subtask, const char *name, const char *book);`

Fixes #8053
Fixes #8392 too
Fixes #8743 last issue
2 years ago
Frans de Jonge f6acb98227
Add Pocketbook 740-3 (#8851)
Thanks to @uatel.

Fixes #8850.
2 years ago
Robert-Jan de Dreu e5e140d5fd
Fix invert for pocketbooks by disabling hardware invert (#8803)
With the inkview library inverting the screen seems possible but needs some 
discussion with the developers of Pocketbook. For now disable HWInvert so 
this feature is not broken while we figure out how to change the invert with inkview.
2 years ago
NiLuJe fb45576429
Kobo: Use the right input protocol on the Nia (#8794)
c.f., https://github.com/baskerville/plato/issues/220
2 years ago
NiLuJe 2d4e1584c7 Kobo: Drop deprecated comment
Inherited from the original Device abstraction implementation,
7 years ago, but it never made any sense on Kobo ;).
2 years ago
NiLuJe eca27fe497 Disable the WAIT_FOR ioctls on the Libra 2
Much like the Libra, it seems to be having issue with these...

Fix #8664
Re #8414
2 years ago
NiLuJe 0408816a54 ReaderFooter: Take the PowerCover into account in the battery level
widget

Since we only use a single icon, we have to take a few shortcuts:

* The icon itself is computed based on the average of both batteries.
* The actual value is the sum of both batteries.
* Much like everywhere else, charging means the *aux* battery charging
  (i.e., connected to a power source).

Re #8741, which does the same for ReaderHeader.
2 years ago
NiLuJe 5518a8109b PowerD: Ensure we actually pull battery capacity during early boot.
(i.e., when MONOTONIC returns something lower than 60).

Fix https://github.com/koreader/koreader/pull/8711#issuecomment-1021106079
2 years ago
Andrej Shadura f3ac95321b
PocketBook: make canAssociateFileExtensions always return true (#8729)
This change drops the #koreader signature check. 

This check prevents KOReader from modifying associations if something else has changed the file without putting a verbatim "#koreader" string back.

While this prevents KOReader from interfering with another application or the system trying to own the file, it also leads to hard to diagnose issues, when the user can inadvertently change associations without realising they’re doing so, and being unable to return back.
2 years ago
Robert-Jan de Dreu e8fa5bdedd
PocketBook: Check NET_CONNECTED to see if wifi is really connected (#8730)
I've emailed with PocketBook about the problem with Wifi on the newer models. They explained the wrong constant was being used:

> Dear Robert,
>
> Thank you for choosing Pocketbook.
​
> Wi-Fi Connection" enabled when no connection:
> https://github.com/koreader/koreader/issues/8617  
> The problem is in incorrect usage of constant. You should use flag NET_CONNECTED with bit AND operation as shown in example below.
>
> function NetworkMgr:isWifiOn()
>     local state = inkview.QueryNetwork()
>     return band(state, C.NET_CONNECTED) ~= 0
> end
>
> Inkpad3 Wifi Standby
> https://github.com/koreader/koreader/issues/4747 
> the same solution for this issue

Related issues:
https://github.com/koreader/koreader/issues/8617
https://github.com/koreader/koreader/issues/4747

Since I made the previous hack and their suggestion seems to work on the PB741 color. I've made this PR to remove my hack.

It might be wise to also test this fix on older models.
2 years ago
roshavagarga 4f707bb49d
PocketBook: add support for PB617 (Basic Lux 3) (#8740) 2 years ago
Robert-Jan de Dreu 943dc99645
PocketBook: handle rendering of interface and books directly with inkview (#8727)
Use ffi/framebuffer_pocketbook.lua, using Pocketbooks's own
inkview library for framebuffer interactions.
2 years ago
Martín Fernández 4423082949
Colordict: use generic send intent. (#8721)
Its custom intent was borked on last update and doesn't work anymore.

Fixes https://github.com/koreader/koreader/issues/8718
2 years ago
Martín Fernández d67d92bcab
android screen: decouple epd and color properties (#8717)
also included new devices: 

- added onyx nova 3
- fixed onyx note 5
2 years ago
poire-z 16e3b2f0ac Allow Backspace to work as back button 2 years ago
NiLuJe e39ee325f9 Cleverer UIManager <-> PowerD circular dependency handling
Thanks to @poire-z ;).
2 years ago
NiLuJe 2462c1c5c1 PowerD: Make sure we immediately display accurate battery capacity on
resume.

(MONOTONIC doesn't trick during suspend, so we could happily display the
pre-suspend capacity for a while).
2 years ago
NiLuJe 69718d6ee1 PowerD: Fix a stupid typo in getCapacity
Regression since #8672
2 years ago
NiLuJe 689ec2a839 PowerD: Prevent potential dependency loop in get*Capacity
Not currently happening in vanilla code, but, not entirely unlikely.
stateChanged already uses a similar guard.

Re https://github.com/koreader/koreader/pull/8672#discussion_r790126388
2 years ago
NiLuJe eb0c2bfc93 Kobo: Handle a few PowerCover quirks...
* The first few capacity reads after connecting to the cover may fail

* The PowerCover may trigger spurious move/add usb_plug uevent,
which translate into Charging events for us.
Instead of blindly lighting up the charging LED on those,
check if the device is actually charging, first.
2 years ago
NiLuJe 607f5db1dd Kobo: Accurately toggle the charging LED on startup
Kobo: Also refresh charging LED state on resume
2 years ago
NiLuJe dc98384177 PowerD: Add a framework to report the status of auxiliary batteries
Implement it on the Kobo Sage, for the PowerCover

TouchMenu: Display auxiliary battery status

Kobo: More accurately report the PowerCover's charging status

i.e., try to actually figure out if the auxiliary battery is charging
instead of just checking the reader's battery (because that one will
often swap between the charging and discharging state as it drains the
aux battery...).

PowerD: Use a cached timestamp when doing battery pull checks
2 years ago
yparitcher 0508014c1b SDL & Android: Do not set FM banner on resize
regression from #8648

FileManager.instance.banner was removed and replaced with TitleBar
2 years ago
Andrej Shadura 11cd34973b
Pocketbook: switch the Wi-Fi on before attempting to connect (#8546)
Fixes #4747.

Apparently, inkview.NetConnect() doesn’t enable the Wi-Fi on its own,
this results in a failure if the device has been put into the sleep or
standby mode, when the Wi-Fi hardware is powered down.

Signed-off-by: Andrej Shadura <andrew.shadura@collabora.co.uk>
2 years ago
Robert-Jan de Dreu e2a5fd5c36
[Pocketbook] wifi: fallback to new API when old API is out of bounds 2 years ago
zwim 6c9e222d33
Screensaver: allow limiting stretch of covers and images (#8570)
ImageWidget: adds stretch_limit_percentage parameter.
Add support for screensaver on the emulator, for easier testing.
2 years ago
zwim a001a13ab6
ReaderRolling: avoid ANR on Android when (re)rendering. (#8501)
Wrap document opening and re-renderings (which can block
the app for some time) with setIgnoreInput() to avoid ANR
on Android.
Any setting update that could possibly cause a re-rendering
should send the UpdatePos event, to ensure the re-rendering
happens in ReaderRolling:onUpdatePos() where precautions
are taken to avoid ANR.
2 years ago
Martín Fernández 3427c207b0
android: bump test activity (#8483)
Now users can test light drivers too. See https://github.com/koreader/android-luajit-launcher/pull/339#issuecomment-977822717
2 years ago
NiLuJe 1ff19f8ba7 Kobo: On sunxi, add a delay between the white flash and the sleep
screen.

Otherwise, on the Sage, weird flash glitches may happen, depending on
what was on screen...
(e.g., there's some weird update merging shenanigans going on
despite those updates being flagged NO_MERGE...).
3 years ago
zwim a7cfc65928
Fix crash when entering a digit on the SDL keyboard (#8388)
Fixes #8387.
3 years ago
NiLuJe e17b136d67
Initial support for the Kobo Libra 2 (#8367)
* Initial support for the Kobo Libra 2

* It's the same touch panel as the Elipsa & Sage.
* Plug in proper nightmode waveforms on mxcfb.

* Bump base

https://github.com/koreader/koreader-base/pull/1423
3 years ago
NiLuJe db21521968
Support frontlight warmth on the Sage (#8366)
Follow-up to #8361.
3 years ago
Mike Kozlowski 2cd4d09db4
Add initial support for Kobo Sage (Cadmus) (#8361) 3 years ago
ElimGarak1 863255c9f4
Add PocketBook InkPad Lite (PB970) (#8335)
Closes #8331.
3 years ago
zwim 0c7d174cd7
[frontlight, kobo, cervantes] Remove auto_warmth (#8154)
The feature is now provided by the "Auto warmth
and night mode" plugin (#8129).
3 years ago
NiLuJe 4a2f519600 Kobo: Use CLOEXEC in the Device module
We have a guarantee that it's supported on this platform.
3 years ago
NiLuJe 53b8ed48bf Kobo: Don't leak fds in isWifiOn
io.lines only closes the fd when the loop is exited sanely, not by a
control flow keyword (i.e., no break or return allowed).

Regression since #8169
3 years ago
NiLuJe 48da545e32 Kobo/Elipsa: More fine-grained control over the amount of online CPU
cores

* Only keep a single core online most of the time.
* Device: Add an enableCPUCores method to allow controlling the amount of
  online CPU cores.
* Move the initial core onlining setup to Kobo:init, instead of the startup script.
* Enable two CPU cores while hinting new (e.g., cache miss) pages in PDF land.
* Enable two CPU cores while processing book metadata.
* Drive-by fix to isolate the DocCache pressure check to KoptInterface
  and actually apply it when it matters most (e.g., k2pdfopt stuff).
3 years ago
zwim debf5dc550
Footer: add Warmth as footer item (#8060) 3 years ago
NiLuJe af8988ef5f
Minor script tweaks (#8169)
* Neater fbdepth usage on sunxi
* Make sure we only ever match *loaded* modules when we check lsmod
3 years ago
NiLuJe edfb29b406 Fix duplicate suspend scheduling in Device:onPowerEvent
We should always unschedule suspend before scheduling it again (i.e.,
use rescheduleSuspend ;)).

Fix #8097 (many thanks to @Mel-kior for the detailed repro!)
3 years ago
Galunid 611a5311b6
Fix warmth settings on some android devices (#8104) 3 years ago
Martín Fdez 6fb52528cd disable light settings on ChromeOS, android TV and e-ink devices without lights 3 years ago
Martín Fdez 8bf19a7327 flush settings before being killed 3 years ago
NiLuJe 1e9346aec6 Fix Wi-Fi toggle on the Elipsa
It turns out that the kernel needs a little push now that the dedicated
wifi power control module is gone ;).

Issue was only exposed if you booted KOReader while the Wi-Fi was down.
3 years ago
NiLuJe bc133e70d3
Input: Minor simplifications around pen/finger discrimination & the snow protocol (#8021)
* Decode EV_KEY:KEY_BATTERY
* Input: Only drop hovering *pen* events.
  There are currently too many broken 0-pressure *finger* events being
  reported on the Elipsa, making a dumb rejection highly annoying.
* Bump base
https://github.com/koreader/koreader-base/pull/1393
* Rely on actual events to detect loss of contact for the "snow"
protocol.
  Allows simplifying the whole thing.
* Use `ipairs` over `pairs` for pure arrays.
3 years ago
Martín Fernández 990b6768f4
disable battery level on desktop Linux (#8026)
This also include ChromeOS laptops (chromebooks) since the power sysfs attributes don't exist in linux containers.
3 years ago
NiLuJe 817e9e26e8
Minor input tweak after #7986 (#8004) 3 years ago
NiLuJe ae35e898fb
Kobo Elipsa support (#7986)
Includes a few minor cleanups along the way ;).
3 years ago
poire-z 16ab5aa194 SDL keyboard input: should go to top level widget only
Avoid the typed input to be added to all
InputText present on the stack: only the
top one should handle it.
3 years ago
hius07 884c664f63
Device status alarm: battery and memory (#7857)
Move former low battery alarm into a device status
alarm menu, and add high memory usage checks.
3 years ago
Martín Fernández ee92ca68e8
workaround for Onyx Poke2 nonsense (#7872)
Requires koreader/android-luajit-launcher#320

Also the luajit-launcher bump adds support for Likebook P78 and sanitizes clipboard text.
3 years ago
Martín Fernández 9f097da4f0
Bump android backend (#7813)
* Bumps the target Sdk to Android 11 (API30)
* Add a crash handler
3 years ago
Frans de Jonge 039947886f
Revert "Hyphenation: add custom hyphenation rules (#7746)" (#7785)
This reverts commit f25da5d0d5.
3 years ago
zwim f25da5d0d5
Hyphenation: add custom hyphenation rules (#7746)
The hyphenation of a word can be changed from its default
by long pressing for 3 seconds and selecting 'Hyphenate'.
These overrides are stored in a per-language file, i.e:
koreader/settings/user-German.hyph.
3 years ago
NiLuJe 1ded7c3907 PocketBook: Support the PB741
Re: https://github.com/koreader/koreader/issues/7747#issuecomment-846850605
3 years ago
NiLuJe 92afc63951 PocketBook: Deal with FW shenanigans on the PB627
Might break it on older FW, who knows.

Fix #7747
3 years ago
Martín Fernández b8d658b922
android: minor fixes (#7753)
* Save settings before installing a new APK & after resume. 
* Move Resume/Suspend events to Resume/Pause callbacks
3 years ago
Martín Fernández dc0d759148
don't log thirdparty app list if they're platform defaults (#7760) 3 years ago
zwim 6e2be98edc
Notifications: options to show none/some/more (#7718)
Notification: adds some functions so it can be used as
a notification manager.
Have various bits of code emitting events that may generate
notifications advertize themselves as the source for following
notifications.
Add a menu to allow selecting some subsets of sources
to show or hide.
3 years ago
poire-z 4b6b12b799 Remove unused "pan_delayed_interval" support 3 years ago
poire-z d0165f8bd1 Fix scrolling, add inertial scroll on non-eInk devices
Add a new reader module: ReaderScrolling, that exposes
some Scrolling options to the menu (which are to be used
by and implemented in ReaderPaging and ReaderRolling
themselves) and implement some inertial scrolling logic
used by both of them.
Default to "Classic scrolling" which is the expected
behaviour on phones and tablets.
The old CreDocument buggy behaviour is available as
"Turbo scrolling" for both Paging and Rolling documents.
Added a "On release scrolling" option that might be
useful on eInk to avoid dynamic pan/scrolling.

Try to avoid bad interactions between pan and swipe,
cancelling unwanted panning if we ended up doing a
swipe or multiswipe.
3 years ago
poire-z 0a3978f60b Reader: remove full refresh on vertical swipes
Small diagonal swipes is what can be used for
full refrehes. Tweak a bit how it is done.
3 years ago
Martín Fdez 23b7bfe0ce move android specific bits outside OTAManager 3 years ago
NiLuJe 4b265bcd7a Allow ingoring the B288 feature bans, for debugging purposes. 3 years ago
NiLuJe f413cd15e8 PB: Unconditionally disable HW rotation on B288 SoCs
Apparently, it's even more broken than usual on some devices/FW combos.

Fix #7663
3 years ago
NiLuJe 628aef2099 OTA: Unbreak exit code on Install
Regression since #7657
3 years ago
NiLuJe bb65a69193
Geom: nil guard a few rect methods (#7664)
We've managed to trip a few of those on dimen fields post-init but
pre-paintTo in a few weird coner-cases, a point at which dimen is often
nil.

ConfigDialog: Deal with that very thing in update()

Fix #7656
3 years ago
Martín Fernández 939fcf7f0e
android: avoid downloading the APK again if there's one download in progress + fix signature error (#7657) 3 years ago
NiLuJe 48c474e245 Device: Add some more logging in onPowerEvent
Could possibly help shed some light on potential SleepCover races...
re #7633
3 years ago
Frans de Jonge 310151fac9
Fix typo (#7655)
Follow-up to #7632.
3 years ago
Martín Fernández d303fdf694
android: Prompt for install updates when they're downloaded (#7632) 3 years ago
zwim 3d9ed32458
Android: Send Suspend/Resume Events on STOP/START (#7630)
* ReaderHeader: Refresh it *now* on Resume, instead of just re-scheduling an update if auto-refresh is enabled..
3 years ago
NiLuJe e0a67bb656
OTA: Handle tar checkpointing visual feedback w/ an FBInk daemon (#7588)
Instead of forking it on every checkpoint.

Won't change much in the grand scheme of things, but FIFOs are fun.
3 years ago
zwim e4c9409f97
[plugin] Add a caching mechanism for CoverImage (#7510) 3 years ago
Martín Fernández 53234fcdc1
add hasSystemFonts device property (#7535)
Add system + user paths to the ReMarkable (has normal linux paths)
3 years ago
NiLuJe 14cd6febbb Kindle Legacy: Cleanup key mappings
The K3 has a mapping similar to the K4, not to the DX & K2.

Fix #7561
3 years ago
gbyl 32802ee7f2
reMarkable: Remove refresh before poweroff (#7563)
This is now handled in a platform-agnostic manner (#7558).

Co-authored-by: gbyl <gbyl@users.noreply.github.com>
3 years ago
NiLuJe 1ac0ad2f1a Android: More input handling tweaks
* Android: Fix #7552 by simply ensuring we drain the input/cmd queue first, simply by scheduling the task to the next tick, instead of locally re-implementing part of the event loop ;). (Requires https://github.com/koreader/koreader-base/pull/1356 for extra safety).
* Android: Clear input state when the window loses focus. (Related to the above fix).

* Bump base:

https://github.com/koreader/koreader-base/pull/1356
https://github.com/koreader/koreader-base/pull/1357

* Bump android-luajit-launcher:

https://github.com/koreader/android-luajit-launcher/pull/293
https://github.com/koreader/android-luajit-launcher/pull/298
https://github.com/koreader/android-luajit-launcher/pull/299
3 years ago
NiLuJe 3274183466 Minor Input & TimeVal cleanups
* Input: Don't create a new TimeVal object for input frame timestamps, just promote our existing table by assigning it the `TimeVal` metatable.
* TimeVal: Export (const) `zero` & `huge` TimeVal objects, because they're common enough in our codebase. (NOTE: not actually const, that's a Lua 5.4 feature ;p).
* GestureDetector: Explain the behavior of the `last_tevs` & `first_tevs` tables, and why one needs a new object and not the other.
* Speaking of, simplify the copy method for `first_tevs`, because it doesn't need to create a new TimeVal object, we can just reference the original, it's unique and re-assigned for each frame.
3 years ago
NiLuJe f2e90f505b
Input: Minor cleanups (#7542)
* TimeVal: Log the results of the COARSE probes in debug logs
* GestureDetector: Print details of failed clock probes in debug logs
* GestureDetector: Skip the BOOTTIME probe when CLOCK_BOOTTIME is unsupported.
* Input: Decode ABS_DISTANCE events in debug logs
* Get rid of duplicated <linux/input.h> constants, use the FFI module everywhere (re #7536)
* Kobo: Get rid of the `touch_alyssum_protocol` quirk. Replace it by setting `main_finger_slot` to `1`, like on the H2O.
3 years ago
Glen Sawyer b6b332e311
Fix for PR #7415 breaking reMarkable touch input (#7536)
The Wacom pen reports sane CLOCK_REALTIME timestamps, but the Touchscreen reports timestamps frozen at the boot time ts (in REALTIME) :s.

So, make everyone use synthetic CLOCK_MONOTONIC timestamps in order to make gesture detection behave.
3 years ago
zwim 10922561dd
Add update of the top and bottom status bars, on +/-Charging (#7379) 3 years ago
NiLuJe 03e9fac156
Input: Process input events in batches (#7483)
Requires https://github.com/koreader/koreader-base/pull/1344 & https://github.com/koreader/koreader-base/pull/1346 (fix #7485)

Assorted input fixes:

* Actually handle errors in the "there's a callback timer" input polling loop.
* Don't break timerfd when the clock probe was inconclusive.

Not directly related, but noticed because of duplicate onInputEvent handlers:

* HookContainer: Fix deregistration to actually deregister properly. "Regression" extant since its inception in #2933 (!).
* Made sure the three plugins (basically the trio of AutoThingies ;p) that were using HookContainer actually unschedule their task on teardown.
3 years ago
NiLuJe 8a923e3e77
Input: Followup tweaks to #7415 (#7478)
* Actually load librt properly on old Linux systems (fix #7472)
* Made sure SDL & Android honored timeouts properly in some edgy (or not so edgy, in SDL's case) cases (c.f., https://github.com/koreader/koreader-base/pull/1343).
* Try harder not to consume a timer callback when the timerfd backend is in use and `select` timed out *not* because of a timerfd expiring. This would take some particularly heinous timing to reproduce (e.g., a timerfd set, but a task deadline expiring *before* it). May or may not help with #7473.
* Decode `BTN_` KEY codes in verbose debug logs.
* Fix MultiTouch on the H2O (GestureDetector was hard-coding the two slots as 0 & 1, but the H2O kernel is a special snowflake that doesn't use slot 0, instead switching to slot 1 & 2).
3 years ago
NiLuJe 1f15184bbb
Kindle: Fix gyro events on Zelda (#7459)
* Kindle: Fix gyro event on Zelda

Like on Kobo, only honor the face-up events.
3 years ago
NiLuJe 6d53f83286
The great Input/GestureDetector/TimeVal spring cleanup (a.k.a., a saner main loop) (#7415)
* ReaderDictionary: Port delay computations to TimeVal
* ReaderHighlight: Port delay computations to TimeVal
* ReaderView: Port delay computations to TimeVal
* Android: Reset gesture detection state on APP_CMD_TERM_WINDOW.
  This prevents potentially being stuck in bogus gesture states when switching apps.
* GestureDetector:
  * Port delay computations to TimeVal
  * Fixed delay computations to handle time warps (large and negative deltas).
  * Simplified timed callback handling to invalidate timers much earlier, preventing accumulating useless timers that no longer have any chance of ever detecting a gesture.
  * Fixed state clearing to handle the actual effective slots, instead of hard-coding slot 0 & slot 1.
  * Simplified timed callback handling in general, and added support for a timerfd backend for better performance and accuracy.
  * The improved timed callback handling allows us to detect and honor (as much as possible) the three possible clock sources usable by Linux evdev events.
    The only case where synthetic timestamps are used (and that only to handle timed callbacks) is limited to non-timerfd platforms where input events use
    a clock source that is *NOT* MONOTONIC.
    AFAICT, that's pretty much... PocketBook, and that's it?
* Input:
  * Use the <linux/input.h> FFI module instead of re-declaring every constant
  * Fixed (verbose) debug logging of input events to actually translate said constants properly.
  * Completely reset gesture detection state on suspend. This should prevent bogus gesture detection on resume.
  * Refactored the waitEvent loop to make it easier to comprehend (hopefully) and much more efficient.
    Of specific note, it no longer does a crazy select spam every 100µs, instead computing and relying on sane timeouts,
    as afforded by switching the UI event/input loop to the MONOTONIC time base, and the refactored timed callbacks in GestureDetector.
* reMarkable: Stopped enforcing synthetic timestamps on input events, as it should no longer be necessary.
* TimeVal:
  * Refactored and simplified, especially as far as metamethods are concerned (based on <bsd/sys/time.h>).
  * Added a host of new methods to query the various POSIX clock sources, and made :now default to MONOTONIC.
  * Removed the debug guard in __sub, as time going backwards can be a perfectly normal occurrence.
  * New methods:
    * Clock sources: :realtime, :monotonic, :monotonic_coarse, :realtime_coarse, :boottime
    * Utility: :tonumber, :tousecs, :tomsecs, :fromnumber, :isPositive, :isZero
* UIManager:
  * Ported event loop & scheduling to TimeVal, and switched to the MONOTONIC time base.
    This ensures reliable and consistent scheduling, as time is ensured never to go backwards.
  * Added a :getTime() method, that returns a cached TimeVal:now(), updated at the top of every UI frame.
    It's used throughout the codebase to cadge a syscall in circumstances where we are guaranteed that a syscall would return a mostly identical value,
    because very few time has passed.
    The only code left that does live syscalls does it because it's actually necessary for accuracy,
    and the only code left that does that in a REALTIME time base is code that *actually* deals with calendar time (e.g., Statistics).
* DictQuickLookup: Port delay computations to TimeVal
* FootNoteWidget: Port delay computations to TimeVal
* HTMLBoxWidget: Port delay computations to TimeVal
* Notification: Port delay computations to TimeVal
* TextBoxWidget: Port delay computations to TimeVal
* AutoSuspend: Port to TimeVal
* AutoTurn:
  * Fix it so that settings are actually honored.
  * Port to TimeVal
* BackgroundRunner: Port to TimeVal
* Calibre: Port benchmarking code to TimeVal
* BookInfoManager: Removed unnecessary yield in the metadata extraction subprocess now that subprocesses get scheduled properly.

* All in all, these changes reduced the CPU cost of a single tap by a factor of ten (!), and got rid of an insane amount of weird poll/wakeup cycles that must have been hell on CPU schedulers and batteries..
3 years ago
NiLuJe b325fa4a50
Initial KOA3 support (#7446)
* Move MXCFB capchecks to front

The fact that this was halfway in front/halfway in base was weird and
mistake-prone (c.f., the amount of times I forgot to update one bit or
the other).

* Initial KOA3 support

Assume it's essentially a KOA2. Meaning no warmth handling for now.

* Bump base

https://github.com/koreader/koreader-base/pull/1339
https://github.com/koreader/koreader-base/pull/1338
3 years ago
NiLuJe 861214ce2a
Kobo: Allow toggling the WAIT_FOR_UPDATE_COMPLETE hack (#7431)
* Allow toggling the MXCFB_WAIT_FOR_UPDATE_COMPLETE bypass

* Drive-by: enable the abort_on_crash menu on Pb & rM, since they support
it
3 years ago
NiLuJe 41182349bc
Re-implement the PB fb fixup insanity (#7404)
* Re-implement the PB fb fixup insanity

It's apparently still necessary on a number of devices.
Fix #7072

* Bump base

(Fix FBInk on the same devices, for another reason).
3 years ago
NiLuJe 0b3747927c
WakeupMgr: Minor usage tweak (#7400)
* Unify logging with AutoSuspend (e.g., keep ourselves to showing the delay in seconds, not the raw timestamp, as that's way harder to interpret, and the RTC module and/or logger will do that for us when the time comes).
* Speaking of, minor revamp of RTC related logging to make it more human-readable.
* On Kobo, if we hit the unexpected wakeup limit, re-engage AutoSuspend's *suspend* check, so that the device has a chance to poweroff instead of being kept awake.
3 years ago
Glen Sawyer 3f0654f530
Hold "Wi-Fi" menu to show network selection instead of auto-connecting (#7395)
* Hold "Wi-Fi connection" to show network connection options.
* Honor backend connections (e.g., if wpa_supplicant found a matching AP in its own config first).
* When user clicks "Wi-Fi connection" in menu, only prompt if state is ambiguous.
3 years ago
NiLuJe fba0b8eec7 Kobo: Refresh the system clock on resume.
Mimics Nickel's behavior, should fix #7092

Thanks to @gtalusan for the pointers ;).

Bump base

(https://github.com/koreader/koreader-base/pull/1322)
3 years ago
NiLuJe bf6c0cdd6c
LuaSettings: Add a method to initialize a setting properly (#7371)
* LuaSettings/DocSettings: Updated readSetting API to allow proper initialization to default.
Use it to initialize tables, e.g., fixing corner-cases in readerFooter that could prevent settings from being saved.
(Fixes an issue reported on Gitter).
* LuaSettings/DocSettings: Add simpler API than the the flip* ones to toggle boolean settings.
* Update LuaSettings/DocSettigns usage throughout the codebase to use the dedicated boolean methods wher appropriate, and clean up some of the more mind-bending uses.
* FileChooser: Implement an extended default exclusion list (fix #2360)
* ScreenSaver: Refactor to avoid the pile of kludges this was threatening to become. Code should be easier to follow and use, and fallbacks now behave as expected (fix #4418).
3 years ago
Glen Sawyer 15ef1a3a1b
reMarkable 2 clean wakeup from sleep (#7345) 3 years ago
Martín Fernández eb57c4e0da
Add a couple of modern android dicts (#7359)
https://play.google.com/store/apps/details?id=gaurav.lookuppro and its free version.

From https://www.mobileread.com/forums/showpost.php?p=4097548&postcount=8
3 years ago
NiLuJe 64611e6acb
Legacy Kindle: Actually handle (system) power events (#7336)
Otherwise, ScreenSaver handling doesn't work, duh'.
I have no idea how I managed to get that working the last time I tested
it :?.
Possibly I tested the final code on a K4 and not a K3?

Fix #7333
3 years ago
Rex Kerr 2510ff4847
Reversing commit 2348cd, changes to warmth values (#7296) 3 years ago
Rex Kerr 2348cdb066
Improved ramp-down of warm-light after max hour (#7272)
previously: warm light stays at 100% for 3 hours and then drops by 50% per hour
now: warm light stays at 100% for 4 hours and then drops by 15% per hour
3 years ago
Martín Fernández 4a89c93290
Remarkable1 wifi (#7216)
* add wifi support to Rm1
* remarkable: common suspend for all models
3 years ago
Glen Sawyer 34b177aa69
Wifi toggle for reMarkable 2 (#7122)
reMarkable 1 is no-op for the moment
3 years ago
NiLuJe dffe86dfe9
Cleanup eye-gouging madness around io.read calls (#7149)
* Don't reinvent the wheel when reading a one-line int or string from sysfs

* Simplify a whole other bunch of read calls
3 years ago
NiLuJe 183e0a2e25
Bump android-luajit-launcher (#7137)
* Check available width when using a viewport

* Mention that available_width should always match width
3 years ago
poire-z 8f79c662cf Notification: closed by any event, but not consuming it
Make Notification have toast=true, and UIManager deal
specifically with such widget:
a "toast" widget gets closed by any event, and let
the event be handled by a lower widget.
This should allow us to not wait or tap to get rid
of a notification, and just go on with what we're
doing.
Also make them have a default timeout of 2s,
used with all existing ones.
3 years ago
yparitcher dc964f3941
reader.lua: rework file/directory argument handling. (#7053)
platform: do not pass a directory on the command line.
The home directory will be properly set by Device.home_dir.

It was sometimes crashing when opened with no args.

Fixes: #7049
3 years ago
NiLuJe 34b764dc06 Kindle Legacy: Probe for SO on the K3 & K4 3 years ago
NiLuJe 5ae5c99197
Legacy Kindle: Unbreak screensavers (#7112)
* The K2 & DXg cannot be SO, so, bypass the check there

* Handle native screensavers on FW 3.x & 4.x
3 years ago
NiLuJe 5756f1f43e
LuaJIT on Android fixes (#7094)
* Don't flag Android as should_restrict_JIT

And allow disabling the C blitter, to put the workaround to the test...

* Add a -d, --debug flag to the log function

Catches KOReader's debug, as well as (our) dlopen & luajit logging

* Bump android-luajit-launcher

https://github.com/koreader/android-luajit-launcher/pull/283
https://github.com/koreader/android-luajit-launcher/pull/282

* Bump base

(https://github.com/koreader/koreader-base/pull/1279)
3 years ago
John Beard 0e494169f2
Keyboard input in InputText (#7037)
For text input, use the SDL events, which contain the decoded
strings.

Still handle keypresses for non-text input.
3 years ago
Glen Sawyer 3bd3493014
Fix double-pressing reMarkable 2 power button twice to wake up (#7065) 3 years ago
Glen Sawyer 578f92e424
Time-adjust on all reMarkable events, not just EV_ABS (#7066) 3 years ago
gbyl d2379fc6e6
remarkable: poweroff.png ghosting fix (#7051) 3 years ago
NiLuJe f1f439d08b
More Android trickery (#7059)
* Modernize jit syntax

It's built-in, no need for a require anymore.

* Flag Android should_restrict_JIT again

It's mildly helpful at putting off the inevitable.
(very, very, very, very mildly).

* Bump android-luajit-launcher

https://github.com/koreader/android-luajit-launcher/pull/281
3 years ago
Frans de Jonge 53909db687
Close Lua state on all os.exit() calls (#7050)
Cf. <https://github.com/koreader/koreader/pull/7044>.
3 years ago
NiLuJe d845741b15
Android: Don't mark the platform as should_restrict_JIT (#7024)
* Android: Don't mark the platform as should_restrict_JIT

And see how much stuff breaks \o/

* Prevent Android users from disabling the C blitter, regardless of the
restrict flag

* Update android-luajit-launcher

https://github.com/koreader/android-luajit-launcher/pull/278
https://github.com/koreader/android-luajit-launcher/pull/275
3 years ago
NiLuJe 09c1f35191
rM: Unbreak PowerEvents (#7043)
Most of this is scheduled with delays for reasons, so this was a stupid
idea, my bad ;).

Fix #7033
3 years ago
NiLuJe 9cda84ef2f Prevent Busted from blowing up on cdata finalizers by properly closing
opened documents...
3 years ago
NiLuJe c0981a55d9 Make sure KindlePowerD's __gc metamethod will actually be called
* Via the newproxy hack.
3 years ago