diff --git a/frontend/device/input.lua b/frontend/device/input.lua index de8dab7b4..fd08282bb 100644 --- a/frontend/device/input.lua +++ b/frontend/device/input.lua @@ -275,12 +275,12 @@ function Input:handleKeyBoardEv(ev) return keycode end - -- Kobo sleep + -- Kobo sleep cover if keycode == "Power_SleepCover" then if ev.value == EVENT_VALUE_KEY_PRESS then - return "Suspend" + return "SleepCoverClosed" else - return "Resume" + return "SleepCoverOpened" end end diff --git a/frontend/device/kobo/device.lua b/frontend/device/kobo/device.lua index 533e3e8ce..1926ff10a 100644 --- a/frontend/device/kobo/device.lua +++ b/frontend/device/kobo/device.lua @@ -118,16 +118,13 @@ function Kobo:init() self.input = require("device/input"):new{ device = self, event_map = { + [59] = "Power_SleepCover", [90] = "Light", [102] = "Home", [116] = "Power", } } - if not G_reader_settings:readSetting("ignore_power_sleepcover") then - self.input.event_map[59] = "Power_SleepCover" - end - Generic.init(self) self.input.open("/dev/input/event0") -- Light button and sleep slider diff --git a/frontend/ui/uimanager.lua b/frontend/ui/uimanager.lua index d789ce578..4a79a0d61 100644 --- a/frontend/ui/uimanager.lua +++ b/frontend/ui/uimanager.lua @@ -86,6 +86,19 @@ function UIManager:init() self.event_handlers["Suspend"]() end end + if not G_reader_settings:readSetting("ignore_power_sleepcover") then + self.event_handlers["SleepCoverClosed"] = self.event_handlers["Suspend"] + self.event_handlers["SleepCoverOpened"] = self.event_handlers["Resume"] + else + -- Closing/opening the cover will still wake up the device, so we + -- need to put it back to sleep if we are in screen saver mode + self.event_handlers["SleepCoverClosed"] = function() + if Device.screen_saver_mode then + self.event_handlers["Suspend"]() + end + end + self.event_handlers["SleepCoverOpened"] = self.event_handlers["SleepCoverClosed"] + end self.event_handlers["Light"] = function() Device:getPowerDevice():toggleFrontlight() end