mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Merge pull request #656 from houqp/new_ui_houqp
dimming on overlap and Kindle Touch support
This commit is contained in:
270
einkfb.c
270
einkfb.c
@@ -19,13 +19,131 @@
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <fcntl.h>
|
||||
//#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "einkfb.h"
|
||||
|
||||
#ifdef EMULATE_READER
|
||||
int emu_w = EMULATE_READER_W;
|
||||
int emu_h = EMULATE_READER_H;
|
||||
int emu_w = EMULATE_READER_W;
|
||||
int emu_h = EMULATE_READER_H;
|
||||
#else
|
||||
static void (*einkUpdateFunc)(FBInfo *fb, lua_State *L) = NULL;
|
||||
|
||||
inline void fbInvert4BppTo8Bpp(FBInfo *fb) {
|
||||
int i = 0, j = 0, h = 0, w = 0, pitch = 0, fb_pitch = 0;
|
||||
uint8_t *shadow_buf = NULL, *fb_buf = NULL;
|
||||
|
||||
shadow_buf = fb->buf->data;
|
||||
fb_buf = fb->real_buf->data;
|
||||
h = fb->buf->h;
|
||||
w = fb->buf->w;
|
||||
pitch = fb->buf->pitch;
|
||||
fb_pitch = fb->real_buf->pitch;
|
||||
|
||||
/* copy bitmap from 4bpp shadow blitbuffer to framebuffer */
|
||||
for (i = (h-1); i > 0; i--) {
|
||||
for (j = (w-1)/2; j > 0; j--) {
|
||||
fb_buf[i*fb_pitch + j*2] = shadow_buf[i*pitch + j];
|
||||
fb_buf[i*fb_pitch + j*2] &= 0xF0;
|
||||
fb_buf[i*fb_pitch + j*2] |= shadow_buf[i*pitch + j]>>4 & 0x0F;
|
||||
|
||||
fb_buf[i*fb_pitch + j*2 + 1] = shadow_buf[i*pitch + j];
|
||||
fb_buf[i*fb_pitch + j*2 + 1] &= 0x0F;
|
||||
fb_buf[i*fb_pitch + j*2 + 1] |= shadow_buf[i*pitch + j]<<4 & 0xF0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void fb4BppTo8Bpp(FBInfo *fb) {
|
||||
int i = 0, j = 0, h = 0, w = 0, pitch = 0, fb_pitch = 0;
|
||||
uint8_t *shadow_buf = NULL, *fb_buf = NULL;
|
||||
|
||||
shadow_buf = fb->buf->data;
|
||||
fb_buf = fb->real_buf->data;
|
||||
/* h is 1024 for PaperWhite */
|
||||
h = fb->buf->h;
|
||||
/* w is 758 for PaperWhite */
|
||||
w = fb->buf->w;
|
||||
/* pitch is 384 for shadow buffer */
|
||||
pitch = fb->buf->pitch;
|
||||
/* pitch is 768 for PaperWhite */
|
||||
fb_pitch = fb->real_buf->pitch;
|
||||
|
||||
/* copy bitmap from 4bpp shadow blitbuffer to framebuffer */
|
||||
for (i = (h-1); i > 0; i--) {
|
||||
for (j = (w-1)/2; j > 0; j--) {
|
||||
fb_buf[i*fb_pitch + j*2] = shadow_buf[i*pitch + j];
|
||||
fb_buf[i*fb_pitch + j*2] &= 0xF0;
|
||||
fb_buf[i*fb_pitch + j*2] |= shadow_buf[i*pitch + j]>>4 & 0x0F;
|
||||
fb_buf[i*fb_pitch + j*2] = ~fb_buf[i*fb_pitch + j*2];
|
||||
|
||||
fb_buf[i*fb_pitch + j*2 + 1] = shadow_buf[i*pitch + j];
|
||||
fb_buf[i*fb_pitch + j*2 + 1] &= 0x0F;
|
||||
fb_buf[i*fb_pitch + j*2 + 1] |= shadow_buf[i*pitch + j]<<4 & 0xF0;
|
||||
fb_buf[i*fb_pitch + j*2 + 1] = ~fb_buf[i*fb_pitch + j*2 + 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void fillUpdateAreaT(update_area_t *myarea, FBInfo *fb, lua_State *L) {
|
||||
int fxtype = luaL_optint(L, 2, 0);
|
||||
|
||||
myarea->x1 = luaL_optint(L, 3, 0);
|
||||
myarea->y1 = luaL_optint(L, 4, 0);
|
||||
myarea->x2 = myarea->x1 + luaL_optint(L, 5, fb->vinfo.xres);
|
||||
myarea->y2 = myarea->y1 + luaL_optint(L, 6, fb->vinfo.yres);
|
||||
myarea->buffer = NULL;
|
||||
myarea->which_fx = fxtype ? fx_update_partial : fx_update_full;
|
||||
}
|
||||
|
||||
inline void fillMxcfbUpdateData(mxcfb_update_data *myarea, FBInfo *fb, lua_State *L) {
|
||||
myarea->update_region.top = luaL_optint(L, 3, 0);
|
||||
myarea->update_region.left = luaL_optint(L, 4, 0);
|
||||
myarea->update_region.width = luaL_optint(L, 5, fb->vinfo.xres);
|
||||
myarea->update_region.height = luaL_optint(L, 6, fb->vinfo.yres);
|
||||
myarea->waveform_mode = 257;
|
||||
myarea->update_mode = 0;
|
||||
myarea->update_marker = 1;
|
||||
myarea->hist_bw_waveform_mode = 0;
|
||||
myarea->hist_gray_waveform_mode = 0;
|
||||
myarea->temp = 0x1001;
|
||||
myarea->flags = 0;
|
||||
/*myarea->alt_buffer_data.virt_addr = NULL;*/
|
||||
myarea->alt_buffer_data.phys_addr = NULL;
|
||||
myarea->alt_buffer_data.width = 0;
|
||||
myarea->alt_buffer_data.height = 0;
|
||||
myarea->alt_buffer_data.alt_update_region.top = 0;
|
||||
myarea->alt_buffer_data.alt_update_region.left = 0;
|
||||
myarea->alt_buffer_data.alt_update_region.width = 0;
|
||||
myarea->alt_buffer_data.alt_update_region.height = 0;
|
||||
}
|
||||
|
||||
void kindle3einkUpdate(FBInfo *fb, lua_State *L) {
|
||||
update_area_t myarea;
|
||||
|
||||
fillUpdateAreaT(&myarea, fb, L);
|
||||
|
||||
ioctl(fb->fd, FBIO_EINK_UPDATE_DISPLAY_AREA, &myarea);
|
||||
}
|
||||
|
||||
void kindle4einkUpdate(FBInfo *fb, lua_State *L) {
|
||||
update_area_t myarea;
|
||||
|
||||
fbInvert4BppTo8Bpp(fb);
|
||||
fillUpdateAreaT(&myarea, fb, L);
|
||||
|
||||
ioctl(fb->fd, FBIO_EINK_UPDATE_DISPLAY_AREA, &myarea);
|
||||
}
|
||||
|
||||
/* for kindle firmware with version >= 5.1, 5.0 is not supported for now */
|
||||
void kindle51einkUpdate(FBInfo *fb, lua_State *L) {
|
||||
mxcfb_update_data myarea;
|
||||
|
||||
fb4BppTo8Bpp(fb);
|
||||
fillMxcfbUpdateData(&myarea, fb, L);
|
||||
|
||||
ioctl(fb->fd, MXCFB_SEND_UPDATE, &myarea);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int openFrameBuffer(lua_State *L) {
|
||||
@@ -65,6 +183,22 @@ static int openFrameBuffer(lua_State *L) {
|
||||
fb->finfo.type);
|
||||
}
|
||||
|
||||
if (strncmp(fb->finfo.id, "mxc_epdc_fb", 11) == 0) {
|
||||
/* Kindle PaperWhite and KT with 5.1 or later firmware */
|
||||
einkUpdateFunc = &kindle51einkUpdate;
|
||||
} else if (strncmp(fb->finfo.id, "eink_fb", 7) == 0) {
|
||||
if (fb->vinfo.bits_per_pixel == 8) {
|
||||
/* kindle4 */
|
||||
einkUpdateFunc = &kindle4einkUpdate;
|
||||
} else {
|
||||
/* kindle2, 3, DXG */
|
||||
einkUpdateFunc = &kindle3einkUpdate;
|
||||
}
|
||||
} else {
|
||||
return luaL_error(L, "eink model %s not supported",
|
||||
fb->finfo.id);
|
||||
}
|
||||
|
||||
if (ioctl(fb->fd, FBIOGET_VSCREENINFO, &fb->vinfo)) {
|
||||
return luaL_error(L, "cannot get variable screen info");
|
||||
}
|
||||
@@ -167,139 +301,11 @@ static int closeFrameBuffer(lua_State *L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef EMULATE_READER
|
||||
inline void fbInvert4BppTo8Bpp(FBInfo *fb) {
|
||||
int i = 0, j = 0, h = 0, w = 0, pitch = 0, fb_pitch = 0;
|
||||
uint8_t *shadow_buf = NULL, *fb_buf = NULL;
|
||||
|
||||
shadow_buf = fb->buf->data;
|
||||
fb_buf = fb->real_buf->data;
|
||||
h = fb->buf->h;
|
||||
w = fb->buf->w;
|
||||
pitch = fb->buf->pitch;
|
||||
fb_pitch = fb->real_buf->pitch;
|
||||
|
||||
/* copy bitmap from 4bpp shadow blitbuffer to framebuffer */
|
||||
for (i = (h-1); i > 0; i--) {
|
||||
for (j = (w-1)/2; j > 0; j--) {
|
||||
fb_buf[i*fb_pitch + j*2] = shadow_buf[i*pitch + j];
|
||||
fb_buf[i*fb_pitch + j*2] &= 0xF0;
|
||||
fb_buf[i*fb_pitch + j*2] |= shadow_buf[i*pitch + j]>>4 & 0x0F;
|
||||
|
||||
fb_buf[i*fb_pitch + j*2 + 1] = shadow_buf[i*pitch + j];
|
||||
fb_buf[i*fb_pitch + j*2 + 1] &= 0x0F;
|
||||
fb_buf[i*fb_pitch + j*2 + 1] |= shadow_buf[i*pitch + j]<<4 & 0xF0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void fb4BppTo8Bpp(FBInfo *fb) {
|
||||
int i = 0, j = 0, h = 0, w = 0, pitch = 0, fb_pitch = 0;
|
||||
uint8_t *shadow_buf = NULL, *fb_buf = NULL;
|
||||
|
||||
shadow_buf = fb->buf->data;
|
||||
fb_buf = fb->real_buf->data;
|
||||
/* h is 1024 for PaperWhite */
|
||||
h = fb->buf->h;
|
||||
/* w is 758 for PaperWhite */
|
||||
w = fb->buf->w;
|
||||
/* pitch is 384 for shadow buffer */
|
||||
pitch = fb->buf->pitch;
|
||||
/* pitch is 768 for PaperWhite */
|
||||
fb_pitch = fb->real_buf->pitch;
|
||||
|
||||
/* copy bitmap from 4bpp shadow blitbuffer to framebuffer */
|
||||
for (i = (h-1); i > 0; i--) {
|
||||
for (j = (w-1)/2; j > 0; j--) {
|
||||
fb_buf[i*fb_pitch + j*2] = shadow_buf[i*pitch + j];
|
||||
fb_buf[i*fb_pitch + j*2] &= 0xF0;
|
||||
fb_buf[i*fb_pitch + j*2] |= shadow_buf[i*pitch + j]>>4 & 0x0F;
|
||||
fb_buf[i*fb_pitch + j*2] = ~fb_buf[i*fb_pitch + j*2];
|
||||
|
||||
fb_buf[i*fb_pitch + j*2 + 1] = shadow_buf[i*pitch + j];
|
||||
fb_buf[i*fb_pitch + j*2 + 1] &= 0x0F;
|
||||
fb_buf[i*fb_pitch + j*2 + 1] |= shadow_buf[i*pitch + j]<<4 & 0xF0;
|
||||
fb_buf[i*fb_pitch + j*2 + 1] = ~fb_buf[i*fb_pitch + j*2 + 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void fillUpdateAreaT(update_area_t *myarea, FBInfo *fb, lua_State *L) {
|
||||
int fxtype = luaL_optint(L, 2, 0);
|
||||
|
||||
myarea->x1 = luaL_optint(L, 3, 0);
|
||||
myarea->y1 = luaL_optint(L, 4, 0);
|
||||
myarea->x2 = myarea->x1 + luaL_optint(L, 5, fb->vinfo.xres);
|
||||
myarea->y2 = myarea->y1 + luaL_optint(L, 6, fb->vinfo.yres);
|
||||
myarea->buffer = NULL;
|
||||
myarea->which_fx = fxtype ? fx_update_partial : fx_update_full;
|
||||
}
|
||||
|
||||
inline void fillMxcfbUpdateData51(mxcfb_update_data51 *myarea, FBInfo *fb, lua_State *L) {
|
||||
myarea->update_region.top = luaL_optint(L, 3, 0);
|
||||
myarea->update_region.left = luaL_optint(L, 4, 0);
|
||||
myarea->update_region.width = luaL_optint(L, 5, fb->vinfo.xres);
|
||||
myarea->update_region.height = luaL_optint(L, 6, fb->vinfo.yres);
|
||||
myarea->waveform_mode = 257;
|
||||
myarea->update_mode = 0;
|
||||
myarea->update_marker = 1;
|
||||
myarea->hist_bw_waveform_mode = 0;
|
||||
myarea->hist_gray_waveform_mode = 0;
|
||||
myarea->temp = 0x1001;
|
||||
myarea->flags = 0;
|
||||
myarea->alt_buffer_data.virt_addr = NULL;
|
||||
myarea->alt_buffer_data.phys_addr = NULL;
|
||||
myarea->alt_buffer_data.width = 0;
|
||||
myarea->alt_buffer_data.height = 0;
|
||||
myarea->alt_buffer_data.alt_update_region.top = 0;
|
||||
myarea->alt_buffer_data.alt_update_region.left = 0;
|
||||
myarea->alt_buffer_data.alt_update_region.width = 0;
|
||||
myarea->alt_buffer_data.alt_update_region.height = 0;
|
||||
}
|
||||
|
||||
inline void Kindle3einkUpdate(FBInfo *fb, lua_State *L) {
|
||||
update_area_t myarea;
|
||||
|
||||
fillUpdateAreaT(&myarea, fb, L);
|
||||
|
||||
ioctl(fb->fd, FBIO_EINK_UPDATE_DISPLAY_AREA, &myarea);
|
||||
}
|
||||
|
||||
inline void kindle4einkUpdate(FBInfo *fb, lua_State *L) {
|
||||
update_area_t myarea;
|
||||
|
||||
fbInvert4BppTo8Bpp(fb);
|
||||
fillUpdateAreaT(&myarea, fb, L);
|
||||
|
||||
ioctl(fb->fd, FBIO_EINK_UPDATE_DISPLAY_AREA, &myarea);
|
||||
}
|
||||
|
||||
inline void kindlePWeinkUpdate(FBInfo *fb, lua_State *L) {
|
||||
mxcfb_update_data51 myarea;
|
||||
|
||||
fb4BppTo8Bpp(fb);
|
||||
fillMxcfbUpdateData51(&myarea, fb, L);
|
||||
|
||||
ioctl(fb->fd, 0x4048462e, &myarea);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int einkUpdate(lua_State *L) {
|
||||
FBInfo *fb = (FBInfo*) luaL_checkudata(L, 1, "einkfb");
|
||||
// for Kindle e-ink display
|
||||
#ifndef EMULATE_READER
|
||||
if (fb->vinfo.bits_per_pixel == 8) {
|
||||
if (fb->buf->h == 1024) {
|
||||
/* Kindle PaperWhite */
|
||||
kindlePWeinkUpdate(fb, L);
|
||||
} else {
|
||||
/* kindle4 */
|
||||
kindle4einkUpdate(fb, L);
|
||||
}
|
||||
} else {
|
||||
/* kindle2, 3, DXG */
|
||||
Kindle3einkUpdate(fb, L);
|
||||
}
|
||||
einkUpdateFunc(fb, L);
|
||||
#else
|
||||
int fxtype = luaL_optint(L, 2, 0);
|
||||
// for now, we only do fullscreen blits in emulation mode
|
||||
|
||||
@@ -124,16 +124,24 @@ function Document:getPageDimensions(pageno, zoom, rotation)
|
||||
return native_dimen
|
||||
end
|
||||
|
||||
--[[
|
||||
This method returns pagesize if bbox is corrupted
|
||||
--]]
|
||||
function Document:getUsedBBoxDimensions(pageno, zoom, rotation)
|
||||
ubbox = self:getUsedBBox(pageno)
|
||||
ubbox_dimen = Geom:new{
|
||||
x = ubbox.x0,
|
||||
y = ubbox.y0,
|
||||
w = ubbox.x1 - ubbox.x0,
|
||||
h = ubbox.y1 - ubbox.y0,
|
||||
}
|
||||
if zoom ~= 1 then
|
||||
ubbox_dimen:transformByScale(zoom)
|
||||
if ubbox.x0 < 0 or ubbox.y0 < 0 or ubbox.x1 < 0 or ubbox.y1 < 0 then
|
||||
-- if document's bbox info is corrupted, we use the page size
|
||||
ubbox_dimen = self:getPageDimensions(pageno, zoom, rotation)
|
||||
else
|
||||
ubbox_dimen = Geom:new{
|
||||
x = ubbox.x0,
|
||||
y = ubbox.y0,
|
||||
w = ubbox.x1 - ubbox.x0,
|
||||
h = ubbox.y1 - ubbox.y0,
|
||||
}
|
||||
if zoom ~= 1 then
|
||||
ubbox_dimen:transformByScale(zoom)
|
||||
end
|
||||
end
|
||||
return ubbox_dimen
|
||||
end
|
||||
|
||||
@@ -1,8 +1,36 @@
|
||||
DocSettings = {}
|
||||
|
||||
function DocSettings:getHistoryPath(fullpath)
|
||||
local i = #fullpath - 1
|
||||
-- search for last slash
|
||||
while i > 0 do
|
||||
if fullpath:sub(i,i) == "/" then
|
||||
break
|
||||
end
|
||||
i = i - 1
|
||||
end
|
||||
-- construct path to configuration file in history dir
|
||||
local filename = fullpath:sub(i+1, -1)
|
||||
local basename = fullpath:sub(1, i)
|
||||
return "./history/["..basename:gsub("/","#").."] "..filename..".lua"
|
||||
end
|
||||
|
||||
function DocSettings:open(docfile)
|
||||
local new = { file = docfile..".kpdfview.lua", data = {} }
|
||||
local ok, stored = pcall(dofile,new.file)
|
||||
local conf_path = nil
|
||||
if docfile == ".reader" then
|
||||
-- we handle reader setting as special case
|
||||
conf_path = "settings.reader.lua"
|
||||
else
|
||||
conf_path = self:getHistoryPath(docfile)
|
||||
end
|
||||
-- construct settings obj
|
||||
local new = { file = conf_path, data = {} }
|
||||
local ok, stored = pcall(dofile, new.file)
|
||||
if not ok then
|
||||
-- try legacy conf path, for backward compatibility. this also
|
||||
-- takes care of reader legacy setting
|
||||
ok, stored = pcall(dofile, docfile..".kpdfview.lua")
|
||||
end
|
||||
if ok then
|
||||
new.data = stored
|
||||
end
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
Device = {
|
||||
screen_saver_mode = false,
|
||||
charging_mode = false,
|
||||
model = nil,
|
||||
}
|
||||
|
||||
function Device:getModel()
|
||||
@@ -15,9 +16,16 @@ function Device:getModel()
|
||||
end
|
||||
end
|
||||
if cpu_mod == "MX50" then
|
||||
local f = lfs.attributes("/sys/devices/system/fl_tps6116x/fl_tps6116x0/fl_intensity")
|
||||
if f then
|
||||
-- for KPW
|
||||
local pw_test_fd = lfs.attributes("/sys/devices/system/fl_tps6116x/fl_tps6116x0/fl_intensity")
|
||||
-- for KT
|
||||
local kt_test_fd = lfs.attributes("/sys/devices/platform/whitney-button")
|
||||
-- another special file for KT is Neonode zForce touchscreen:
|
||||
-- /sys/devices/platform/zforce.0/
|
||||
if pw_test_fd then
|
||||
return "KindlePaperWhite"
|
||||
elseif kt_test_fd then
|
||||
return "KindleTouch"
|
||||
else
|
||||
return "Kindle4"
|
||||
end
|
||||
@@ -58,9 +66,18 @@ function Device:isKindle2()
|
||||
end
|
||||
end
|
||||
|
||||
function Device:hasNoKeyboard()
|
||||
if not self.model then
|
||||
self.model = self:getModel()
|
||||
end
|
||||
return self:isTouchDevice() or (self.model == "Kindle4")
|
||||
end
|
||||
|
||||
function Device:isTouchDevice()
|
||||
local model = self:getModel()
|
||||
return (model == "Kindle4") or (model == "KindlePaperWhite") or util.isEmulated()
|
||||
if not self.model then
|
||||
self.model = self:getModel()
|
||||
end
|
||||
return (self.model == "KindlePaperWhite") or (self.model == "KindleTouch") or util.isEmulated()
|
||||
end
|
||||
|
||||
function Device:intoScreenSaver()
|
||||
|
||||
@@ -3,7 +3,7 @@ require "ui/menu"
|
||||
FileChooser = Menu:new{
|
||||
height = Screen:getHeight(),
|
||||
width = Screen:getWidth(),
|
||||
path = ".",
|
||||
path = lfs.currentdir(),
|
||||
parent = nil,
|
||||
show_hidden = false,
|
||||
filter = function(filename) return true end,
|
||||
|
||||
@@ -274,4 +274,8 @@ function math.roundAwayFromZero(num)
|
||||
end
|
||||
end
|
||||
|
||||
function math.round(num)
|
||||
return math.floor(num + 0.5)
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -1,18 +1,5 @@
|
||||
require "ui/geometry"
|
||||
|
||||
-- Synchronization events (SYN.code).
|
||||
SYN_REPORT = 0
|
||||
SYN_CONFIG = 1
|
||||
SYN_MT_REPORT = 2
|
||||
|
||||
-- For multi-touch events (ABS.code).
|
||||
ABS_MT_SLOT = 47
|
||||
ABS_MT_POSITION_X = 53
|
||||
ABS_MT_POSITION_Y = 54
|
||||
ABS_MT_TRACKING_ID = 57
|
||||
ABS_MT_PRESSURE = 58
|
||||
|
||||
|
||||
GestureRange = {
|
||||
ges = nil,
|
||||
range = nil,
|
||||
@@ -207,7 +194,6 @@ function GestureDetector:tapState(ev)
|
||||
sec = 0, usec = self.HOLD_INTERVAL
|
||||
}
|
||||
Input:setTimeout(function()
|
||||
print("hold timer", self.state == self.tapState)
|
||||
if self.state == self.tapState then
|
||||
-- timer set in tapState, so we switch to hold
|
||||
return self:switchState("holdState")
|
||||
|
||||
@@ -14,6 +14,19 @@ EVENT_VALUE_KEY_PRESS = 1
|
||||
EVENT_VALUE_KEY_REPEAT = 2
|
||||
EVENT_VALUE_KEY_RELEASE = 0
|
||||
|
||||
-- Synchronization events (SYN.code).
|
||||
SYN_REPORT = 0
|
||||
SYN_CONFIG = 1
|
||||
SYN_MT_REPORT = 2
|
||||
|
||||
-- For multi-touch events (ABS.code).
|
||||
ABS_MT_SLOT = 47
|
||||
ABS_MT_POSITION_X = 53
|
||||
ABS_MT_POSITION_Y = 54
|
||||
ABS_MT_TRACKING_ID = 57
|
||||
ABS_MT_PRESSURE = 58
|
||||
|
||||
|
||||
|
||||
--[[
|
||||
an interface for key presses
|
||||
@@ -239,13 +252,34 @@ function Input:init()
|
||||
else
|
||||
input.open("fake_events")
|
||||
local dev_mod = Device:getModel()
|
||||
|
||||
input.open("/dev/input/event0")
|
||||
if dev_mod ~= "KindlePaperWhite" then
|
||||
-- we don't have event1 in KindlePaperWhite
|
||||
if dev_mod ~= "KindleTouch" then
|
||||
-- event0 in KindleTouch is "WM8962 Beep Generator" (useless)
|
||||
input.open("/dev/input/event0")
|
||||
end
|
||||
if dev_mod ~= "KindleTouch" and dev_mod ~= "KindlePaperWhite" then
|
||||
-- event1 in KindleTouch is "imx-yoshi Headset" (useless)
|
||||
-- and we don't have event1 in KindlePaperWhite
|
||||
input.open("/dev/input/event1")
|
||||
elseif dev_mod == "KindlePaperWhite" then
|
||||
end
|
||||
if dev_mod == "KindlePaperWhite" then
|
||||
print("Auto-detected Kindle PaperWhite")
|
||||
elseif dev_mod == "KindleTouch" then
|
||||
input.open("/dev/input/event2") -- Home button
|
||||
input.open("/dev/input/event3") -- touchscreen
|
||||
-- update event hook
|
||||
function Input:eventAdjustHook(ev)
|
||||
if ev.type == EV_ABS then
|
||||
--@TODO handle coordinates properly after
|
||||
--screen rotate. (houqp)
|
||||
if ev.code == ABS_MT_POSITION_X then
|
||||
ev.value = math.round(ev.value * (600/4095))
|
||||
elseif ev.code == ABS_MT_POSITION_Y then
|
||||
ev.value = math.round(ev.value * (800/4095))
|
||||
end
|
||||
end
|
||||
return ev
|
||||
end
|
||||
print("Auto-detected Kindle Touch")
|
||||
elseif dev_mod == "Kindle4" then
|
||||
print("Auto-detected Kindle 4")
|
||||
self:adjustKindle4EventMap()
|
||||
@@ -263,6 +297,15 @@ function Input:init()
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
different device models shoudl overload this method if
|
||||
necessary to make event compatible to KPV.
|
||||
--]]
|
||||
function Input:eventAdjustHook(ev)
|
||||
-- do nothing by default
|
||||
return ev
|
||||
end
|
||||
|
||||
function Input:adjustKindle4EventMap()
|
||||
self.event_map[193] = "LPgBack"
|
||||
self.event_map[104] = "LPgFwd"
|
||||
@@ -334,6 +377,7 @@ function Input:waitEvent(timeout_us, timeout_s)
|
||||
end
|
||||
end
|
||||
if ok and ev then
|
||||
ev = self:eventAdjustHook(ev)
|
||||
if ev.type == EV_KEY then
|
||||
local keycode = self.event_map[ev.code]
|
||||
if not keycode then
|
||||
|
||||
@@ -3,6 +3,8 @@ ReaderPaging = InputContainer:new{
|
||||
number_of_pages = 0,
|
||||
visible_area = nil,
|
||||
page_area = nil,
|
||||
show_overlap_enable = true,
|
||||
overlap = 20,
|
||||
}
|
||||
|
||||
function ReaderPaging:init()
|
||||
@@ -67,6 +69,10 @@ end
|
||||
|
||||
function ReaderPaging:onReadSettings(config)
|
||||
self:gotoPage(config:readSetting("last_page") or 1)
|
||||
local soe = config:readSetting("show_overlap_enable")
|
||||
if not soe then
|
||||
self.show_overlap_enable = soe
|
||||
end
|
||||
end
|
||||
|
||||
function ReaderPaging:onCloseDocument()
|
||||
@@ -112,7 +118,7 @@ end
|
||||
|
||||
function ReaderPaging:onViewRecalculate(visible_area, page_area)
|
||||
-- we need to remember areas to handle page turn event
|
||||
self.visible_area = visible_area
|
||||
self.visible_area = visible_area:copy()
|
||||
self.page_area = page_area
|
||||
end
|
||||
|
||||
@@ -144,28 +150,76 @@ function ReaderPaging:onGotoPageRel(diff)
|
||||
x_pan_off = self.visible_area.w * diff
|
||||
end
|
||||
end
|
||||
|
||||
-- adjust offset to help with page turn decision
|
||||
-- we dont take overlap into account here yet, otherwise new_va will
|
||||
-- always intersect with page_area
|
||||
x_pan_off = math.roundAwayFromZero(x_pan_off)
|
||||
y_pan_off = math.roundAwayFromZero(y_pan_off)
|
||||
new_va.x = math.roundAwayFromZero(self.visible_area.x+x_pan_off)
|
||||
new_va.y = math.roundAwayFromZero(self.visible_area.y+y_pan_off)
|
||||
|
||||
if (new_va:notIntersectWith(self.page_area)) then
|
||||
if new_va:notIntersectWith(self.page_area) then
|
||||
-- view area out of page area, do a page turn
|
||||
self:gotoPage(self.current_page + diff)
|
||||
-- if we are going back to previous page, reset
|
||||
-- view to bottom of previous page
|
||||
-- view area to bottom of previous page
|
||||
if x_pan_off < 0 then
|
||||
self.view:PanningUpdate(self.page_area.w, 0)
|
||||
elseif y_pan_off < 0 then
|
||||
self.view:PanningUpdate(0, self.page_area.h)
|
||||
end
|
||||
-- reset dim_area
|
||||
--self.view.dim_area.h = 0
|
||||
--self.view.dim_area.w = 0
|
||||
--
|
||||
else
|
||||
-- not end of page yet, goto next view
|
||||
-- adjust panning step according to overlap
|
||||
if self.show_overlap_enable then
|
||||
if x_pan_off > self.overlap then
|
||||
-- moving to next view, move view
|
||||
x_pan_off = x_pan_off - self.overlap
|
||||
elseif x_pan_off < -self.overlap then
|
||||
x_pan_off = x_pan_off + self.overlap
|
||||
end
|
||||
if y_pan_off > self.overlap then
|
||||
y_pan_off = y_pan_off - self.overlap
|
||||
elseif y_pan_off < -self.overlap then
|
||||
y_pan_off = y_pan_off + self.overlap
|
||||
end
|
||||
-- we have to calculate again to count into overlap
|
||||
new_va.x = math.roundAwayFromZero(self.visible_area.x+x_pan_off)
|
||||
new_va.y = math.roundAwayFromZero(self.visible_area.y+y_pan_off)
|
||||
end
|
||||
-- fit new view area into page area
|
||||
new_va:offsetWithin(self.page_area, 0, 0)
|
||||
self.view:PanningUpdate(
|
||||
new_va.x - self.visible_area.x,
|
||||
new_va.y - self.visible_area.y)
|
||||
-- calculate panning offsets
|
||||
local panned_x = new_va.x - self.visible_area.x
|
||||
local panned_y = new_va.y - self.visible_area.y
|
||||
-- adjust for crazy float point overflow...
|
||||
if math.abs(panned_x) < 1 then
|
||||
panned_x = 0
|
||||
end
|
||||
if math.abs(panned_y) < 1 then
|
||||
panned_y = 0
|
||||
end
|
||||
-- singal panning update
|
||||
self.view:PanningUpdate(panned_x, panned_y)
|
||||
-- update dime area in ReaderView
|
||||
if self.show_overlap_enable then
|
||||
self.view.dim_area.h = new_va.h - math.abs(panned_y)
|
||||
self.view.dim_area.w = new_va.w - math.abs(panned_x)
|
||||
if panned_y < 0 then
|
||||
self.view.dim_area.y = new_va.y - panned_y
|
||||
else
|
||||
self.view.dim_area.y = 0
|
||||
end
|
||||
if panned_x < 0 then
|
||||
self.view.dim_area.x = new_va.x - panned_x
|
||||
else
|
||||
self.view.dim_area.x = 0
|
||||
end
|
||||
end
|
||||
-- update self.visible_area
|
||||
self.visible_area = new_va
|
||||
end
|
||||
|
||||
@@ -1,29 +1,12 @@
|
||||
require "ui/reader/readerpanning"
|
||||
|
||||
ReaderRolling = InputContainer:new{
|
||||
key_events = {
|
||||
GotoNextView = { {Input.group.PgFwd}, doc = "go to next view", event = "GotoViewRel", args = 1 },
|
||||
GotoPrevView = { {Input.group.PgBack}, doc = "go to previous view", event = "GotoViewRel", args = -1 },
|
||||
|
||||
MoveUp = { {"Up"}, doc = "move view up", event = "Panning", args = {0, -1} },
|
||||
MoveDown = { {"Down"}, doc = "move view down", event = "Panning", args = {0, 1} },
|
||||
|
||||
GotoFirst = { {"1"}, doc = "go to start", event = "GotoPercent", args = 0},
|
||||
Goto11 = { {"2"}, doc = "go to 11%", event = "GotoPercent", args = 11},
|
||||
Goto22 = { {"3"}, doc = "go to 22%", event = "GotoPercent", args = 22},
|
||||
Goto33 = { {"4"}, doc = "go to 33%", event = "GotoPercent", args = 33},
|
||||
Goto44 = { {"5"}, doc = "go to 44%", event = "GotoPercent", args = 44},
|
||||
Goto55 = { {"6"}, doc = "go to 55%", event = "GotoPercent", args = 55},
|
||||
Goto66 = { {"7"}, doc = "go to 66%", event = "GotoPercent", args = 66},
|
||||
Goto77 = { {"8"}, doc = "go to 77%", event = "GotoPercent", args = 77},
|
||||
Goto88 = { {"9"}, doc = "go to 88%", event = "GotoPercent", args = 88},
|
||||
GotoLast = { {"0"}, doc = "go to end", event = "GotoPercent", args = 100},
|
||||
},
|
||||
|
||||
old_doc_height = nil,
|
||||
current_pos = 0,
|
||||
doc_height = nil,
|
||||
panning_steps = ReaderPanning.panning_steps,
|
||||
show_overlap_enable = true,
|
||||
overlap = 20,
|
||||
}
|
||||
|
||||
function ReaderRolling:init()
|
||||
@@ -103,6 +86,10 @@ end
|
||||
|
||||
function ReaderRolling:onReadSettings(config)
|
||||
self:gotoPercent(config:readSetting("last_percent") or 0)
|
||||
local soe = config:readSetting("show_overlap_enable")
|
||||
if not soe then
|
||||
self.show_overlap_enable = soe
|
||||
end
|
||||
end
|
||||
|
||||
function ReaderRolling:onCloseDocument()
|
||||
@@ -132,7 +119,15 @@ end
|
||||
|
||||
function ReaderRolling:onGotoViewRel(diff)
|
||||
DEBUG("goto relative screen:", diff)
|
||||
self:gotoPos(self.current_pos + diff * self.ui.dimen.h)
|
||||
local pan_diff = diff * self.ui.dimen.h
|
||||
if self.show_overlap_enable then
|
||||
if pan_diff > self.overlap then
|
||||
pan_diff = pan_diff - self.overlap
|
||||
elseif pan_diff < -self.overlap then
|
||||
pan_diff = pan_diff + self.overlap
|
||||
end
|
||||
end
|
||||
self:gotoPos(self.current_pos + pan_diff)
|
||||
return true
|
||||
end
|
||||
|
||||
@@ -167,6 +162,18 @@ function ReaderRolling:gotoPos(new_pos)
|
||||
if new_pos == self.current_pos then return end
|
||||
if new_pos < 0 then new_pos = 0 end
|
||||
if new_pos > self.doc_height then new_pos = self.doc_height end
|
||||
-- adjust dim_area according to new_pos
|
||||
if self.show_overlap_enable then
|
||||
local panned_step = new_pos - self.current_pos
|
||||
self.view.dim_area.x = 0
|
||||
self.view.dim_area.h = self.ui.dimen.h - math.abs(panned_step)
|
||||
self.view.dim_area.w = self.ui.dimen.w
|
||||
if panned_step < 0 then
|
||||
self.view.dim_area.y = self.ui.dimen.h - self.view.dim_area.h
|
||||
elseif panned_step > 0 then
|
||||
self.view.dim_area.y = 0
|
||||
end
|
||||
end
|
||||
self.ui:handleEvent(Event:new("PosUpdate", new_pos))
|
||||
end
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ ReaderView = WidgetContainer:new{
|
||||
visible_area = Geom:new{x = 0, y = 0},
|
||||
-- dimen for current viewing page
|
||||
page_area = Geom:new{},
|
||||
-- dimen for area to dim
|
||||
dim_area = Geom:new{w = 0, h = 0},
|
||||
}
|
||||
|
||||
function ReaderView:paintTo(bb, x, y)
|
||||
@@ -54,8 +56,18 @@ function ReaderView:paintTo(bb, x, y)
|
||||
self.visible_area,
|
||||
self.state.pos)
|
||||
end
|
||||
-- dim last read area
|
||||
if self.dim_area.w ~= 0 and self.dim_area.h ~= 0 then
|
||||
bb:dimRect(
|
||||
self.dim_area.x, self.dim_area.y,
|
||||
self.dim_area.w, self.dim_area.h
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
This method is supposed to be only used by ReaderPaging
|
||||
--]]
|
||||
function ReaderView:recalculate()
|
||||
local page_size = nil
|
||||
if self.ui.document.info.has_pages then
|
||||
@@ -77,11 +89,14 @@ function ReaderView:recalculate()
|
||||
self.visible_area:setSizeTo(self.dimen)
|
||||
-- and recalculate it according to page size
|
||||
self.visible_area:offsetWithin(self.page_area, 0, 0)
|
||||
-- clear dim area
|
||||
self.dim_area.w = 0
|
||||
self.dim_area.h = 0
|
||||
self.ui:handleEvent(
|
||||
Event:new("ViewRecalculate", self.visible_area, self.page_area))
|
||||
else
|
||||
self.visible_area:setSizeTo(self.dimen)
|
||||
end
|
||||
self.ui:handleEvent(
|
||||
Event:new("ViewRecalculate", self.visible_area, self.page_area))
|
||||
-- flag a repaint so self:paintTo will be called
|
||||
UIManager:setDirty(self.dialog)
|
||||
end
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
/*
|
||||
* Copyright 2004-2011 Freescale Semiconductor, Inc. All Rights Reserved.
|
||||
*
|
||||
* Modified by houqp, added mxcfb_update_data51 struct from GeekMaster's video
|
||||
* player, refer to:
|
||||
* http://www.mobileread.com/forums/showthread.php?t=177455&page=10
|
||||
*/
|
||||
|
||||
/*
|
||||
* - Modified by houqp, added mxcfb_update_data struct from GeekMaster's
|
||||
* video player, refer to:
|
||||
* http://www.mobileread.com/forums/showthread.php?t=177455&page=10
|
||||
*
|
||||
* - Modified mxcfb_alt_buffer_data struct according to include/linux/mxcfb.h
|
||||
* from Kindle 5.3.0 firmware. Thanks to eureka@mobileread.
|
||||
* http://www.mobileread.com/forums/showpost.php?p=2337118&postcount=818
|
||||
*
|
||||
*
|
||||
* The code contained herein is licensed under the GNU Lesser General
|
||||
* Public License. You may obtain a copy of the GNU Lesser General
|
||||
* Public License Version 2.1 or later at the following locations:
|
||||
@@ -96,14 +99,15 @@ struct mxcfb_rect {
|
||||
#define FB_TEMP_AUTO_UPDATE_DISABLE -1
|
||||
|
||||
struct mxcfb_alt_buffer_data {
|
||||
void *virt_addr;
|
||||
/* virt_addr is not included in amazon's source */
|
||||
/* void *virt_addr; */
|
||||
__u32 phys_addr;
|
||||
__u32 width; /* width of entire buffer */
|
||||
__u32 height; /* height of entire buffer */
|
||||
struct mxcfb_rect alt_update_region; /* region within buffer to update */
|
||||
};
|
||||
|
||||
struct mxcfb_update_data51 {
|
||||
struct mxcfb_update_data {
|
||||
struct mxcfb_rect update_region;
|
||||
__u32 waveform_mode;
|
||||
__u32 update_mode;
|
||||
@@ -114,9 +118,11 @@ struct mxcfb_update_data51 {
|
||||
uint flags;
|
||||
struct mxcfb_alt_buffer_data alt_buffer_data;
|
||||
};
|
||||
typedef struct mxcfb_update_data51 mxcfb_update_data51;
|
||||
typedef struct mxcfb_update_data mxcfb_update_data;
|
||||
|
||||
struct mxcfb_update_data {
|
||||
/* this is only used in kindle firmware 5.0, later version (5.1) has changed
|
||||
* the struct to mxcfb_update_data (see above) */
|
||||
struct mxcfb_update_data_50x {
|
||||
struct mxcfb_rect update_region;
|
||||
__u32 waveform_mode;
|
||||
__u32 update_mode;
|
||||
@@ -156,7 +162,7 @@ struct mxcfb_waveform_modes {
|
||||
#define MXCFB_SET_WAVEFORM_MODES _IOW('F', 0x2B, struct mxcfb_waveform_modes)
|
||||
#define MXCFB_SET_TEMPERATURE _IOW('F', 0x2C, int32_t)
|
||||
#define MXCFB_SET_AUTO_UPDATE_MODE _IOW('F', 0x2D, __u32)
|
||||
#define MXCFB_SEND_UPDATE _IOW('F', 0x2E, struct mxcfb_update_data)
|
||||
#define MXCFB_SEND_UPDATE_50X _IOW('F', 0x2E, struct mxcfb_update_data_50x)
|
||||
#define MXCFB_WAIT_FOR_UPDATE_COMPLETE _IOW('F', 0x2F, __u32)
|
||||
#define MXCFB_SET_PWRDOWN_DELAY _IOW('F', 0x30, int32_t)
|
||||
#define MXCFB_GET_PWRDOWN_DELAY _IOR('F', 0x31, int32_t)
|
||||
@@ -168,6 +174,9 @@ struct mxcfb_waveform_modes {
|
||||
#define MXCFB_SET_TEMP_AUTO_UPDATE_PERIOD _IOR('F', 0x36, int32_t)
|
||||
#define MXCFB_SET_MERGE_ON_WAVEFORM_MISMATCH _IOW('F', 0x37, int32_t)
|
||||
|
||||
/* IOCTLs for E-ink panel updates, kindle firmware version >= 5.1 */
|
||||
#define MXCFB_SEND_UPDATE _IOW('F', 0x2E, struct mxcfb_update_data)
|
||||
|
||||
#ifdef __KERNEL__
|
||||
|
||||
extern struct fb_videomode mxcfb_modedb[];
|
||||
|
||||
@@ -62,9 +62,6 @@ end
|
||||
|
||||
-- option parsing:
|
||||
longopts = {
|
||||
password = "p",
|
||||
goto = "g",
|
||||
gamma = "G",
|
||||
debug = "d",
|
||||
help = "h",
|
||||
}
|
||||
@@ -97,7 +94,7 @@ else
|
||||
DEBUG = function() end
|
||||
end
|
||||
|
||||
if Device.isKindle4() or Device:isTouchDevice() then
|
||||
if Device:hasNoKeyboard() then
|
||||
-- remove menu item shortcut for K4
|
||||
Menu.is_enable_shortcut = false
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user