mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Virtual keyboard: auto releasable Shift and keypopups (#9659)
Long-press on Shift to keep it non-auto-released.
This commit is contained in:
@@ -51,7 +51,7 @@ local arabic_comma = ar_popup.arabic_comma
|
||||
return {
|
||||
min_layer = 1,
|
||||
max_layer = 4,
|
||||
shiftmode_keys = {["بدّل"] = true}, -- بدّل means "Shift".
|
||||
shiftmode_keys = {[""] = true},
|
||||
symbolmode_keys = {["رمز"] = true,["حرف"]=true}, -- رمز means "Symbol", حرف means "letter" (traditionally "ABC" on QWERTY layouts)
|
||||
utf8mode_keys = {["🌐"] = true}, -- The famous globe key for layout switching
|
||||
umlautmode_keys = {["Äéß"] = false}, -- No need for this keyboard panel
|
||||
@@ -104,7 +104,7 @@ return {
|
||||
},
|
||||
-- fourth row
|
||||
{
|
||||
{ "بدّل", "بدّل", "بدّل", "بدّل",
|
||||
{ label = "",
|
||||
width = 1.40},
|
||||
{ label = "🌐", },
|
||||
{ "رمز", "رمز", "حرف", "حرف",
|
||||
|
||||
@@ -51,6 +51,10 @@ local VirtualKey = InputContainer:extend{
|
||||
face = Font:getFace("infont"),
|
||||
}
|
||||
|
||||
-- For caps lock, it's necessary because after setLayout, the new shift key is no longer the same virtual key
|
||||
-- thus rendering its preset .ignore_key_release property useless
|
||||
local ignore_key_release
|
||||
|
||||
function VirtualKey:init()
|
||||
local label_font_size = G_reader_settings:readSetting("keyboard_key_font_size", DEFAULT_LABEL_SIZE)
|
||||
self.face = Font:getFace("infont", label_font_size)
|
||||
@@ -58,8 +62,19 @@ function VirtualKey:init()
|
||||
if self.keyboard.symbolmode_keys[self.label] ~= nil then
|
||||
self.callback = function () self.keyboard:setLayer("Sym") end
|
||||
self.skiptap = true
|
||||
elseif self.keyboard.shiftmode_keys[self.label] ~= nil then
|
||||
self.callback = function () self.keyboard:setLayer("Shift") end
|
||||
elseif self.keyboard.shiftmode_keys[self.label] ~= nil or self.keyboard.shiftmode_keys[self.key] ~= nil then
|
||||
-- self.key needed because the shift key's label could be the capslock instead of the shift
|
||||
local key = self.key or self.label
|
||||
local releasable = key == ""
|
||||
self.callback = function()
|
||||
self.keyboard.release_shift = releasable
|
||||
self.keyboard:setLayer("Shift")
|
||||
end
|
||||
self.hold_callback = function()
|
||||
ignore_key_release = true
|
||||
if releasable then self.keyboard.release_shift = false end
|
||||
self.keyboard:setLayer("Shift")
|
||||
end
|
||||
self.skiptap = true
|
||||
elseif self.keyboard.utf8mode_keys[self.label] ~= nil then
|
||||
self.key_chars = self:genKeyboardLayoutKeyChars()
|
||||
@@ -144,7 +159,15 @@ function VirtualKey:init()
|
||||
self.keyboard:scrollDown()
|
||||
end
|
||||
else
|
||||
self.callback = function () self.keyboard:addChar(self.key) end
|
||||
self.callback = function()
|
||||
self.keyboard:addChar(self.key)
|
||||
if self.close_after_callback_widget then
|
||||
UIManager:close(self.close_after_callback_widget)
|
||||
end
|
||||
if self.keyboard.shiftmode and not self.keyboard.symbolmode and self.keyboard.release_shift then
|
||||
self.keyboard:setLayer("Shift")
|
||||
end
|
||||
end
|
||||
self.hold_callback = function()
|
||||
if not self.key_chars then return end
|
||||
|
||||
@@ -279,7 +302,7 @@ function VirtualKey:init()
|
||||
},
|
||||
},
|
||||
}
|
||||
if (self.keyboard.shiftmode_keys[self.label] ~= nil and self.keyboard.shiftmode) or
|
||||
if ((self.keyboard.shiftmode_keys[self.label] ~= nil or self.keyboard.shiftmode_keys[self.key]) and self.keyboard.shiftmode) or
|
||||
(self.keyboard.umlautmode_keys[self.label] ~= nil and self.keyboard.umlautmode) or
|
||||
(self.keyboard.symbolmode_keys[self.label] ~= nil and self.keyboard.symbolmode) then
|
||||
self[1].background = Blitbuffer.COLOR_LIGHT_GRAY
|
||||
@@ -419,6 +442,10 @@ function VirtualKey:onSwipeKey(arg, ges)
|
||||
end
|
||||
|
||||
function VirtualKey:onHoldReleaseKey()
|
||||
if ignore_key_release then
|
||||
ignore_key_release = nil
|
||||
return true
|
||||
end
|
||||
if self.ignore_key_release then
|
||||
self.ignore_key_release = nil
|
||||
return true
|
||||
@@ -577,6 +604,7 @@ function VirtualKeyPopup:init()
|
||||
key_chars = key_chars,
|
||||
width = parent_key.width,
|
||||
height = parent_key.height,
|
||||
close_after_callback_widget = self,
|
||||
}
|
||||
-- Support any function as a callback.
|
||||
if v_func then
|
||||
@@ -958,6 +986,10 @@ function VirtualKeyboard:addKeys()
|
||||
- self.key_padding
|
||||
local key_height = base_key_height
|
||||
label = label or self.KEYS[i][j].label or key
|
||||
if label == "" and self.shiftmode and (not self.release_shift or self.symbolmode) then
|
||||
key = label
|
||||
label = "" -- capslock symbol
|
||||
end
|
||||
local virtual_key = VirtualKey:new{
|
||||
key = key,
|
||||
key_chars = key_chars,
|
||||
|
||||
Reference in New Issue
Block a user