From 818043752f212935ee0393461027ed93aab18be2 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Sun, 11 Nov 2012 13:58:00 +0800 Subject: [PATCH 1/5] refine single tap touch input simulation in input.c --- input.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/input.c b/input.c index ca81569d5..57c27eaf4 100644 --- a/input.c +++ b/input.c @@ -56,7 +56,7 @@ void slider_handler(int sig) } } #else -pid_t emu_event_pid = -1; +int is_in_touch = 0; static inline void genEmuEvent(lua_State *L, int fd, int type, int code, int value) { struct input_event input; @@ -302,20 +302,26 @@ static int waitForInput(lua_State *L) { genEmuEvent(L, inputfds[0], EV_KEY, event.key.keysym.scancode, 0); break; case SDL_MOUSEMOTION: - /* ignore move motion here, we might use it for other - * gesture in future. */ - /*printf("Mouse moved by %d,%d to (%d,%d)\n", */ - /*event.motion.xrel, event.motion.yrel,*/ - /*event.motion.x, event.motion.y);*/ + if (is_in_touch) { + if (event.motion.xrel != 0) + genEmuEvent(L, inputfds[0], EV_ABS, ABS_MT_POSITION_X, event.button.x); + if (event.motion.yrel != 0) + genEmuEvent(L, inputfds[0], EV_ABS, ABS_MT_POSITION_Y, event.button.y); + genEmuEvent(L, inputfds[0], EV_SYN, SYN_REPORT, 0); + } + break; + case SDL_MOUSEBUTTONUP: + is_in_touch = 0; + genEmuEvent(L, inputfds[0], EV_ABS, ABS_MT_TRACKING_ID, -1); + genEmuEvent(L, inputfds[0], EV_SYN, SYN_REPORT, 0); break; case SDL_MOUSEBUTTONDOWN: /* use mouse click to simulate single tap */ + is_in_touch = 1; genEmuEvent(L, inputfds[0], EV_ABS, ABS_MT_TRACKING_ID, 0); genEmuEvent(L, inputfds[0], EV_ABS, ABS_MT_POSITION_X, event.button.x); genEmuEvent(L, inputfds[0], EV_ABS, ABS_MT_POSITION_Y, event.button.y); genEmuEvent(L, inputfds[0], EV_SYN, SYN_REPORT, 0); - genEmuEvent(L, inputfds[0], EV_ABS, ABS_MT_TRACKING_ID, -1); - genEmuEvent(L, inputfds[0], EV_SYN, SYN_REPORT, 0); /*printf("Mouse button %d pressed at (%d,%d)\n",*/ /*event.button.button, event.button.x, event.button.y);*/ break; From 36a4ead6302b15e8cf9bcd108c882190f737a7ab Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Sun, 11 Nov 2012 14:29:56 +0800 Subject: [PATCH 2/5] update document.lua according to API change in cre.cpp --- frontend/document/document.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/document/document.lua b/frontend/document/document.lua index f9ed27091..2dee7dfde 100644 --- a/frontend/document/document.lua +++ b/frontend/document/document.lua @@ -203,7 +203,7 @@ end function Document:drawCurrentView(target, x, y, rect, pos) self._document:gotoPos(pos) tile_bb = Blitbuffer.new(rect.w, rect.h) - self._document:drawCurrentView(tile_bb) + self._document:drawCurrentPage(tile_bb) target:blitFrom(tile_bb, x, y, 0, 0, rect.w, rect.h) end From 263c8bb110583623dfdd7237a832f522f2721177 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Wed, 14 Nov 2012 22:12:00 -0500 Subject: [PATCH 3/5] add time subtable to lua inputevent table --- input.c | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/input.c b/input.c index 57c27eaf4..0379c9611 100644 --- a/input.c +++ b/input.c @@ -224,6 +224,29 @@ static int closeInputDevices(lua_State *L) { #endif } +static inline void set_event_table(lua_State *L, struct input_event input) { + lua_newtable(L); + lua_pushstring(L, "type"); + lua_pushinteger(L, (int) input.type); + lua_settable(L, -3); + lua_pushstring(L, "code"); + lua_pushinteger(L, (int) input.code); + lua_settable(L, -3); + lua_pushstring(L, "value"); + lua_pushinteger(L, (int) input.value); + lua_settable(L, -3); + + lua_pushstring(L, "time"); + lua_newtable(L); + lua_pushstring(L, "sec"); + lua_pushinteger(L, (int) input.time.tv_sec); + lua_settable(L, -3); + lua_pushstring(L, "usec"); + lua_pushinteger(L, (int) input.time.tv_usec); + lua_settable(L, -3); + lua_settable(L, -3); +} + static int waitForInput(lua_State *L) { struct input_event input; int n; @@ -259,16 +282,7 @@ static int waitForInput(lua_State *L) { if(inputfds[i] != -1 && FD_ISSET(inputfds[i], &fds)) { n = read(inputfds[i], &input, sizeof(struct input_event)); if(n == sizeof(struct input_event)) { - lua_newtable(L); - lua_pushstring(L, "type"); - lua_pushinteger(L, (int) input.type); - lua_settable(L, -3); - lua_pushstring(L, "code"); - lua_pushinteger(L, (int) input.code); - lua_settable(L, -3); - lua_pushstring(L, "value"); - lua_pushinteger(L, (int) input.value); - lua_settable(L, -3); + set_event_table(L, input); return 1; } } @@ -280,16 +294,7 @@ static int waitForInput(lua_State *L) { /* so far we only use inputfds[0] in emu mode */ n = read(inputfds[0], &input, sizeof(struct input_event)); if(n == sizeof(struct input_event)) { - lua_newtable(L); - lua_pushstring(L, "type"); - lua_pushinteger(L, (int) input.type); - lua_settable(L, -3); - lua_pushstring(L, "code"); - lua_pushinteger(L, (int) input.code); - lua_settable(L, -3); - lua_pushstring(L, "value"); - lua_pushinteger(L, (int) input.value); - lua_settable(L, -3); + set_event_table(L, input); return 1; } From 262d742204a3b0d9f2ffccf9c0399d3b01592a1f Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Fri, 16 Nov 2012 08:22:23 +0800 Subject: [PATCH 4/5] add back waitForInput timeout for emulator --- input.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/input.c b/input.c index 57c27eaf4..77c20a454 100644 --- a/input.c +++ b/input.c @@ -227,8 +227,8 @@ static int closeInputDevices(lua_State *L) { static int waitForInput(lua_State *L) { struct input_event input; int n; -#ifndef EMULATE_READER int usecs = luaL_optint(L, 1, -1); // we check for <0 later +#ifndef EMULATE_READER fd_set fds; struct timeval timeout; int i, num, nfds; @@ -293,7 +293,17 @@ static int waitForInput(lua_State *L) { return 1; } - SDL_WaitEvent(&event); + int ticks = SDL_GetTicks(); + if (usecs < 0) + SDL_WaitEvent(&event); + else { + while (SDL_GetTicks()-ticks <= usecs/1000) { + if (SDL_PollEvent(&event)) break; + SDL_Delay(10); + } + if (SDL_GetTicks()-ticks > usecs/1000) + return luaL_error(L, "Waiting for input failed: timeout\n"); + } switch(event.type) { case SDL_KEYDOWN: genEmuEvent(L, inputfds[0], EV_KEY, event.key.keysym.scancode, 1); From e3617676a18e1991f812dc5dd3dad0a98bbd144c Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Fri, 23 Nov 2012 01:10:34 -0500 Subject: [PATCH 5/5] fix deprecated debug call in credocument.lua --- frontend/document/credocument.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/document/credocument.lua b/frontend/document/credocument.lua index 1697fc0e8..7ea9f91d2 100644 --- a/frontend/document/credocument.lua +++ b/frontend/document/credocument.lua @@ -34,7 +34,7 @@ function CreDocument:engineInit() if _v ~= "Dingbats.cff" and _v ~= "StandardSymL.cff" then local ok, err = pcall(cre.registerFont, Font.fontdir..'/'.._v) if not ok then - Debug(err) + DEBUG(err) end end end