Commit Graph

919 Commits (master)

Author SHA1 Message Date
nairyo 65031ae14f
Dictionary lookup window: use from/to language to determine glyph form (#10184)
For example, to determine whether the Japanese or Chinese form should be shown.

* Dictionaries.lua - use iso3 codes everywhere
readerdictionary.lua - convert iso to bcp tag, to construct ifo_lang
isolanguage.lua - map from iso3 to full language name, map from iso3 to bcp language tag

* Make the full language names translatable

* Store ifo information from dictionaries.lua in downloaded dictionaries
1 year ago
NiLuJe 9f37863f00
rM: Handle input shenanigans on mainline kernels (#10168)
Add a dedicated handler to handle mixed pen + panel, when panel sends both mt + st and stylus only st
Don't stomp on panel slots in the Wacom protocol handler
Get rid of a few superfluous nil guards
Return early in the EV_KEY handler for touch-related events (i.e., BTN_)
1 year ago
NiLuJe d0b78c01aa
Hotfix followup to #10139 (#10151)
Don't blow up if we fall back to exec'ing ping
Fix https://github.com/koreader/koreader/pull/10139#issuecomment-1437678458
1 year ago
NiLuJe 5330c24b77
Device: Handle network info data gathering ourselves (#10139)
i.e., we now query routes, interfaces, wireless extensions & ping ourselves, dropping the dependency on specific CLI tools altogether.
1 year ago
NiLuJe 203094d47d Device:retrieveNetworkInfo: Drop the "HWaddr" bit from the parsed output
i.e., just display "ifname MAC"
1 year ago
NiLuJe 6dc41fe02a Device:retrieveNetworkInfo: Make "Default gateway" translatable
re: #8739
1 year ago
Andrej Shadura 328670b515
Device:retrieveNetworkInfo: Add a fallback to net-tools (#8739)
Some devices don't ship with iproute2 compatible tools, but may ship
with net-tools compatible ones.

Unify code w/ SDL's similar codepaths for its NetworkMgr:isConnected
implementation
1 year ago
yparitcher 706c8c5610 fix broken escaping 1 year ago
NiLuJe 15b236e3e9
Kobo: Mimic Nickel's poweroff behavior on sunxi (#10122)
It goes through init, unlike on other models.

Re: #10121
1 year ago
NiLuJe 96850c23a0
NetworkMgr: Refine isConnected check (#10098)
Much easier to deal with thanks to the cleanup work done in #10062 ;).

* `carrier` is set to 1 as soon as the device is *administratively* up (in practice, as soon as we run `ifconfig up`). This is perfectly fine for `isWifiOn`, but absolutely not for `isConnected`, because we are not, actually, connected to *anything*, no attempt at associating has even been made at that point. Besides being semantically wrong, in practice, this will horribly break the connectivity check, because it expects that `isConnected` means we can talk to at least the LAN.
* Delving into the Linux docs reveals that `operstate` looks like a better candidate, as it reflects *operational status*; for Wi-Fi, that means associated and successfully authenticated. That's... closer, but still not it, because we still don't have an IP, so we technically can't talk to anything other than the AP.
* So, I've brought out the big guns (`getifaddrs`), and replicated a bit of code that I already use in the USBNetwork hack on Kindle, to detect whether we actually have an IP assigned. (Other approaches, like `/proc/net/route`, may not be entirely fool-proof, and/or get complicated when IPv6 enters the fray (which it does, on Kobo, Mk. 8+ devices are IPv6-enabled)).

TL;DR: Bunch of C via ffi, and `isConnected` now returns true only when the device is operationally up *and* we have an IP assigned.

Pulls in https://github.com/koreader/koreader-base/pull/1579 & https://github.com/koreader/lj-wpaclient/pull/10
1 year ago
NiLuJe b1c30a7b1e
Input: Don't set unnecessary input translations when viewports are involved (#10104) 1 year ago
yparitcher 0e53631f48 NetworkManager: isWifiOn isConnected consistent usage.
cervantes kindle kobo remarkable: use sysfs carrier file to determine connection state

cleanup hasWifiManager checks

gateway check: use ip if available

Fixes: #10087
Closes: #10092
1 year ago
zwim 50ab620da1
Screen Warmth: Fix a bug with syncing screen warmth on start (#10066) 1 year ago
Sargun Vohra 15fb73384f
EInk: Add a setting to toggle flashing on pages with images (#10049)
With minor code cleanups along the way ;).
1 year ago
yparitcher 747c3eaf9d
Kindle: NetworkMgr: isWifiOn isConnected (#10059)
isWifiOn for kindle currently returns if the interface is connected, change this to doing what is says isWifiOn the file is only present if the wireless interface is up.

isConnected pings the gateway, rely on the kernel for a more reliable check.

Whan connecting to my android phone's wifi hotspot to remote debug from my phone, the network is connected yet the phone(gateway) does not respond to pings leading koreader to shut down the connection thinking it is unsuccessful
1 year ago
Jej 198a84a772
Minor updates in comments (#10038) 1 year ago
NiLuJe bb900aa9a7
WakeupMgr: Explicitly invalidate the current alarm in unsetWakeupAlarm (#10032)
Apparently, toggling the rtc interrupt doesn't quite work on some boards? (fix #10031)

(Drive-by tweak to UIManager: Less confusing logging when quit gets tripped both via quit
and _gated_quit (i.e., on poweroff))
1 year ago
NiLuJe 16fb32d5a4
Kobo: Unbreak a slew of devices (#10019)
Fix #10020, Regression since #10008

(hasMultiTouch is set by `Generic.init`, but we use it before that;
so just set it properly ourselves in our superclass, because we don't
actually need to rely on Generic's autodetection).
1 year ago
NiLuJe f74921724a Android: Don't pile on event hooks to handle viewport changes
Untested, hopefully sane :s
1 year ago
NiLuJe 64af750c6c Kobo: Unbreak input translation when a viewport is active
Generic is responsible for setting up the translation via input hooks;
since our own input hooks involve swapping or mirroring X/Y, we need to
run our own hooks *first*, so that the viewport translation actually
does the right thing...

Probably broken for a good long while, I'd just assumed the inaccuracies
on the H2O were due to the IR grid... :/.

Reported @ https://www.mobileread.com/forums/showthread.php?t=351340
1 year ago
NiLuJe 5c1305719a
Kobo: Unbreak automagic_sysfs on the Libra 2 (#9998)
Regression since #9902, because I'd forgotten that the default Kobo block *does* set those...
Reported by @ptrm on Gitter, thanks!

Take two, essentially revert 8a16518918
We have defaults for most of those in the Kobo superclass, so these can never really be `nil`.
1 year ago
NiLuJe 8d133507ad Device: Handle screen_saver_lock + WiFi corner-cases
If Wi-Fi is restored on resume, going back to suspend while the
screensaver is shown via the screen_saver_lock flag would have attempted
to suspend *without* killing Wi-Fi first.

This implodes on the vast majority of NTX boards, so take the usual
precautions.
1 year ago
NiLuJe 144706654d Device: Drop unused device capabilities 1 year ago
Robert-Jan de Dreu c9df3a000f
PB: Implement GSensor support for more moderm devices (#9873)
(Bumps base for https://github.com/koreader/koreader-base/pull/1566)
1 year ago
NiLuJe 788ccac561
Input/Device: Refactor Gyro events handling (#9935)
* Get rid of the `canToggleGSensor` Device cap, it's now mandatory for `hasGSensor` devices. (This means Kindles can now toggle the gyro, fix #9136).
* This also means that `Device:toggleGSensor` is now implemented by `Generic`.
* Update the Screen & Gyro rotation constants to be clearer (c.f., https://github.com/koreader/koreader-base/pull/1568) (/!\ This might conceivably break some `rotation_map` user-patches).
* Input: Move the platform-specific gyro handling to Device implementations, and let Input only handle a single, custom protocol (`EV_MSC:MSC_GYRO`).
* Input: Refine the `rotation_map` disable method implemented in 43b021d37c. Instead of directly poking at the internal field, use a new method, `disableRotationMap` (/!\ Again, this might break some `rotation_map` user-patches).
* Input: Minor tweaks to event adjust hooks to make them more modular, allowing the Kobo implementation to build and use a single composite hook. API compatibility maintained with wrappers.
1 year ago
Frans de Jonge 99df719562
[i18n] Make gateway strings translateable (#9933)
See <https://www.mobileread.com/forums/showthread.php?p=4282773#post4282773>.
1 year ago
NiLuJe 9b936d3f3c AutoSuspend: On Kindle, periodically reset the system's timeout so that
our own timeout can actually be honored.

Fix #7874, fix #9868
1 year ago
NiLuJe 3a8d94ad56 Kindle: Unbreak ScreenSaver tracking on SO devices
Fix #9883, regression since c7f5bfb72a
1 year ago
NiLuJe 8a16518918 Kobo: Only probe necessary entries in automagic_sysfs codepath
e.g., on the Sage, only the power_dev stuff changes between HW revs,
the rest of the hardcoded stuff is still relevant, so skip probing
those.
1 year ago
Robert-Jan de Dreu 9a573ae812
PocketBook: remove old input selection global (#9871) 1 year ago
charlesangus cad4c24118
Kobo: Handle power button input device on new Sage HW revision (#9896)
Co-authored-by: Frans de Jonge <fransdejonge@gmail.com>
Co-authored-by: NiLuJe <ninuje@gmail.com>
1 year ago
zwim d1cd2a1c8d
Restart KOReader: add a ConfirmBox instead of a plain InfoMessage (#9853) 1 year ago
Robert-Jan de Dreu f953f041ea
PocketBook: use inkview to adjust image colors to look more bright (#9756)
Adjust image colors for PocketBook color devices to supply
brighter image colors. Make it a config option so we can
adjust it to a sensible default for all devices later.
Also enable HW Dithering for color devices: the dithering
flag allows us to figure out if what is viewed is an
image or text. This way we can enable color rendering
or not based on the dithering flag.
1 year ago
NiLuJe 3a92f3385c PB: Handle KEY_HOME
It possibly historically never made it out of InkView in the past, but
apparently that's no longer the case and/or every other key behaves the
same way anyway, so it's harmless at worst.

Fix #9791
1 year ago
NiLuJe c5700b718d Android: Get rid of the Camera key hack
Unnecessary now that we have a standard mechanism to disable touch input
;).
2 years ago
NiLuJe 58ba4076a8 Kobo: Detect the original Touch "A" variant properly.
Because, of course, it has different input quirks than the B...

Fix #9742
2 years ago
NiLuJe c7f5bfb72a ScreenSaver: Handle Power button presses properly if the screensaver
lock is enabled

Fix #9744
2 years ago
NiLuJe 47734eefef DeviceListener: Unify Notification usage 2 years ago
zwim a1256f6758
Fix regression (introduced in #9657) (#9759)
This should fix #9741.
2 years ago
zwim cd69382934
[plugin] AutoWarmth: fix frontlight toggle during day (#9735) 2 years ago
NiLuJe 9863a9c0bb ExternalKeyboard: Use the evdev number passed along by base to avoid sweeping the full list of input devices
This required some... creative thinking to avoid complexifying common
Input/UIManager codepaths ;p.
2 years ago
NiLuJe c740ee3174 Kindle: Make sure Device:untar actually works
The fuse proxy strikes again... Fix #9704
2 years ago
NiLuJe 5cb358f653 PocketBook: Move low-level input event type translation to the low-level
input modules.

There was a weird mix of touch being handled there, and key/msc here,
which was weird and made the logs extremely confusing to read.
2 years ago
NiLuJe 3dd87a38b3 Kindle: Oh, hey, turns out that was the new Basic
I'd completely forgotten they'd announced one ;o).
2 years ago
NiLuJe 43b021d37c Input: Allow disabling rotation_map entirely
(This involves moving it to the instance object to avoid inheritance).

Pocketbook: Disable rotation_map on the Era (fix #9556)
It would appear that InkView handles the translation for us, now...
2 years ago
NiLuJe 9470d473da Kindle: Lower some PM log messages to debug 2 years ago
NiLuJe b1504ea718 Kobo: Downgrade some suspend logging messages to debug, and *all*
standby logging messages to debug (except for warnings/errors, of course).
2 years ago
NiLuJe cac37ad018 Kobo: Flag all the boards similar to the Libra 2 as unreliable (Clara 2E
& Nia).

And also disable the jump marker on those, like we did for the Libra 2.
2 years ago
NiLuJe bf574bfaaf GestureDetector: Only show the final adjustGesCoordinate log if the gesture actually was adjusted. 2 years ago
NiLuJe b523c2e8b9 InputContainer: Fall cleanup ;).
Get rid of the doc & seqtext fields, as they are not actually used (nor
are they particularly useful, the event handler's name should be pretty
self-explanatory).

Also, tweak the key_events documentation to highlight the quirks of the
API, especially as far as array nesting is involved...

Random drive-by cleanup of the declarations of key_events & ges_events
to re-use the existing instance object (now that we know they're sane
;p) for tables with a single member (less GC pressure).
2 years ago
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