kobo(fix): prevent usb plug events from interrupting sleep

pull/2245/head
Qingping Hou 8 years ago
parent ca93494783
commit 902403bf0a

@ -265,6 +265,10 @@ function Input:handleKeyBoardEv(ev)
return
end
if type(keycode) == "function" then
return keycode(ev)
end
-- take device rotation into account
if self.rotation_map[self.device.screen:getRotationMode()][keycode] then
keycode = self.rotation_map[self.device.screen:getRotationMode()][keycode]
@ -275,15 +279,6 @@ function Input:handleKeyBoardEv(ev)
return keycode
end
-- Kobo sleep cover
if keycode == "Power_SleepCover" then
if ev.value == EVENT_VALUE_KEY_PRESS then
return "SleepCoverClosed"
else
return "SleepCoverOpened"
end
end
if keycode == "Power" then
-- Kobo generates Power keycode only, we need to decide whether it's
-- power-on or power-off ourselves.
@ -300,10 +295,6 @@ function Input:handleKeyBoardEv(ev)
end
end
if ev.value == EVENT_VALUE_KEY_RELEASE and keycode == "Light" then
return keycode
end
-- handle modifier keys
if self.modifiers[keycode] ~= nil then
if ev.value == EVENT_VALUE_KEY_PRESS then
@ -538,6 +529,14 @@ function Input:cleanAbsxy()
self:setCurrentMtSlot("abs_y", nil)
end
function Input:isEvKeyPress(ev)
return ev.value == EVENT_VALUE_KEY_PRESS
end
function Input:isEvKeyRelease(ev)
return ev.value == EVENT_VALUE_KEY_RELEASE
end
-- main event handling:

@ -118,8 +118,25 @@ function Kobo:init()
self.input = require("device/input"):new{
device = self,
event_map = {
[59] = "Power_SleepCover",
[90] = "Light",
[59] = function(ev)
if self.input:isEvKeyPress(ev) then
return "SleepCoverClosed"
else
return "SleepCoverOpened"
end
end,
[90] = function(ev)
if self.input:isEvKeyRelease(ev) then
return "Light"
end
end,
[330] = function(ev)
if self.input:isEvKeyPress(ev) then
return "USBPlugIn"
else
return "USBPlugOut"
end
end,
[102] = "Home",
[116] = "Power",
}
@ -338,7 +355,7 @@ elseif codename == "alyssum" then
elseif codename == "pika" then
return KoboPika
elseif codename == "daylight" then
return KoboDaylight
return KoboDaylight
else
error("unrecognized Kobo model "..codename)
end

@ -108,6 +108,12 @@ function UIManager:init()
self.event_handlers["Light"] = function()
Device:getPowerDevice():toggleFrontlight()
end
self.event_handlers["USBPlugIn"] = function()
if Device.screen_saver_mode then
self.event_handlers["Suspend"]()
end
end
self.event_handlers["USBPlugOut"] = self.event_handlers["USBPlugIn"]
self.event_handlers["__default__"] = function(input_event)
if Device.screen_saver_mode then
-- Suspension in Kobo can be interrupted by screen updates. We

Loading…
Cancel
Save