Oasis orientation

pull/2206/head
bingo619 8 years ago
parent c0cc3b677c
commit 43797ed813

@ -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

@ -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

@ -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

@ -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

Loading…
Cancel
Save