Skip to content

Commit

Permalink
Gesture: Add toggle for orientation lock (koreader#11795)
Browse files Browse the repository at this point in the history
  • Loading branch information
thialfi17 committed May 11, 2024
1 parent eb6e5e3 commit 1398154
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
13 changes: 13 additions & 0 deletions frontend/device/devicelistener.lua
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,19 @@ if Device:hasGSensor() then
Notification:notify(new_text)
return true
end

function DeviceListener:onLockGSensor()
G_reader_settings:flipNilOrFalse("input_lock_gsensor")
Device:lockGSensor(G_reader_settings:isTrue("input_lock_gsensor"))
local new_text
if G_reader_settings:isTrue("input_lock_gsensor") then
new_text = _("Orientation locked.")
else
new_text = _("Orientation unlocked.")
end
Notification:notify(new_text)
return true
end
end

if not Device:isAlwaysFullscreen() then
Expand Down
2 changes: 2 additions & 0 deletions frontend/dispatcher.lua
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ local settingsList = {
----
toggle_key_repeat = {category="none", event="ToggleKeyRepeat", title=_("Toggle key repeat"), device=true, condition=Device:hasKeys() and Device:canKeyRepeat(), separator=true},
toggle_gsensor = {category="none", event="ToggleGSensor", title=_("Toggle accelerometer"), device=true, condition=Device:hasGSensor()},
lock_gsensor = {category="none", event="LockGSensor", title=_("Lock auto rotation to current orientation"), device=true, condition=Device:hasGSensor()},
toggle_rotation = {category="none", event="SwapRotation", title=_("Toggle orientation"), device=true},
invert_rotation = {category="none", event="InvertRotation", title=_("Invert rotation"), device=true},
iterate_rotation = {category="none", event="IterateRotation", title=_("Rotate by 90° CW"), device=true},
Expand Down Expand Up @@ -303,6 +304,7 @@ local dispatcher_menu_order = {
----
"toggle_key_repeat",
"toggle_gsensor",
"lock_gsensor",
"rotation_mode",
"toggle_rotation",
"invert_rotation",
Expand Down
3 changes: 1 addition & 2 deletions frontend/ui/elements/screen_rotation_menu_table.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ If you need to do so, you'll have to use the UI toggles.]]),
return G_reader_settings:isTrue("input_lock_gsensor")
end,
callback = function()
G_reader_settings:flipNilOrFalse("input_lock_gsensor")
Device:lockGSensor(G_reader_settings:isTrue("input_lock_gsensor"))
UIManager:broadcastEvent(Event:new("LockGSensor"))
end,
})
end
Expand Down

0 comments on commit 1398154

Please sign in to comment.