mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
[SDL] Add quit through regular window manager actions (#3206)
* [SDL] Add quit through regular window manager actions Depends on https://github.com/koreader/koreader-base/pull/506 * proper exit and fix bug in restart function as a bonus
This commit is contained in:
2
base
2
base
Submodule base updated: 58112413f2...8c6551aa61
@@ -218,11 +218,31 @@ dbg:guard(ReaderMenu, 'setUpdateItemTable',
|
||||
end)
|
||||
|
||||
function ReaderMenu:exitOrRestart(callback)
|
||||
self:onTapCloseMenu()
|
||||
if self.menu_container then self:onTapCloseMenu() end
|
||||
UIManager:nextTick(function()
|
||||
self.ui:onClose()
|
||||
if callback ~= nil then
|
||||
callback()
|
||||
-- show an empty widget so that the callback always happens
|
||||
local Widget = require("ui/widget/widget")
|
||||
local widget = Widget:new{
|
||||
width = Screen:getWidth(),
|
||||
height = Screen:getHeight(),
|
||||
}
|
||||
UIManager:show(widget)
|
||||
local waiting = function(waiting)
|
||||
-- if we don't do this you can get a situation where either the
|
||||
-- program won't exit due to remaining widgets until they're
|
||||
-- dismissed or if the callback forces all widgets to close,
|
||||
-- that the save document ConfirmBox is also closed
|
||||
if self.ui and self.ui.document and self.ui.document:isEdited() then
|
||||
logger.dbg("waiting for save settings")
|
||||
UIManager:scheduleIn(1, function() waiting(waiting) end)
|
||||
else
|
||||
callback()
|
||||
UIManager:close(widget)
|
||||
end
|
||||
end
|
||||
UIManager:scheduleIn(1, function() waiting(waiting) end)
|
||||
end
|
||||
end)
|
||||
local FileManager = require("apps/filemanager/filemanager")
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
local Event = require("ui/event")
|
||||
local TimeVal = require("ui/timeval")
|
||||
local input = require("ffi/input")
|
||||
--[[--
|
||||
An interface to get input events.
|
||||
]]
|
||||
|
||||
local DEBUG = require("dbg")
|
||||
local logger = require("logger")
|
||||
local _ = require("gettext")
|
||||
local Event = require("ui/event")
|
||||
local Key = require("device/key")
|
||||
local GestureDetector = require("device/gesturedetector")
|
||||
local TimeVal = require("ui/timeval")
|
||||
local framebuffer = require("ffi/framebuffer")
|
||||
local input = require("ffi/input")
|
||||
local logger = require("logger")
|
||||
local _ = require("gettext")
|
||||
|
||||
-- luacheck: push
|
||||
-- luacheck: ignore
|
||||
@@ -56,9 +60,6 @@ local DEVICE_ORIENTATION_LANDSCAPE_ROTATED = 22
|
||||
|
||||
-- luacheck: pop
|
||||
|
||||
--[[
|
||||
an interface to get input events
|
||||
]]
|
||||
local Input = {
|
||||
-- this depends on keyboard layout and should be overridden:
|
||||
event_map = {},
|
||||
@@ -155,7 +156,7 @@ function Input:init()
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
--[[--
|
||||
wrapper for FFI input open
|
||||
|
||||
Note that we adhere to the "." syntax here for compatibility.
|
||||
@@ -165,7 +166,7 @@ function Input.open(device, is_emu_events)
|
||||
input.open(device, is_emu_events and 1 or 0)
|
||||
end
|
||||
|
||||
--[[
|
||||
--[[--
|
||||
Different device models can implement their own hooks
|
||||
and register them.
|
||||
--]]
|
||||
@@ -193,7 +194,7 @@ function Input:gestureAdjustHook(ges)
|
||||
-- do nothing by default
|
||||
end
|
||||
|
||||
-- catalogue of predefined hooks:
|
||||
--- Catalog of predefined hooks.
|
||||
function Input:adjustTouchSwitchXY(ev)
|
||||
if ev.type == EV_ABS then
|
||||
if ev.code == ABS_X then
|
||||
@@ -298,6 +299,32 @@ function Input:handleKeyBoardEv(ev)
|
||||
end
|
||||
end
|
||||
|
||||
-- quit on Alt + F4
|
||||
-- this is also emitted by the close event in SDL
|
||||
if self.modifiers["Alt"] and keycode == "F4" then
|
||||
local Device = require("frontend/device")
|
||||
local UIManager = require("ui/uimanager")
|
||||
|
||||
local savequit_caller = nil
|
||||
local save_quit = function()
|
||||
Device:saveSettings()
|
||||
UIManager:quit()
|
||||
end
|
||||
|
||||
local FileManager = require("apps/filemanager/filemanager")
|
||||
if FileManager.instance then
|
||||
savequit_caller = FileManager.instance.menu
|
||||
end
|
||||
|
||||
local ReaderUI = require("apps/reader/readerui")
|
||||
local readerui_instance = ReaderUI:_getRunningInstance()
|
||||
if readerui_instance then
|
||||
savequit_caller = readerui_instance.menu
|
||||
end
|
||||
|
||||
savequit_caller:exitOrRestart(save_quit)
|
||||
end
|
||||
|
||||
-- handle modifier keys
|
||||
if self.modifiers[keycode] ~= nil then
|
||||
if ev.value == EVENT_VALUE_KEY_PRESS then
|
||||
@@ -321,8 +348,8 @@ function Input:handleMiscEv(ev)
|
||||
-- should be handled by a misc event protocol plugin
|
||||
end
|
||||
|
||||
--[[
|
||||
parse each touch ev from kernel and build up tev.
|
||||
--[[--
|
||||
Parse each touch ev from kernel and build up tev.
|
||||
tev will be sent to GestureDetector:feedEvent
|
||||
|
||||
Events for a single tap motion from Linux kernel (MT protocol B):
|
||||
@@ -536,11 +563,10 @@ function Input:isEvKeyRelease(ev)
|
||||
end
|
||||
|
||||
|
||||
-- main event handling:
|
||||
|
||||
--- Main event handling.
|
||||
function Input:waitEvent(timeout_us)
|
||||
-- wrapper for input.waitForEvents that will retry for some cases
|
||||
local ok, ev
|
||||
-- wrapper for input.waitForEvents that will retry for some cases
|
||||
while true do
|
||||
if #self.timer_callbacks > 0 then
|
||||
local wait_deadline = TimeVal:now() + TimeVal:new{
|
||||
|
||||
@@ -16,6 +16,7 @@ return {
|
||||
[44] = " ", -- Spacebar
|
||||
[58] = "Menu", -- F[1]
|
||||
[59] = "Power", -- F[2]
|
||||
[61] = "F4", -- F[4]
|
||||
[63] = "LPgBack", -- F[6]
|
||||
[64] = "LPgFwd", -- F[7]
|
||||
[68] = "VPlus", -- F[11]
|
||||
|
||||
Reference in New Issue
Block a user