From 9654e9ce6c98e89f9ad01163ce0ce4e42ca536cb Mon Sep 17 00:00:00 2001 From: chrox Date: Sun, 18 Oct 2015 00:12:06 +0800 Subject: [PATCH] fix #1608 with touch coordinates detection Some kobo touch devices have X Y coordinates in touch events swapped. This patch provides a GUI to probe if the device needs to swap the XY. The Kobo Touch users will be directed to tap on the upper right corner of the screen and the probe will check if the X value is smaller than the Y value in the tap event. --- Makefile | 2 +- reader.lua | 5 +- resources/kobo-touch-probe.png | Bin 0 -> 3582 bytes utils/kobo_touch_proble.lua | 97 +++++++++++++++++++++++++++++++++ utils/wtest.lua | 4 +- 5 files changed, 104 insertions(+), 4 deletions(-) create mode 100644 resources/kobo-touch-probe.png create mode 100755 utils/kobo_touch_proble.lua diff --git a/Makefile b/Makefile index b31b7f261..278021d52 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ UBUNTUTOUCH_SDL_DIR:=$(UBUNTUTOUCH_DIR)/ubuntu-touch-sdl WIN32_DIR=$(PLATFORM_DIR)/win32 # files to link from main directory -INSTALL_FILES=reader.lua frontend resources defaults.lua datastorage.lua l10n \ +INSTALL_FILES=reader.lua frontend resources defaults.lua datastorage.lua l10n utils \ git-rev README.md COPYING # for gettext diff --git a/reader.lua b/reader.lua index c4a990c0f..f508f2852 100755 --- a/reader.lua +++ b/reader.lua @@ -112,7 +112,7 @@ if G_reader_settings:readSetting("night_mode") then Screen:toggleNightMode() end --- restore kobo frontlight settings +-- restore kobo frontlight settings and probe kobo touch coordinates if Device:isKobo() then local powerd = Device:getPowerDevice() if powerd and powerd.restore_settings then @@ -121,6 +121,9 @@ if Device:isKobo() then powerd:setIntensityWithoutHW(intensity) -- powerd:setIntensity(intensity) end + if Device:getCodeName() == "trilogy" then + require("utils/kobo_touch_proble") + end end if ARGV[argidx] and ARGV[argidx] ~= "" then diff --git a/resources/kobo-touch-probe.png b/resources/kobo-touch-probe.png new file mode 100644 index 0000000000000000000000000000000000000000..9d17da287142ecde7d4535f12e2c19055d16cc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=fP{;KPK^ByJm=~9!G7CFi0WP>*y)}(Z=DqQ6nVBob%o(5Ij)yK}#KDk|x*a9a5-+cVu? zcUYK3A%s|TjfW%s^O}0vC|3{3G@hkzeAjsc@ZvmA)0XZBLN>9dy{G1Ay(UbE+mOH9 zs;;V!o~W~yW3eZK(P5SDr6<&#Oy|xHs(Q?+qfX^0PbBQcauE>l?&{WV zQbRn6KBuDBxt-J#szl@|gs7dPa`gV%`#O}vLs4^$d#S^`w_H9!HDL$3ujLjfc9-=V zaoH$@$W?vFw%O-|5M}KEXp|!^Cxs9jRewn1RqnrWB7Up5%oO6nv#Rmi-yIHIAuc;OCiJ; z12e~-G7ZASf7&&Y8vdEPfuez;fuez;fuez;fx_(cKb68fBlpd5w*UYD07*qoM6N<$ Ef{=uVqW}N^ literal 0 HcmV?d00001 diff --git a/utils/kobo_touch_proble.lua b/utils/kobo_touch_proble.lua new file mode 100755 index 000000000..227883db5 --- /dev/null +++ b/utils/kobo_touch_proble.lua @@ -0,0 +1,97 @@ +-- touch probe utility +-- usage: ./luajit util/kobo_touch_proble.lua + +require "defaults" +package.path = "common/?.lua;rocks/share/lua/5.1/?.lua;frontend/?.lua;" .. package.path +package.cpath = "common/?.so;common/?.dll;/usr/lib/lua/?.so;rocks/lib/lua/5.1/?.so;" .. package.cpath + +local DocSettings = require("docsettings") +local _ = require("gettext") + +-- read settings and check for language override +-- has to be done before requiring other files because +-- they might call gettext on load +G_reader_settings = DocSettings:open(".reader") +local lang_locale = G_reader_settings:readSetting("language") +if lang_locale then + _.changeLang(lang_locale) +end +local InputContainer = require("ui/widget/container/inputcontainer") +local CenterContainer = require("ui/widget/container/centercontainer") +local RightContainer = require("ui/widget/container/rightcontainer") +local OverlapGroup = require("ui/widget/overlapgroup") +local ImageWidget = require("ui/widget/imagewidget") +local TextWidget = require("ui/widget/textwidget") +local GestureRange = require("ui/gesturerange") +local UIManager = require("ui/uimanager") +local Blitbuffer = require("ffi/blitbuffer") +local Geom = require("ui/geometry") +local Device = require("device") +local Screen = require("device").screen +local Input = require("device").input +local Font = require("ui/font") +local DEBUG = require("dbg") +--DEBUG:turnOn() + +local TouchProbe = InputContainer:new{ +} + +function TouchProbe:init() + self.ges_events = { + TapProbe = { + GestureRange:new{ + ges = "tap", + range = Geom:new{ + x = 0, y = 0, + w = Screen:getWidth(), + h = Screen:getHeight(), + }, + } + }, + } + local image_widget = ImageWidget:new{ + file = "resources/kobo-touch-probe.png", + } + self[1] = OverlapGroup:new{ + dimen = Screen:getSize(), + CenterContainer:new{ + dimen = Screen:getSize(), + TextWidget:new{ + text = _("Tap the upper right corner"), + face = Font:getFace("cfont", 30), + }, + }, + RightContainer:new{ + dimen = { + h = image_widget:getSize().h, + w = Screen:getSize().w, + }, + image_widget, + }, + } +end + +function TouchProbe:onTapProbe(arg, ges) + --DEBUG("onTapProbe", ges) + local need_to_switch_xy = ges.pos.x < ges.pos.y + --DEBUG("Need to switch xy", need_to_switch_xy) + G_reader_settings:saveSetting("kobo_touch_switch_xy", need_to_switch_xy) + G_reader_settings:close() + if need_to_switch_xy then + Input:registerEventAdjustHook(Input.adjustTouchSwitchXY) + end + UIManager:quit() +end + +-- if user has not set KOBO_TOUCH_MIRRORED yet +if KOBO_TOUCH_MIRRORED == nil then + local switch_xy = G_reader_settings:readSetting("kobo_touch_switch_xy") + -- and has no probe before + if switch_xy == nil then + UIManager:show(TouchProbe:new{}) + UIManager:run() + -- otherwise, we will use probed result + else + KOBO_TOUCH_MIRRORED = switch_xy + end +end diff --git a/utils/wtest.lua b/utils/wtest.lua index dd44ecfbd..859295c18 100755 --- a/utils/wtest.lua +++ b/utils/wtest.lua @@ -3,8 +3,8 @@ require "defaults" print(package.path) -package.path = "?.lua;common/?.lua;frontend/?.lua" -package.cpath = "?.so;common/?.so;/usr/lib/lua/?.so" +package.path = "common/?.lua;rocks/share/lua/5.1/?.lua;frontend/?.lua;" .. package.path +package.cpath = "common/?.so;common/?.dll;/usr/lib/lua/?.so;rocks/lib/lua/5.1/?.so;" .. package.cpath local DocSettings = require("docsettings") local _ = require("gettext")