mirror of https://github.com/koreader/koreader
Merge pull request #1783 from houqp/keyboard
support input for keyboard only devices like kindle k3 and dxgpull/1784/head
commit
1c64335e7d
@ -1 +1 @@
|
||||
Subproject commit e7c0c2fee99e0162b568dec97a351e226697a4a2
|
||||
Subproject commit 8b751543a9292315fedc6d6e95fcf333bbd4f7e9
|
@ -0,0 +1,14 @@
|
||||
return {
|
||||
[1] = {
|
||||
"Q", "W", "E", "R", "T", "Y", "U", "I", "Q", "P",
|
||||
},
|
||||
[2] = {
|
||||
"A", "S", "D", "F", "G", "H", "J", "K", "L", "Del",
|
||||
},
|
||||
[3] = {
|
||||
"Z", "X", "C", "V", "B", "N", "M", ".", "Sym", "Enter",
|
||||
},
|
||||
[4] = {
|
||||
"Sym", "Alt", "space", "Aa", "Home", "Back",
|
||||
},
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
return {
|
||||
[1] = {
|
||||
"Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P",
|
||||
},
|
||||
[2] = {
|
||||
"A", "S", "D", "F", "G", "H", "J", "K", "L", "Del",
|
||||
},
|
||||
[3] = {
|
||||
"Z", "X", "C", "V", "B", "N", "M", ".", "Sym", "Enter",
|
||||
},
|
||||
[4] = {
|
||||
"Sym", "Alt", "space", "Aa", "Home", "Back",
|
||||
},
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
||||
|
||||
--[[
|
||||
TopContainer contains its content (1 widget) at the top of its own dimensions
|
||||
--]]
|
||||
local TopContainer = WidgetContainer:new()
|
||||
|
||||
return TopContainer
|
@ -0,0 +1,172 @@
|
||||
local CenterContainer = require("ui/widget/container/centercontainer")
|
||||
local BottomContainer = require("ui/widget/container/bottomcontainer")
|
||||
local TopContainer = require("ui/widget/container/topcontainer")
|
||||
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local FrameContainer = require("ui/widget/container/framecontainer")
|
||||
local HorizontalGroup = require("ui/widget/horizontalgroup")
|
||||
local HorizontalSpan = require("ui/widget/horizontalspan")
|
||||
local VerticalGroup = require("ui/widget/verticalgroup")
|
||||
local TextWidget = require("ui/widget/textwidget")
|
||||
local Blitbuffer = require("ffi/blitbuffer")
|
||||
local Device = require("device")
|
||||
local Font = require("ui/font")
|
||||
local Screen = Device.screen
|
||||
local Geom = require("ui/geometry")
|
||||
local util = require("util")
|
||||
local DEBUG = require("dbg")
|
||||
|
||||
|
||||
local PhysicalNumericKey = WidgetContainer:new{
|
||||
key = nil,
|
||||
label = nil,
|
||||
physical_key_label = nil,
|
||||
|
||||
keyboard = nil,
|
||||
callback = nil,
|
||||
mapping = nil,
|
||||
|
||||
width = nil,
|
||||
height = nil,
|
||||
bordersize = 2,
|
||||
face = Font:getFace("infont", 22),
|
||||
pkey_face = Font:getFace("infont", 14),
|
||||
}
|
||||
|
||||
function PhysicalNumericKey:init()
|
||||
local label_widget = TextWidget:new{
|
||||
text = self.label,
|
||||
face = self.face,
|
||||
}
|
||||
self[1] = FrameContainer:new{
|
||||
margin = 0,
|
||||
bordersize = self.bordersize,
|
||||
background = Blitbuffer.COLOR_WHITE,
|
||||
radius = 5,
|
||||
padding = 0,
|
||||
CenterContainer:new{
|
||||
dimen = Geom:new{
|
||||
w = self.width - 2*self.bordersize,
|
||||
h = self.height - 2*self.bordersize,
|
||||
},
|
||||
VerticalGroup:new{
|
||||
label_widget,
|
||||
TextWidget:new{
|
||||
fgcolor = Blitbuffer.COLOR_GREY,
|
||||
text = self.physical_key_label,
|
||||
face = self.pkey_face,
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
self.dimen = Geom:new{
|
||||
w = self.width,
|
||||
h = self.height,
|
||||
}
|
||||
end
|
||||
|
||||
-- start of PhysicalKeyboard
|
||||
|
||||
local PhysicalKeyboard = InputContainer:new{
|
||||
is_always_active = true,
|
||||
inputbox = nil, -- expect ui/widget/inputtext instance
|
||||
bordersize = 2,
|
||||
padding = 2,
|
||||
height = math.max(Screen:getWidth(), Screen:getHeight())*0.33,
|
||||
key_padding = Screen:scaleBySize(6),
|
||||
}
|
||||
|
||||
function PhysicalKeyboard:init()
|
||||
local all_keys = {}
|
||||
for _,row in ipairs(Device.keyboard_layout) do
|
||||
util.arrayAppend(all_keys, row)
|
||||
end
|
||||
self.key_events = {
|
||||
KeyPress = { { all_keys }, }
|
||||
}
|
||||
|
||||
self.dimen = Geom:new{ w = 0, h = 0 }
|
||||
|
||||
self:setType(self.inputbox.input_type)
|
||||
end
|
||||
|
||||
function PhysicalKeyboard:setType(t)
|
||||
if t == "number" then
|
||||
self.mapping = {
|
||||
{"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"}
|
||||
}
|
||||
self.key_transformer = {}
|
||||
for i,row in ipairs(self.mapping) do
|
||||
for j,key in ipairs(row) do
|
||||
local pkey = Device.keyboard_layout[i][j]
|
||||
self.key_transformer[pkey] = self.mapping[i][j]
|
||||
end
|
||||
end
|
||||
self:setupNumericMappingUI()
|
||||
else
|
||||
-- default mapping
|
||||
self.mapping = Device.keyboard_layout
|
||||
end
|
||||
end
|
||||
|
||||
function PhysicalKeyboard:onKeyPress(ev)
|
||||
local key = ev.key
|
||||
if key == "Back" then
|
||||
DEBUG("TODO: exit keyboard")
|
||||
elseif key == "Del" then
|
||||
self.inputbox:delChar()
|
||||
else
|
||||
if self.key_transformer then
|
||||
key = self.key_transformer[key]
|
||||
end
|
||||
self.inputbox:addChar(key)
|
||||
end
|
||||
end
|
||||
|
||||
function PhysicalKeyboard:setupNumericMappingUI()
|
||||
local key_rows = VerticalGroup:new{}
|
||||
local key_margin = 1
|
||||
local row_len = #self.mapping[1]
|
||||
local base_key_width = math.floor((self.width - row_len*(self.key_padding+2*key_margin) - 2*self.padding)/10)
|
||||
local base_key_height = math.floor((self.height - self.key_padding - 2*self.padding)/4)
|
||||
local key_width = math.floor(base_key_width + self.key_padding)
|
||||
|
||||
for i, kb_row in ipairs(self.mapping) do
|
||||
local row = HorizontalGroup:new{}
|
||||
for j, key in ipairs(kb_row) do
|
||||
if j > 1 then
|
||||
table.insert(row, HorizontalSpan:new{width=key_margin*2})
|
||||
end
|
||||
table.insert(row, PhysicalNumericKey:new{
|
||||
label = key,
|
||||
physical_key_label = Device.keyboard_layout[i][j],
|
||||
width = key_width,
|
||||
height = base_key_height,
|
||||
})
|
||||
end
|
||||
table.insert(key_rows, row)
|
||||
end
|
||||
|
||||
local keyboard_frame = FrameContainer:new{
|
||||
margin = 0,
|
||||
bordersize = 0,
|
||||
radius = 0,
|
||||
padding = self.padding,
|
||||
TopContainer:new{
|
||||
dimen = Geom:new{
|
||||
w = self.width - 2*self.bordersize -2*self.padding,
|
||||
h = self.height - 2*self.bordersize -2*self.padding,
|
||||
},
|
||||
key_rows,
|
||||
}
|
||||
}
|
||||
|
||||
self[1] = BottomContainer:new{
|
||||
dimen = Screen:getSize(),
|
||||
keyboard_frame,
|
||||
}
|
||||
|
||||
self.dimen = keyboard_frame:getSize()
|
||||
end
|
||||
|
||||
return PhysicalKeyboard
|
@ -0,0 +1,272 @@
|
||||
#!/bin/bash
|
||||
|
||||
CURDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
function setup_env {
|
||||
files=("./koreader-emulator-*/koreader")
|
||||
export EMU_DIR=${files[0]}
|
||||
}
|
||||
|
||||
function kodev-fetch-thirdparty {
|
||||
make fetchthirdparty
|
||||
}
|
||||
|
||||
SUPPORTED_TARGETS="
|
||||
kindle For kindle with touch support
|
||||
kindle-legacy For kindle2/3/4/DXG
|
||||
kobo
|
||||
android
|
||||
pocketbook
|
||||
ubuntu-touch
|
||||
emu (*default) If no TARGET is given, assume emulator
|
||||
win32
|
||||
"
|
||||
|
||||
function kodev-build {
|
||||
BUILD_HELP_MSG="
|
||||
usage: build <TARGET>
|
||||
|
||||
TARGET:
|
||||
${SUPPORTED_TARGETS}"
|
||||
|
||||
case $1 in
|
||||
-h | --help)
|
||||
echo "${BUILD_HELP_MSG}"
|
||||
exit 0
|
||||
;;
|
||||
kindle)
|
||||
make TARGET=kindle
|
||||
;;
|
||||
kobo)
|
||||
make TARGET=kobo
|
||||
;;
|
||||
kindle-legacy)
|
||||
make TARGET=kindle-legacy
|
||||
;;
|
||||
android)
|
||||
if [ ! -d ${CURDIR}/base/toolchain/android-toolchain ]; then
|
||||
make android-toolchain
|
||||
fi
|
||||
make TARGET=android
|
||||
;;
|
||||
pocketbook)
|
||||
if [ ! -d ${CURDIR}/base/toolchain/pocketbook-toolchain ]; then
|
||||
make pocketbook-toolchain
|
||||
fi
|
||||
make TARGET=pocketbook
|
||||
;;
|
||||
ubuntu-touch)
|
||||
make TARGET=ubuntu-touch
|
||||
;;
|
||||
win32)
|
||||
make TARGET=win32
|
||||
;;
|
||||
*)
|
||||
make
|
||||
setup_env
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
function kodev-clean {
|
||||
CLEAN_HELP_MSG="
|
||||
usage: clean <TARGET>
|
||||
|
||||
TARGET:
|
||||
${SUPPORTED_TARGETS}"
|
||||
|
||||
case $1 in
|
||||
-h | --help)
|
||||
echo "${CLEAN_HELP_MSG}"
|
||||
exit 0
|
||||
;;
|
||||
kindle)
|
||||
make TARGET=kindle clean
|
||||
;;
|
||||
kobo)
|
||||
make TARGET=kobo clean
|
||||
;;
|
||||
kindle-legacy)
|
||||
make TARGET=kindle-legacy clean
|
||||
;;
|
||||
android)
|
||||
make TARGET=android clean
|
||||
;;
|
||||
pocketbook)
|
||||
make TARGET=pocketbook clean
|
||||
;;
|
||||
ubuntu-touch)
|
||||
make TARGET=ubuntu-touch clean
|
||||
;;
|
||||
win32)
|
||||
make TARGET=win32 clean
|
||||
;;
|
||||
*)
|
||||
make clean
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
function kodev-release {
|
||||
# SUPPORTED_RELEASE_TARGETS=$(echo ${SUPPORTED_TARGETS} | sed 's/win32//')
|
||||
SUPPORTED_RELEASE_TARGETS="${SUPPORTED_TARGETS/emu*/""}"
|
||||
RELEASE_HELP_MSG="
|
||||
usage: release <TARGET>
|
||||
|
||||
TARGET:
|
||||
${SUPPORTED_RELEASE_TARGETS}"
|
||||
|
||||
if [ $# -lt 1 ]; then
|
||||
echo "${RELEASE_HELP_MSG}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
case $1 in
|
||||
-h | --help)
|
||||
echo "${RELEASE_HELP_MSG}"
|
||||
exit 0
|
||||
;;
|
||||
kindle)
|
||||
kodev-build kindle
|
||||
make TARGET=kindle update
|
||||
;;
|
||||
kobo)
|
||||
kodev-build kobo
|
||||
make TARGET=kobo update
|
||||
;;
|
||||
kindle-legacy)
|
||||
kodev-build kindle-legacy
|
||||
make TARGET=kindle-legacy update
|
||||
;;
|
||||
android)
|
||||
kodev-build android
|
||||
make TARGET=android update
|
||||
;;
|
||||
pocketbook)
|
||||
kodev-build pocketbook
|
||||
make TARGET=pocketbook update
|
||||
;;
|
||||
ubuntu-touch)
|
||||
kodev-build pocketbook
|
||||
make TARGET=ubuntu-touch update
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported target for release: $1."
|
||||
echo "${RELEASE_HELP_MSG}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
function kodev-wbuilder {
|
||||
kodev-build
|
||||
echo "[*] Running wbuilder.lua..."
|
||||
pushd ${EMU_DIR}
|
||||
EMULATE_READER_W=540 EMULATE_READER_H=720 ./luajit ./utils/wbuilder.lua
|
||||
popd
|
||||
}
|
||||
|
||||
function kodev-run {
|
||||
RUN_HELP_MSG="
|
||||
usage: run <OPTIONS> <ARGS>
|
||||
|
||||
OPTIONS:
|
||||
|
||||
--no-build run reader without rebuilding
|
||||
--disable-touch use this if you want to simulate keyboard only devices
|
||||
"
|
||||
while [[ $1 == '--'* ]]; do
|
||||
PARAM=`echo $1 | awk -F= '{print $1}'`
|
||||
VALUE=`echo $1 | awk -F= '{print $2}'`
|
||||
case $PARAM in
|
||||
--disable-touch)
|
||||
export DISABLE_TOUCH=1
|
||||
;;
|
||||
--no-build)
|
||||
no_build=true
|
||||
;;
|
||||
-h | --help)
|
||||
echo "${RUN_HELP_MSG}"
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "ERROR: unknown option \"$PARAM\""
|
||||
echo "${RUN_HELP_MSG}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
if [ ! ${no_build} ]; then
|
||||
echo "[*] Building KOReader..."
|
||||
kodev-build
|
||||
else
|
||||
setup_env
|
||||
fi
|
||||
|
||||
echo "[*] Running KOReader..."
|
||||
pushd ${EMU_DIR}
|
||||
|
||||
if [ $# -lt 1 ]; then
|
||||
args=${CURDIR}/test
|
||||
else
|
||||
args="$1"
|
||||
[[ $args != /* ]] && args="${CURDIR}/$1"
|
||||
fi
|
||||
|
||||
EMULATE_READER_W=540 EMULATE_READER_H=720 ./reader.lua -d $args
|
||||
popd
|
||||
}
|
||||
|
||||
HELP_MSG="
|
||||
usage: $0 COMMAND <ARGS>
|
||||
|
||||
Supported commands:
|
||||
|
||||
build Build KOReader
|
||||
clean Clean KOReader build
|
||||
run Run KOReader
|
||||
wbuilder Run wbuilder.lua script (useful for building new UI widget)
|
||||
"
|
||||
|
||||
if [ $# -lt 1 ]; then
|
||||
echo "Missing command."
|
||||
echo "${HELP_MSG}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
case $1 in
|
||||
fetch-thirdparty)
|
||||
kodev-fetch-thirdparty
|
||||
;;
|
||||
clean)
|
||||
shift 1
|
||||
kodev-clean $@
|
||||
;;
|
||||
build)
|
||||
shift 1
|
||||
kodev-build $@
|
||||
;;
|
||||
release)
|
||||
shift 1
|
||||
kodev-release $@
|
||||
;;
|
||||
wbuilder)
|
||||
kodev-wbuilder
|
||||
;;
|
||||
run)
|
||||
shift 1
|
||||
kodev-run $@
|
||||
;;
|
||||
--help | -h)
|
||||
echo "${HELP_MSG}"
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "Unknown command: $1."
|
||||
echo "${HELP_MSG}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
Loading…
Reference in New Issue