|
|
|
@ -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;
|
|
|
|
@ -224,11 +224,34 @@ 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;
|
|
|
|
|
#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;
|
|
|
|
@ -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,20 +294,21 @@ 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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
@ -302,20 +317,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;
|
|
|
|
|