From 7a84cfef4a648f5c0e00980acfebec8a80eaec54 Mon Sep 17 00:00:00 2001 From: David <97603719+Commodore64user@users.noreply.github.com> Date: Wed, 5 Jun 2024 07:51:45 +0100 Subject: [PATCH] Individually invert left or right side page turn buttons on Kindle (#11963) K4 is ergonomically designed to be held with one hand (one's hand wrapped around the back and both thumb and middle finger on either PgFwd buttons). This PR allows users to individually invert left and right page turners such that it can be operated just with one hand. It also closes #9350 Not sure if there are any other devices with two sets of page turn buttons, so currently limited to kindle, excluding kindle Voyage, but could be added too, albeit with some gymnastics. --- frontend/device/generic/device.lua | 24 +++++++++++++++++ frontend/ui/elements/physical_buttons.lua | 33 +++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/frontend/device/generic/device.lua b/frontend/device/generic/device.lua index d4bd7ed64..6dc5e650f 100644 --- a/frontend/device/generic/device.lua +++ b/frontend/device/generic/device.lua @@ -170,6 +170,30 @@ function Device:invertButtons() end end +function Device:invertButtonsLeft() + if self:hasKeys() and self.input and self.input.event_map then + for key, value in pairs(self.input.event_map) do + if value == "LPgFwd" then + self.input.event_map[key] = "LPgBack" + elseif value == "LPgBack" then + self.input.event_map[key] = "LPgFwd" + end + end + end +end + +function Device:invertButtonsRight() + if self:hasKeys() and self.input and self.input.event_map then + for key, value in pairs(self.input.event_map) do + if value == "RPgFwd" then + self.input.event_map[key] = "RPgBack" + elseif value == "RPgBack" then + self.input.event_map[key] = "RPgFwd" + end + end + end +end + function Device:init() if not self.screen then error("screen/framebuffer must be implemented") diff --git a/frontend/ui/elements/physical_buttons.lua b/frontend/ui/elements/physical_buttons.lua index 454ba3e2e..5ddd825e4 100644 --- a/frontend/ui/elements/physical_buttons.lua +++ b/frontend/ui/elements/physical_buttons.lua @@ -9,16 +9,49 @@ local PhysicalButtons = { sub_item_table = { { text = _("Invert page turn buttons"), + enabled_func = function() + return not (G_reader_settings:isTrue("input_invert_left_page_turn_keys") or G_reader_settings:isTrue("input_invert_right_page_turn_keys")) + end, checked_func = function() return G_reader_settings:isTrue("input_invert_page_turn_keys") end, callback = function() UIManager:broadcastEvent(Event:new("SwapPageTurnButtons")) end, + separator = true, } }, } +if Device:hasDPad() and Device:useDPadAsActionKeys() then + table.insert(PhysicalButtons.sub_item_table, { + text = _("Invert left-side page turn buttons"), + enabled_func = function() + return not G_reader_settings:isTrue("input_invert_page_turn_keys") + end, + checked_func = function() + return G_reader_settings:isTrue("input_invert_left_page_turn_keys") + end, + callback = function() + G_reader_settings:flipNilOrFalse("input_invert_left_page_turn_keys") + Device:invertButtonsLeft() + end, + }) + table.insert(PhysicalButtons.sub_item_table, { + text = _("Invert right-side page turn buttons"), + enabled_func = function() + return not G_reader_settings:isTrue("input_invert_page_turn_keys") + end, + checked_func = function() + return G_reader_settings:isTrue("input_invert_right_page_turn_keys") + end, + callback = function() + G_reader_settings:flipNilOrFalse("input_invert_right_page_turn_keys") + Device:invertButtonsRight() + end, + }) +end + if Device:canKeyRepeat() then table.insert(PhysicalButtons.sub_item_table, { text = _("Disable key repeat"),