Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce Device:useDPadAsActionKeys() #11900

Merged
merged 9 commits into from
May 26, 2024
2 changes: 1 addition & 1 deletion frontend/apps/filemanager/filemanager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ function FileManager:registerKeyEvents()
self.key_events.Home = { { "Home" } }
-- Override the menu.lua way of handling the back key
self.file_chooser.key_events.Back = { { Device.input.group.Back } }
if Device:hasFiveWay() and not Device:hasKeyboard() then
if Device:hasScreenKB() then
self.key_events.KeyToggleWifi = { { "ScreenKB", "Home" }, event = "ToggleWifi" }
end
if not Device:hasFewKeys() then
Expand Down
2 changes: 1 addition & 1 deletion frontend/apps/filemanager/filemanagermenu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ end
function FileManagerMenu:registerKeyEvents()
if Device:hasKeys() then
self.key_events.ShowMenu = { { "Menu" } }
if Device:hasFiveWay() and not Device:hasKeyboard() then
if Device:hasScreenKB() then
self.key_events.OpenLastDoc = { { "ScreenKB", "Back" } }
end
end
Expand Down
2 changes: 1 addition & 1 deletion frontend/apps/reader/modules/readerbookmark.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function ReaderBookmark:onGesture() end
function ReaderBookmark:registerKeyEvents()
if Device:hasKeyboard() then
self.key_events.ShowBookmark = { { "B" } }
elseif Device:hasFiveWay() then
elseif Device:hasScreenKB() then
self.key_events.ShowBookmark = { { "ScreenKB", "Left" } }
self.key_events.ToggleBookmark = { { "ScreenKB", "Right" } }
end
Expand Down
16 changes: 8 additions & 8 deletions frontend/apps/reader/modules/readerfont.lua
Original file line number Diff line number Diff line change
Expand Up @@ -142,20 +142,20 @@ function ReaderFont:onGesture() end

function ReaderFont:registerKeyEvents()
if Device:hasKeyboard() then
-- add shortcut for keyboard
self.key_events = {
ShowFontMenu = { { "F" } },
IncreaseSize = {
self.key_events.ShowFontMenu = { { "F" } }
if not (Device:hasScreenKB() or Device:hasSymKey()) then
-- add shortcut for keyboard
self.key_events.IncreaseSize = {
{ "Shift", Input.group.PgFwd },
event = "ChangeSize",
args = 0.5
},
DecreaseSize = {
}
self.key_events.DecreaseSize = {
{ "Shift", Input.group.PgBack },
event = "ChangeSize",
args = -0.5
},
}
}
end
end
end

Expand Down
8 changes: 2 additions & 6 deletions frontend/apps/reader/modules/readerhighlight.lua
Original file line number Diff line number Diff line change
Expand Up @@ -246,16 +246,12 @@ function ReaderHighlight:registerKeyEvents()
self.key_events.QuickLeftHighlightIndicator = { { "Shift", "Left" }, event = "MoveHighlightIndicator", args = {-1, 0, QUICK_INDICATOR_MOVE} }
self.key_events.QuickRightHighlightIndicator = { { "Shift", "Right" }, event = "MoveHighlightIndicator", args = {1, 0, QUICK_INDICATOR_MOVE} }
self.key_events.StartHighlightIndicator = { { "H" } }
if Device:hasFiveWay() then
self.key_events.KeyContentSelection = { { { "Up", "Down" } }, event = "StartHighlightIndicator" }
end
elseif Device:hasFiveWay() then
elseif Device:hasScreenKB() then
local QUICK_INDICATOR_MOVE = true
self.key_events.QuickUpHighlightIndicator = { { "ScreenKB", "Up" }, event = "MoveHighlightIndicator", args = {0, -1, QUICK_INDICATOR_MOVE} }
self.key_events.QuickDownHighlightIndicator = { { "ScreenKB", "Down" }, event = "MoveHighlightIndicator", args = {0, 1, QUICK_INDICATOR_MOVE} }
self.key_events.QuickLeftHighlightIndicator = { { "ScreenKB", "Left" }, event = "MoveHighlightIndicator", args = {-1, 0, QUICK_INDICATOR_MOVE} }
self.key_events.QuickRightHighlightIndicator = { { "ScreenKB", "Right" }, event = "MoveHighlightIndicator", args = {1, 0, QUICK_INDICATOR_MOVE} }
self.key_events.KeyContentSelection = { { { "Up", "Down" } }, event = "StartHighlightIndicator" }
end
end

