mirror of
https://github.com/koreader/koreader
synced 2024-10-31 21:20:20 +00:00
Merge pull request #596 from kai771/emu_rotate
Implements Kindle screen rotate on emulator and forces portrait mode on doc close
This commit is contained in:
commit
07ff1474a3
28
einkfb.c
28
einkfb.c
@ -23,6 +23,11 @@
|
||||
|
||||
#include "einkfb.h"
|
||||
|
||||
#ifdef EMULATE_READER
|
||||
int emu_w = EMULATE_READER_W;
|
||||
int emu_h = EMULATE_READER_H;
|
||||
#endif
|
||||
|
||||
static int openFrameBuffer(lua_State *L) {
|
||||
const char *fb_device = luaL_checkstring(L, 1);
|
||||
FBInfo *fb = (FBInfo*) lua_newuserdata(L, sizeof(FBInfo));
|
||||
@ -89,14 +94,14 @@ static int openFrameBuffer(lua_State *L) {
|
||||
if(SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||
return luaL_error(L, "cannot initialize SDL.");
|
||||
}
|
||||
if(!(fb->screen = SDL_SetVideoMode(EMULATE_READER_W, EMULATE_READER_H, 32, SDL_HWSURFACE))) {
|
||||
if(!(fb->screen = SDL_SetVideoMode(emu_w, emu_h, 32, SDL_HWSURFACE))) {
|
||||
return luaL_error(L, "can't get video surface %dx%d for 32bpp.",
|
||||
EMULATE_READER_W, EMULATE_READER_H);
|
||||
emu_w, emu_h);
|
||||
}
|
||||
fb->vinfo.xres = EMULATE_READER_W;
|
||||
fb->vinfo.yres = EMULATE_READER_H;
|
||||
fb->buf->pitch = (EMULATE_READER_W + 1) / 2;
|
||||
fb->buf->data = calloc(fb->buf->pitch * EMULATE_READER_H, sizeof(char));
|
||||
fb->vinfo.xres = emu_w;
|
||||
fb->vinfo.yres = emu_h;
|
||||
fb->buf->pitch = (emu_w + 1) / 2;
|
||||
fb->buf->data = calloc(fb->buf->pitch * emu_h, sizeof(char));
|
||||
if(fb->buf->data == NULL) {
|
||||
return luaL_error(L, "cannot get framebuffer emu memory");
|
||||
}
|
||||
@ -191,7 +196,6 @@ static int einkUpdate(lua_State *L) {
|
||||
/* NOTICE!!! You must close and reopen framebuffer after called this method.
|
||||
* Otherwise, screen resolution will not be updated! */
|
||||
static int einkSetOrientation(lua_State *L) {
|
||||
#ifndef EMULATE_READER
|
||||
FBInfo *fb = (FBInfo*) luaL_checkudata(L, 1, "einkfb");
|
||||
int mode = luaL_optint(L, 2, 0);
|
||||
|
||||
@ -199,6 +203,7 @@ static int einkSetOrientation(lua_State *L) {
|
||||
return luaL_error(L, "Wrong rotation mode %d given!", mode);
|
||||
}
|
||||
|
||||
#ifndef EMULATE_READER
|
||||
/* ioctl has a different definition for rotation mode. */
|
||||
if (mode == 1)
|
||||
mode = 2;
|
||||
@ -206,6 +211,15 @@ static int einkSetOrientation(lua_State *L) {
|
||||
mode = 1;
|
||||
|
||||
ioctl(fb->fd, FBIO_EINK_SET_DISPLAY_ORIENTATION, mode);
|
||||
#else
|
||||
if (mode == 0 || mode == 2) {
|
||||
emu_w = EMULATE_READER_W;
|
||||
emu_h = EMULATE_READER_H;
|
||||
}
|
||||
else if (mode == 1 || mode == 3) {
|
||||
emu_w = EMULATE_READER_H;
|
||||
emu_h = EMULATE_READER_W;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
@ -116,11 +116,14 @@ end
|
||||
G_screen_saver_mode = false
|
||||
G_charging_mode = false
|
||||
fb = einkfb.open("/dev/fb0")
|
||||
G_width, G_height = fb:getSize()
|
||||
-- read current rotation mode
|
||||
Screen:updateRotationMode()
|
||||
Screen.native_rotation_mode = Screen.cur_rotation_mode
|
||||
|
||||
-- force portrait mode
|
||||
Screen:setRotationMode(0)
|
||||
G_width, G_height = fb:getSize()
|
||||
|
||||
-- set up reader's setting: font
|
||||
G_reader_settings = DocSettings:open(".reader")
|
||||
fontmap = G_reader_settings:readSetting("fontmap")
|
||||
|
13
screen.lua
13
screen.lua
@ -47,6 +47,19 @@ Screen = {
|
||||
saved_bb = nil,
|
||||
}
|
||||
|
||||
function Screen:setRotationMode(mode)
|
||||
if mode < 0 or mode > 3 then
|
||||
Debug("Illegal mode parameter to Screen:setRotatonMode()!")
|
||||
return
|
||||
end
|
||||
|
||||
self.cur_rotation_mode = mode
|
||||
-- you have to reopen framebuffer after rotate
|
||||
fb:setOrientation(self.cur_rotation_mode)
|
||||
fb:close()
|
||||
fb = einkfb.open("/dev/fb0")
|
||||
end
|
||||
|
||||
-- @orien: 1 for clockwise rotate, -1 for anti-clockwise
|
||||
-- Remember to reread screen resolution after this function call
|
||||
function Screen:screenRotate(orien)
|
||||
|
@ -1876,6 +1876,14 @@ function UniReader:screenRotate(orien)
|
||||
self:clearCache()
|
||||
end
|
||||
|
||||
function UniReader:setRotationMode(mode)
|
||||
Screen:setRotationMode(mode)
|
||||
-- update global width and height variable
|
||||
G_width, G_height = fb:getSize()
|
||||
self:clearCache()
|
||||
end
|
||||
|
||||
|
||||
function UniReader:cleanUpTocTitle(title)
|
||||
return (title:gsub("\13", ""))
|
||||
end
|
||||
@ -2487,6 +2495,7 @@ function UniReader:inputLoop()
|
||||
self.toc_cview = nil
|
||||
self.toc_curidx_to_x = nil
|
||||
self.show_overlap = 0
|
||||
self:setRotationMode(0)
|
||||
self:setDefaults()
|
||||
if self.doc ~= nil then
|
||||
self.doc:close()
|
||||
|
Loading…
Reference in New Issue
Block a user