diff --git a/frontend/ui/data/keyboardlayouts/el_keyboard.lua b/frontend/ui/data/keyboardlayouts/el_keyboard.lua index d8ccea17d..7b37c81c8 100644 --- a/frontend/ui/data/keyboardlayouts/el_keyboard.lua +++ b/frontend/ui/data/keyboardlayouts/el_keyboard.lua @@ -111,9 +111,11 @@ local _Z_el = el_popup._Z_el local _z_el = el_popup._z_el return { - shiftmode_keys = {["Shift"] = true}, + min_layer = 1, + max_layer = 12, + shiftmode_keys = {[""] = true}, symbolmode_keys = {["Sym"] = true, ["ABC"] = true}, - utf8mode_keys = {["IM"] = true}, + utf8mode_keys = {["🌐"] = true}, umlautmode_keys = {["Äéß"] = true}, keys = { -- first row @@ -143,8 +145,7 @@ return { }, -- third row { -- 1 2 3 4 5 6 7 8 9 10 11 12 - { label = "Shift", - icon = "resources/icons/appbar.arrow.shift.png", + { label = "", width = 1.5 }, { _Z_el, _z_el, "&", "7", _Z_, _z_, "Щ", "щ", "Á", "á", "Ű", "ű", }, @@ -163,9 +164,7 @@ return { { { "Sym", "Sym", "ABC", "ABC", "Sym", "Sym", "ABC", "ABC", "Sym", "Sym", "ABC", "ABC", width = 1.5}, - { label = "IM", - icon = "resources/icons/appbar.globe.wire.png", - }, + { label = "🌐", }, { "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", }, { label = "space", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", diff --git a/frontend/ui/data/keyboardlayouts/en_keyboard.lua b/frontend/ui/data/keyboardlayouts/en_keyboard.lua index c1bda1e96..78e4163dd 100644 --- a/frontend/ui/data/keyboardlayouts/en_keyboard.lua +++ b/frontend/ui/data/keyboardlayouts/en_keyboard.lua @@ -57,9 +57,11 @@ local _Z_ = en_popup._Z_ local _z_ = en_popup._z_ return { - shiftmode_keys = {["Shift"] = true}, + min_layer = 1, + max_layer = 12, + shiftmode_keys = {[""] = true}, symbolmode_keys = {["Sym"] = true, ["ABC"] = true}, - utf8mode_keys = {["IM"] = true}, + utf8mode_keys = {["🌐"] = true}, umlautmode_keys = {["Äéß"] = true}, keys = { -- first row @@ -89,8 +91,7 @@ return { }, -- third row { -- 1 2 3 4 5 6 7 8 9 10 11 12 - { label = "Shift", - icon = "resources/icons/appbar.arrow.shift.png", + { label = "", width = 1.5 }, { _Z_, _z_, "&", "7", "Я", "я", ":", "7", "Á", "á", "Ű", "ű", }, @@ -109,9 +110,7 @@ return { { { "Sym", "Sym", "ABC", "ABC", "Sym", "Sym", "ABC", "ABC", "Sym", "Sym", "ABC", "ABC", width = 1.5}, - { label = "IM", - icon = "resources/icons/appbar.globe.wire.png", - }, + { label = "🌐", }, { "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", }, { label = "space", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", diff --git a/frontend/ui/data/keyboardlayouts/he_keyboard.lua b/frontend/ui/data/keyboardlayouts/he_keyboard.lua index afd9c0e18..8ff4ca35c 100644 --- a/frontend/ui/data/keyboardlayouts/he_keyboard.lua +++ b/frontend/ui/data/keyboardlayouts/he_keyboard.lua @@ -4,58 +4,6 @@ local com = en_popup.com -- comma (,) local prd = en_popup.prd -- period (.) local _at = en_popup._at local _eq = en_popup._eq -- equals sign (=) -local _A_ = en_popup._A_ -local _a_ = en_popup._a_ -local _B_ = en_popup._B_ -local _b_ = en_popup._b_ -local _C_ = en_popup._C_ -local _c_ = en_popup._c_ -local _D_ = en_popup._D_ -local _d_ = en_popup._d_ -local _E_ = en_popup._E_ -local _e_ = en_popup._e_ -local _F_ = en_popup._F_ -local _f_ = en_popup._f_ -local _G_ = en_popup._G_ -local _g_ = en_popup._g_ -local _H_ = en_popup._H_ -local _h_ = en_popup._h_ -local _I_ = en_popup._I_ -local _i_ = en_popup._i_ -local _J_ = en_popup._J_ -local _j_ = en_popup._j_ -local _K_ = en_popup._K_ -local _k_ = en_popup._k_ -local _L_ = en_popup._L_ -local _l_ = en_popup._l_ -local _M_ = en_popup._M_ -local _m_ = en_popup._m_ -local _N_ = en_popup._N_ -local _n_ = en_popup._n_ -local _O_ = en_popup._O_ -local _o_ = en_popup._o_ -local _P_ = en_popup._P_ -local _p_ = en_popup._p_ -local _Q_ = en_popup._Q_ -local _q_ = en_popup._q_ -local _R_ = en_popup._R_ -local _r_ = en_popup._r_ -local _S_ = en_popup._S_ -local _s_ = en_popup._s_ -local _T_ = en_popup._T_ -local _t_ = en_popup._t_ -local _U_ = en_popup._U_ -local _u_ = en_popup._u_ -local _V_ = en_popup._V_ -local _v_ = en_popup._v_ -local _W_ = en_popup._W_ -local _w_ = en_popup._w_ -local _X_ = en_popup._X_ -local _x_ = en_popup._x_ -local _Y_ = en_popup._Y_ -local _y_ = en_popup._y_ -local _Z_ = en_popup._Z_ -local _z_ = en_popup._z_ local aleph = he_popup.aleph local beis = he_popup.beis local gimmel = he_popup.gimmel @@ -81,49 +29,49 @@ local shin = he_popup.shin local taf = he_popup.taf return { - shiftmode_keys = {["Shift"] = true}, - symbolmode_keys = {["Sym"] = true, ["ABC"] = true}, - utf8mode_keys = {["IM"] = true}, - umlautmode_keys = {["Äéß"] = true}, + min_layer = 1, + max_layer = 4, + shiftmode_keys = {[""] = true}, + symbolmode_keys = {["Sym"] = true, ["אבג"] = true}, + utf8mode_keys = {["🌐"] = true}, keys = { -- first row - { -- 1 2 3 4 5 6 7 8 9 10 11 12 - { _Q_, _q_, "„", "0", "׳", "״", "?", "!", "Å", "å", "1", "ª", }, - { _W_, _w_, "!", "1", "֘֘֙֙ ", kuf, "(", "1", "Ä", "ä", "2", "º", }, - { _E_, _e_, _at, "2", "֘ ", reish, ")", "2", "Ö", "ö", "3", "¡", }, - { _R_, _r_, "#", "3", "֗", aleph, "~", "3", "ß", "ß", "4", "¿", }, - { _T_, _t_, "+", _eq, "֖ ", tes, "Ә", "ә", "À", "à", "5", "¼", }, - { _Y_, _y_, "€", "(", "֕ ", vov, "І", "і", "Â", "â", "6", "½", }, - { _U_, _u_, "‰", ")", "֔ ", "ן", "Ң", "ң", "Æ", "æ", "7", "¾", }, - { _I_, _i_, "|", "\\", "֓ ", mem_sofis, "Ғ", "ғ", "Ü", "ü", "8", "©", }, - { _O_, _o_, "?", "/", "֒ ", pey, "Х", "х", "È", "è", "9", "®", }, - { _P_, _p_, "~", "`", "֑ ", pey_sofis, "Ъ", "ъ", "É", "é", "0", "™", }, + { -- 1 2 3 4 + { "׳", "״", "„", "0", }, + { "֘֘֙֙ ", kuf, "!", "1", }, + { "֘ ", reish, _at, "2", }, + { "֗", aleph, "#", "3", }, + { "֖ ", tes, "+", _eq, }, + { "֕ ", vov, "€", "(", }, + { "֔ ", "ן", "‰", ")", }, + { "֓ ", mem_sofis, "|", "\\", }, + { "֒ ", pey, "?", "/", }, + { "֑ ", pey_sofis, "~", "`", }, }, -- second row - { -- 1 2 3 4 5 6 7 8 9 10 11 12 - { _A_, _a_, "…", _at, "ּ ", shin, "*", "0", "Ê", "ê", "Ş", "ş", }, - { _S_, _s_, "$", "4", "ֻ ", daled, "+", "4", "Ë", "ë", "İ", "ı", }, - { _D_, _d_, "%", "5", "ִ ", gimmel, "-", "5", "Î", "î", "Ğ", "ğ", }, - { _F_, _f_, "^", "6", "ֹ", chof, _eq, "6", "Ï", "ï", "Ć", "ć", }, - { _G_, _g_, ":", ";", "ְ ", ayin, "Ү", "ү", "Ô", "ô", "Č", "č", }, - { _H_, _h_, '"', "'", "ֵ ", yud, "Ұ", "ұ", "Œ", "œ", "Đ", "đ", }, - { _J_, _j_, "{", "[", "ֶ ", "ח", "Қ", "қ", "Ù", "ù", "Š", "š", }, - { _K_, _k_, "}", "]", "ַ ", lamed, "Ж", "ж", "Û", "û", "Ž", "ž", }, - { _L_, _l_, "_", "-", "ָ ", "ך", "Э", "э", "Ÿ", "ÿ", "Ő", "ő", }, + { -- 1 2 3 4 + { "ּ ", shin, "…", _at, }, + { "ֻ ", daled, "$", "4", }, + { "ִ ", gimmel, "%", "5", }, + { "ֹ", chof, "^", "6", }, + { "ְ ", ayin, ":", ";", }, + { "ֵ ", yud, '"', "'", }, + { "ֶ ", "ח", "{", "[", }, + { "ַ ", lamed, "}", "]", }, + { "ָ ", "ך", "_", "-", }, }, -- third row - { -- 1 2 3 4 5 6 7 8 9 10 11 12 - { label = "Shift", - icon = "resources/icons/appbar.arrow.shift.png", + { -- 1 2 3 4 + { label = "", width = 1.5 }, - { _Z_, _z_, "&", "7", "׃", zayin, ":", "7", "Á", "á", "Ű", "ű", }, - { _X_, _x_, "*", "8", "׀", samech, ";", "8", "Ø", "ø", "Ã", "ã", }, - { _C_, _c_, "£", "9", "ׄ ", beis, "'", "9", "Í", "í", "Þ", "þ", }, - { _V_, _v_, "<", com, "ׅ ", hey, "Ө", "ө", "Ñ", "ñ", "Ý", "ý", }, - { _B_, _b_, ">", prd, "־", nun, "Һ", "һ", "Ó", "ó", "†", "‡", }, - { _N_, _n_, "‘", "↑", "ֿ ", mem, "Б", "б", "Ú", "ú", "–", "—", }, - { _M_, _m_, "’", "↓", "ֽ ", tzadik, "Ю", "ю", "Ç", "ç", "…", "¨", }, + { "׃", zayin, "&", "7", }, + { "׀", samech, "*", "8", }, + { "ׄ ", beis, "£", "9", }, + { "ׅ ", hey, "<", com, }, + { "־", nun, ">", prd, }, + { "ֿ ", mem, "‘", "↑", }, + { "ֽ ", tzadik, "’", "↓", }, { label = "Backspace", icon = "resources/icons/appbar.clear.reflect.horizontal.png", width = 1.5 @@ -131,19 +79,15 @@ return { }, -- fourth row { - { "Sym", "Sym", "ABC", "ABC", "Sym", "Sym", "ABC", "ABC", "Sym", "Sym", "ABC", "ABC", + { "Sym", "Sym", "אבג", "אבג", width = 1.5}, - { label = "IM", - icon = "resources/icons/appbar.globe.wire.png", - }, - { "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", }, - { label = "space", - " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", + { label = "🌐", }, + { " ", " ", " ", " ", width = 3.0}, - { com, com, "“", "←", com, taf, "Ё", "ё", "Ũ", "ũ", com, com, }, - { prd, prd, "”", "→", prd, "ץ", prd, prd, "Ĩ", "ĩ", prd, prd, }, + { com, taf, "“", "←", }, + { prd, "ץ", "”", "→", }, { label = "Enter", - "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", + "\n", "\n", "\n", "\n", icon = "resources/icons/appbar.arrow.enter.png", width = 1.5, }, diff --git a/frontend/ui/data/keyboardlayouts/ja_keyboard.lua b/frontend/ui/data/keyboardlayouts/ja_keyboard.lua index cc85dbb6d..47be2df67 100644 --- a/frontend/ui/data/keyboardlayouts/ja_keyboard.lua +++ b/frontend/ui/data/keyboardlayouts/ja_keyboard.lua @@ -1,5 +1,7 @@ return { - shiftmode_keys = {["Shift"] = true}, + min_layer = 1, + max_layer = 12, + shiftmode_keys = {[""] = true}, symbolmode_keys = {["記号"] = true, ["かな"] = true}, utf8mode_keys = {["゛"] = true}, umlautmode_keys = {["゜"] = true}, @@ -86,8 +88,7 @@ return { }, -- sixth row { - { label = "Shift", - icon = "resources/icons/appbar.arrow.shift.png", + { label = "", width = 1.5 }, { "記号", "記号", "かな", "かな", "記号", "記号", "かな", "かな", "記号", "記号", "かな", "かな", diff --git a/frontend/ui/data/keyboardlayouts/ko_KR_keyboard.lua b/frontend/ui/data/keyboardlayouts/ko_KR_keyboard.lua index 04a97a366..9b6668e22 100644 --- a/frontend/ui/data/keyboardlayouts/ko_KR_keyboard.lua +++ b/frontend/ui/data/keyboardlayouts/ko_KR_keyboard.lua @@ -146,9 +146,11 @@ local _z_ = en_popup._z_ -- Based on English keyboard layout, but modifications are made for Korean layout return { - shiftmode_keys = {["Shift"] = true}, + min_layer = 1, + max_layer = 12, + shiftmode_keys = {[""] = true}, symbolmode_keys = {["Sym"] = true, ["ABC"] = true}, - utf8mode_keys = {["IM"] = true}, + utf8mode_keys = {["🌐"] = true}, umlautmode_keys = {["Äéß"] = false}, -- Disabled 'umlaut' keys keys = { -- [shift, unshift, symbol-shift, symbol-unshift] @@ -183,8 +185,7 @@ return { }, -- third row { -- 1 2 3 4 5 6 7 8 9 10 11 12 - { label = "Shift", - icon = "resources/icons/appbar.arrow.shift.png", + { label = "", width = 1.5 }, { _Z_, _z_, "&", "7", "ㅋ", "ㅋ", "「", "7", "Á", "á", "Ű", "ű", }, @@ -203,8 +204,7 @@ return { { { "Sym", "Sym", "ABC", "ABC", "Sym", "Sym", "ABC", "ABC", "Sym", "Sym", "ABC", "ABC", width = 1.5}, - { label = "IM", - icon = "resources/icons/appbar.globe.wire.png", + { label = "🌐", width = 2, }, -- { "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", }, diff --git a/frontend/ui/data/keyboardlayouts/pt_keyboard.lua b/frontend/ui/data/keyboardlayouts/pt_keyboard.lua index 69d6c5f32..4780116ce 100644 --- a/frontend/ui/data/keyboardlayouts/pt_keyboard.lua +++ b/frontend/ui/data/keyboardlayouts/pt_keyboard.lua @@ -1,7 +1,9 @@ return { - shiftmode_keys = {["Shift"] = true}, + min_layer = 1, + max_layer = 12, + shiftmode_keys = {[""] = true}, symbolmode_keys = {["Sym"] = true, ["ABC"] = true}, - utf8mode_keys = {["IM"] = true}, + utf8mode_keys = {["🌐"] = true}, umlautmode_keys = {["Äéß"] = true}, keys = { -- first row @@ -31,8 +33,7 @@ return { }, -- third row { -- 1 2 3 4 5 6 7 8 9 10 11 12 - { label = "Shift", - icon = "resources/icons/appbar.arrow.shift.png", + { label = "", width = 1.5 }, { "Z", "z", "&", "7", "Z", "z", "&", "7", "Á", "á", "Ű", "ű", }, @@ -51,9 +52,7 @@ return { { { "Sym", "Sym", "ABC", "ABC", "Sym", "Sym", "ABC", "ABC", "Sym", "Sym", "ABC", "ABC", width = 1.5}, - { label = "IM", - icon = "resources/icons/appbar.globe.wire.png", - }, + { label = "🌐", }, { "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", }, { label = "space", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", diff --git a/frontend/ui/data/keyboardlayouts/yazhert.lua b/frontend/ui/data/keyboardlayouts/yazhert.lua index 777dadd9d..fc922d43d 100644 --- a/frontend/ui/data/keyboardlayouts/yazhert.lua +++ b/frontend/ui/data/keyboardlayouts/yazhert.lua @@ -1,7 +1,9 @@ return { - shiftmode_keys = {["Shift"] = true}, + min_layer = 1, + max_layer = 12, + shiftmode_keys = {[""] = true}, symbolmode_keys = {["Sym"] = true, ["ABC"] = true}, - utf8mode_keys = {["IM"] = true}, + utf8mode_keys = {["🌐"] = true}, umlautmode_keys = {["Äéß"] = true}, keys = { -- first row @@ -31,8 +33,7 @@ return { }, -- third row { -- 1 2 3 4 5 6 7 8 9 10 11 12 - { label = "Shift", - icon = "resources/icons/appbar.arrow.shift.png", + { label = "", width = 1.5 }, { "Z", "z", "$", "(", "З", "з", "Щ", "щ", "Á", "á", "Ű", "ű", }, @@ -51,9 +52,7 @@ return { { { "Sym", "Sym", "ABC", "ABC", "Sym", "Sym", "ABC", "ABC", "Sym", "Sym", "ABC", "ABC", width = 1.5}, - { label = "IM", - icon = "resources/icons/appbar.globe.wire.png", - }, + { label = "🌐", }, { "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", }, { label = "space", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", diff --git a/frontend/ui/elements/menu_keyboard_layout.lua b/frontend/ui/elements/menu_keyboard_layout.lua index 352572fb6..67f10981f 100644 --- a/frontend/ui/elements/menu_keyboard_layout.lua +++ b/frontend/ui/elements/menu_keyboard_layout.lua @@ -6,12 +6,25 @@ local sub_item_table = {} for k, _ in orderedPairs(VirtualKeyboard.lang_to_keyboard_layout) do table.insert(sub_item_table, { - text = Language:getLanguageName(k), + text_func = function() + local text = Language:getLanguageName(k) + if VirtualKeyboard:getKeyboardLayout() == k then + text = text .. " ★" + end + return text + end, checked_func = function() - return VirtualKeyboard:getKeyboardLayout() == k + local keyboard_layouts = G_reader_settings:readSetting("keyboard_layouts") or {} + return keyboard_layouts[k] == true end, callback = function() + local keyboard_layouts = G_reader_settings:readSetting("keyboard_layouts") or {} + keyboard_layouts[k] = not keyboard_layouts[k] + G_reader_settings:saveSetting("keyboard_layouts", keyboard_layouts) + end, + hold_callback = function(touchmenu_instance) G_reader_settings:saveSetting("keyboard_layout", k) + if touchmenu_instance then touchmenu_instance:updateItems() end end, }) end diff --git a/frontend/ui/widget/inputtext.lua b/frontend/ui/widget/inputtext.lua index a45ac55b0..7d8935553 100644 --- a/frontend/ui/widget/inputtext.lua +++ b/frontend/ui/widget/inputtext.lua @@ -372,13 +372,13 @@ function InputText:initTextBox(text, char_added) end function InputText:initKeyboard() - local keyboard_layout = 2 + local keyboard_layer = 2 if self.input_type == "number" then - keyboard_layout = 4 + keyboard_layer = 4 end self.key_events = nil self.keyboard = Keyboard:new{ - keyboard_layout = keyboard_layout, + keyboard_layer = keyboard_layer, inputbox = self, width = Screen:getWidth(), } diff --git a/frontend/ui/widget/keyboardlayoutdialog.lua b/frontend/ui/widget/keyboardlayoutdialog.lua new file mode 100644 index 000000000..31cc5d86b --- /dev/null +++ b/frontend/ui/widget/keyboardlayoutdialog.lua @@ -0,0 +1,163 @@ +--[[-- +This widget displays a keyboard layout dialog. +]] + +local Blitbuffer = require("ffi/blitbuffer") +local ButtonTable = require("ui/widget/buttontable") +local CenterContainer = require("ui/widget/container/centercontainer") +local Font = require("ui/font") +local FrameContainer = require("ui/widget/container/framecontainer") +local Geom = require("ui/geometry") +local InputContainer = require("ui/widget/container/inputcontainer") +local Language = require("ui/language") +local LineWidget = require("ui/widget/linewidget") +local RadioButtonTable = require("ui/widget/radiobuttontable") +local Size = require("ui/size") +local TextWidget = require("ui/widget/textwidget") +local UIManager = require("ui/uimanager") +local VerticalGroup = require("ui/widget/verticalgroup") +local VerticalSpan = require("ui/widget/verticalspan") +local _ = require("gettext") +local Screen = require("device").screen +local orderedPairs = require("ffi/util").orderedPairs + +local KeyboardLayoutDialog = InputContainer:new{ + is_always_active = true, + title = _("Keyboard Layout"), + modal = true, + width = Screen:getWidth() * 0.8, + face = Font:getFace("cfont", 22), + title_face = Font:getFace("x_smalltfont"), + title_padding = Size.padding.default, + title_margin = Size.margin.title, + button_padding = Size.padding.default, + border_size = Size.border.window, +} + + +function KeyboardLayoutDialog:init() + -- Title & description + self.title_widget = FrameContainer:new{ + padding = self.title_padding, + margin = self.title_margin, + bordersize = 0, + TextWidget:new{ + text = self.title, + face = self.title_face, + max_width = self.width, + } + } + self.title_bar = LineWidget:new{ + dimen = Geom:new{ + w = self.width, + h = Size.line.thick, + } + } + + local buttons = {} + local radio_buttons = {} + for k, _ in orderedPairs(self.parent.keyboard.lang_to_keyboard_layout) do + table.insert(radio_buttons, { + { + text = Language:getLanguageName(k), + checked = self.parent.keyboard:getKeyboardLayout() == k, + provider = k, + }, + }) + end + + table.insert(buttons, { + { + text = _("Cancel"), + callback = function() + UIManager:close(self.parent.keyboard_layout_dialog) + end, + }, + { + text = _("Switch to layout"), + is_enter_default = true, + callback = function() + local provider = self.parent.keyboard_layout_dialog.radio_button_table.checked_button.provider + self.parent.keyboard:setKeyboardLayout(provider) + UIManager:close(self.parent.keyboard_layout_dialog) + end, + }, + }) + + self.radio_button_table = RadioButtonTable:new{ + radio_buttons = radio_buttons, + width = self.width * 0.9, + focused = true, + scroll = false, + parent = self, + face = self.face, + } + + -- Buttons Table + self.button_table = ButtonTable:new{ + width = self.width - 2*self.button_padding, + button_font_face = "cfont", + button_font_size = 20, + buttons = buttons, + zero_sep = true, + show_parent = self, + } + + self.dialog_frame = FrameContainer:new{ + radius = Size.radius.window, + bordersize = Size.border.window, + padding = 0, + margin = 0, + background = Blitbuffer.COLOR_WHITE, + VerticalGroup:new{ + align = "center", + self.title_widget, + self.title_bar, + VerticalSpan:new{ + width = Size.span.vertical_large*2, + }, + CenterContainer:new{ + dimen = Geom:new{ + w = self.title_bar:getSize().w, + h = self.radio_button_table:getSize().h, + }, + self.radio_button_table, + }, + VerticalSpan:new{ + width = Size.span.vertical_large*2, + }, + -- buttons + CenterContainer:new{ + dimen = Geom:new{ + w = self.title_bar:getSize().w, + h = self.button_table:getSize().h, + }, + self.button_table, + } + } + } + + self[1] = CenterContainer:new{ + dimen = Geom:new{ + w = Screen:getWidth(), + h = Screen:getHeight(), + }, + self.dialog_frame, + } +end + + +function KeyboardLayoutDialog:onShow() + UIManager:setDirty(self, function() + return "ui", self.dialog_frame.dimen + end) +end + +function KeyboardLayoutDialog:onCloseWidget() + UIManager:setDirty(nil, function() + return "partial", self[1][1].dimen + end) + return true +end + +return KeyboardLayoutDialog diff --git a/frontend/ui/widget/virtualkeyboard.lua b/frontend/ui/widget/virtualkeyboard.lua index 3fee7f7b2..3d107a76e 100644 --- a/frontend/ui/widget/virtualkeyboard.lua +++ b/frontend/ui/widget/virtualkeyboard.lua @@ -12,6 +12,7 @@ local HorizontalGroup = require("ui/widget/horizontalgroup") local HorizontalSpan = require("ui/widget/horizontalspan") local ImageWidget = require("ui/widget/imagewidget") local InputContainer = require("ui/widget/container/inputcontainer") +local KeyboardLayoutDialog = require("ui/widget/keyboardlayoutdialog") local Size = require("ui/size") local TextWidget = require("ui/widget/textwidget") local UIManager = require("ui/uimanager") @@ -19,6 +20,7 @@ local VerticalGroup = require("ui/widget/verticalgroup") local VerticalSpan = require("ui/widget/verticalspan") local WidgetContainer = require("ui/widget/container/widgetcontainer") local logger = require("logger") +local orderedPairs = require("ffi/util").orderedPairs local util = require("util") local Screen = Device.screen @@ -31,7 +33,7 @@ local VirtualKey = InputContainer:new{ keyboard = nil, callback = nil, - -- This is to inhibit the key's own refresh (useful to avoid conflicts on Layout changing keys) + -- This is to inhibit the key's own refresh (useful to avoid conflicts on Layer changing keys) skiptap = nil, skiphold = nil, @@ -45,16 +47,60 @@ local VirtualKey = InputContainer:new{ function VirtualKey:init() if self.keyboard.symbolmode_keys[self.label] ~= nil then - self.callback = function () self.keyboard:setLayout("Sym") end + 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:setLayout("Shift") end + self.callback = function () self.keyboard:setLayer("Shift") end self.skiptap = true elseif self.keyboard.utf8mode_keys[self.label] ~= nil then - self.callback = function () self.keyboard:setLayout("IM") end + self.key_chars = self:genkeyboardLayoutKeyChars() + self.callback = function () + local current = G_reader_settings:readSetting("keyboard_layout") + local keyboard_layouts = G_reader_settings:readSetting("keyboard_layouts") or {} + local enabled = false + local next_layout = nil + for k, v in orderedPairs(keyboard_layouts) do + if enabled and v == true then + next_layout = k + break + end + if k == current then + enabled = true + end + end + if not next_layout then + for k, v in orderedPairs(keyboard_layouts) do + if enabled and v == true then + next_layout = k + break + end + end + end + if next_layout then + self.keyboard:setKeyboardLayout(next_layout) + end + end + self.hold_callback = function() + if util.tableSize(self.key_chars) > 3 then + self.popup = VirtualKeyPopup:new{ + parent_key = self, + } + else + self.keyboard_layout_dialog = KeyboardLayoutDialog:new{ + parent = self, + } + UIManager:show(self.keyboard_layout_dialog) + end + end + self.swipe_callback = function(ges) + local key_function = self.key_chars[ges.direction.."_func"] + if key_function then + key_function() + end + end self.skiptap = true elseif self.keyboard.umlautmode_keys[self.label] ~= nil then - self.callback = function () self.keyboard:setLayout("Äéß") end + self.callback = function () self.keyboard:setLayer("Äéß") end self.skiptap = true elseif self.label == "Backspace" then self.callback = function () self.keyboard:delChar() end @@ -162,9 +208,47 @@ function VirtualKey:init() }, } end + if (self.keyboard.shiftmode_keys[self.label] ~= nil and self.keyboard.shiftmode) or + (self.keyboard.umlautmode_keys[self.label] ~= nil and self.keyboard.umlautmode) then + self[1].background = Blitbuffer.COLOR_LIGHT_GRAY + end self.flash_keyboard = G_reader_settings:readSetting("flash_keyboard") ~= false end +function VirtualKey:genkeyboardLayoutKeyChars() + local positions = { + "northeast", + "north", + "northwest", + "west", + } + local keyboard_layouts = G_reader_settings:readSetting("keyboard_layouts") or {} + local key_chars = { + { label = "🌐", + }, + east = { label = "🌐", }, + east_func = function () + self.keyboard_layout_dialog = KeyboardLayoutDialog:new{ + parent = self, + } + UIManager:show(self.keyboard_layout_dialog) + end, + } + local index = 1 + for k, v in orderedPairs(keyboard_layouts) do + if v == true then + key_chars[positions[index]] = string.sub(k, 1, 2) + key_chars[positions[index] .. "_func"] = function() + UIManager:tickAfterNext(function() UIManager:close(self.popup) end) + self.keyboard:setKeyboardLayout(k) + end + if index >= 4 then break end + index = index + 1 + end + end + return key_chars +end + function VirtualKey:update_keyboard(want_flash, want_fast) -- NOTE: We mainly use "fast" when inverted & "ui" when not, with a cherry on top: -- we flash the *full* keyboard instead when we release a hold. @@ -398,9 +482,13 @@ function VirtualKeyPopup:init() h_key_padding[i].width = h_key_padding[2].width end + local key = type(v) == "table" and v.key or v + local label = type(v) == "table" and v.label or key + local icon = type(v) == "table" and v.icon local virtual_key = VirtualKey:new{ - key = v, - label = v, + key = key, + label = label, + icon = icon, keyboard = parent_key.keyboard, key_chars = key_chars, width = parent_key.width, @@ -548,12 +636,9 @@ local VirtualKeyboard = FocusManager:new{ symbolmode_keys = {}, utf8mode_keys = {}, umlautmode_keys = {}, - min_layout = 2, - max_layout = 12, - keyboard_layout = 2, + keyboard_layer = 2, shiftmode = false, symbolmode = false, - utf8mode = false, umlautmode = false, layout = {}, @@ -585,7 +670,9 @@ function VirtualKeyboard:init() self.utf8mode_keys = keyboard.utf8mode_keys self.umlautmode_keys = keyboard.umlautmode_keys self.height = Screen:scaleBySize(64 * #self.KEYS) - self:initLayout(self.keyboard_layout) + self.min_layer = keyboard.min_layer + self.max_layer = keyboard.max_layer + self:initLayer(self.keyboard_layer) if Device:hasDPad() then self.key_events.PressKey = { {"Press"}, doc = "select key" } end @@ -601,6 +688,12 @@ function VirtualKeyboard:getKeyboardLayout() return G_reader_settings:readSetting("keyboard_layout") or G_reader_settings:readSetting("language") end +function VirtualKeyboard:setKeyboardLayout(layout) + G_reader_settings:saveSetting("keyboard_layout", layout) + self:init() + self:_refresh(true) +end + function VirtualKeyboard:onClose() UIManager:close(self) return true @@ -631,26 +724,25 @@ function VirtualKeyboard:onCloseWidget() return true end -function VirtualKeyboard:initLayout(layout) - local function VKLayout(b1, b2, b3, b4) +function VirtualKeyboard:initLayer(layer) + local function VKLayer(b1, b2, b3) local function boolnum(bool) return bool and 1 or 0 end - return 2 - boolnum(b1) + 2 * boolnum(b2) + 4 * boolnum(b3) + 8 * boolnum(b4) - end - - if layout then - -- to be sure layout is selected properly - layout = math.max(layout, self.min_layout) - layout = math.min(layout, self.max_layout) - self.keyboard_layout = layout - -- fill the layout modes - self.shiftmode = (layout == 1 or layout == 3 or layout == 5 or layout == 7 or layout == 9 or layout == 11) - self.symbolmode = (layout == 3 or layout == 4 or layout == 7 or layout == 8 or layout == 11 or layout == 12) - self.utf8mode = (layout == 5 or layout == 6 or layout == 7 or layout == 8) - self.umlautmode = (layout == 9 or layout == 10 or layout == 11 or layout == 12) - else -- or, without input parameter, restore layout from current layout modes - self.keyboard_layout = VKLayout(self.shiftmode, self.symbolmode, self.utf8mode, self.umlautmode) + return 2 - boolnum(b1) + 2 * boolnum(b2) + 4 * boolnum(b3) + end + + if layer then + -- to be sure layer is selected properly + layer = math.max(layer, self.min_layer) + layer = math.min(layer, self.max_layer) + self.keyboard_layer = layer + -- fill the layer modes + self.shiftmode = (layer == 1 or layer == 3 or layer == 5 or layer == 7 or layer == 9 or layer == 11) + self.symbolmode = (layer == 3 or layer == 4 or layer == 7 or layer == 8 or layer == 11 or layer == 12) + self.umlautmode = (layer == 5 or layer == 6 or layer == 7 or layer == 8) + else -- or, without input parameter, restore layer from current layer modes + self.keyboard_layer = VKLayer(self.shiftmode, self.symbolmode, self.umlautmode) end self:addKeys() end @@ -667,7 +759,7 @@ function VirtualKeyboard:addKeys() local layout_horizontal = {} for j = 1, #self.KEYS[i] do local key - local key_chars = self.KEYS[i][j][self.keyboard_layout] + local key_chars = self.KEYS[i][j][self.keyboard_layer] if type(key_chars) == "table" then key = key_chars[1] else @@ -688,7 +780,7 @@ function VirtualKeyboard:addKeys() width = key_width, height = key_height, } - if not key_chars then + if not virtual_key.key_chars then virtual_key.swipe_callback = nil end table.insert(horizontal_group, virtual_key) @@ -725,19 +817,15 @@ function VirtualKeyboard:addKeys() self.dimen = keyboard_frame:getSize() end -function VirtualKeyboard:setLayout(key) +function VirtualKeyboard:setLayer(key) if key == "Shift" then self.shiftmode = not self.shiftmode elseif key == "Sym" or key == "ABC" then self.symbolmode = not self.symbolmode elseif key == "Äéß" then self.umlautmode = not self.umlautmode - if self.umlautmode then self.utf8mode = false end - elseif key == "IM" then - self.utf8mode = not self.utf8mode - if self.utf8mode then self.umlautmode = false end end - self:initLayout() + self:initLayer() self:_refresh(true) end