Expand Down Expand Up @@ -377,7 +373,7 @@ local highlight_dialog_position = {

function ReaderHighlight:addToMainMenu(menu_items)
-- insert table to main reader menu
if not Device:isTouchDevice() and Device:hasDPad() and not Device:hasFiveWay() then
if not Device:isTouchDevice() and Device:hasDPad() and not Device:useDPadAsActionKeys() then
menu_items.start_content_selection = {
text = _("Start content selection"),
callback = function()
Expand Down
26 changes: 12 additions & 14 deletions frontend/apps/reader/modules/readerlink.lua
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,25 @@ end
function ReaderLink:onGesture() end

function ReaderLink:registerKeyEvents()
if Device:hasKeys() and not Device:hasFiveWay() then
if Device:hasScreenKB() or Device:hasSymKey() then
self.key_events.GotoSelectedPageLink = { { "Press" }, event = "GotoSelectedPageLink" }
if Device:hasKeyboard() then
self.key_events.AddCurrentLocationToStack = { { "Shift", "Down" } }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here Shift + Press

self.key_events.SelectNextPageLink = { { "Shift", "LPgFwd" }, event = "SelectNextPageLink" }
self.key_events.SelectPrevPageLink = { { "Shift", "LPgBack" }, event = "SelectPrevPageLink" }
else
self.key_events.AddCurrentLocationToStack = { { "ScreenKB", "Down" } }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you change this to ScreenKB and Press (instead of Down) there is something I want to try and if successful would go on KB+Down. Also, any idea why this doesn't show a notification when one uses it? normally at the top of the screen a little box appears saying, "added to stack or whatever" (yes all notifications under Screen menu are ON).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like notification true or false is passed as an argument. DIspatcher sets arg=true.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve already tried that and still won’t show it… not sure why

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm yes, the true comes through if you add args=true but it doesn't seem to show the notification. You say it works from Dispatcher?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the defaults

Being SOURCE_OTHER, which is described as all other sources (e.g. keyboard), which is indeed masked out unless you explicitly request notifications from all sources.

TL;DR: behaving as expected ;).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, so how do we set a source and/or make it show the notification?

Copy link
Member

@NiLuJe NiLuJe May 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We... don't because it's behaving as expected and keyboard shortcuts shouldn't display notifications unless the user asks for it?

Copy link
Contributor

@Commodore64user Commodore64user May 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but this is 'different'...? I need the notification to be shown so it provides feedback on NT kindles, otherwise it would appear as if nothing was happening.

Essentially it should work same as if it was coming from dispatcher.

Copy link
Member

@NiLuJe NiLuJe May 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then you need a custom event that either wraps the current one between Notification:setNotifySource(Notification.SOURCE_ALWAYS_SHOW) <-> Notification:resetNotifySource() (double-check that for obvious typos) or reimplement the current one except that it passes Notification.SOURCE_ALWAYS_SHOW as the second arg to Notify.

self.key_events.SelectNextPageLink = { { "ScreenKB", "LPgFwd" }, event = "SelectNextPageLink" }
self.key_events.SelectPrevPageLink = { { "ScreenKB", "LPgBack" }, event = "SelectPrevPageLink" }
end
elseif Device:hasKeys() then
self.key_events = {
SelectNextPageLink = {
{ "Tab" },
event = "SelectNextPageLink",
},
SelectPrevPageLink = {
{ "Shift", "Tab" },
{ "Sym", "Tab" }, -- Shift or Sym + Tab
event = "SelectPrevPageLink",
},
GotoSelectedPageLink = {
Expand All @@ -252,18 +262,6 @@ function ReaderLink:registerKeyEvents()
-- when G_reader_settings:readSetting("back_in_reader") == "previous_location"
}
end
if Device:hasFiveWay() then
self.key_events.GotoSelectedPageLink = { { "Press" }, event = "GotoSelectedPageLink" }
if Device:hasKeyboard() then
self.key_events.AddCurrentLocationToStack = { { "Shift", "Down" } }
self.key_events.SelectNextPageLink = { { "Shift", "LPgFwd" }, event = "SelectNextPageLink" }
self.key_events.SelectPrevPageLink = { { "Shift", "LPgBack" }, event = "SelectPrevPageLink" }
else
self.key_events.AddCurrentLocationToStack = { { "ScreenKB", "Down" } }
self.key_events.SelectNextPageLink = { { "ScreenKB", "LPgFwd" }, event = "SelectNextPageLink" }
self.key_events.SelectPrevPageLink = { { "ScreenKB", "LPgBack" }, event = "SelectPrevPageLink" }
end
end
end

ReaderLink.onPhysicalKeyboardConnected = ReaderLink.registerKeyEvents
Expand Down
3 changes: 1 addition & 2 deletions frontend/apps/reader/modules/readerpaging.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ end
function ReaderPaging:onGesture() end

function ReaderPaging:registerKeyEvents()
if Device:hasFiveWay() then
-- this targets all devices (kindles) non-touch with dPads (i.e dx, kk, k4 and others)
if Device:hasDPad() and Device:useDPadAsActionKeys() then
self.key_events.GotoNextPos = {
{ { "RPgFwd", "LPgFwd" } },
event = "GotoPosRel",
Expand Down
6 changes: 3 additions & 3 deletions frontend/apps/reader/modules/readerrolling.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ end
function ReaderRolling:onGesture() end

function ReaderRolling:registerKeyEvents()
if Device:hasFiveWay() then
if Device:hasScreenKB() or Device:hasSymKey() then
self.key_events.GotoNextView = {
{ { "RPgFwd", "LPgFwd" } },
event = "GotoViewRel",
Expand Down Expand Up @@ -151,7 +151,7 @@ function ReaderRolling:registerKeyEvents()
args = -1,
}
end
if Device:hasFiveWay() then
if Device:hasDPad() and Device:useDPadAsActionKeys() then
self.key_events.GotoNextChapter = {
{ "Right" },
event = "GotoNextChapter",
Expand All @@ -174,7 +174,7 @@ function ReaderRolling:registerKeyEvents()
args = {0, 1},
}
end
if Device:hasFiveWay() and not Device:hasKeyboard() then
if Device:hasScreenKB() then
self.key_events.MoveUp = {
{ "ScreenKB", "RPgBack" },
event = "Panning",
Expand Down
6 changes: 3 additions & 3 deletions frontend/apps/reader/modules/readertoc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ end
function ReaderToc:onGesture() end

function ReaderToc:registerKeyEvents()
if Device:hasKeyboard() then
self.key_events.ShowToc = { { "T" } }
elseif Device:hasFiveWay() then
if Device:hasScreenKB() then
self.key_events.ShowToc = { { "ScreenKB", "Up" } }
elseif Device:hasKeyboard() then
self.key_events.ShowToc = { { "T" } }
end
end

Expand Down
5 changes: 4 additions & 1 deletion frontend/apps/reader/readerui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,10 @@ function ReaderUI:registerKeyEvents()
if Device:hasKeys() then
self.key_events.Home = { { "Home" } }
self.key_events.Reload = { { "F5" } }
if Device:hasFiveWay() then
if Device:hasDPad() and Device:useDPadAsActionKeys() then
self.key_events.KeyContentSelection = { { { "Up", "Down" } }, event = "StartHighlightIndicator" }
end
if Device:hasScreenKB() or Device:hasSymKey() then
if Device:hasKeyboard() then
self.key_events.KeyToggleWifi = { { "Shift", "Home" }, event = "ToggleWifi" }
self.key_events.OpenLastDoc = { { "Shift", "Back" } }
Expand Down
4 changes: 3 additions & 1 deletion frontend/device/generic/device.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ local Device = {
hasAuxBattery = no,
hasKeyboard = no,
hasKeys = no,
hasFiveWay = no,
hasScreenKB = no, -- in practice only some Kindles
hasSymKey = no, -- in practice only some Kindles
canKeyRepeat = no,
hasDPad = no,
useDPadAsActionKeys = no,
hasExitOptions = yes,
hasFewKeys = no,
hasWifiToggle = yes,
Expand Down
12 changes: 8 additions & 4 deletions frontend/device/kindle/device.lua
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,9 @@ local Kindle2 = Kindle:extend{
isREAGL = no,
hasKeyboard = yes,
hasKeys = yes,
hasFiveWay = yes,
hasSymKey = yes,
hasDPad = yes,
useDPadAsActionKeys = yes,
canHWInvert = no,
canModifyFBInfo = no,
canUseCBB = no, -- 4bpp
Expand All @@ -532,8 +533,9 @@ local KindleDXG = Kindle:extend{
isREAGL = no,
hasKeyboard = yes,
hasKeys = yes,
hasFiveWay = yes,
hasSymKey = yes,
hasDPad = yes,
useDPadAsActionKeys = yes,
canHWInvert = no,
canModifyFBInfo = no,
canUseCBB = no, -- 4bpp
Expand All @@ -546,8 +548,9 @@ local Kindle3 = Kindle:extend{
isREAGL = no,
hasKeyboard = yes,
hasKeys = yes,
hasFiveWay = yes,
hasSymKey = yes,
hasDPad = yes,
useDPadAsActionKeys = yes,
canHWInvert = no,
canModifyFBInfo = no,
canUseCBB = no, -- 4bpp
Expand All @@ -558,8 +561,9 @@ local Kindle4 = Kindle:extend{
model = "Kindle4",
isREAGL = no,
hasKeys = yes,
hasFiveWay = yes,
hasScreenKB = yes,
hasDPad = yes,
useDPadAsActionKeys = yes,
canHWInvert = no,
canModifyFBInfo = no,
-- NOTE: It could *technically* use the C BB, as it's running @ 8bpp, but it's expecting an inverted palette...
Expand Down
1 change: 1 addition & 0 deletions frontend/device/sdl/device.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ local Device = Generic:extend{
hasBattery = SDL.getPowerInfo,
hasKeyboard = yes,
hasKeys = yes,
hasSymKey = os.getenv("DISABLE_TOUCH") == "1" and yes or no,
hasDPad = yes,
hasWifiToggle = no,
hasSeamlessWifiToggle = no,
Expand Down
2 changes: 1 addition & 1 deletion frontend/device/sdl/event_map_sdl2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ return {
[1073741893] = "F12", -- F[12]

[1073742049] = "Shift", -- left shift
[1073742053] = "Sym", -- right shift
[1073742053] = os.getenv("DISABLE_TOUCH") == "1" and "Sym" or "Shift", -- right shift
[1073742050] = "Alt", -- left alt
[1073742054] = "AA", -- right alt key
[1073741925] = "ContextMenu", -- Context menu key
Expand Down
2 changes: 1 addition & 1 deletion frontend/ui/widget/screenshoter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function Screenshoter:registerKeyEvents()
{ "Alt", "Shift", "G" }, -- same as stock Kindle firmware
event = "KeyPressShoot",
}
elseif Device:hasFiveWay() then
elseif Device:hasScreenKB() then
-- kindle 4 case: same as stock firmware.
self.key_events.KeyPressShoot = {
{ "ScreenKB", "Menu" },
Expand Down
Loading