From 43797ed81385405849ed54124e11997a16533978 Mon Sep 17 00:00:00 2001 From: bingo619 <348872073@qq.com> Date: Tue, 2 Aug 2016 19:21:27 +1000 Subject: [PATCH] Oasis orientation --- frontend/device/gesturedetector.lua | 38 +++++++++++++++++++++++++++++ frontend/device/input.lua | 36 ++++++++++++++++++++++++++- frontend/device/kindle/device.lua | 14 +++++++++-- frontend/ui/uimanager.lua | 6 +++++ 4 files changed, 91 insertions(+), 3 deletions(-) diff --git a/frontend/device/gesturedetector.lua b/frontend/device/gesturedetector.lua index 81be40dab..3b5fb0147 100644 --- a/frontend/device/gesturedetector.lua +++ b/frontend/device/gesturedetector.lua @@ -674,6 +674,44 @@ function GestureDetector:adjustGesCoordinate(ges) ges.direction = "horizontal" end end + + elseif self.screen.cur_rotation_mode == 2 then + -- in portrait mode rotated 180 + if ges.pos then + ges.pos.x, ges.pos.y = (self.screen:getWidth() - ges.pos.x), (self.screen:getHeight() - ges.pos.y) + end + if ges.ges == "swipe" or ges.ges == "pan" + or ges.ges == "two_finger_swipe" + or ges.ges == "two_finger_pan" then + if ges.direction == "north" then + ges.direction = "south" + elseif ges.direction == "south" then + ges.direction = "north" + elseif ges.direction == "east" then + ges.direction = "west" + elseif ges.direction == "west" then + ges.direction = "east" + elseif ges.direction == "northeast" then + ges.direction = "southwest" + elseif ges.direction == "northwest" then + ges.direction = "southeast" + elseif ges.direction == "southeast" then + ges.direction = "northwest" + elseif ges.direction == "southwest" then + ges.direction = "northeast" + end + if ges.relative then + ges.relative.x, ges.relative.y = -ges.relative.x, -ges.relative.y + end + elseif ges.ges == "pinch" or ges.ges == "spread" + or ges.ges == "inward_pan" + or ges.ges == "outward_pan" then + if ges.direction == "horizontal" then + ges.direction = "horizontal" + elseif ges.direction == "vertical" then + ges.direction = "vertical" + end + end end return ges end diff --git a/frontend/device/input.lua b/frontend/device/input.lua index dc429194c..742ff647a 100644 --- a/frontend/device/input.lua +++ b/frontend/device/input.lua @@ -38,6 +38,15 @@ local ABS_MT_POSITION_X = 53 local ABS_MT_POSITION_Y = 54 local ABS_MT_TRACKING_ID = 57 local ABS_MT_PRESSURE = 58 + +-- For device orientation events (ABS.code) + +local ABS_PRESSURE = 24 +local DEVICE_ORIENTATION_PORTRAIT = 19 +local DEVICE_ORIENTATION_PORTRAIT_ROTATED = 20 +local DEVICE_ORIENTATION_LANDSCAPE = 21 +local DEVICE_ORIENTATION_LANDSCAPE_ROTATED = 21 + -- luacheck: pop --[[ @@ -83,7 +92,7 @@ local Input = { rotation_map = { [0] = {}, [1] = { Up = "Right", Right = "Down", Down = "Left", Left = "Up" }, - [2] = { Up = "Down", Right = "Left", Down = "Up", Left = "Right" }, + [2] = { Up = "Down", Right = "Left", Down = "Up", Left = "Right", LPgFwd = "LPgBack", LPgBack = "LPgFwd", RPgFwd = "RPgBack", RPgBack = "RPgFwd" }, [3] = { Up = "Left", Right = "Up", Down = "Right", Left = "Down" } }, @@ -449,6 +458,29 @@ function Input:handleTouchEvPhoenix(ev) end end +function Input:handleOrientationEv(ev) + + if ev.type == EV_ABS then + if ev.code == ABS_PRESSURE and self.device.screen:getScreenMode() == 'portrait' then + local refreshUI = false + local rotation_mode = 0 + if ev.value == DEVICE_ORIENTATION_PORTRAIT then + refreshUI = true + elseif ev.value == DEVICE_ORIENTATION_PORTRAIT_ROTATED then + refreshUI = true + rotation_mode = 2 + end + + local oldRotation = self.device.screen:getRotationMode() + if refreshUI and rotation_mode ~= oldRotation then + self.device.screen:setRotationMode(rotation_mode) + local UIManager = require("ui/uimanager") + UIManager:onRotation() + end + end + end +end + -- helpers for touch event data management: @@ -550,6 +582,8 @@ function Input:waitEvent(timeout_us) if ev.type == EV_KEY then DEBUG("key ev", ev) return self:handleKeyBoardEv(ev) + elseif ev.type == EV_ABS and ev.code == ABS_PRESSURE then + return self:handleOrientationEv(ev) elseif ev.type == EV_ABS or ev.type == EV_SYN then return self:handleTouchEv(ev) elseif ev.type == EV_MSC then diff --git a/frontend/device/kindle/device.lua b/frontend/device/kindle/device.lua index f3b7f7898..9f4fe8f96 100644 --- a/frontend/device/kindle/device.lua +++ b/frontend/device/kindle/device.lua @@ -342,8 +342,7 @@ function KindleOasis:init() self.input = require("device/input"):new{ device = self, - - -- TODO: Physical buttons handle orientation? + event_map = { [104] = "RPgFwd", [109] = "RPgBack", @@ -354,6 +353,17 @@ function KindleOasis:init() self.input.open(self.touch_dev) self.input.open("/dev/input/by-path/platform-gpiokey.0-event") + + -- get rotate dev by EV=d + local std_out = io.popen("cat /proc/bus/input/devices | grep -e 'Handlers\\|EV=' | grep -B1 'EV=d'| grep -o 'event[0-9]'", "r") + if std_out then + local rotation_dev = std_out:read() + std_out:close() + if rotation_dev then + self.input.open("/dev/input/"..rotation_dev) + end + end + self.input.open("fake_events") end diff --git a/frontend/ui/uimanager.lua b/frontend/ui/uimanager.lua index 5c6156eaa..5f54bbc57 100644 --- a/frontend/ui/uimanager.lua +++ b/frontend/ui/uimanager.lua @@ -672,6 +672,12 @@ function UIManager:handleInput() end end + +function UIManager:onRotation() + self:setDirty('all', 'full') + self:forceRePaint() +end + function UIManager:initLooper() if DUSE_TURBO_LIB and not self.looper then TURBO_SSL = true -- luacheck: ignore