diff --git a/frontend/device/input.lua b/frontend/device/input.lua index fd08282bb..b5b3979ec 100644 --- a/frontend/device/input.lua +++ b/frontend/device/input.lua @@ -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: diff --git a/frontend/device/kobo/device.lua b/frontend/device/kobo/device.lua index 1926ff10a..37f7a2a56 100644 --- a/frontend/device/kobo/device.lua +++ b/frontend/device/kobo/device.lua @@ -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 diff --git a/frontend/ui/uimanager.lua b/frontend/ui/uimanager.lua index baaea7dd0..9fbac1d61 100644 --- a/frontend/ui/uimanager.lua +++ b/frontend/ui/uimanager.lua @@ -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