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

Add vertical edge gesture #5156

Merged
merged 6 commits into from Aug 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
136 changes: 134 additions & 2 deletions frontend/apps/reader/modules/readerfrontlight.lua
Expand Up @@ -10,6 +10,7 @@ local _ = require("gettext")

local ReaderFrontLight = InputContainer:new{
steps = {0,1,1,1,1,2,2,2,3,4,5,6,7,8,9,10},
steps_fl = { 0.1, 0.1, 0.2, 0.4, 0.7, 1.1, 1.6, 2.2, 2.9, 3.7, 4.6, 5.6, 6.7, 7.9, 9.2, 10.6, },
gestureScale = Screen:getWidth() * FRONTLIGHT_SENSITIVITY_DECREASE,
}

Expand Down Expand Up @@ -64,22 +65,153 @@ function ReaderFrontLight:onAdjust(arg, ges)
return true
end

-- direction +1 - increase frontlight
-- direction -1 - decrease frontlight
function ReaderFrontLight:onChangeFlIntensity(ges, direction)
local powerd = Device:getPowerDevice()
local gestureScale
if ges.direction == "south" or ges.direction == "north" then
gestureScale = Screen:getHeight() * 7/8 * 0.8
elseif ges.direction == "west" or ges.direction == "east" then
gestureScale = Screen:getWidth() * 7/8 * 0.8
else
local width = Screen:getWidth()
local height = Screen:getHeight()
-- diagonal
gestureScale = math.sqrt(width * width + height * height) * 7/8 * 0.8
end
if powerd.fl_intensity == nil then return false end

local steps_tbl = {}
local scale = (powerd.fl_max - powerd.fl_min) / 2 / 10.6
for i = 1, #self.steps_fl, 1
do
steps_tbl[i] = math.ceil(self.steps_fl[i] * scale)
end

if ges.distance == nil then
ges.distance = 1
end
local step = math.ceil(#steps_tbl * ges.distance / gestureScale)
local delta_int = steps_tbl[step] or steps_tbl[#steps_tbl]
if direction ~= -1 and direction ~= 1 then
-- set default value (increase frontlight)
direction = 1
end
local new_intensity = powerd.fl_intensity + direction * delta_int

if new_intensity == nil then return true end
-- when new_intensity <=0, toggle light off
if new_intensity <= 0 then
powerd:turnOffFrontlight()
else
powerd:setIntensity(new_intensity)
end
self:onShowIntensity()
if self.view and self.view.footer_visible and self.view.footer.settings.frontlight then
self.view.footer:updateFooter()
end
return true
end

-- direction +1 - increase frontlight warmth
-- direction -1 - decrease frontlight warmth
function ReaderFrontLight:onChangeFlWarmth(ges, direction)
local powerd = Device:getPowerDevice()
if powerd.fl_warmth == nil then return false end

if powerd.auto_warmth then
UIManager:show(Notification:new{
text = _("Warmth is handled automatically."),
timeout = 1.0,
})
return true
end

local gestureScale
if ges.direction == "south" or ges.direction == "north" then
gestureScale = Screen:getHeight() * 7/8 * 0.8
elseif ges.direction == "west" or ges.direction == "east" then
gestureScale = Screen:getWidth() * 7/8 * 0.8
else
local width = Screen:getWidth()
local height = Screen:getHeight()
-- diagonal
gestureScale = math.sqrt(width * width + height * height) * 7/8 * 0.8
end

local steps_tbl = {}
local scale = (powerd.fl_max - powerd.fl_min) / 2 / 10.6
for i = 1, #self.steps_fl, 1
do
steps_tbl[i] = math.ceil(self.steps_fl[i] * scale)
end

if ges.distance == nil then
ges.distance = 1
end

local step = math.ceil(#steps_tbl * ges.distance / gestureScale)
local delta_int = steps_tbl[step] or steps_tbl[#steps_tbl]
local warmth
if direction ~= -1 and direction ~= 1 then
-- set default value (increase frontlight)
direction = 1
end
warmth = powerd.fl_warmth + direction * delta_int
if warmth > 100 then
warmth = 100
elseif warmth < 0 then
warmth = 0
end
powerd:setWarmth(warmth)
self:onShowWarmth()
return true
end


function ReaderFrontLight:onShowOnOff()
local powerd = Device:getPowerDevice()
local new_text
if powerd.is_fl_on then
new_text = _("Frontlight enabled.")
else
new_text = _("Frontlight disabled.")
end
UIManager:show(Notification:new{
text = new_text,
timeout = 1.0,
})
return true
end

function ReaderFrontLight:onShowIntensity()
if not Device:hasFrontlight() then return true end
local powerd = Device:getPowerDevice()
local new_text
if powerd:isFrontlightOff() then
new_text = _("Frontlight is off.")
new_text = _("Frontlight disabled.")
else
new_text = T(_("Frontlight intensity is set to %1."), powerd:frontlightIntensity())
end
UIManager:show(Notification:new{
text = new_text,
timeout = 2,
timeout = 1,
})
return true
end

function ReaderFrontLight:onShowWarmth(value)
local powerd = Device:getPowerDevice()
if powerd.fl_warmth ~= nil then
UIManager:show(Notification:new{
text = T(_("Warmth set to %1."), powerd.fl_warmth),
timeout = 1.0,
})
end
return true
end

function ReaderFrontLight:onSwipe(arg, ges)
if ges.direction == "north" or ges.direction == "south" then
logger.dbg("onSwipe activated")
Expand Down
123 changes: 122 additions & 1 deletion frontend/apps/reader/modules/readergesture.lua
Expand Up @@ -61,6 +61,10 @@ local action_strings = {
show_config_menu = _("Show bottom menu"),
show_frontlight_dialog = _("Show frontlight dialog"),
toggle_frontlight = _("Toggle frontlight"),
increase_frontlight = _("Increase frontlight brightness"),
decrease_frontlight = _("Decrease frontlight brightness"),
increase_frontlight_warmth = _("Increase frontlight warmth"),
decrease_frontlight_warmth = _("Decrease frontlight warmth"),
toggle_gsensor = _("Toggle accelerometer"),
toggle_rotation = _("Toggle rotation"),

Expand Down Expand Up @@ -157,6 +161,10 @@ function ReaderGesture:init()
hold_top_right_corner = "ignore",
hold_bottom_left_corner = "ignore",
hold_bottom_right_corner = "ignore",
one_finger_swipe_left_edge_down = Device:hasFrontlight() and "decrease_frontlight" or "ignore",
one_finger_swipe_left_edge_up = Device:hasFrontlight() and "increase_frontlight" or "ignore",
one_finger_swipe_right_edge_down = Device:hasNaturalLight() and "decrease_frontlight_warmth" or "ignore",
one_finger_swipe_right_edge_up = Device:hasNaturalLight() and "increase_frontlight_warmth" or "ignore",
two_finger_tap_top_left_corner = "ignore",
two_finger_tap_top_right_corner = "ignore",
two_finger_tap_bottom_left_corner = "ignore",
Expand Down Expand Up @@ -357,6 +365,28 @@ function ReaderGesture:addToMainMenu(menu_items)
text = _("Short diagonal swipe"),
sub_item_table = self:buildMenu("short_diagonal_swipe", self.default_gesture["short_diagonal_swipe"]),
},
{
text = _("One-finger swipe"),
sub_item_table = {
{
text_func = function() return actionTextFunc("one_finger_swipe_left_edge_down", _("Left edge down")) end,
sub_item_table = self:buildMenu("one_finger_swipe_left_edge_down", self.default_gesture["one_finger_swipe_left_edge_down"]),
},
{
text_func = function() return actionTextFunc("one_finger_swipe_left_edge_up", _("Left edge up")) end,
sub_item_table = self:buildMenu("one_finger_swipe_left_edge_up", self.default_gesture["one_finger_swipe_left_edge_up"]),
},
{
text_func = function() return actionTextFunc("one_finger_swipe_right_edge_down", _("Right edge down")) end,
sub_item_table = self:buildMenu("one_finger_swipe_right_edge_down", self.default_gesture["one_finger_swipe_right_edge_down"]),
},
{
text_func = function() return actionTextFunc("one_finger_swipe_right_edge_up", _("Right edge up")) end,
sub_item_table = self:buildMenu("one_finger_swipe_right_edge_up", self.default_gesture["one_finger_swipe_right_edge_up"]),
},
},
},

},
}
menu_items.gesture_intervals = {
Expand Down Expand Up @@ -610,7 +640,12 @@ function ReaderGesture:buildMenu(ges, default)
{"show_menu", true},
{"show_config_menu", not self.is_docless, true},
{"show_frontlight_dialog", Device:hasFrontlight()},
{"toggle_frontlight", Device:hasFrontlight(), true},
{"toggle_frontlight", Device:hasFrontlight()},
{"increase_frontlight", Device:hasFrontlight()},
{"decrease_frontlight", Device:hasFrontlight(), true},
{"increase_frontlight_warmth", Device:hasNaturalLight()},
{"decrease_frontlight_warmth", Device:hasNaturalLight(), true},

{"toggle_gsensor", Device:canToggleGSensor()},
{"toggle_rotation", not self.is_docless, true},

Expand Down Expand Up @@ -792,6 +827,15 @@ function ReaderGesture:setupGesture(ges, action)
ratio_w = 1, ratio_h = 1,
}

local zone_left_edge = {
ratio_x = 0, ratio_y = 1/8,
ratio_w = 1/8, ratio_h = 7/8,
}
local zone_right_edge = {
ratio_x = 7/8, ratio_y = 1/8,
ratio_w = 1/8, ratio_h = 7/8,
}

-- legacy global variable DTAP_ZONE_FLIPPING may still be defined in default.persistent.lua
local dtap_zone_top_left = DTAP_ZONE_FLIPPING and DTAP_ZONE_FLIPPING or DTAP_ZONE_TOP_LEFT
local zone_top_left_corner = {
Expand Down Expand Up @@ -823,6 +867,9 @@ function ReaderGesture:setupGesture(ges, action)

local overrides_tap_corner
local overrides_hold_corner
local overrides_vertical_edge
local overrides_pan, overrides_pan_release
local overrides_swipe_pan, overrides_swipe_pan_release
if self.is_docless then
overrides_tap_corner = {
"filemanager_tap",
Expand All @@ -838,6 +885,17 @@ function ReaderGesture:setupGesture(ges, action)
overrides_hold_corner = {
"readerfooter_hold",
}
overrides_vertical_edge = {
"paging_swipe",
"rolling_swipe",
}
overrides_pan = {
"paging_swipe",
"rolling_swipe",
}
overrides_pan_release = {
"paging_pan_release",
}
end

if ges == "multiswipe" then
Expand Down Expand Up @@ -881,6 +939,34 @@ function ReaderGesture:setupGesture(ges, action)
ges_type = "hold"
zone = zone_bottom_left_corner
overrides = overrides_hold_corner
elseif ges == "one_finger_swipe_left_edge_down" then
ges_type = "swipe"
zone = zone_left_edge
direction = {south = true}
overrides = overrides_vertical_edge
overrides_swipe_pan = overrides_pan
overrides_swipe_pan_release = overrides_pan_release
elseif ges == "one_finger_swipe_left_edge_up" then
ges_type = "swipe"
zone = zone_left_edge
direction = {north = true}
overrides = overrides_vertical_edge
overrides_swipe_pan = overrides_pan
overrides_swipe_pan_release = overrides_pan_release
elseif ges == "one_finger_swipe_right_edge_down" then
ges_type = "swipe"
zone = zone_right_edge
direction = {south = true}
overrides = overrides_vertical_edge
overrides_swipe_pan = overrides_pan
overrides_swipe_pan_release = overrides_pan_release
elseif ges == "one_finger_swipe_right_edge_up" then
ges_type = "swipe"
zone = zone_right_edge
direction = {north = true}
overrides = overrides_vertical_edge
overrides_swipe_pan = overrides_pan
overrides_swipe_pan_release = overrides_pan_release
elseif ges == "two_finger_tap_top_left_corner" then
ges_type = "two_finger_tap"
zone = zone_top_left_corner
Expand Down Expand Up @@ -939,6 +1025,13 @@ function ReaderGesture:setupGesture(ges, action)
else return
end
self:registerGesture(ges, action, ges_type, zone, overrides, direction, distance)
-- make dummy zone to disable panning and panning_release when gesture is swipe
if ges_type == "swipe" and ges ~= "short_diagonal_swipe" then
local pan_gesture = ges.."_pan"
local pan_release_gesture = ges.."_pan_release"
self:registerGesture(pan_gesture, "", "pan", zone, overrides_swipe_pan, direction, distance)
self:registerGesture(pan_release_gesture, "", "pan_release", zone, overrides_swipe_pan_release, direction, distance)
end
end

function ReaderGesture:registerGesture(ges, action, ges_type, zone, overrides, direction, distance)
Expand Down Expand Up @@ -1081,6 +1174,34 @@ function ReaderGesture:gestureAction(action, ges)
else
self.ui:handleEvent(Event:new("ShowFlDialog"))
end
elseif action == "increase_frontlight" then
if self.ges_mode == "gesture_fm" then
local ReaderFrontLight = require("apps/reader/modules/readerfrontlight")
ReaderFrontLight:onChangeFlIntensity(ges, 1)
else
self.ui:handleEvent(Event:new("ChangeFlIntensity", ges, 1))
end
elseif action == "decrease_frontlight" then
if self.ges_mode == "gesture_fm" then
local ReaderFrontLight = require("apps/reader/modules/readerfrontlight")
ReaderFrontLight:onChangeFlIntensity(ges, -1)
else
self.ui:handleEvent(Event:new("ChangeFlIntensity", ges, -1))
end
elseif action == "increase_frontlight_warmth" then
if self.ges_mode == "gesture_fm" then
local ReaderFrontLight = require("apps/reader/modules/readerfrontlight")
ReaderFrontLight:onChangeFlWarmth(ges, 1)
else
self.ui:handleEvent(Event:new("ChangeFlWarmth", ges, 1))
end
elseif action == "decrease_frontlight_warmth" then
if self.ges_mode == "gesture_fm" then
local ReaderFrontLight = require("apps/reader/modules/readerfrontlight")
ReaderFrontLight:onChangeFlWarmth(ges, -1)
else
self.ui:handleEvent(Event:new("ChangeFlWarmth", ges, -1))
end
elseif action == "toggle_bookmark" then
self.ui:handleEvent(Event:new("ToggleBookmark"))
elseif action == "toggle_frontlight" then
Expand Down
3 changes: 2 additions & 1 deletion frontend/pluginloader.lua
Expand Up @@ -3,7 +3,8 @@ local logger = require("logger")

local DEFAULT_PLUGIN_PATH = "plugins"
local OBSOLETE_PLUGINS = {
storagestat = true
storagestat = true,
kobolight = true,
}

local function sandboxPluginEventHandlers(plugin)
Expand Down
1 change: 0 additions & 1 deletion frontend/ui/elements/filemanager_menu_order.lua
Expand Up @@ -76,7 +76,6 @@ local order = {
},
taps_and_gestures = {
"gesture_manager",
"frontlight_gesture_controller",
"gesture_intervals",
"----------------------------",
"menu_activate",
Expand Down
1 change: 0 additions & 1 deletion frontend/ui/elements/reader_menu_order.lua
Expand Up @@ -95,7 +95,6 @@ local order = {
},
taps_and_gestures = {
"gesture_manager",
"frontlight_gesture_controller",
"gesture_intervals",
"----------------------------",
"follow_links",
Expand Down
6 changes: 0 additions & 6 deletions plugins/kobolight.koplugin/_meta.lua

This file was deleted.

Binary file removed plugins/kobolight.koplugin/demo.png
Binary file not shown.
Binary file removed plugins/kobolight.koplugin/demo_ka1.png
Binary file not shown.